feat: export switch port usage as PDF instead of a Ports tab
Switches get an "Export switch port usage" button that downloads an A4 landscape PDF: key figures, a front panel with one colour per VLAN label (full colour = connected, pale = free, dashed with a cross = disabled, text colour chosen for contrast), a VLAN legend and the full port list with peers. The PDF follows the language of the user's NetBox preferences (German or English). The Ports tab with its script and styles is removed. ReportLab becomes a dependency. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
8f2cc22f88
commit
8eb075db9f
13 files changed
+611
-452
No files matched your search
@@ -1,131 +0,0 @@
|
||||
{% extends 'dcim/device/base.html' %}
|
||||
{% load static %}
|
||||
|
||||
{% block content %}
|
||||
<div id="nbu-ports" data-nbu-ports>
|
||||
{# ---------- Key figures and controls ---------- #}
|
||||
<div class="row g-3 mb-3">
|
||||
<div class="col-6 col-lg-3">
|
||||
<div class="card h-100 mb-0"><div class="card-body py-2">
|
||||
<div class="text-muted small text-uppercase">Ports</div>
|
||||
<div class="fs-3 fw-semibold lh-sm">{{ summary.total }}</div>
|
||||
<div class="small text-muted">physische Schnittstellen</div>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-6 col-lg-3">
|
||||
<div class="card h-100 mb-0"><div class="card-body py-2">
|
||||
<div class="text-muted small text-uppercase">Belegt</div>
|
||||
<div class="fs-3 fw-semibold lh-sm text-success">{{ summary.connected }} <span class="fs-6 text-muted">({{ summary.percent }} %)</span></div>
|
||||
<div class="progress mt-1" style="height: .4rem"><div class="progress-bar bg-success" style="width: {{ summary.percent }}%"></div></div>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-6 col-lg-3">
|
||||
<div class="card h-100 mb-0"><div class="card-body py-2">
|
||||
<div class="text-muted small text-uppercase">Frei</div>
|
||||
<div class="fs-3 fw-semibold lh-sm">{{ summary.free }}</div>
|
||||
<div class="small text-muted">aktiviert, ohne Kabel</div>
|
||||
</div></div>
|
||||
</div>
|
||||
<div class="col-6 col-lg-3">
|
||||
<div class="card h-100 mb-0"><div class="card-body py-2">
|
||||
<div class="text-muted small text-uppercase">Deaktiviert</div>
|
||||
<div class="fs-3 fw-semibold lh-sm text-secondary">{{ summary.disabled }}</div>
|
||||
<div class="small text-muted">Schnittstelle abgeschaltet</div>
|
||||
</div></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# ---------- Front panel ---------- #}
|
||||
<div class="card">
|
||||
<h2 class="card-header d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="me-auto"><i class="mdi mdi-ethernet me-1" aria-hidden="true"></i>Portbelegung</span>
|
||||
<div class="btn-group btn-group-sm" role="group" aria-label="Farbmodus">
|
||||
<input type="radio" class="btn-check" name="nbu-port-mode" id="nbu-port-mode-state" value="state" checked>
|
||||
<label class="btn btn-outline-primary" for="nbu-port-mode-state">Belegung</label>
|
||||
<input type="radio" class="btn-check" name="nbu-port-mode" id="nbu-port-mode-vlan" value="vlan">
|
||||
<label class="btn btn-outline-primary" for="nbu-port-mode-vlan">VLAN</label>
|
||||
</div>
|
||||
<a href="?export=csv" class="btn btn-sm btn-outline-secondary"><i class="mdi mdi-download" aria-hidden="true"></i> CSV</a>
|
||||
<button type="button" class="btn btn-sm btn-outline-secondary" onclick="window.print()"><i class="mdi mdi-printer" aria-hidden="true"></i> Drucken</button>
|
||||
</h2>
|
||||
<div class="card-body">
|
||||
{% if not groups %}
|
||||
<p class="text-muted mb-0">Dieses Gerät hat keine physischen Schnittstellen.</p>
|
||||
{% endif %}
|
||||
{% for group in groups %}
|
||||
<div class="nbu-port-group mb-3">
|
||||
<div class="small text-muted mb-1">{{ group.title }} <span class="text-body-secondary">· {{ group.ports|length }} Ports</span></div>
|
||||
<div class="nbu-port-panel">
|
||||
{% for column in group.columns %}
|
||||
<div class="nbu-port-column">
|
||||
{% for port in column %}
|
||||
<a href="#nbu-port-row-{{ port.pk }}"
|
||||
class="nbu-port nbu-port-{{ port.state }}{% if group.optical %} nbu-port-optical{% endif %}"
|
||||
data-nbu-port="{{ port.pk }}"
|
||||
data-vlan="{{ port.vlan }}"
|
||||
{% if port.color %}style="--nbu-vlan-color: {{ port.color }}"{% endif %}
|
||||
data-bs-toggle="tooltip" data-bs-html="true"
|
||||
title="<strong>{{ port.name|force_escape }}</strong>{% if port.label %}<br>VLAN: {{ port.label|force_escape }}{% endif %}<br>{{ port.state_label }}{% if port.peer %}<br>↔ {{ port.peer|force_escape }}{% endif %}{% if port.description %}<br><em>{{ port.description|force_escape }}</em>{% endif %}{% if port.lag %}<br>LAG: {{ port.lag|force_escape }}{% endif %}<br><span class='opacity-75'>{{ port.type_display|force_escape }}</span>">
|
||||
<span class="nbu-port-number">{{ port.short }}</span>
|
||||
<span class="nbu-port-vlan">{% if port.vlan %}{{ port.vlan }}{% else %} {% endif %}</span>
|
||||
</a>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
|
||||
{# Legends #}
|
||||
<div class="nbu-port-legend small" data-nbu-legend="state">
|
||||
<span><span class="nbu-port-swatch nbu-port-connected"></span>{{ states.connected }}</span>
|
||||
<span><span class="nbu-port-swatch nbu-port-free"></span>{{ states.free }}</span>
|
||||
<span><span class="nbu-port-swatch nbu-port-disabled"></span>{{ states.disabled }}</span>
|
||||
</div>
|
||||
<div class="nbu-port-legend small d-none" data-nbu-legend="vlan">
|
||||
{% for vlan, color, total, connected in legend %}
|
||||
<button type="button" class="btn btn-sm btn-link p-0 text-reset text-decoration-none" data-nbu-vlan-filter="{{ vlan }}">
|
||||
<span class="nbu-port-swatch" style="background: {{ color|default:'var(--bs-secondary-bg)' }}"></span>{{ vlan|default:"ohne Label" }}
|
||||
<span class="text-muted">({{ connected }}/{{ total }})</span>
|
||||
</button>
|
||||
{% empty %}
|
||||
<span class="text-muted">Keine Labels gepflegt.</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{# ---------- Table ---------- #}
|
||||
<div class="card">
|
||||
<h2 class="card-header d-flex flex-wrap align-items-center gap-2">
|
||||
<span class="me-auto">Alle Schnittstellen</span>
|
||||
<input type="search" class="form-control form-control-sm" style="max-width: 18rem" placeholder="Suchen: Port, VLAN, Gegenstelle …" data-nbu-port-search>
|
||||
</h2>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover table-sm align-middle mb-0">
|
||||
<thead>
|
||||
<tr><th>Port</th><th>Status</th><th>VLAN (Label)</th><th>Gegenstelle</th><th>Beschreibung</th><th>Typ</th><th>LAG</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for port in ports %}
|
||||
<tr id="nbu-port-row-{{ port.pk }}" data-nbu-port-row="{{ port.pk }}" data-vlan="{{ port.vlan }}">
|
||||
<td class="text-nowrap"><a href="{{ port.url }}">{{ port.name }}</a>{% if port.mgmt_only %} <span class="badge text-bg-info">Mgmt</span>{% endif %}</td>
|
||||
<td>
|
||||
<span class="badge {% if port.state == 'connected' %}text-bg-success{% elif port.state == 'disabled' %}text-bg-secondary{% else %}text-bg-light border{% endif %}">{{ port.state_label }}</span>
|
||||
</td>
|
||||
<td>
|
||||
{% if port.label %}<span class="badge" style="background: {{ port.color }}">{{ port.label }}</span>{% else %}<span class="text-muted">—</span>{% endif %}
|
||||
</td>
|
||||
<td>{% if port.peer_url %}<a href="{{ port.peer_url }}">{{ port.peer }}</a>{% else %}{{ port.peer|default:"—" }}{% endif %}</td>
|
||||
<td class="small">{{ port.description|default:"—" }}</td>
|
||||
<td class="small text-muted">{{ port.type_display }}</td>
|
||||
<td class="small">{{ port.lag|default:"—" }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script src="{% static 'netbox_utilities/switch_ports.js' %}" defer></script>
|
||||
{% endblock content %}
|
||||
@@ -0,0 +1,4 @@
|
||||
<a href="{% url 'plugins:netbox_utilities:device_switch_ports_pdf' pk=object.pk %}" class="btn btn-outline-secondary">
|
||||
<i class="mdi mdi-file-pdf-box" aria-hidden="true"></i>
|
||||
{{ label }}
|
||||
</a>
|
||||
Reference in new issue
Block a user