Inventory links, cutsheet marks on faceplates, and single page titles
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 54s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m1s
Lint / JS (eslint) (pull_request) Successful in 19s
Test / Python Tests (pytest) (push) Successful in 2m6s
Security / Python Security (bandit) (pull_request) Successful in 1m18s
Lint / Python (flake8) (pull_request) Successful in 53s
Test / Python Tests (pytest) (pull_request) Successful in 1m1s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 54s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 1m1s
Lint / JS (eslint) (pull_request) Successful in 19s
Test / Python Tests (pytest) (push) Successful in 2m6s
Security / Python Security (bandit) (pull_request) Successful in 1m18s
Lint / Python (flake8) (pull_request) Successful in 53s
Test / Python Tests (pytest) (pull_request) Successful in 1m1s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Device pages get an Inventory button: it opens the device's HomeBox record
once an admin pastes its URL (stored in the new device_links table; only
URLs on inventory.base_url are accepted), and searches the inventory for
the model until then. Tickets link the record too.
Faceplate ports with a documented cable get a corner dot: green matches,
red mismatch, grey documented but unconfirmed. The port's tooltip names
the cable, and a legend toggle (remembered per browser) hides them.
Page titles no longer repeat GANDALF ("Alert History - GANDALF - GANDALF").
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+43
-2
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/* global DEVICE_NAME, deviceUrl, refreshModem, _toIso, fmtRate, fmtErrors, renderPortInspector, selectPortByIdx, highlightSelectedPort, FACEPLATES */
|
||||
/* global DEVICE_NAME, CAN_EDIT, deviceUrl, refreshModem, _toIso, fmtRate, fmtErrors, renderPortInspector, selectPortByIdx, highlightSelectedPort, FACEPLATES */
|
||||
|
||||
// Per-device page: overview, alerts, and a compact interface/port table. Host
|
||||
// rows expand in place; switch and router rows open the port inspector panel.
|
||||
@@ -332,6 +332,47 @@ function updateInterfaceSection(rows, title, hasChassis) {
|
||||
document.getElementById('device-error-count').textContent = rows.filter(rowHasProblem).length;
|
||||
}
|
||||
|
||||
// ── Inventory (HomeBox) link ────────────────────────────────────────────
|
||||
function inventoryActions(d) {
|
||||
const inv = d.inventory || {};
|
||||
const edit = CAN_EDIT
|
||||
? `<button type="button" class="lt-btn lt-btn-ghost lt-btn-sm" data-action="edit-inventory"
|
||||
aria-label="${inv.url ? 'Change' : 'Set'} the inventory link for ${esc(d.name)}">✎</button>` : '';
|
||||
if (inv.url) {
|
||||
return `<a class="lt-btn lt-btn-secondary lt-btn-sm" href="${esc(inv.url)}" target="_blank" rel="noopener">📦 Inventory ↗</a>${edit}`;
|
||||
}
|
||||
if (!inv.search_url) return edit;
|
||||
return `<a class="lt-btn lt-btn-ghost lt-btn-sm" href="${esc(inv.search_url)}" target="_blank" rel="noopener"
|
||||
title="No inventory record is linked yet">📦 Find in inventory ↗</a>${edit}`;
|
||||
}
|
||||
|
||||
function openInventoryEditor() {
|
||||
const inv = (_device && _device.inventory) || {};
|
||||
const form = document.getElementById('inventory-form');
|
||||
form.url.value = inv.url || '';
|
||||
document.getElementById('inventory-search').href = inv.search_url || '#';
|
||||
lt.modal.open('inventory-modal');
|
||||
form.url.focus();
|
||||
}
|
||||
|
||||
async function saveInventory(e) {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await lt.api.put(`/api/device/${encodeURIComponent(DEVICE_NAME)}/inventory`, { url: e.target.url.value.trim() });
|
||||
lt.modal.close('inventory-modal');
|
||||
lt.toast.success(e.target.url.value.trim() ? 'Inventory link saved' : 'Inventory link removed');
|
||||
await loadDevice();
|
||||
} catch (err) {
|
||||
lt.toast.error(err.message || 'Save failed');
|
||||
}
|
||||
}
|
||||
|
||||
document.addEventListener('click', e => {
|
||||
if (e.target.closest('[data-action="edit-inventory"]')) openInventoryEditor();
|
||||
});
|
||||
const _inventoryForm = document.getElementById('inventory-form');
|
||||
if (_inventoryForm) _inventoryForm.addEventListener('submit', saveInventory);
|
||||
|
||||
function render(d) {
|
||||
_device = d;
|
||||
document.getElementById('device-dot').className = `dot-${d.status || 'unknown'}`;
|
||||
@@ -340,7 +381,7 @@ function render(d) {
|
||||
(d.updated ? ` · updated ${new Date(_toIso(d.updated)).toLocaleTimeString()}` : '');
|
||||
|
||||
const unifi = d.source === 'unifi';
|
||||
document.getElementById('device-actions').innerHTML = `
|
||||
document.getElementById('device-actions').innerHTML = inventoryActions(d) + `
|
||||
<button class="lt-btn lt-btn-ghost lt-btn-sm btn-suppress" data-sup-type="${unifi ? 'unifi_device' : 'host'}"
|
||||
data-sup-name="${esc(d.name)}" data-sup-detail="" aria-label="Suppress alerts for ${esc(d.name)}">🔕 Suppress</button>`;
|
||||
|
||||
|
||||
+29
-7
@@ -107,7 +107,13 @@ function portLabelSvg(p, port) {
|
||||
return `<text class="fp-label" x="${x}" y="${y}" text-anchor="middle"${size}>${p.text || p.idx}</text>${bolt}`;
|
||||
}
|
||||
|
||||
function faceplatePortSvg(p, port, swName, title) {
|
||||
// Cutsheet status dot in a port's corner: ok (matches), bad (mismatch), doc (documented, not confirmed)
|
||||
function cutsheetMarkSvg(mark, x, y) {
|
||||
if (!mark) return '';
|
||||
return `<circle class="fp-mark fp-mark-${mark}" cx="${x}" cy="${y}" r="3.2"/>`;
|
||||
}
|
||||
|
||||
function faceplatePortSvg(p, port, swName, title, mark) {
|
||||
// The drawn port number can differ from the index UniFi reports (see anyPort)
|
||||
const idx = (p.anyPort && port) ? port.port_idx : p.idx;
|
||||
const attrs = `class="fp-port${port && port.up ? ' fp-up' : ''}" data-switch="${lt.escHtml(swName)}" data-port-idx="${idx}"
|
||||
@@ -117,6 +123,7 @@ function faceplatePortSvg(p, port, swName, title) {
|
||||
<title>${title}</title>
|
||||
${sfpSvg(port, p.w, p.h)}
|
||||
<rect class="fp-hit" x="-1" y="-1" width="${p.w + 2}" height="${p.h + 2}" rx="2"/>
|
||||
${cutsheetMarkSvg(mark, p.w - 3, 3)}
|
||||
</g>
|
||||
${sfpLedSvg(p, port)}${portLabelSvg(p, port)}`;
|
||||
}
|
||||
@@ -125,6 +132,7 @@ function faceplatePortSvg(p, port, swName, title) {
|
||||
<title>${title}</title>
|
||||
<g transform="scale(1 ${p.flip ? -1 : 1})">${rj45Svg(port, p)}</g>
|
||||
<rect class="fp-hit" x="-18" y="-${p.flip ? 11 : 17}" width="36" height="28" rx="2"/>
|
||||
${cutsheetMarkSvg(mark, 14, p.flip ? 13 : -13)}
|
||||
</g>${portLabelSvg(p, port)}`;
|
||||
}
|
||||
|
||||
@@ -469,9 +477,17 @@ function faceplateLegendSwatch(cls) {
|
||||
return `<span class="fp-legend-led fp-led-${cls}"></span>`;
|
||||
}
|
||||
|
||||
function faceplateLegendHtml(spec) {
|
||||
const items = spec.legend.map(([cls, text]) =>
|
||||
const CUTSHEET_MARK_LEGEND = [['ok', 'Matches cutsheet'], ['bad', 'Cutsheet mismatch'], ['doc', 'Documented, unconfirmed']];
|
||||
|
||||
function faceplateLegendHtml(spec, marks) {
|
||||
let items = spec.legend.map(([cls, text]) =>
|
||||
`<div class="chassis-legend-item">${faceplateLegendSwatch(cls)}${text}</div>`).join('');
|
||||
if (marks && marks.size) {
|
||||
items += CUTSHEET_MARK_LEGEND.filter(([m]) => marks.has(m)).map(([m, text]) =>
|
||||
`<div class="chassis-legend-item fp-mark-key"><svg class="fp-legend-icon" viewBox="0 0 8 8"><circle class="fp-mark fp-mark-${m}" cx="4" cy="4" r="3.2"/></svg>${text}</div>`).join('');
|
||||
items += `<label class="chassis-legend-item fp-mark-toggle"><input type="checkbox" data-action="toggle-cutsheet-marks"
|
||||
${document.body.classList.contains('fp-marks-off') ? '' : 'checked'}> Cutsheet marks</label>`;
|
||||
}
|
||||
const hasDetail = spec.ports.length || spec.outlets;
|
||||
return `<div class="chassis-legend">
|
||||
${items}
|
||||
@@ -479,14 +495,20 @@ function faceplateLegendHtml(spec) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
// ctx: { swName, portMap, outlets, online, titleFor(port, idx, role) }
|
||||
// ctx: { swName, portMap, outlets, online, titleFor(port, idx, role), cutsheetFor?(idx) -> {mark, text} }
|
||||
function renderFaceplate(model, ctx) {
|
||||
const spec = FACEPLATES[model];
|
||||
const anyPort = Object.values(ctx.portMap)[0];
|
||||
const marks = new Set();
|
||||
const ports = spec.ports.map(p => {
|
||||
const port = ctx.portMap[p.idx] || (p.anyPort ? anyPort : undefined);
|
||||
const title = ctx.titleFor(port, p.idx, spec.roles && spec.roles[p.idx]);
|
||||
return faceplatePortSvg(p, port, ctx.swName, title);
|
||||
let title = ctx.titleFor(port, p.idx, spec.roles && spec.roles[p.idx]);
|
||||
const cs = ctx.cutsheetFor ? ctx.cutsheetFor((p.anyPort && port) ? port.port_idx : p.idx) : null;
|
||||
if (cs) {
|
||||
marks.add(cs.mark);
|
||||
title += lt.escHtml(` · ${cs.text}`);
|
||||
}
|
||||
return faceplatePortSvg(p, port, ctx.swName, title, cs && cs.mark);
|
||||
}).join('');
|
||||
const outletData = Object.fromEntries((ctx.outlets || []).map(o => [o.index, o]));
|
||||
const outlets = (spec.outlets || []).map(o => faceplateOutletSvg(o, outletData[o.idx])).join('');
|
||||
@@ -510,7 +532,7 @@ function renderFaceplate(model, ctx) {
|
||||
${ports}
|
||||
</svg>
|
||||
</div>
|
||||
</div>${faceplateLegendHtml(spec)}`;
|
||||
</div>${faceplateLegendHtml(spec, marks)}`;
|
||||
}
|
||||
|
||||
// Where an fp-scroll panel should start: its port area
|
||||
|
||||
@@ -112,6 +112,32 @@ function cutsheetPanelHtml(swName, idx) {
|
||||
}).join('');
|
||||
}
|
||||
|
||||
// The faceplate dot for one port: the worst state of the cables documented on it
|
||||
const MARK_RANK = { bad: 3, doc: 2, ok: 1 };
|
||||
|
||||
function cutsheetMarkFor(idx) {
|
||||
const entries = ((_apiData && _apiData.cutsheet) || []).filter(e => e.port === String(idx) && e.status !== 'retired');
|
||||
if (!entries.length) return null;
|
||||
let best = null;
|
||||
entries.forEach(e => {
|
||||
const mark = CUTSHEET_PROBLEM.has(e.verdict) ? 'bad' : (e.verdict === 'match' ? 'ok' : 'doc');
|
||||
if (!best || MARK_RANK[mark] > MARK_RANK[best.mark]) {
|
||||
best = { mark, text: `cable ${e.label || 'unlabeled'}: ${e.detail}` };
|
||||
}
|
||||
});
|
||||
return best;
|
||||
}
|
||||
|
||||
document.addEventListener('change', e => {
|
||||
if (!e.target.matches('[data-action="toggle-cutsheet-marks"]')) return;
|
||||
const off = !e.target.checked;
|
||||
document.body.classList.toggle('fp-marks-off', off);
|
||||
try { localStorage.setItem('gandalf.cutsheetMarks', off ? 'off' : 'on'); } catch (_) { /* private mode */ }
|
||||
});
|
||||
try {
|
||||
if (localStorage.getItem('gandalf.cutsheetMarks') === 'off') document.body.classList.add('fp-marks-off');
|
||||
} catch (_) { /* private mode */ }
|
||||
|
||||
// ── SFP module section of the port panel ────────────────────────────────
|
||||
function sfpPanelHtml(sfp) {
|
||||
if (!sfp) return '';
|
||||
@@ -206,6 +232,7 @@ function renderChassis(swName, sw) {
|
||||
if (FACEPLATES[model]) {
|
||||
return `<div class="inspector-chassis">${header}${renderFaceplate(model, {
|
||||
swName, portMap, outlets: sw.outlets, online: sw.online, titleFor: faceplatePortTitle,
|
||||
cutsheetFor: cutsheetMarkFor,
|
||||
})}</div>`;
|
||||
}
|
||||
|
||||
|
||||
@@ -1422,3 +1422,12 @@ polygon.fp-led-off { fill: #6b6c71; }
|
||||
.ev-cards .ev-c-desc { flex: 1 1 100%; color: var(--text-muted); white-space: normal; overflow: visible; }
|
||||
.ev-cards .ev-c-action { flex: 1 1 100%; }
|
||||
}
|
||||
|
||||
/* ── Cutsheet marks on faceplates ──────────────────────────────────── */
|
||||
.fp-mark { stroke: #101418; stroke-width: 1.2; pointer-events: none; }
|
||||
.fp-mark-ok { fill: var(--accent-green, #00ff88); }
|
||||
.fp-mark-bad { fill: var(--status-critical, #e0312b); }
|
||||
.fp-mark-doc { fill: #9aa7b4; }
|
||||
body.fp-marks-off .fp-svg .fp-mark { display: none; }
|
||||
.fp-mark-toggle { cursor: pointer; gap: 6px; }
|
||||
.fp-mark-toggle input { margin: 0; }
|
||||
|
||||
Reference in New Issue
Block a user