From 8a6f1660f0e604b58fc0e3b8cdaffc935e70155e Mon Sep 17 00:00:00 2001 From: Johannes Kreuzer Date: Thu, 14 May 2020 15:52:47 +0200 Subject: [PATCH] Update for support of netbox deployments, which are not in the webserver root (e.g. /netbox/) --- netbox_topology_views/api/views.py | 8 ++++---- netbox_topology_views/static_dev/js/home.js | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/netbox_topology_views/api/views.py b/netbox_topology_views/api/views.py index 8aed3ba..781261b 100644 --- a/netbox_topology_views/api/views.py +++ b/netbox_topology_views/api/views.py @@ -66,12 +66,12 @@ class SearchViewSet(ViewSet): node = {} node["id"] = device.id node["name"] = device.name - node["label"] = device.name + device.device_type.display_name + node["label"] = device.name + " " + device.device_type.display_name node["shape"] = 'image' if device.device_role.slug in settings.PLUGINS_CONFIG["netbox_topology_views"]["device_img"]: - node["image"] = '/static/netbox_topology_views/img/' + device.device_role.slug + ".png" + node["image"] = '../../static/netbox_topology_views/img/' + device.device_role.slug + ".png" else: - node["image"] = "/static/netbox_topology_views/img/role-unknown.png" + node["image"] = "../../static/netbox_topology_views/img/role-unknown.png" for device_custom_field in device.custom_field_values.all(): if device_custom_field.field.name == "coordinates": @@ -86,4 +86,4 @@ class SearchViewSet(ViewSet): results["nodes"] = nodes results["edges"] = edges - return Response(results) \ No newline at end of file + return Response(results) diff --git a/netbox_topology_views/static_dev/js/home.js b/netbox_topology_views/static_dev/js/home.js index 83f4d6a..8b9ee68 100644 --- a/netbox_topology_views/static_dev/js/home.js +++ b/netbox_topology_views/static_dev/js/home.js @@ -11,7 +11,7 @@ var options = { }, nodes: { shape: 'image', - brokenImage: '/static/netbox_topology_views/img/role-unknown.png', + brokenImage: '../../static/netbox_topology_views/img/role-unknown.png', size: 35, font: { multi: 'md', @@ -46,7 +46,7 @@ function startLoadSearchBar() { theme: "bootstrap", multiple: true, ajax: { - url: "/api/dcim/device-roles/?brief=true", + url: "../../api/dcim/device-roles/?brief=true", dataType: "json", type: "GET", data: function (params) { @@ -73,7 +73,7 @@ function startLoadSearchBar() { theme: "bootstrap", multiple: true, ajax: { - url: "/api/dcim/sites/?brief=true", + url: "../../api/dcim/sites/?brief=true", dataType: "json", type: "GET", data: function (params) { @@ -99,7 +99,7 @@ function startLoadSearchBar() { var deviceRolesSelect = $('#device-roles'); $.ajax({ type: 'GET', - url: '/api/plugins/topology-views/preselectdeviceroles/' + url: '../../api/plugins/topology-views/preselectdeviceroles/' }).then(function (data) { $.each(data.results, function (index, device_role_to_preload) { var option = new Option(device_role_to_preload.name, device_role_to_preload.id, true, true); @@ -123,7 +123,7 @@ function handleButtonPress() { var value3 = $("#sites").val(); $.ajax({ type: "POST", - url: "/api/plugins/topology-views/search/search/", + url: "../../api/plugins/topology-views/search/search/", data: JSON.stringify({ 'name': value, 'devicerole': value2, @@ -157,7 +157,7 @@ function handleButtonPress() { if ($('#checkSaveCoordinates').is(":checked")) { nodes.update({ id: node_id, physics: false }); $.ajax({ - url: "/api/save_coords", + url: "../../api/save_coords", type: 'POST', dataType: 'json', headers: { "X-CSRFToken": csrftoken }, @@ -191,4 +191,4 @@ function handleButtonPress() { }, }); }); -} \ No newline at end of file +}