Cutsheet: tabs for Cables, To do, Patch panels, Inventory and History

The 9-section page becomes five tabs; counts sit on the tabs instead of a row of
chips. To do holds undocumented links, UniFi port names and labels to make. The
text-only rack list is gone (the rack page draws it). Patch panels list only ports
with a cable or label, with a Show all toggle. Links to a section, cable or item
open the tab that holds it, so dashboard and rack links still land. ?problems=1
ticks Problems only. Printing still prints every tab, or just the labels.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-15 14:59:15 -05:00
co-authored by Claude Opus 5.5
parent c535bfd9fb
commit 4646d9be90
3 changed files with 190 additions and 151 deletions
+68 -42
View File
@@ -67,16 +67,19 @@ function renderSummary() {
const problems = cables.filter(c => c.problem).length;
const matches = cables.filter(c => c.verdict === 'match').length;
const labels = _cs.labels.cables.length + _cs.labels.ports.length;
const chip = (n, text, cls, target) =>
`<a class="cs-chip ${cls}" href="#${target}"><b>${n}</b> ${esc(text)}</a>`;
document.getElementById('cs-summary').innerHTML = [
chip(cables.length, 'cables', '', 'cs-cables-section'),
chip(matches, 'match what Gandalf sees', 'cs-chip-ok', 'cs-cables-section'),
chip(problems, problems === 1 ? 'problem' : 'problems', problems ? 'cs-chip-bad' : '', 'cs-cables-section'),
chip(_cs.suggestions.length, 'undocumented links', _cs.suggestions.length ? 'cs-chip-warn' : '', 'cs-suggest-section'),
chip(portFixes(), 'port names to fix', portFixes() ? 'cs-chip-warn' : '', 'cs-portnames-section'),
chip(labels, 'labels to make', labels ? 'cs-chip-warn' : '', 'cs-labels-section'),
].join('');
document.getElementById('cs-summary').innerHTML =
`<b class="cs-ok">${matches}</b> of ${cables.length} match what Gandalf sees`
+ (problems ? ` · <b class="cs-bad">${problems}</b> ${problems === 1 ? 'problem' : 'problems'}` : '');
// Each tab says how much is in it; To do counts what needs doing
const todo = _cs.suggestions.length + portFixes() + labels;
const tabCount = (id, n, cls) => {
const el = document.getElementById(`cs-tabcount-${id}`);
el.textContent = n ? String(n) : '';
el.className = `cs-tab-count${cls ? ` ${cls}` : ''}`;
};
tabCount('cables', cables.length, problems ? 'cs-tab-count-bad' : '');
tabCount('todo', todo, todo ? 'cs-tab-count-warn' : '');
tabCount('items', _cs.items.length, '');
}
function cableMatches(c, words, status, problemsOnly) {
@@ -209,6 +212,9 @@ function farEnd(c, name, port, side) {
return endText(c, end);
}
// Panels whose every port is shown, not just the ones with something on them
const _panelsShowAll = new Set();
function renderPanels() {
const panels = _cs.items.filter(i => i.kind === 'patch_panel').sort((a, b) => natural(a.name, b.name));
const wrap = document.getElementById('cs-panels');
@@ -220,10 +226,14 @@ function renderPanels() {
for (const l of _cs.port_labels) labels[`${l.item_id}|${l.port}`] = l;
wrap.innerHTML = panels.map(p => {
const rows = [];
const all = _panelsShowAll.has(p.id);
let used = 0;
for (let n = 1; n <= (p.port_count || 0); n++) {
const front = cableAt(p.name, n, 'front');
const rear = cableAt(p.name, n, 'rear');
const lab = labels[`${p.id}|${n}`];
if (front || rear || lab) used += 1;
else if (!all) continue;
const cell = (c, side) => c
? `<a class="cs-id" href="#cable-${esc(c.id)}">${esc(c.label || 'unlabeled')}</a> → ${farEnd(c, p.name, n, side)}`
: '<span class="val-neutral">-</span>';
@@ -236,17 +246,24 @@ function renderPanels() {
<td>${cell(rear, 'rear')}</td>
</tr>`);
}
return `
<div class="lt-frame cs-panel" id="item-${esc(p.id)}">
<span class="lt-frame-bl">&#x255A;</span><span class="lt-frame-br">&#x255D;</span>
<div class="lt-section-header">${esc(p.name)}${p.rack_u ? ` · U${esc(p.rack_u)}` : ''}${p.location ? ` · ${esc(p.location)}` : ''}</div>
const total = p.port_count || 0;
const toggle = total && used < total
? `<button type="button" class="cs-link-btn no-print" data-action="panel-all" data-id="${esc(p.id)}" aria-expanded="${all}">${all ? `Show only the ${used} in use` : `Show all ${total} ports`}</button>`
: '';
const table = rows.length ? `
<div class="lt-table-wrap">
<table class="lt-table lt-table-sm">
<caption class="lt-sr-only">Ports on ${esc(p.name)}</caption>
<thead><tr><th>Port</th><th>Label</th><th>Front (patch cord)</th><th>Rear (run)</th></tr></thead>
<tbody>${rows.join('')}</tbody>
</table>
</div>
</div>` : '';
return `
<div class="lt-frame cs-panel" id="item-${esc(p.id)}">
<span class="lt-frame-bl">&#x255A;</span><span class="lt-frame-br">&#x255D;</span>
<div class="lt-section-header">${esc(p.name)}${p.rack_u ? ` · U${esc(p.rack_u)}` : ''}${p.location ? ` · ${esc(p.location)}` : ''}</div>
<p class="cs-panel-use">${used} of ${total} ports have a cable or label${used ? '' : '; nothing documented yet'}. ${toggle}</p>
${table}
</div>`;
}).join('');
}
@@ -282,27 +299,6 @@ function renderLabels() {
${unlabeled.length ? `<p class="cs-hint">${unlabeled.length} more cable(s) have no ID yet.</p>` : ''}`;
}
function renderRack() {
const placed = _cs.items.filter(i => i.rack_u).sort((a, b) => (b.rack_u + (b.rack_height || 1)) - (a.rack_u + (a.rack_height || 1)));
const wrap = document.getElementById('cs-rack');
if (!placed.length) {
wrap.innerHTML = emptyState('🗄️', 'No rack positions recorded', CS_CAN_EDIT ? 'Set a rack unit on a panel, shelf or device in the inventory.' : '');
return;
}
wrap.innerHTML = `
<div class="cs-rack">
${placed.map(i => {
const top = i.rack_u + (i.rack_height || 1) - 1;
return `
<div class="cs-rack-unit" style="--u:${Math.min(i.rack_height || 1, 8)}">
<span class="cs-rack-u">${i.rack_height > 1 ? `U${esc(top)}-${esc(i.rack_u)}` : `U${esc(i.rack_u)}`}</span>
<span class="cs-rack-name">${deviceLink(i.name)}</span>
<span class="cs-rack-kind">${esc(KIND_TEXT[i.kind] || i.kind)}</span>
</div>`;
}).join('')}
</div>`;
}
function rackText(i) {
if (i.shelf) return `on ${esc(i.shelf)}${i.slot ? `, position ${esc(i.slot)}` : ''}`;
if (!i.rack_u) return '-';
@@ -380,7 +376,6 @@ function render() {
renderPortNames();
renderPanels();
renderLabels();
renderRack();
renderItems();
renderHistory();
renderDatalists();
@@ -396,13 +391,39 @@ async function load() {
return;
}
render();
const hash = window.location.hash;
if (hash && /^#(cable|item)-\d+$/.test(hash)) {
const el = document.getElementById(hash.slice(1));
if (el) { el.classList.add('cs-flash'); el.scrollIntoView({ block: 'center' }); }
}
reveal(window.location.hash);
}
// Open the tab holding a section, cable or item (links from the dashboard, the rack and
// other tabs point at them), then scroll to it. Cables and items flash so they're easy to spot.
function reveal(hash) {
if (!hash || !/^#[\w-]+$/.test(hash)) return false;
const el = document.getElementById(hash.slice(1));
if (!el) return false;
const panel = el.closest('.lt-tab-panel');
if (panel && !panel.classList.contains('active')) lt.tabs.switch(panel.id);
if (el.classList.contains('lt-tab-panel')) return true;
if (/^#(cable|item)-\d+$/.test(hash)) {
el.classList.remove('cs-flash');
void el.offsetWidth;
el.classList.add('cs-flash');
el.scrollIntoView({ block: 'center' });
} else {
el.scrollIntoView({ block: 'start' });
}
return true;
}
window.addEventListener('hashchange', () => reveal(window.location.hash));
document.addEventListener('click', e => {
// A link to something on another tab: switch tabs even when the hash is already set
const a = e.target.closest('a[href^="#"]');
if (a && a.getAttribute('href').length > 1 && reveal(a.getAttribute('href'))) {
e.preventDefault();
history.replaceState(null, '', a.getAttribute('href'));
}
});
// ── Editing ─────────────────────────────────────────────────────────────
function fillPorts(end) {
const device = document.querySelector(`#cs-cable-form [name="${end}_device"]`).value;
@@ -706,6 +727,11 @@ document.addEventListener('click', e => {
else if (action === 'edit-item') openItem(_cs.items.find(i => String(i.id) === btn.dataset.id));
else if (action === 'edit-port-label') openPortLabel(btn.dataset.item, btn.dataset.port);
else if (action === 'print-labels') printLabels();
else if (action === 'panel-all') {
const id = Number(btn.dataset.id);
if (_panelsShowAll.has(id)) _panelsShowAll.delete(id); else _panelsShowAll.add(id);
renderPanels();
}
else if (action === 'trace-start') startTrace();
else if (action === 'trace-stop') { stopTrace(); traceStatus('Stopped.'); }
else if (action === 'trace-record') {
+14 -9
View File
@@ -1094,7 +1094,6 @@ polygon.fp-led-off { fill: #6b6c71; }
.cs-trace-status { margin-top: 10px; font-size: .88rem; line-height: 1.6; }
.cs-trace-found { font-size: 1rem; margin-bottom: 6px; }
.cs-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.cs-summary { display: flex; flex-wrap: wrap; gap: 8px; margin: 0 0 18px; }
.cs-chip { padding: 5px 10px; border: 1px solid var(--border-color, #234); border-radius: 3px; font-size: .82rem;
color: inherit; text-decoration: none; }
.cs-chip b { font-size: .95rem; }
@@ -1102,6 +1101,16 @@ polygon.fp-led-off { fill: #6b6c71; }
.cs-chip-bad { border-color: var(--status-critical, #e0312b); }
.cs-chip-bad b { color: var(--status-critical, #e0312b); }
.cs-chip-warn b { color: var(--accent-amber, #f0a020); }
.cs-summary { font-size: .82rem; color: var(--text-secondary); margin: 0 0 10px; }
.cs-summary .cs-ok { color: var(--accent-green); }
.cs-summary .cs-bad { color: var(--accent-red); }
/* Tabs: wrap on phones rather than scroll the page sideways */
.cs-tabs { flex-wrap: wrap; }
.cs-tab-count { color: var(--text-secondary); font-weight: 400; margin-left: 2px; }
.cs-tab-count:empty { display: none; }
.cs-tab-count-bad { color: var(--accent-red); }
.cs-tab-count-warn { color: var(--accent-amber); }
.cs-panel-use { font-size: .8rem; color: var(--text-secondary); margin: 6px 12px 8px; }
.cs-portname-group { margin: 0 0 12px; }
.cs-portname-group > summary { cursor: pointer; list-style-position: inside; margin-bottom: 8px; }
.cs-portname-group code { white-space: nowrap; }
@@ -1130,12 +1139,6 @@ polygon.fp-led-off { fill: #6b6c71; }
.cs-label-text { font-family: var(--font-mono, monospace); font-size: 1.05rem; font-weight: 700; letter-spacing: .05em; }
.cs-label-copies { font-size: .8rem; color: var(--text-muted, #8aa); }
.cs-label-where { grid-column: 1 / -1; font-size: .74rem; color: var(--text-muted, #8aa); }
.cs-rack { display: flex; flex-direction: column; gap: 3px; max-width: 560px; }
.cs-rack-unit { display: grid; grid-template-columns: 70px 1fr auto; gap: 10px; align-items: center;
min-height: calc(var(--u, 1) * 26px); padding: 4px 10px; border: 1px solid var(--border-color, #234);
border-radius: 2px; background: rgba(255,255,255,.02); }
.cs-rack-u { font-family: var(--font-mono, monospace); font-size: .78rem; color: var(--text-muted, #8aa); }
.cs-rack-kind { font-size: .74rem; color: var(--text-muted, #8aa); }
.cs-end { border: 1px solid var(--border-color, #234); border-radius: 3px; padding: 4px 12px 0; margin: 0 0 12px; }
.cs-end legend { font-size: .78rem; padding: 0 6px; color: var(--text-muted, #8aa); text-transform: uppercase; }
.cs-side[hidden] { display: none; }
@@ -1153,11 +1156,11 @@ polygon.fp-led-off { fill: #6b6c71; }
.cs-table td.cs-id { font-size: 1rem; }
.cs-row-problem { box-shadow: inset 3px 0 0 var(--status-critical, #e0312b); }
.cs-row-problem td:first-child { box-shadow: none; }
.cs-rack-unit { grid-template-columns: 56px 1fr; }
.cs-rack-kind { display: none; }
}
@media print {
.no-print, .lt-header, .lt-nav-drawer, .lt-nav-drawer-overlay { display: none !important; }
/* Printing shows every tab, or only the labels */
.lt-tab-panel { display: block !important; }
body.cs-print-labels .g-section:not(#cs-labels-section),
body.cs-print-labels .lt-page-header, body.cs-print-labels .cs-summary { display: none !important; }
.cs-label-card { break-inside: avoid; border-color: #000; color: #000; }
@@ -1747,3 +1750,5 @@ body.fp-marks-off .fp-svg .fp-mark { display: none; }
.g-brand-expansion b { color: var(--accent-cyan); font-weight: 700; }
.g-help-about { font-size: .86em; color: var(--text-secondary); margin: 0 0 12px; line-height: 1.5; }
.g-help-about b { color: var(--accent-cyan); }
/* A tab holding one section already says what it is: skip the repeated heading */
.lt-tab-panel > .g-section:only-child > .g-section-header { display: none; }