From 1ff68d7026be8e86a7a9e81ca070337a95f7d73c Mon Sep 17 00:00:00 2001 From: Louis Date: Wed, 22 Jul 2026 13:33:49 +0200 Subject: [PATCH] fix: export all rendered devices from rack elevations --- netbox_topology_views/__init__.py | 2 +- .../netbox_topology_views/rack_elevation.html | 27 +++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/netbox_topology_views/__init__.py b/netbox_topology_views/__init__.py index d50a9a6..7d65aa5 100644 --- a/netbox_topology_views/__init__.py +++ b/netbox_topology_views/__init__.py @@ -6,7 +6,7 @@ class TopologyViewsConfig(PluginConfig): verbose_name = "Topology views" description = "A plugin to render topology maps" version = "4.5.1" - author = "Mattijs Vanhaverbeke" + author = "Mattijs Vanhaverbeke & LKE" author_email = "author@example.com" base_url = "netbox_topology_views" required_settings = [] diff --git a/netbox_topology_views/templates/netbox_topology_views/rack_elevation.html b/netbox_topology_views/templates/netbox_topology_views/rack_elevation.html index 1592b97..d3c2ea1 100644 --- a/netbox_topology_views/templates/netbox_topology_views/rack_elevation.html +++ b/netbox_topology_views/templates/netbox_topology_views/rack_elevation.html @@ -41,7 +41,7 @@
{% for rack in racks %} -
+
{{ rack.name }}
{{ rack.site }}{% if rack.location %} · {{ rack.location }}{% endif %} · {{ rack.u_height }}U
@@ -63,6 +63,9 @@ {% for device in rack.elevation_devices %} {% if device.elevation_face == face %} {{ device.name|default:device.device_type.model }} @@ -311,6 +314,25 @@ const drawioDocument = cells => `${cells}`; + const renderedRackData = racks => racks.map(rack => { + const card = document.querySelector(`.rack-card[data-rack-id="${rack.id}"]`); + if (!card) return rack; + const rackUnits = Number.parseFloat(card.dataset.rackUnits) || rack.u_height || 1; + const devices = Array.from(card.querySelectorAll('.rack-device')).map(device => { + const bottom = Number.parseFloat(device.style.bottom) || 0; + const height = Number.parseFloat(device.style.height) || (100 / rackUnits); + return { + name: device.dataset.deviceName || device.querySelector('span')?.textContent || 'Gerät', + type: device.dataset.deviceType || '', + position: bottom / 100 * rackUnits + 1, + height: Math.max(height / 100 * rackUnits, 1), + face: device.dataset.face === 'rear' ? 'rear' : 'front', + color: device.dataset.deviceColor || '#1685fc', + }; + }); + return {...rack, devices}; + }); + const buildRackDrawio = racks => { const unit = 22, faceWidth = 250, labelWidth = 28, faceGap = 28, rackGap = 44, header = 55; const rackWidth = labelWidth + faceWidth * 2 + faceGap; @@ -451,7 +473,8 @@ }; document.querySelectorAll('.rack-export').forEach(button => button.addEventListener('click', () => { - const racks = button.dataset.scope === 'all' ? rackData : rackData.filter(rack => String(rack.id) === button.dataset.scope); + const selectedRacks = button.dataset.scope === 'all' ? rackData : rackData.filter(rack => String(rack.id) === button.dataset.scope); + const racks = renderedRackData(selectedRacks); const name = button.dataset.scope === 'all' ? 'racks-gesamt' : `rack-${safeName(racks[0]?.name)}`; exportGraphic(buildRackSvg(racks), button.dataset.format, name); }));