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:
+68
-42
@@ -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">╚</span><span class="lt-frame-br">╝</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">╚</span><span class="lt-frame-br">╝</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') {
|
||||
|
||||
Reference in New Issue
Block a user