Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
91a690f1c8 | ||
|
|
5f498f9ce2 | ||
|
|
195ac47542 | ||
|
|
a25be917ee | ||
|
|
079361b190 |
@@ -31,9 +31,16 @@ PLUGINS = ["netbox_topology_views"]
|
|||||||
|
|
||||||
Then run `python3 manage.py collectstatic --no-input`
|
Then run `python3 manage.py collectstatic --no-input`
|
||||||
|
|
||||||
|
### Versions
|
||||||
|
|
||||||
|
| netbox version | netbox-topology-views version |
|
||||||
|
| ------------- |-------------|
|
||||||
|
| >= 2.10.0 | >= v0.5.0 |
|
||||||
|
| < 2.10.0 | =< v0.4.10 |
|
||||||
|
|
||||||
### Custom field: coordinates
|
### Custom field: coordinates
|
||||||
|
|
||||||
There is also support for custom fiels.
|
There is also support for custom fields.
|
||||||
|
|
||||||
If you create a custom field "coordinates" for "dcim > device" with type "text" and name "coordinates" you will see the same layout every time.
|
If you create a custom field "coordinates" for "dcim > device" with type "text" and name "coordinates" you will see the same layout every time.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,22 @@
|
|||||||
|
# Setup Dev
|
||||||
|
+ install docker
|
||||||
|
+ install docker compose
|
||||||
|
+ install npm
|
||||||
|
+ clone netbox repo
|
||||||
|
+ clone netbox_topology_views repo
|
||||||
|
+ create venv: `/usr/bin/python3 -m venv venv`
|
||||||
|
+ activate venv: `source venv/bin/activate`
|
||||||
|
+ install deps: `pip3 install -r requirements.txt`
|
||||||
|
+ install build tools: `python3 -m pip install --upgrade build setuptools wheel`
|
||||||
|
|
||||||
|
|
||||||
|
# Build
|
||||||
|
+ build the package: `python3 setup.py develop`
|
||||||
|
+ build the resources `npm run resources`
|
||||||
|
|
||||||
|
# Test
|
||||||
|
+ copy configuration.py from dev_setup to the netbox/netbox/ folder
|
||||||
|
+ run in the netbox repo: `python3 netbox/manage.py migrate`
|
||||||
|
+ (first time only) run in the netbox repo: `python3 netbox/manage.py createsuperuser`
|
||||||
|
+ run in the netbox repo: `python3 netbox/manage.py runserver`
|
||||||
|
+ browse to http://127.0.0.1:8000
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
###################################################################
|
||||||
|
# This file serves as a base configuration for testing purposes #
|
||||||
|
# only. It is not intended for production use. #
|
||||||
|
###################################################################
|
||||||
|
|
||||||
|
ALLOWED_HOSTS = ['*']
|
||||||
|
|
||||||
|
DATABASE = {
|
||||||
|
'NAME': 'netbox',
|
||||||
|
'USER': 'netbox',
|
||||||
|
'PASSWORD': 'J5brHrAXFLQSif0K',
|
||||||
|
'HOST': 'localhost',
|
||||||
|
'PORT': '',
|
||||||
|
'CONN_MAX_AGE': 300,
|
||||||
|
}
|
||||||
|
|
||||||
|
DEBUG = True
|
||||||
|
|
||||||
|
PLUGINS = [
|
||||||
|
'netbox_topology_views',
|
||||||
|
]
|
||||||
|
|
||||||
|
REDIS = {
|
||||||
|
'tasks': {
|
||||||
|
'HOST': 'localhost',
|
||||||
|
'PORT': 6379,
|
||||||
|
'PASSWORD': 't4Ph722qJ5QHeQ1qfu36',
|
||||||
|
'DATABASE': 0,
|
||||||
|
'SSL': False,
|
||||||
|
},
|
||||||
|
'caching': {
|
||||||
|
'HOST': 'localhost',
|
||||||
|
'PORT': 6378,
|
||||||
|
'PASSWORD': 'H733Kdjndks81',
|
||||||
|
'DATABASE': 1,
|
||||||
|
'SSL': False,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
SECRET_KEY = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
version: '3.4'
|
||||||
|
services:
|
||||||
|
postgres:
|
||||||
|
image: postgres:12-alpine
|
||||||
|
environment:
|
||||||
|
POSTGRES_PASSWORD: J5brHrAXFLQSif0K #just for local dev
|
||||||
|
POSTGRES_DB: netbox
|
||||||
|
POSTGRES_USER: netbox
|
||||||
|
ports:
|
||||||
|
- "5432:5432"
|
||||||
|
volumes:
|
||||||
|
- netbox-postgres-data:/var/lib/postgresql/data
|
||||||
|
|
||||||
|
redis:
|
||||||
|
image: redis:6-alpine
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
|
- redis-server --appendonly yes --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
||||||
|
environment:
|
||||||
|
REDIS_PASSWORD: t4Ph722qJ5QHeQ1qfu36 #just for local dev
|
||||||
|
volumes:
|
||||||
|
- netbox-redis-data:/data
|
||||||
|
ports:
|
||||||
|
- "6379:6379"
|
||||||
|
redis-cache:
|
||||||
|
image: redis:6-alpine
|
||||||
|
command:
|
||||||
|
- sh
|
||||||
|
- -c # this is to evaluate the $REDIS_PASSWORD from the env
|
||||||
|
- redis-server --requirepass $$REDIS_PASSWORD ## $$ because of docker-compose
|
||||||
|
environment:
|
||||||
|
REDIS_PASSWORD: H733Kdjndks81 #just for local dev
|
||||||
|
ports:
|
||||||
|
- "6378:6379"
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
netbox-postgres-data:
|
||||||
|
driver: local
|
||||||
|
netbox-redis-data:
|
||||||
|
driver: local
|
||||||
@@ -3,8 +3,8 @@ from extras.plugins import PluginConfig
|
|||||||
class TopologyViewsConfig(PluginConfig):
|
class TopologyViewsConfig(PluginConfig):
|
||||||
name = 'netbox_topology_views'
|
name = 'netbox_topology_views'
|
||||||
verbose_name = 'Topology views'
|
verbose_name = 'Topology views'
|
||||||
description = 'An plugin to render toplogoy maps'
|
description = 'An plugin to render topology maps'
|
||||||
version = '0.5.0'
|
version = '0.5.1'
|
||||||
author = 'Mattijs Vanhaverbeke'
|
author = 'Mattijs Vanhaverbeke'
|
||||||
author_email = 'author@example.com'
|
author_email = 'author@example.com'
|
||||||
base_url = 'topology-views'
|
base_url = 'topology-views'
|
||||||
|
|||||||
+122
-106
@@ -78,7 +78,7 @@ class SearchViewSet(ReadOnlyModelViewSet):
|
|||||||
queryset = Device.objects.all()
|
queryset = Device.objects.all()
|
||||||
serializer_class = TopologyDummySerializer
|
serializer_class = TopologyDummySerializer
|
||||||
|
|
||||||
def _filter(self, site, role, name, tags, region):
|
def _filter(self, site, role, name, tags, region, location):
|
||||||
filter_devices = Device.objects.all()
|
filter_devices = Device.objects.all()
|
||||||
if name is not None:
|
if name is not None:
|
||||||
filter_devices = filter_devices.filter(name__contains=name)
|
filter_devices = filter_devices.filter(name__contains=name)
|
||||||
@@ -90,6 +90,8 @@ class SearchViewSet(ReadOnlyModelViewSet):
|
|||||||
filter_devices = filter_devices.filter(tags__id__in=tags)
|
filter_devices = filter_devices.filter(tags__id__in=tags)
|
||||||
if region is not None:
|
if region is not None:
|
||||||
filter_devices = filter_devices.filter(site__region__id__in=region)
|
filter_devices = filter_devices.filter(site__region__id__in=region)
|
||||||
|
if location is not None:
|
||||||
|
filter_devices = filter_devices.filter(location__id__in=location)
|
||||||
return filter_devices
|
return filter_devices
|
||||||
|
|
||||||
|
|
||||||
@@ -115,7 +117,15 @@ class SearchViewSet(ReadOnlyModelViewSet):
|
|||||||
if regions == []:
|
if regions == []:
|
||||||
regions = None
|
regions = None
|
||||||
|
|
||||||
devices = self._filter(sites, devicerole, name, tags, regions)
|
locations = request.query_params.getlist('locations[]', None)
|
||||||
|
if locations == []:
|
||||||
|
locations = None
|
||||||
|
|
||||||
|
hide_unconnected = request.query_params.get('hide_unconnected', None)
|
||||||
|
if hide_unconnected == "":
|
||||||
|
hide_unconnected = None
|
||||||
|
|
||||||
|
devices = self._filter(sites, devicerole, name, tags, regions, locations)
|
||||||
|
|
||||||
nodes = []
|
nodes = []
|
||||||
edges = []
|
edges = []
|
||||||
@@ -124,41 +134,21 @@ class SearchViewSet(ReadOnlyModelViewSet):
|
|||||||
circuit_ids = []
|
circuit_ids = []
|
||||||
for device in devices:
|
for device in devices:
|
||||||
cables = device.get_cables()
|
cables = device.get_cables()
|
||||||
for cable in cables:
|
if cables.exists():
|
||||||
if cable.termination_a_type.name != "circuit termination" and cable.termination_b_type.name != "circuit termination":
|
device_has_connections = True
|
||||||
if cable.id not in cable_ids:
|
for cable in cables:
|
||||||
if cable.termination_a_type.name not in ignore_cable_type and cable.termination_b_type.name not in ignore_cable_type:
|
if cable.termination_a_type.name != "circuit termination" and cable.termination_b_type.name != "circuit termination":
|
||||||
cable_ids.append(cable.id)
|
if cable.id not in cable_ids:
|
||||||
edge_ids += 1
|
if cable.termination_a_type.name not in ignore_cable_type and cable.termination_b_type.name not in ignore_cable_type:
|
||||||
|
cable_ids.append(cable.id)
|
||||||
cable_a_dev_name = cable.termination_a.device.name
|
|
||||||
if cable_a_dev_name is None:
|
|
||||||
cable_a_dev_name = "device A name unknown"
|
|
||||||
cable_a_name = cable.termination_a.name
|
|
||||||
if cable_a_name is None:
|
|
||||||
cable_a_name = "cable A name unknown"
|
|
||||||
cable_b_dev_name = cable.termination_b.device.name
|
|
||||||
if cable_b_dev_name is None:
|
|
||||||
cable_b_dev_name = "device B name unknown"
|
|
||||||
cable_b_name = cable.termination_b.name
|
|
||||||
if cable_b_name is None:
|
|
||||||
cable_b_name = "cable B name unknown"
|
|
||||||
|
|
||||||
edge = {}
|
|
||||||
edge["id"] = edge_ids
|
|
||||||
edge["from"] = cable.termination_a.device.id
|
|
||||||
edge["to"] = cable.termination_b.device.id
|
|
||||||
edge["title"] = "Cable between <br> " + cable_a_dev_name + " [" + cable_a_name + "]<br>" + cable_b_dev_name + " [" + cable_b_name + "]"
|
|
||||||
if cable.color != "":
|
|
||||||
edge["color"] = "#" + cable.color
|
|
||||||
edges.append(edge)
|
|
||||||
else:
|
|
||||||
if cable.termination_a_type.name == "circuit termination":
|
|
||||||
if settings.PLUGINS_CONFIG["netbox_topology_views"]["enable_circuit_terminations"]:
|
|
||||||
if cable.termination_a.circuit.id not in circuit_ids:
|
|
||||||
circuit_ids.append(cable.termination_a.circuit.id)
|
|
||||||
edge_ids += 1
|
edge_ids += 1
|
||||||
|
|
||||||
|
cable_a_dev_name = cable.termination_a.device.name
|
||||||
|
if cable_a_dev_name is None:
|
||||||
|
cable_a_dev_name = "device A name unknown"
|
||||||
|
cable_a_name = cable.termination_a.name
|
||||||
|
if cable_a_name is None:
|
||||||
|
cable_a_name = "cable A name unknown"
|
||||||
cable_b_dev_name = cable.termination_b.device.name
|
cable_b_dev_name = cable.termination_b.device.name
|
||||||
if cable_b_dev_name is None:
|
if cable_b_dev_name is None:
|
||||||
cable_b_dev_name = "device B name unknown"
|
cable_b_dev_name = "device B name unknown"
|
||||||
@@ -168,86 +158,112 @@ class SearchViewSet(ReadOnlyModelViewSet):
|
|||||||
|
|
||||||
edge = {}
|
edge = {}
|
||||||
edge["id"] = edge_ids
|
edge["id"] = edge_ids
|
||||||
|
edge["from"] = cable.termination_a.device.id
|
||||||
edge["to"] = cable.termination_b.device.id
|
edge["to"] = cable.termination_b.device.id
|
||||||
edge["dashes"] = True
|
edge["title"] = "Cable between <br> " + cable_a_dev_name + " [" + cable_a_name + "]<br>" + cable_b_dev_name + " [" + cable_b_name + "]"
|
||||||
title = ""
|
if cable.color != "":
|
||||||
|
edge["color"] = "#" + cable.color
|
||||||
|
edges.append(edge)
|
||||||
|
else:
|
||||||
|
if cable.termination_a_type.name == "circuit termination":
|
||||||
|
if settings.PLUGINS_CONFIG["netbox_topology_views"]["enable_circuit_terminations"]:
|
||||||
|
if cable.termination_a.circuit.id not in circuit_ids:
|
||||||
|
circuit_ids.append(cable.termination_a.circuit.id)
|
||||||
|
edge_ids += 1
|
||||||
|
|
||||||
title += "Circuit provider: " + cable.termination_a.circuit.provider.name + "<br>"
|
cable_b_dev_name = cable.termination_b.device.name
|
||||||
title += "Termination between <br>"
|
if cable_b_dev_name is None:
|
||||||
title += cable_b_dev_name + " [" + cable_b_name + "]<br>"
|
cable_b_dev_name = "device B name unknown"
|
||||||
# To Many if's
|
cable_b_name = cable.termination_b.name
|
||||||
if cable.termination_a.circuit.termination_a is not None:
|
if cable_b_name is None:
|
||||||
if cable.termination_a.circuit.termination_a.cable is not None:
|
cable_b_name = "cable B name unknown"
|
||||||
if cable.termination_a.circuit.termination_a.cable.id != cable.id:
|
|
||||||
if cable.termination_a.circuit.termination_a.cable.termination_b is not None:
|
|
||||||
if cable.termination_a.circuit.termination_a.cable.termination_b.device is not None:
|
|
||||||
edge["from"] = cable.termination_a.circuit.termination_a.cable.termination_b.device.id
|
|
||||||
|
|
||||||
cable_a_dev_name = cable.termination_a.circuit.termination_a.cable.termination_b.device.name
|
edge = {}
|
||||||
if cable_a_dev_name is None:
|
edge["id"] = edge_ids
|
||||||
cable_a_dev_name = "device B name unknown"
|
edge["to"] = cable.termination_b.device.id
|
||||||
cable_b_name = cable.termination_a.circuit.termination_a.cable.termination_b.name
|
edge["dashes"] = True
|
||||||
if cable_a_name is None:
|
title = ""
|
||||||
cable_a_name = "cable B name unknown"
|
|
||||||
title += cable_a_dev_name + " [" + cable_a_name + "]<br>"
|
|
||||||
edge["title"] = title
|
|
||||||
edges.append(edge)
|
|
||||||
# To Many if's
|
|
||||||
if cable.termination_a.circuit.termination_z is not None:
|
|
||||||
if cable.termination_a.circuit.termination_z.cable is not None:
|
|
||||||
if cable.termination_a.circuit.termination_z.cable.id != cable.id:
|
|
||||||
if cable.termination_a.circuit.termination_z.cable.termination_b is not None:
|
|
||||||
if cable.termination_a.circuit.termination_z.cable.termination_b.device is not None:
|
|
||||||
edge["from"] = cable.termination_a.circuit.termination_z.cable.termination_b.device.id
|
|
||||||
|
|
||||||
cable_a_dev_name = cable.termination_a.circuit.termination_z.cable.termination_b.device.name
|
title += "Circuit provider: " + cable.termination_a.circuit.provider.name + "<br>"
|
||||||
if cable_a_dev_name is None:
|
title += "Termination between <br>"
|
||||||
cable_a_dev_name = "device B name unknown"
|
title += cable_b_dev_name + " [" + cable_b_name + "]<br>"
|
||||||
cable_a_name = cable.termination_a.circuit.termination_z.cable.termination_b.name
|
# To Many if's
|
||||||
if cable_a_name is None:
|
if cable.termination_a.circuit.termination_a is not None:
|
||||||
cable_a_name = "cable B name unknown"
|
if cable.termination_a.circuit.termination_a.cable is not None:
|
||||||
title += cable_a_dev_name + " [" + cable_a_name + "]<br>"
|
if cable.termination_a.circuit.termination_a.cable.id != cable.id:
|
||||||
edge["title"] = title
|
if cable.termination_a.circuit.termination_a.cable.termination_b is not None:
|
||||||
edges.append(edge)
|
if cable.termination_a.circuit.termination_a.cable.termination_b.device is not None:
|
||||||
dev_name = device.name
|
edge["from"] = cable.termination_a.circuit.termination_a.cable.termination_b.device.id
|
||||||
if dev_name is None:
|
|
||||||
dev_name = "device name unknown"
|
|
||||||
|
|
||||||
node_content = ""
|
cable_a_dev_name = cable.termination_a.circuit.termination_a.cable.termination_b.device.name
|
||||||
|
if cable_a_dev_name is None:
|
||||||
|
cable_a_dev_name = "device B name unknown"
|
||||||
|
cable_b_name = cable.termination_a.circuit.termination_a.cable.termination_b.name
|
||||||
|
if cable_a_name is None:
|
||||||
|
cable_a_name = "cable B name unknown"
|
||||||
|
title += cable_a_dev_name + " [" + cable_a_name + "]<br>"
|
||||||
|
edge["title"] = title
|
||||||
|
edges.append(edge)
|
||||||
|
# To Many if's
|
||||||
|
if cable.termination_a.circuit.termination_z is not None:
|
||||||
|
if cable.termination_a.circuit.termination_z.cable is not None:
|
||||||
|
if cable.termination_a.circuit.termination_z.cable.id != cable.id:
|
||||||
|
if cable.termination_a.circuit.termination_z.cable.termination_b is not None:
|
||||||
|
if cable.termination_a.circuit.termination_z.cable.termination_b.device is not None:
|
||||||
|
edge["from"] = cable.termination_a.circuit.termination_z.cable.termination_b.device.id
|
||||||
|
|
||||||
if device.device_type.display_name is not None:
|
cable_a_dev_name = cable.termination_a.circuit.termination_z.cable.termination_b.device.name
|
||||||
node_content += "<tr><th>Type: </th><td>" + device.device_type.display_name + "</td></tr>"
|
if cable_a_dev_name is None:
|
||||||
if device.device_role.name is not None:
|
cable_a_dev_name = "device B name unknown"
|
||||||
node_content += "<tr><th>Role: </th><td>" + device.device_role.name + "</td></tr>"
|
cable_a_name = cable.termination_a.circuit.termination_z.cable.termination_b.name
|
||||||
if device.serial != "":
|
if cable_a_name is None:
|
||||||
node_content += "<tr><th>Serial: </th><td>" + device.serial + "</td></tr>"
|
cable_a_name = "cable B name unknown"
|
||||||
if device.primary_ip is not None:
|
title += cable_a_dev_name + " [" + cable_a_name + "]<br>"
|
||||||
node_content += "<tr><th>IP Address: </th><td>" + str(device.primary_ip.address) + "</td></tr>"
|
edge["title"] = title
|
||||||
|
edges.append(edge)
|
||||||
dev_title = "<table> %s </table>" % (node_content)
|
|
||||||
|
|
||||||
node = {}
|
|
||||||
node["id"] = device.id
|
|
||||||
node["name"] = dev_name
|
|
||||||
node["label"] = dev_name
|
|
||||||
node["title"] = dev_title
|
|
||||||
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"
|
|
||||||
else:
|
else:
|
||||||
node["image"] = "../../static/netbox_topology_views/img/role-unknown.png"
|
device_has_connections = False
|
||||||
|
|
||||||
if device.device_role.color != "":
|
if hide_unconnected == 'false' or (hide_unconnected == 'true' and device_has_connections is True):
|
||||||
node["color.border"] = "#" + device.device_role.color
|
dev_name = device.name
|
||||||
|
if dev_name is None:
|
||||||
|
dev_name = "device name unknown"
|
||||||
|
|
||||||
if "coordinates" in device.custom_field_data:
|
node_content = ""
|
||||||
if device.custom_field_data["coordinates"] != "":
|
|
||||||
cords = device.custom_field_data["coordinates"].split(";")
|
if device.device_type.display_name is not None:
|
||||||
node["x"] = int(cords[0])
|
node_content += "<tr><th>Type: </th><td>" + device.device_type.display_name + "</td></tr>"
|
||||||
node["y"] = int(cords[1])
|
if device.device_role.name is not None:
|
||||||
node["physics"] = False
|
node_content += "<tr><th>Role: </th><td>" + device.device_role.name + "</td></tr>"
|
||||||
|
if device.serial != "":
|
||||||
nodes.append(node)
|
node_content += "<tr><th>Serial: </th><td>" + device.serial + "</td></tr>"
|
||||||
|
if device.primary_ip is not None:
|
||||||
|
node_content += "<tr><th>IP Address: </th><td>" + str(device.primary_ip.address) + "</td></tr>"
|
||||||
|
|
||||||
|
dev_title = "<table> %s </table>" % (node_content)
|
||||||
|
|
||||||
|
node = {}
|
||||||
|
node["id"] = device.id
|
||||||
|
node["name"] = dev_name
|
||||||
|
node["label"] = dev_name
|
||||||
|
node["title"] = dev_title
|
||||||
|
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"
|
||||||
|
else:
|
||||||
|
node["image"] = "../../static/netbox_topology_views/img/role-unknown.png"
|
||||||
|
|
||||||
|
if device.device_role.color != "":
|
||||||
|
node["color.border"] = "#" + device.device_role.color
|
||||||
|
|
||||||
|
if "coordinates" in device.custom_field_data:
|
||||||
|
if device.custom_field_data["coordinates"] != "":
|
||||||
|
cords = device.custom_field_data["coordinates"].split(";")
|
||||||
|
node["x"] = int(cords[0])
|
||||||
|
node["y"] = int(cords[1])
|
||||||
|
node["physics"] = False
|
||||||
|
|
||||||
|
nodes.append(node)
|
||||||
|
|
||||||
results = {}
|
results = {}
|
||||||
results["nodes"] = nodes
|
results["nodes"] = nodes
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -33,6 +33,7 @@ var options = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var selected_regions = [];
|
var selected_regions = [];
|
||||||
|
var selected_sites = [];
|
||||||
|
|
||||||
function iniPlotboxIndex() {
|
function iniPlotboxIndex() {
|
||||||
document.addEventListener('DOMContentLoaded', function () {
|
document.addEventListener('DOMContentLoaded', function () {
|
||||||
@@ -113,6 +114,25 @@ function startLoadSearchBar() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#sites').on('select2:select', function (e) {
|
||||||
|
var data = e.params.data;
|
||||||
|
var index = selected_sites.indexOf(data.id.toString());
|
||||||
|
if (index == -1) {
|
||||||
|
selected_sites.push(data.id.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#sites').on('select2:unselect', function (e) {
|
||||||
|
var data = e.params.data;
|
||||||
|
var index = selected_sites.indexOf(data.id.toString());
|
||||||
|
if (index > -1) {
|
||||||
|
selected_sites.splice(index, 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$('#sites').on('select2:clear', function (e) {
|
||||||
|
selected_sites = [];
|
||||||
|
});
|
||||||
|
|
||||||
$('#tags').select2({
|
$('#tags').select2({
|
||||||
allowClear: true,
|
allowClear: true,
|
||||||
placeholder: "---------",
|
placeholder: "---------",
|
||||||
@@ -178,7 +198,6 @@ function startLoadSearchBar() {
|
|||||||
$('#regions').on('select2:unselect', function (e) {
|
$('#regions').on('select2:unselect', function (e) {
|
||||||
var data = e.params.data;
|
var data = e.params.data;
|
||||||
var index = selected_regions.indexOf(data.id.toString());
|
var index = selected_regions.indexOf(data.id.toString());
|
||||||
console.log(index);
|
|
||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
selected_regions.splice(index, 1);
|
selected_regions.splice(index, 1);
|
||||||
}
|
}
|
||||||
@@ -187,6 +206,47 @@ function startLoadSearchBar() {
|
|||||||
selected_regions = [];
|
selected_regions = [];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
$('#locations').select2({
|
||||||
|
allowClear: true,
|
||||||
|
placeholder: "---------",
|
||||||
|
theme: "bootstrap",
|
||||||
|
multiple: true,
|
||||||
|
ajax: {
|
||||||
|
url: function (params) {
|
||||||
|
var base_url = "../../api/dcim/locations/?brief=true";
|
||||||
|
if (selected_sites.length == 0) {
|
||||||
|
return base_url;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for (var i = 0; i < selected_sites.length; i++) {
|
||||||
|
var tmp = "&site_id=" + selected_sites[i];
|
||||||
|
base_url = base_url + tmp;
|
||||||
|
}
|
||||||
|
return base_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
dataType: "json",
|
||||||
|
type: "GET",
|
||||||
|
data: function (params) {
|
||||||
|
var queryParameters = {
|
||||||
|
q: params.term
|
||||||
|
}
|
||||||
|
return queryParameters;
|
||||||
|
},
|
||||||
|
processResults: function (data) {
|
||||||
|
return {
|
||||||
|
results: $.map(data.results, function (item) {
|
||||||
|
return {
|
||||||
|
text: item.name,
|
||||||
|
id: item.id
|
||||||
|
}
|
||||||
|
})
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
var deviceRolesSelect = $('#device-roles');
|
var deviceRolesSelect = $('#device-roles');
|
||||||
$.ajax({
|
$.ajax({
|
||||||
@@ -232,6 +292,8 @@ function handleButtonPress() {
|
|||||||
var value3 = $("#sites").val();
|
var value3 = $("#sites").val();
|
||||||
var value4 = $("#tags").val();
|
var value4 = $("#tags").val();
|
||||||
var value5 = $("#regions").val();
|
var value5 = $("#regions").val();
|
||||||
|
var value6 = $('#checkHideUnconnected').is(":checked");
|
||||||
|
var value7 = $("#locations").val();
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: "../../api/plugins/topology-views/search/search/",
|
url: "../../api/plugins/topology-views/search/search/",
|
||||||
@@ -240,7 +302,9 @@ function handleButtonPress() {
|
|||||||
'devicerole[]': value2,
|
'devicerole[]': value2,
|
||||||
'sites[]': value3,
|
'sites[]': value3,
|
||||||
'tags[]': value4,
|
'tags[]': value4,
|
||||||
'regions[]': value5
|
'regions[]': value5,
|
||||||
|
'hide_unconnected': value6,
|
||||||
|
'locations[]': value7
|
||||||
},
|
},
|
||||||
headers: { "X-CSRFToken": csrftoken },
|
headers: { "X-CSRFToken": csrftoken },
|
||||||
contentType: "application/json; charset=utf-8",
|
contentType: "application/json; charset=utf-8",
|
||||||
|
|||||||
@@ -41,18 +41,28 @@
|
|||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="device-roles">Device roles</label>
|
<label for="device-roles">Device roles</label>
|
||||||
<select class="form-control" multiple="multiple" id="device-roles"></select>
|
<select class="form-control" multiple="multiple" id="device-roles"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="regions">Regions</label>
|
||||||
|
<select class="form-control" multiple="multiple" id="regions"></select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="sites">Sites</label>
|
<label for="sites">Sites</label>
|
||||||
<select class="form-control" multiple="multiple" id="sites"></select>
|
<select class="form-control" multiple="multiple" id="sites"></select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
<label for="locations">Locations</label>
|
||||||
|
<select class="form-control" multiple="multiple" id="locations"></select>
|
||||||
|
</div>
|
||||||
|
<div class="form-group">
|
||||||
<label for="tags">Tags</label>
|
<label for="tags">Tags</label>
|
||||||
<select class="form-control" multiple="multiple" id="tags"></select>
|
<select class="form-control" multiple="multiple" id="tags"></select>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="regions">Regions</label>
|
<div class="custom-control custom-checkbox">
|
||||||
<select class="form-control" multiple="multiple" id="regions"></select>
|
<input type="checkbox" class="custom-control-input" id="checkHideUnconnected">
|
||||||
|
<label class="custom-control-label" for="checkHideUnconnected">Hide Unconnected</label>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<hr class="mb-4">
|
<hr class="mb-4">
|
||||||
<button class="btn btn-primary btn-lg btn-block" type="submit" id="start-search">Search</button>
|
<button class="btn btn-primary btn-lg btn-block" type="submit" id="start-search">Search</button>
|
||||||
|
|||||||
Generated
+4
-4
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "netbox_topology_views",
|
"name": "netbox_topology_views",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -4772,9 +4772,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"y18n": {
|
"y18n": {
|
||||||
"version": "3.2.1",
|
"version": "3.2.2",
|
||||||
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.1.tgz",
|
"resolved": "https://registry.npmjs.org/y18n/-/y18n-3.2.2.tgz",
|
||||||
"integrity": "sha1-bRX7qITAhnnA136I53WegR4H+kE=",
|
"integrity": "sha512-uGZHXkHnhF0XeeAPgnKfPv1bgKAYyVvmNL1xlKsPYZPaIHxGti2hHqvOCQv71XMsLxu1QjergkqogUnms5D3YQ==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"yallist": {
|
"yallist": {
|
||||||
|
|||||||
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"private": true,
|
"private": true,
|
||||||
"name": "netbox_topology_views",
|
"name": "netbox_topology_views",
|
||||||
"version": "0.5.0",
|
"version": "0.5.1",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"resources": "gulp build",
|
"resources": "gulp build",
|
||||||
"resources_dev": "gulp build_dev"
|
"resources_dev": "gulp build_dev"
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from setuptools import setup, find_packages
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='netbox-topology-views',
|
name='netbox-topology-views',
|
||||||
version='0.5.0',
|
version='0.5.1',
|
||||||
description='An NetBox plugin to create Topology maps',
|
description='An NetBox plugin to create Topology maps',
|
||||||
url='https://github.com/mattieserver/netbox-topology-views',
|
url='https://github.com/mattieserver/netbox-topology-views',
|
||||||
author='Mattijs Vanhaverbeke',
|
author='Mattijs Vanhaverbeke',
|
||||||
|
|||||||
Reference in New Issue
Block a user