feat: Ports tab for switches with front-panel view and VLAN colours
Devices with the role "Switch" get a Ports tab: key figures, a front-panel view of all physical interfaces grouped per stack member/line card and medium (odd ports on top, even below), coloured by usage or by the VLAN noted in the interface label, with a VLAN legend and filter, tooltips with peer and description, a searchable table of all interfaces, CSV export and a print view. Peers follow the cable path through patch panels. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
9fd3e01cdf
commit
9ecad07c96
9 files changed
+776
No files matched your search
@@ -400,3 +400,89 @@ a.nbu-disk-slot[draggable="true"] {
|
||||
.nbu-disk-group-header[aria-expanded="true"] .nbu-disk-group-chevron {
|
||||
transform: rotate(90deg);
|
||||
}
|
||||
|
||||
/* ---------- Switch ports tab ---------- */
|
||||
.nbu-port-panel {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: .25rem;
|
||||
padding: .5rem;
|
||||
border-radius: .5rem;
|
||||
background: var(--bs-tertiary-bg);
|
||||
border: 1px solid var(--bs-border-color);
|
||||
}
|
||||
.nbu-port-column {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: .25rem;
|
||||
}
|
||||
.nbu-port {
|
||||
--nbu-vlan-color: var(--bs-secondary-bg);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 3.1rem;
|
||||
height: 2.6rem;
|
||||
border-radius: .3rem;
|
||||
border: 2px solid transparent;
|
||||
text-decoration: none;
|
||||
line-height: 1.05;
|
||||
transition: opacity .15s, transform .1s;
|
||||
}
|
||||
.nbu-port:hover {
|
||||
transform: translateY(-1px);
|
||||
text-decoration: none;
|
||||
}
|
||||
.nbu-port-number {
|
||||
font-weight: 600;
|
||||
font-size: .8rem;
|
||||
}
|
||||
.nbu-port-vlan {
|
||||
font-size: .62rem;
|
||||
max-width: 100%;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding: 0 .15rem;
|
||||
}
|
||||
.nbu-port-optical {
|
||||
border-radius: .1rem;
|
||||
width: 3.4rem;
|
||||
}
|
||||
/* Colour mode "Belegung" */
|
||||
.nbu-port-connected { background: var(--bs-success); color: #fff; }
|
||||
.nbu-port-free { background: var(--bs-body-bg); color: var(--bs-body-color); border-color: var(--bs-border-color); }
|
||||
.nbu-port-disabled {
|
||||
background: repeating-linear-gradient(45deg, var(--bs-secondary-bg), var(--bs-secondary-bg) 4px, var(--bs-tertiary-bg) 4px, var(--bs-tertiary-bg) 8px);
|
||||
color: var(--bs-secondary-color);
|
||||
border-color: var(--bs-border-color);
|
||||
}
|
||||
/* Colour mode "VLAN": fill by VLAN, the border shows whether the port is in use */
|
||||
.nbu-ports-vlan .nbu-port { background: var(--nbu-vlan-color); color: #fff; }
|
||||
.nbu-ports-vlan .nbu-port:not([style]) { color: var(--bs-body-color); }
|
||||
.nbu-ports-vlan .nbu-port-free { opacity: .55; border-color: transparent; }
|
||||
.nbu-ports-vlan .nbu-port-connected { border-color: var(--bs-body-color); }
|
||||
.nbu-ports-vlan .nbu-port-disabled { opacity: .35; }
|
||||
.nbu-port-dimmed { opacity: .15 !important; }
|
||||
|
||||
.nbu-port-legend {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: .4rem 1rem;
|
||||
align-items: center;
|
||||
}
|
||||
.nbu-port-swatch {
|
||||
display: inline-block;
|
||||
width: .9rem;
|
||||
height: .9rem;
|
||||
border-radius: .2rem;
|
||||
margin-right: .3rem;
|
||||
vertical-align: -.1rem;
|
||||
border: 1px solid var(--bs-border-color);
|
||||
}
|
||||
|
||||
@media print {
|
||||
.nbu-port, .nbu-port-swatch, .badge { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
|
||||
[data-nbu-port-search], .btn-group, .btn { display: none !important; }
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
// "Ports" tab of switches: colour mode, VLAN filter, search and tile → table row highlighting.
|
||||
(function () {
|
||||
"use strict";
|
||||
|
||||
const STORAGE_KEY = "netbox_utilities.port_mode";
|
||||
|
||||
function init() {
|
||||
const root = document.querySelector("[data-nbu-ports]");
|
||||
if (!root) return;
|
||||
|
||||
const tiles = Array.from(root.querySelectorAll("[data-nbu-port]"));
|
||||
const rows = Array.from(root.querySelectorAll("[data-nbu-port-row]"));
|
||||
const search = root.querySelector("[data-nbu-port-search]");
|
||||
let vlanFilter = null;
|
||||
|
||||
if (window.bootstrap && window.bootstrap.Tooltip) {
|
||||
tiles.forEach((tile) => window.bootstrap.Tooltip.getOrCreateInstance(tile, { container: "body" }));
|
||||
}
|
||||
|
||||
function setMode(mode) {
|
||||
root.classList.toggle("nbu-ports-vlan", mode === "vlan");
|
||||
root.querySelectorAll("[data-nbu-legend]").forEach((legend) => {
|
||||
legend.classList.toggle("d-none", legend.dataset.nbuLegend !== mode);
|
||||
});
|
||||
const radio = root.querySelector(`input[name="nbu-port-mode"][value="${mode}"]`);
|
||||
if (radio) radio.checked = true;
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, mode);
|
||||
} catch (error) {
|
||||
/* private mode: the choice is just not remembered */
|
||||
}
|
||||
if (mode !== "vlan") applyFilter(null);
|
||||
}
|
||||
|
||||
function applyFilter(vlan) {
|
||||
vlanFilter = vlan;
|
||||
tiles.forEach((tile) => tile.classList.toggle("nbu-port-dimmed", vlan !== null && tile.dataset.vlan !== vlan));
|
||||
root.querySelectorAll("[data-nbu-vlan-filter]").forEach((button) => {
|
||||
button.classList.toggle("fw-bold", vlan !== null && button.dataset.nbuVlanFilter === vlan);
|
||||
});
|
||||
filterRows();
|
||||
}
|
||||
|
||||
function filterRows() {
|
||||
const query = (search && search.value || "").trim().toLowerCase();
|
||||
rows.forEach((row) => {
|
||||
const matchesText = !query || row.textContent.toLowerCase().includes(query);
|
||||
const matchesVlan = vlanFilter === null || row.dataset.vlan === vlanFilter;
|
||||
row.classList.toggle("d-none", !(matchesText && matchesVlan));
|
||||
});
|
||||
if (query) {
|
||||
const visible = new Set(rows.filter((row) => !row.classList.contains("d-none")).map((row) => row.dataset.nbuPortRow));
|
||||
tiles.forEach((tile) => tile.classList.toggle("nbu-port-dimmed", !visible.has(tile.dataset.nbuPort)));
|
||||
} else if (vlanFilter === null) {
|
||||
tiles.forEach((tile) => tile.classList.remove("nbu-port-dimmed"));
|
||||
}
|
||||
}
|
||||
|
||||
root.querySelectorAll('input[name="nbu-port-mode"]').forEach((radio) => {
|
||||
radio.addEventListener("change", () => setMode(radio.value));
|
||||
});
|
||||
root.querySelectorAll("[data-nbu-vlan-filter]").forEach((button) => {
|
||||
button.addEventListener("click", () => {
|
||||
const vlan = button.dataset.nbuVlanFilter;
|
||||
applyFilter(vlanFilter === vlan ? null : vlan);
|
||||
});
|
||||
});
|
||||
if (search) search.addEventListener("input", filterRows);
|
||||
|
||||
tiles.forEach((tile) => {
|
||||
tile.addEventListener("click", () => {
|
||||
const row = document.getElementById(`nbu-port-row-${tile.dataset.nbuPort}`);
|
||||
if (!row) return;
|
||||
row.classList.add("table-active");
|
||||
window.setTimeout(() => row.classList.remove("table-active"), 2000);
|
||||
});
|
||||
});
|
||||
|
||||
let saved = "state";
|
||||
try {
|
||||
saved = localStorage.getItem(STORAGE_KEY) || "state";
|
||||
} catch (error) {
|
||||
/* ignore */
|
||||
}
|
||||
setMode(saved === "vlan" ? "vlan" : "state");
|
||||
}
|
||||
|
||||
if (document.readyState === "loading") {
|
||||
document.addEventListener("DOMContentLoaded", init);
|
||||
} else {
|
||||
init();
|
||||
}
|
||||
})();
|
||||
Reference in new issue
Block a user