* fix restore saved filter options * fix restore saved filter group options * fix htmx export to xml
This commit is contained in:
@@ -3,6 +3,7 @@ import sys
|
||||
|
||||
from circuits.models import Circuit
|
||||
from dcim.models import Device, DeviceRole, PowerFeed, PowerPanel
|
||||
from extras.models import SavedFilter
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import PermissionRequiredMixin
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
@@ -108,7 +109,30 @@ class ExportTopoToXML(PermissionRequiredMixin, ViewSet):
|
||||
|
||||
if request.GET:
|
||||
|
||||
save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks,show_neighbors = get_query_settings(request)
|
||||
filter_id, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks,show_neighbors = get_query_settings(request)
|
||||
|
||||
# Read options from saved filters as NetBox does not handle custom plugin filters
|
||||
if "filter_id" in request.GET and request.GET["filter_id"] != '':
|
||||
try:
|
||||
saved_filter = SavedFilter.objects.get(pk=filter_id)
|
||||
saved_filter_params = getattr(saved_filter, 'parameters')
|
||||
|
||||
if save_coords == False and 'save_coords' in saved_filter_params: save_coords = saved_filter_params['save_coords']
|
||||
if show_power == False and 'show_power' in saved_filter_params: show_power = saved_filter_params['show_power']
|
||||
if show_circuit == False and 'show_circuit' in saved_filter_params: show_circuit = saved_filter_params['show_circuit']
|
||||
if show_logical_connections == False and 'show_logical_connections' in saved_filter_params: show_logical_connections = saved_filter_params['show_logical_connections']
|
||||
if show_single_cable_logical_conns == False and 'show_single_cable_logical_conns' in saved_filter_params: show_single_cable_logical_conns = saved_filter_params['show_single_cable_logical_conns']
|
||||
if show_cables == False and 'show_cables' in saved_filter_params: show_cables = saved_filter_params['show_cables']
|
||||
if show_wireless == False and 'show_wireless' in saved_filter_params: show_wireless = saved_filter_params['show_wireless']
|
||||
if group_sites == False and 'group_sites' in saved_filter_params: group_sites = saved_filter_params['group_sites']
|
||||
if group_locations == False and 'group_locations' in saved_filter_params: group_locations = saved_filter_params['group_locations']
|
||||
if group_racks == False and 'group_racks' in saved_filter_params: group_racks = saved_filter_params['group_racks']
|
||||
if show_neighbors == False and 'show_neighbors' in saved_filter_params: show_neighbors = saved_filter_params['show_neighbors']
|
||||
except SavedFilter.DoesNotExist: # filter_id not found
|
||||
pass
|
||||
except Exception as inst:
|
||||
print(type(inst))
|
||||
|
||||
if 'group' not in request.query_params:
|
||||
group_id = "default"
|
||||
else:
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -42,11 +42,6 @@ const csrftoken = getCookie('csrftoken')
|
||||
// Render vis graph
|
||||
let graph = null // vis graph instance
|
||||
|
||||
let searchParams = new URLSearchParams(window.location.search)
|
||||
let group_sites = searchParams.get('group_sites')
|
||||
let group_locations = searchParams.get('group_locations')
|
||||
let group_racks = searchParams.get('group_racks')
|
||||
|
||||
const container = document.querySelector('#visgraph')
|
||||
const coordSaveCheckbox = document.querySelector('#id_save_coords')
|
||||
;(function handleLoadData() {
|
||||
@@ -74,6 +69,11 @@ const coordSaveCheckbox = document.querySelector('#id_save_coords')
|
||||
title: htmlTitle(node.title)
|
||||
}))
|
||||
)
|
||||
|
||||
const group_sites = topologyData.options.group_sites
|
||||
const group_locations = topologyData.options.group_locations
|
||||
const group_racks = topologyData.options.group_racks
|
||||
|
||||
graph = new Network(container, { nodes, edges }, options)
|
||||
graph.fit()
|
||||
|
||||
|
||||
@@ -107,6 +107,10 @@ def get_model_role(model: Type[Model]) -> Role:
|
||||
)
|
||||
|
||||
def get_query_settings(request):
|
||||
filter_id = ''
|
||||
if "filter_id" in request.GET:
|
||||
filter_id = request.GET["filter_id"]
|
||||
|
||||
save_coords = False
|
||||
if "save_coords" in request.GET:
|
||||
if request.GET["save_coords"] == "on":
|
||||
@@ -174,7 +178,7 @@ def get_query_settings(request):
|
||||
if request.GET["show_neighbors"] == "on" :
|
||||
show_neighbors = True
|
||||
|
||||
return save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, show_neighbors
|
||||
return filter_id, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, show_neighbors
|
||||
|
||||
class LinePattern():
|
||||
wireless = [2, 10, 2, 10]
|
||||
|
||||
@@ -27,7 +27,7 @@ from django.db.models.functions import Lower
|
||||
from django.http import HttpRequest, HttpResponseRedirect, QueryDict
|
||||
from django.shortcuts import render, get_object_or_404
|
||||
from django.views.generic import View
|
||||
from extras.models import Tag
|
||||
from extras.models import Tag, SavedFilter
|
||||
from wireless.models import WirelessLink
|
||||
from netbox.views.generic import (
|
||||
ObjectView,
|
||||
@@ -351,6 +351,7 @@ def get_topology_data(
|
||||
nodes_devices = {}
|
||||
edges = []
|
||||
nodes = []
|
||||
options = {}
|
||||
edge_ids = 0
|
||||
nodes_circuits: Dict[int, Circuit] = {}
|
||||
nodes_powerpanel: Dict[int, PowerPanel] = {}
|
||||
@@ -664,6 +665,13 @@ def get_topology_data(
|
||||
)
|
||||
)
|
||||
|
||||
if group_locations:
|
||||
options['group_locations'] = 'on'
|
||||
if group_racks:
|
||||
options['group_racks'] = 'on'
|
||||
if group_sites:
|
||||
options['group_sites'] = 'on'
|
||||
|
||||
for qs_device in queryset:
|
||||
if qs_device.pk not in nodes_devices and show_unconnected:
|
||||
nodes_devices[qs_device.pk] = qs_device
|
||||
@@ -676,6 +684,7 @@ def get_topology_data(
|
||||
results["nodes"] = nodes
|
||||
results["edges"] = edges
|
||||
results["group"] = group_id
|
||||
results["options"] = options
|
||||
return results
|
||||
|
||||
|
||||
@@ -701,8 +710,30 @@ class TopologyHomeView(PermissionRequiredMixin, View):
|
||||
|
||||
if request.GET:
|
||||
|
||||
save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, show_neighbors = get_query_settings(request)
|
||||
filter_id, save_coords, show_unconnected, show_power, show_circuit, show_logical_connections, show_single_cable_logical_conns, show_cables, show_wireless, group_sites, group_locations, group_racks, show_neighbors = get_query_settings(request)
|
||||
|
||||
# Read options from saved filters as NetBox does not handle custom plugin filters
|
||||
if "filter_id" in request.GET and request.GET["filter_id"] != '':
|
||||
try:
|
||||
saved_filter = SavedFilter.objects.get(pk=filter_id)
|
||||
saved_filter_params = getattr(saved_filter, 'parameters')
|
||||
|
||||
if save_coords == False and 'save_coords' in saved_filter_params: save_coords = saved_filter_params['save_coords']
|
||||
if show_power == False and 'show_power' in saved_filter_params: show_power = saved_filter_params['show_power']
|
||||
if show_circuit == False and 'show_circuit' in saved_filter_params: show_circuit = saved_filter_params['show_circuit']
|
||||
if show_logical_connections == False and 'show_logical_connections' in saved_filter_params: show_logical_connections = saved_filter_params['show_logical_connections']
|
||||
if show_single_cable_logical_conns == False and 'show_single_cable_logical_conns' in saved_filter_params: show_single_cable_logical_conns = saved_filter_params['show_single_cable_logical_conns']
|
||||
if show_cables == False and 'show_cables' in saved_filter_params: show_cables = saved_filter_params['show_cables']
|
||||
if show_wireless == False and 'show_wireless' in saved_filter_params: show_wireless = saved_filter_params['show_wireless']
|
||||
if group_sites == False and 'group_sites' in saved_filter_params: group_sites = saved_filter_params['group_sites']
|
||||
if group_locations == False and 'group_locations' in saved_filter_params: group_locations = saved_filter_params['group_locations']
|
||||
if group_racks == False and 'group_racks' in saved_filter_params: group_racks = saved_filter_params['group_racks']
|
||||
if show_neighbors == False and 'show_neighbors' in saved_filter_params: show_neighbors = saved_filter_params['show_neighbors']
|
||||
except SavedFilter.DoesNotExist: # filter_id not found
|
||||
pass
|
||||
except Exception as inst:
|
||||
print(type(inst))
|
||||
|
||||
if "group" not in request.GET:
|
||||
group_id = "default"
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user