Rack: front and rear mounting, rack settings in the page
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 49s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 51s
Lint / Python (flake8) (pull_request) Successful in 55s
Test / Python Tests (pytest) (push) Successful in 1m4s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 52s
Test / Python Tests (pytest) (pull_request) Successful in 55s
Lint / JS (eslint) (push) Successful in 7s
Lint / Python (flake8) (push) Successful in 49s
Lint / Notify on failure (push) Skipped
Lint / Deploy (push) Skipped
Security / Python Security (bandit) (push) Successful in 51s
Lint / Python (flake8) (pull_request) Successful in 55s
Test / Python Tests (pytest) (push) Successful in 1m4s
Lint / JS (eslint) (pull_request) Successful in 7s
Lint / Notify on failure (pull_request) Skipped
Lint / Deploy (pull_request) Skipped
Security / Python Security (bandit) (pull_request) Successful in 52s
Test / Python Tests (pytest) (pull_request) Successful in 55s
Items are mounted from the front, the rear, or full depth. On a 4-post rack a front and a rear item can share a unit; a full-depth one takes both sides, and the rear view shows its back. Overlaps are checked per side. Shelf contents take the shelf's side. A Front / Rear switch flips the drawing. Racks are saved in Gandalf (new cutsheet_racks table) and edited on the rack page by admins: name, height, notes, add and delete. Renaming moves the rack's items; saving the first rack carries over the items of the config default it replaces. Config racks remain the fallback. Faceplates are stretched to the full width only when the drawing is close to the slot's proportions, so the PDU is not squashed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cd3d2f05ee
commit
c50e1f8322
11 files changed
+453
-52
No files matched your search
+7
-5
@@ -260,7 +260,8 @@ function renderRack() {
|
||||
function rackText(i) {
|
||||
if (i.shelf) return `on ${esc(i.shelf)}`;
|
||||
if (!i.rack_u) return '–';
|
||||
const where = `U${esc(i.rack_u)}${i.rack_height > 1 ? ` (${esc(i.rack_height)}U)` : ''}`;
|
||||
const side = { rear: ' rear', full: ' full depth' }[i.mount] || '';
|
||||
const where = `U${esc(i.rack_u)}${i.rack_height > 1 ? ` (${esc(i.rack_height)}U)` : ''}${side}`;
|
||||
return (_cs.racks || []).length > 1 ? `${where} · ${esc(i.rack || _cs.racks[0])}` : where;
|
||||
}
|
||||
|
||||
@@ -388,13 +389,14 @@ function openCable(cable, prefill) {
|
||||
function openItem(item) {
|
||||
const form = document.getElementById('cs-item-form');
|
||||
form.reset();
|
||||
const data = Object.assign({ kind: 'patch_panel' }, item || {});
|
||||
const data = Object.assign({ kind: 'patch_panel', mount: 'front' }, item || {});
|
||||
document.getElementById('cs-rack-list').innerHTML = (_cs.racks || []).map(r => `<option value="${esc(r)}">`).join('');
|
||||
document.getElementById('cs-known-devices').innerHTML = (_cs.devices || []).map(d => `<option value="${esc(d)}">`).join('');
|
||||
const shelves = _cs.items.filter(i => i.kind === 'shelf' && (!item || i.id !== item.id));
|
||||
form.shelf.innerHTML = '<option value="">Not on a shelf</option>' +
|
||||
shelves.map(i => `<option value="${esc(i.name)}">${esc(i.name)}</option>`).join('');
|
||||
for (const key of ['id', 'name', 'device', 'kind', 'port_count', 'rack_u', 'rack_height', 'rack', 'shelf', 'location', 'notes']) {
|
||||
for (const key of ['id', 'name', 'device', 'kind', 'port_count', 'rack_u', 'rack_height', 'rack', 'mount', 'shelf',
|
||||
'location', 'notes']) {
|
||||
form[key].value = data[key] == null ? '' : data[key];
|
||||
}
|
||||
if (!item) form.port_count.value = 24;
|
||||
@@ -447,8 +449,8 @@ async function saveCable(e) {
|
||||
async function saveItem(e) {
|
||||
e.preventDefault();
|
||||
const form = e.target;
|
||||
const body = formData(form, ['name', 'device', 'kind', 'port_count', 'rack_u', 'rack_height', 'rack', 'shelf', 'location',
|
||||
'notes']);
|
||||
const body = formData(form, ['name', 'device', 'kind', 'port_count', 'rack_u', 'rack_height', 'rack', 'mount', 'shelf',
|
||||
'location', 'notes']);
|
||||
const id = form.id.value;
|
||||
await save(() => id ? lt.api.put(`/api/cutsheet/items/${encodeURIComponent(id)}`, body)
|
||||
: lt.api.post('/api/cutsheet/items', body), 'Saved', 'cs-item-modal');
|
||||
|
||||
+108
-13
@@ -1,5 +1,5 @@
|
||||
'use strict';
|
||||
/* global FACEPLATES, renderFaceplate */
|
||||
/* global FACEPLATES, renderFaceplate, RACK_CAN_EDIT */
|
||||
// Rack page: draws the rack front from /api/rack. Switches use their real faceplates,
|
||||
// patch panels a generic panel; hovering a port lights up every port on the same cable run.
|
||||
|
||||
@@ -114,9 +114,18 @@ function plateHtml(item) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function backHtml(item) {
|
||||
// A full-depth item seen from the rear: its back, not its faceplate
|
||||
return `<div class="rack-plate rack-back">
|
||||
${statusDot(item.status)}<a class="device-link rack-plate-name" href="${esc(item.url)}">${esc(item.name)}</a>
|
||||
<span class="rack-plate-sub">back of a full-depth ${esc(KIND_TEXT[item.kind] || item.kind).toLowerCase()}</span>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
function itemHtml(item) {
|
||||
let body;
|
||||
if (item.switch && isRackFaceplate(item.switch.model)) body = switchHtml(item);
|
||||
if (item.through) body = backHtml(item);
|
||||
else if (item.switch && isRackFaceplate(item.switch.model)) body = switchHtml(item);
|
||||
else if (item.kind === 'patch_panel') body = panelSvg(item);
|
||||
else if (item.kind === 'shelf') body = shelfHtml(item);
|
||||
else body = plateHtml(item);
|
||||
@@ -161,7 +170,14 @@ function renderTabs(data) {
|
||||
return `<button type="button" class="rack-tab${on ? ' active' : ''}" role="tab" aria-selected="${on}"
|
||||
data-rack="${esc(r.name)}">${esc(r.name)} <span class="rack-tab-count">${r.count}</span></button>`;
|
||||
}).join('');
|
||||
document.getElementById('rack-title').textContent = data.racks.length > 1 ? `${data.rack} · front` : 'Front';
|
||||
document.getElementById('rack-title').textContent = `${data.rack} · ${data.face}`;
|
||||
document.querySelectorAll('.rack-face-btn').forEach(b => {
|
||||
const on = b.dataset.face === data.face;
|
||||
b.classList.toggle('active', on);
|
||||
b.setAttribute('aria-pressed', on);
|
||||
});
|
||||
const rear = (data.racks.find(r => r.name === data.rack) || {}).rear || 0;
|
||||
document.querySelector('.rack-face-btn[data-face="rear"]').textContent = rear ? `Rear (${rear})` : 'Rear';
|
||||
}
|
||||
|
||||
function render(data) {
|
||||
@@ -183,8 +199,17 @@ function render(data) {
|
||||
u = low - 1;
|
||||
}
|
||||
document.getElementById('rack').innerHTML = rows.join('');
|
||||
// Every rack device is 19" wide: fill the slot rather than keep each drawing's own proportions
|
||||
document.querySelectorAll('#rack .fp-svg').forEach(s => s.setAttribute('preserveAspectRatio', 'none'));
|
||||
// Every rack device is 19" wide: stretch a faceplate to fill its slot when its drawing is close to
|
||||
// the slot's proportions. A drawing far from them (the PDU's is twice as tall as a real 1U) keeps its
|
||||
// shape rather than being squashed.
|
||||
document.querySelectorAll('#rack .rack-slot').forEach(slot => {
|
||||
const svg = slot.querySelector('.fp-svg');
|
||||
if (!svg) return;
|
||||
const [, , w, h] = svg.getAttribute('viewBox').split(' ').map(Number);
|
||||
const n = parseInt(slot.closest('.rack-row').style.getPropertyValue('--n'), 10);
|
||||
const off = (w / h) / (RATIO / n);
|
||||
svg.setAttribute('preserveAspectRatio', off > 0.85 && off < 1.15 ? 'none' : 'xMidYMid meet');
|
||||
});
|
||||
document.getElementById('rack-show-empty').checked = showEmpty();
|
||||
document.getElementById('rack-count').textContent = data.items.length;
|
||||
|
||||
@@ -283,19 +308,37 @@ function currentRack() {
|
||||
return new URLSearchParams(location.search).get('rack') || '';
|
||||
}
|
||||
|
||||
function currentFace() {
|
||||
return new URLSearchParams(location.search).get('face') === 'rear' ? 'rear' : 'front';
|
||||
}
|
||||
|
||||
function setView(changes) {
|
||||
const q = new URLSearchParams(location.search);
|
||||
Object.entries(changes).forEach(([k, v]) => (v ? q.set(k, v) : q.delete(k)));
|
||||
const qs = q.toString();
|
||||
history.replaceState(null, '', qs ? `?${qs}` : location.pathname);
|
||||
_rack = null;
|
||||
load();
|
||||
}
|
||||
|
||||
document.getElementById('rack-tabs').addEventListener('click', e => {
|
||||
const tab = e.target.closest('[data-rack]');
|
||||
if (!tab) return;
|
||||
const first = _rack && _rack.racks[0] && _rack.racks[0].name;
|
||||
history.replaceState(null, '', tab.dataset.rack === first ? location.pathname : `?rack=${encodeURIComponent(tab.dataset.rack)}`);
|
||||
_rack = null;
|
||||
load();
|
||||
setView({ rack: tab.dataset.rack === first ? '' : tab.dataset.rack });
|
||||
});
|
||||
|
||||
document.querySelector('.rack-face').addEventListener('click', e => {
|
||||
const btn = e.target.closest('[data-face]');
|
||||
if (btn) setView({ face: btn.dataset.face === 'rear' ? 'rear' : '' });
|
||||
});
|
||||
|
||||
async function load() {
|
||||
try {
|
||||
const rack = currentRack();
|
||||
render(await lt.api.get(`/api/rack${rack ? `?rack=${encodeURIComponent(rack)}` : ''}`));
|
||||
const q = new URLSearchParams();
|
||||
if (currentRack()) q.set('rack', currentRack());
|
||||
if (currentFace() === 'rear') q.set('face', 'rear');
|
||||
render(await lt.api.get(`/api/rack${q.toString() ? `?${q}` : ''}`));
|
||||
} catch (err) {
|
||||
if (_rack) return; // keep the last drawing on a failed refresh
|
||||
document.getElementById('rack').innerHTML = `<div class="lt-empty-state lt-empty-state--sm">
|
||||
@@ -342,7 +385,7 @@ function buildExport() {
|
||||
root.appendChild(svgEl('rect', { width: '100%', height: '100%', fill: '#ffffff' }));
|
||||
const stamp = new Date().toLocaleString();
|
||||
root.appendChild(svgEl('text', { x: pad, y: pad + 14, 'font-size': 18, 'font-weight': 700, fill: '#111' },
|
||||
`${_rack.rack} · front`));
|
||||
`${_rack.rack} · ${_rack.face}`));
|
||||
root.appendChild(svgEl('text', { x: W + gutter + pad, y: pad + 14, 'font-size': 11, fill: '#666', 'text-anchor': 'end' },
|
||||
`Gandalf · ${stamp}`));
|
||||
|
||||
@@ -370,7 +413,7 @@ function buildExport() {
|
||||
const clone = art.cloneNode(true);
|
||||
inlineStyles(art, clone);
|
||||
['x', 'y', 'width', 'height'].forEach((k, i) => clone.setAttribute(k, [x, y, W, h][i]));
|
||||
clone.setAttribute('preserveAspectRatio', art.classList.contains('fp-svg') ? 'none' : 'xMidYMid meet');
|
||||
clone.setAttribute('preserveAspectRatio', art.getAttribute('preserveAspectRatio') || 'xMidYMid meet');
|
||||
clone.removeAttribute('style');
|
||||
root.appendChild(clone);
|
||||
} else if (plate) {
|
||||
@@ -406,7 +449,7 @@ async function exportRack(kind) {
|
||||
return;
|
||||
}
|
||||
const svg = buildExport();
|
||||
const base = `${_rack.rack.replace(/[^\w.-]+/g, '-')}-rack`;
|
||||
const base = `${_rack.rack.replace(/[^\w.-]+/g, '-')}-${_rack.face}`;
|
||||
if (kind === 'svg') {
|
||||
download(new Blob([svg], { type: 'image/svg+xml' }), `${base}.svg`);
|
||||
return;
|
||||
@@ -436,3 +479,55 @@ document.getElementById('rack-show-empty').addEventListener('change', e => {
|
||||
});
|
||||
|
||||
document.querySelectorAll('[data-export]').forEach(btn => btn.addEventListener('click', () => exportRack(btn.dataset.export)));
|
||||
|
||||
// ── Rack settings (admins) ──────────────────────────────────────────────
|
||||
function openRackForm(adding) {
|
||||
const form = document.getElementById('rack-form');
|
||||
form.reset();
|
||||
const r = adding ? null : (_rack.racks.find(x => x.name === _rack.rack) || {});
|
||||
form.id.value = r && r.id ? r.id : '';
|
||||
// The default rack exists only in config until saved; its items follow the new name
|
||||
form.previous.value = r && !r.id ? r.name : '';
|
||||
form.name.value = r ? r.name : '';
|
||||
form.units.value = r ? r.units : 42;
|
||||
form.notes.value = r ? (r.notes || '') : '';
|
||||
form.querySelector('[data-action="delete-rack"]').hidden = !(r && r.id);
|
||||
document.getElementById('rack-modal-title').textContent = adding ? 'Add a rack' : 'Rack settings';
|
||||
lt.modal.open('rack-modal');
|
||||
form.name.focus();
|
||||
}
|
||||
|
||||
async function saveRack(e) {
|
||||
e.preventDefault();
|
||||
const form = e.target;
|
||||
const body = { name: form.name.value.trim(), units: form.units.value, notes: form.notes.value, previous: form.previous.value };
|
||||
try {
|
||||
if (form.id.value) await lt.api.put(`/api/cutsheet/racks/${encodeURIComponent(form.id.value)}`, body);
|
||||
else await lt.api.post('/api/cutsheet/racks', body);
|
||||
lt.modal.close('rack-modal');
|
||||
lt.toast.success('Rack saved');
|
||||
setView({ rack: body.name });
|
||||
} catch (err) {
|
||||
lt.toast.error(err.message || 'Save failed');
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteRack() {
|
||||
const form = document.getElementById('rack-form');
|
||||
if (!form.id.value || !window.confirm(`Delete the rack ${form.name.value}?`)) return;
|
||||
try {
|
||||
await lt.api.delete(`/api/cutsheet/racks/${encodeURIComponent(form.id.value)}`);
|
||||
lt.modal.close('rack-modal');
|
||||
lt.toast.success('Rack deleted');
|
||||
setView({ rack: '' });
|
||||
} catch (err) {
|
||||
lt.toast.error(err.message || 'Delete failed');
|
||||
}
|
||||
}
|
||||
|
||||
if (RACK_CAN_EDIT) {
|
||||
document.querySelector('[data-action="rack-settings"]').addEventListener('click', () => _rack && openRackForm(false));
|
||||
document.querySelector('[data-action="add-rack"]').addEventListener('click', () => _rack && openRackForm(true));
|
||||
document.getElementById('rack-form').addEventListener('submit', saveRack);
|
||||
document.querySelector('[data-action="delete-rack"]').addEventListener('click', deleteRack);
|
||||
}
|
||||
@@ -1515,3 +1515,11 @@ body.fp-marks-off .fp-svg .fp-mark { display: none; }
|
||||
.rack-shelf-thing:hover, .rack-shelf-thing:focus-visible { outline: 2px solid var(--accent-cyan); }
|
||||
.rack-shelf-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
@container (max-height: 50px) { .rack-shelf-label { display: none; } .rack-shelf-thing { font-size: .6rem; gap: 3px; } }
|
||||
.rack-bar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
|
||||
max-width: 1000px; margin: 0 auto 14px; }
|
||||
.rack-bar .rack-tabs { margin: 0 !important; }
|
||||
.rack-face { display: inline-flex; border: 1px solid var(--border-color); border-radius: 3px; overflow: hidden; margin-left: auto; }
|
||||
.rack-face-btn { background: none; border: 0; color: inherit; font: inherit; font-size: .82rem; padding: 6px 14px; cursor: pointer; }
|
||||
.rack-face-btn + .rack-face-btn { border-left: 1px solid var(--border-color); }
|
||||
.rack-face-btn.active { background: var(--accent-cyan-dim); color: var(--accent-cyan); }
|
||||
.rack-back { opacity: .75; background: repeating-linear-gradient(135deg, var(--rk-plate-b) 0 8px, var(--rk-frame) 8px 16px); }
|
||||
Reference in new issue
Block a user