disable physics if not saving coords (#139)
* initial commit * keeps x/y when not saving coords Co-authored-by: Mattijs Vanhaverbeke <mattijs.vanhaverbeke@ebo-enterprises.com>
This commit is contained in:
co-authored by
Mattijs Vanhaverbeke
parent
af1666b3ba
commit
0b6df3bd28
@@ -4,7 +4,7 @@ class TopologyViewsConfig(PluginConfig):
|
|||||||
name = 'netbox_topology_views'
|
name = 'netbox_topology_views'
|
||||||
verbose_name = 'Topology views'
|
verbose_name = 'Topology views'
|
||||||
description = 'An plugin to render topology maps'
|
description = 'An plugin to render topology maps'
|
||||||
version = '2.0.2'
|
version = '2.0.4'
|
||||||
author = 'Mattijs Vanhaverbeke'
|
author = 'Mattijs Vanhaverbeke'
|
||||||
author_email = 'author@example.com'
|
author_email = 'author@example.com'
|
||||||
base_url = 'netbox_topology_views'
|
base_url = 'netbox_topology_views'
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ from circuits.models import CircuitTermination, ProviderNetwork
|
|||||||
from extras.models import Tag
|
from extras.models import Tag
|
||||||
|
|
||||||
|
|
||||||
def create_node(device):
|
def create_node(device, save_coords):
|
||||||
dev_name = device.name
|
dev_name = device.name
|
||||||
if dev_name is None:
|
if dev_name is None:
|
||||||
dev_name = "device name unknown"
|
dev_name = "device name unknown"
|
||||||
@@ -59,6 +59,8 @@ def create_node(device):
|
|||||||
if device.device_role.color != "":
|
if device.device_role.color != "":
|
||||||
node["color.border"] = "#" + device.device_role.color
|
node["color.border"] = "#" + device.device_role.color
|
||||||
|
|
||||||
|
node["physics"] = True
|
||||||
|
|
||||||
if "coordinates" in device.custom_field_data:
|
if "coordinates" in device.custom_field_data:
|
||||||
if device.custom_field_data["coordinates"] is not None:
|
if device.custom_field_data["coordinates"] is not None:
|
||||||
if ";" in device.custom_field_data["coordinates"]:
|
if ";" in device.custom_field_data["coordinates"]:
|
||||||
@@ -66,6 +68,11 @@ def create_node(device):
|
|||||||
node["x"] = int(cords[0])
|
node["x"] = int(cords[0])
|
||||||
node["y"] = int(cords[1])
|
node["y"] = int(cords[1])
|
||||||
node["physics"] = False
|
node["physics"] = False
|
||||||
|
else:
|
||||||
|
if save_coords:
|
||||||
|
node["physics"] = False
|
||||||
|
else:
|
||||||
|
node["physics"] = True
|
||||||
return node
|
return node
|
||||||
|
|
||||||
def create_edge(edge_id, cable, termination_a, termination_b, path = None, circuit = None):
|
def create_edge(edge_id, cable, termination_a, termination_b, path = None, circuit = None):
|
||||||
@@ -96,7 +103,7 @@ def create_edge(edge_id, cable, termination_a, termination_b, path = None, circu
|
|||||||
|
|
||||||
return edge
|
return edge
|
||||||
|
|
||||||
def get_topology_data(queryset, hide_unconnected, intermediate_dev_role_ids, end2end_connections):
|
def get_topology_data(queryset, hide_unconnected, save_coords, intermediate_dev_role_ids, end2end_connections):
|
||||||
nodes_devices = {}
|
nodes_devices = {}
|
||||||
edges = []
|
edges = []
|
||||||
edge_ids = 0
|
edge_ids = 0
|
||||||
@@ -252,7 +259,7 @@ def get_topology_data(queryset, hide_unconnected, intermediate_dev_role_ids, end
|
|||||||
nodes_devices[qs_device.id] = qs_device
|
nodes_devices[qs_device.id] = qs_device
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
results["nodes"] = [create_node(d) for d in nodes_devices.values()]
|
results["nodes"] = [create_node(d, save_coords) for d in nodes_devices.values()]
|
||||||
results["edges"] = edges
|
results["edges"] = edges
|
||||||
return results
|
return results
|
||||||
|
|
||||||
@@ -269,6 +276,11 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
|||||||
topo_data = None
|
topo_data = None
|
||||||
|
|
||||||
if request.GET:
|
if request.GET:
|
||||||
|
save_coords = False
|
||||||
|
if 'save_coords' in request.GET:
|
||||||
|
if request.GET["save_coords"] == "on":
|
||||||
|
save_coords = True
|
||||||
|
|
||||||
hide_unconnected = False
|
hide_unconnected = False
|
||||||
if "hide_unconnected" in request.GET:
|
if "hide_unconnected" in request.GET:
|
||||||
if request.GET["hide_unconnected"] == "on" :
|
if request.GET["hide_unconnected"] == "on" :
|
||||||
@@ -286,9 +298,9 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
|||||||
|
|
||||||
if "draw_init" in request.GET:
|
if "draw_init" in request.GET:
|
||||||
if request.GET["draw_init"].lower() == "true":
|
if request.GET["draw_init"].lower() == "true":
|
||||||
topo_data = get_topology_data(self.queryset, hide_unconnected, intermediate_dev_role_ids, end2end_connections)
|
topo_data = get_topology_data(self.queryset, hide_unconnected, save_coords, intermediate_dev_role_ids, end2end_connections)
|
||||||
else:
|
else:
|
||||||
topo_data = get_topology_data(self.queryset, hide_unconnected, intermediate_dev_role_ids, end2end_connections)
|
topo_data = get_topology_data(self.queryset, hide_unconnected, save_coords, intermediate_dev_role_ids, end2end_connections)
|
||||||
else:
|
else:
|
||||||
preselected_device_roles = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_device_roles"]
|
preselected_device_roles = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_device_roles"]
|
||||||
preselected_intermediate_dev_roles = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_intermediate_dev_roles"]
|
preselected_intermediate_dev_roles = settings.PLUGINS_CONFIG["netbox_topology_views"]["preselected_intermediate_dev_roles"]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ with open(path.join(top_level_directory, 'README.md'), encoding='utf-8') as file
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='netbox-topology-views',
|
name='netbox-topology-views',
|
||||||
version='2.0.3',
|
version='2.0.4',
|
||||||
description='An NetBox plugin to create Topology maps',
|
description='An NetBox plugin to create Topology maps',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
|
|||||||
Reference in New Issue
Block a user