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:
Andrea Dainese
2022-08-05 17:53:15 +02:00
committed by GitHub
co-authored by Mattijs Vanhaverbeke
parent af1666b3ba
commit 0b6df3bd28
3 changed files with 19 additions and 7 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ class TopologyViewsConfig(PluginConfig):
name = 'netbox_topology_views'
verbose_name = 'Topology views'
description = 'An plugin to render topology maps'
version = '2.0.2'
version = '2.0.4'
author = 'Mattijs Vanhaverbeke'
author_email = 'author@example.com'
base_url = 'netbox_topology_views'
+17 -5
View File
@@ -16,7 +16,7 @@ from circuits.models import CircuitTermination, ProviderNetwork
from extras.models import Tag
def create_node(device):
def create_node(device, save_coords):
dev_name = device.name
if dev_name is None:
dev_name = "device name unknown"
@@ -59,6 +59,8 @@ def create_node(device):
if device.device_role.color != "":
node["color.border"] = "#" + device.device_role.color
node["physics"] = True
if "coordinates" in device.custom_field_data:
if device.custom_field_data["coordinates"] is not None:
if ";" in device.custom_field_data["coordinates"]:
@@ -66,6 +68,11 @@ def create_node(device):
node["x"] = int(cords[0])
node["y"] = int(cords[1])
node["physics"] = False
else:
if save_coords:
node["physics"] = False
else:
node["physics"] = True
return node
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
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 = {}
edges = []
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
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
return results
@@ -269,6 +276,11 @@ class TopologyHomeView(PermissionRequiredMixin, View):
topo_data = None
if request.GET:
save_coords = False
if 'save_coords' in request.GET:
if request.GET["save_coords"] == "on":
save_coords = True
hide_unconnected = False
if "hide_unconnected" in request.GET:
if request.GET["hide_unconnected"] == "on" :
@@ -286,9 +298,9 @@ class TopologyHomeView(PermissionRequiredMixin, View):
if "draw_init" in request.GET:
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:
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:
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"]
+1 -1
View File
@@ -7,7 +7,7 @@ with open(path.join(top_level_directory, 'README.md'), encoding='utf-8') as file
setup(
name='netbox-topology-views',
version='2.0.3',
version='2.0.4',
description='An NetBox plugin to create Topology maps',
long_description=long_description,
long_description_content_type='text/markdown',