diff --git a/cmd/rollcall/web/app.js b/cmd/rollcall/web/app.js index c5222da..02dab8a 100644 --- a/cmd/rollcall/web/app.js +++ b/cmd/rollcall/web/app.js @@ -118,7 +118,7 @@ function render() { const r = route(); $$('.side a[data-nav]').forEach(a => a.classList.toggle('active', a.dataset.nav === r.page || (r.page === 'machine' && a.dataset.nav === 'machines'))); const main = $('#main'); - if (r.page !== 'sites') { main.dataset.view = ''; if (SITE.map) { SITE.map.remove(); SITE.map = null; } SITE.edit = null; } + if (r.page !== 'sites') { main.dataset.view = ''; if (SITE.map) { SITE.map.remove(); SITE.map = null; } SITE.edit = null; room3dStop(); } switch (r.page) { case 'machines': main.innerHTML = pageMachines(); wireMachines(); break; case 'machine': if (!detailCache[r.id]) { main.innerHTML = '
loading…
'; loadDetail(r.id); } else { main.innerHTML = pageMachine(detailCache[r.id], r.tab); wireMachine(detailCache[r.id]); } break; @@ -602,13 +602,14 @@ function wireJobs() { $('#refresh').onclick = () => refresh(true); } // ---------------------------------------------------------------- racks // rackElev: a rack's front, servers spanning their height (shared by the // Racks page and the floor plans in sites.js) -function rackElev(rk) { - const keyOf = (b, rm, n) => `${b}|${rm}|${n}`; +// rackBlocks: a rack's machines as blocks of units. A server spans its height +// (size from the firmware or the model, 1U and !known when unknown); sleds of +// one multi-node chassis share one block. top: the blocks drawn, by top unit; +// a block overlapping one below it is left out and named in clash. +function rackBlocks(rk) { const placed = S.machines.filter(m => m.location && m.location.rack); const lo = x => String(x || '').toLowerCase(); // a rack typed in by hand and the same from NetBox may differ in case const ms = placed.filter(m => lo(m.location.building) === lo(rk.building) && lo(m.location.room) === lo(rk.room) && lo(m.location.rack) === lo(rk.name)); - // blocks of units: a server spans its height (size from the firmware or the - // model, ?U when unknown); sleds of one multi-node chassis share one block const H = rk.height || 42, noU = [], blocks = []; for (const m of ms) { if (!(m.location.unit > 0)) { noU.push(m); continue; } @@ -620,12 +621,19 @@ function rackElev(rk) { blocks.forEach((a, i) => blocks.slice(i + 1).forEach(b => { if (a.unit <= b.unit + b.h - 1 && b.unit <= a.unit + a.h - 1) clash.push(`${a.ms.map(nameOf).join('+')} and ${b.ms.map(nameOf).join('+')} overlap at U${Math.max(a.unit, b.unit)}`); })); const top = {}, covered = new Set(); for (const b of blocks) { const t = Math.min(H, b.unit + b.h - 1); if (top[t] || [...Array(t - b.unit + 1).keys()].some(k => covered.has(b.unit + k))) continue; top[t] = b; for (let u = b.unit; u <= t; u++) covered.add(u); } + return { ms, H, noU, top, covered, clash }; +} +const worstState = ms => ms.map(x => x.state).sort((x, y) => ['bad', 'warn', 'ok', 'idle'].indexOf(stateClass(x)) - ['bad', 'warn', 'ok', 'idle'].indexOf(stateClass(y)))[0]; + +function rackElev(rk) { + const keyOf = (b, rm, n) => `${b}|${rm}|${n}`; + const { ms, H, noU, top, covered, clash } = rackBlocks(rk); let rows = ''; for (let u = H; u >= 1; u--) { rows += `