Rooms in 3D: racks at their places and height, servers on their units
CI / agent (push) Successful in 4s
CI / site (push) Successful in 3s
CI / go (push) Successful in 49s

The room page gets a 2D / 3D switch (remembered per browser). The 3D view
draws the floor's 600 mm tiles, each rack at its place, facing and real
height (see-through while it has no place yet), and every server as a block
on the rack's front over its units, coloured by state; the sleds of a
multi-node chassis sit side by side, servers of unknown height are
see-through. Drag turns, right or shift drag moves, wheel or pinch zooms,
a double click brings a rack close; a click selects a rack (same address
and side panel as the floor plan), and a click on a server of the selected
rack opens the machine. The servers in the side panel's elevation now open
their machine on the floor plan page too.

The renderer outlives the 5 s re-render: its canvas moves into the new page
and the scene is rebuilt only when racks, machines, the selection or the
theme changed, so the camera stays where it was. Leaving the page frees the
WebGL context. Racks are still placed in the 2D editor.

three.js 0.160.0 (MIT) is vendored as web/vendor/three/three.module.min.js,
taken from the npm tarball whose sha512 matched the registry's integrity
field, and loaded with import() on first use: nothing is fetched from
outside. rackElev's block placement is split out as rackBlocks so the
elevation and the 3D fronts agree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ilker ManapandClaude Opus 5.5 committed 2026-11-01 08:47:25 +01:00
1 parent 54bda28b82
commit 6da78311f3
7 files changed
+316 -15

No files matched your search

+14 -6
View File
@@ -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 = '<p class="muted">loading…</p>'; 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 += `<div class="u">${u}</div>`;
const b = top[u];
if (b) {
const m = b.ms[0], worst = b.ms.map(x => x.state).sort((x, y) => ['bad', 'warn', 'ok', 'idle'].indexOf(stateClass(x)) - ['bad', 'warn', 'ok', 'idle'].indexOf(stateClass(y)))[0];
const m = b.ms[0], worst = worstState(b.ms);
const span = Math.min(H, b.unit + b.h - 1) - b.unit + 1;
const label = b.node ? `${b.ms.length} node${b.ms.length > 1 ? 's' : ''}: ${b.ms.map(nameOf).join(', ')}` : nameOf(m);
const tip = b.ms.map(x => `${nameOf(x)} · ${x.state} · ${(x.manufacturer || '') + ' ' + (x.product || '')}`).join('\n') + (b.known ? `\n${b.h}U${b.node ? ' chassis' : ''} (${(m.size || {}).source})` : '\nheight unknown: set rack_units for this model');
+1
View File
@@ -52,6 +52,7 @@
<script src="topo.js"></script>
<script src="netview.js"></script>
<script src="sites.js"></script>
<script src="room3d.js"></script>
<script src="app.js"></script>
</body>
</html>
+249
View File
@@ -0,0 +1,249 @@
'use strict';
// A room in 3D (three.js, loaded on first use): the floor's 600 mm tiles,
// racks at their places and real height, each server a block on the rack's
// front at its units, coloured by state, the sleds of one chassis side by
// side. The same data as the floor plan (sites.js); racks are placed in the
// 2D editor. The renderer outlives the page's re-render: its canvas moves
// into the new page and the scene is rebuilt only when what it shows changed.
const R3 = { gl: null, T: null, key: '', sig: '', orb: null, pick: [], trash: [], ctx: null, ro: null, queued: false };
const U_M = 0.04445, TILE = 0.6, PLINTH = 0.1, TOPCAP = 0.08, RAIL = 0.483; // 19" between the rails
const roomView = {
get() { try { return localStorage.getItem('rollcall.roomview') === '3d' ? '3d' : '2d'; } catch (e) { return '2d'; } },
set(v) { try { localStorage.setItem('rollcall.roomview', v); } catch (e) { /* the choice is not kept */ } },
};
function loadThree() {
if (!loadThree.p) loadThree.p = import('./vendor/three/three.module.min.js').catch(e => { loadThree.p = null; throw e; });
return loadThree.p;
}
// room3dStop frees the renderer when no 3D room is shown
function room3dStop() {
if (!R3.gl) return;
clearScene(); R3.gl.dispose(); R3.gl.forceContextLoss(); R3.gl.domElement.remove();
if (R3.ro) R3.ro.disconnect();
Object.assign(R3, { gl: null, key: '', sig: '', orb: null, ro: null });
}
async function room3d(site, roomArg, racks) {
const el = $('#room3d'); if (!el) return;
let T;
try { T = await loadThree(); } catch (e) { el.innerHTML = `<div class="empty">3D did not load: ${esc(e.message)}</div>`; return; }
if (!el.isConnected) return; // the page moved on while loading
if (!R3.gl) {
try { R3.gl = new T.WebGLRenderer({ antialias: true }); } catch (e) {
el.innerHTML = '<div class="empty">This browser has no WebGL: use the 2D floor plan.</div>'; return;
}
R3.T = T; R3.scene = new T.Scene(); R3.camera = new T.PerspectiveCamera(45, 1, 0.05, 1000); R3.ray = new T.Raycaster();
R3.tip = document.createElement('div'); R3.tip.className = 'r3-tip';
R3.gl.setPixelRatio(Math.min(2, window.devicePixelRatio || 1));
controls(R3.gl.domElement);
}
R3.ctx = { site: site.name, roomArg };
el.append(R3.gl.domElement, R3.tip); R3.tip.hidden = true;
if (R3.ro) R3.ro.disconnect();
R3.ro = new ResizeObserver(() => { size(); draw(); }); R3.ro.observe(el);
const room = roomArg === '-' ? '' : roomArg, key = site.name + '|' + lc(room);
const blocks = racks.map(r => rackBlocks(r));
const css = getComputedStyle(document.body);
const sig = JSON.stringify([racks.map((r, i) => [r.name, r.x, r.y, r.facing, r.height, r.auto, Object.values(blocks[i].top).map(b => [b.unit, b.h, b.known, b.ms.map(m => m.id + m.state)])]),
SITE.sel, css.getPropertyValue('--bg'), css.getPropertyValue('--accent')]);
if (key !== R3.key) { R3.key = key; R3.orb = null; }
if (sig !== R3.sig) { build(site, room, racks, blocks); R3.sig = sig; }
if (!R3.orb) fit();
size(); draw();
}
function clearScene() {
for (const x of R3.trash) x.dispose();
R3.trash = []; R3.pick = [];
if (R3.scene) R3.scene.clear();
}
function build(site, room, racks, blocks) {
const T = R3.T, sc = R3.scene;
clearScene();
const keep = x => { R3.trash.push(x); return x; };
const css = getComputedStyle(document.body), cv = n => new T.Color(css.getPropertyValue(n).trim() || '#888888');
sc.background = cv('--bg');
const mats = {}; // one material per colour and look
const mat = (k, make) => mats[k] || (mats[k] = keep(make()));
const stateMat = (cls, known) => mat(cls + known, () => {
const c = cv({ ok: '--ok', warn: '--warn', bad: '--danger' }[cls] || '--muted');
return new T.MeshStandardMaterial({ color: c, emissive: c, emissiveIntensity: 0.25, roughness: 0.55, transparent: !known, opacity: known ? 1 : 0.55 });
});
const lineMat = name => mat('l' + name, () => new T.LineBasicMaterial({ color: cv(name) }));
const box = (w, h, d) => keep(new T.BoxGeometry(w, h, d));
sc.add(new T.HemisphereLight(0xffffff, 0x50555c, 1.7));
const sun = new T.DirectionalLight(0xffffff, 1.3); sun.position.set(-6, 12, 8); sc.add(sun);
// the floor: tiles and the room's outline
const { W, D } = roomSize(site, room, racks);
const floor = new T.Mesh(keep(new T.PlaneGeometry(W * TILE, D * TILE)), mat('floor', () => new T.MeshStandardMaterial({ color: cv('--panel'), roughness: 1 })));
floor.rotation.x = -Math.PI / 2; floor.position.set(W * TILE / 2, 0, D * TILE / 2); sc.add(floor);
const grid = [];
for (let x = 1; x < W; x++) grid.push(x * TILE, 0.001, 0, x * TILE, 0.001, D * TILE);
for (let y = 1; y < D; y++) grid.push(0, 0.001, y * TILE, W * TILE, 0.001, y * TILE);
const lines = (pts, m) => { const g = keep(new T.BufferGeometry()); g.setAttribute('position', new T.Float32BufferAttribute(pts, 3)); return new T.LineSegments(g, m); };
sc.add(lines(grid, lineMat('--line')));
const w = W * TILE, d = D * TILE;
R3.room = { w, d, racks: racks.length ? [Math.min(...racks.map(r => r.x)) * TILE, Math.min(...racks.map(r => r.y)) * TILE,
Math.max(...racks.map(r => r.x + footprint(r).w)) * TILE, Math.max(...racks.map(r => r.y + footprint(r).h)) * TILE] : null };
sc.add(lines([0, 0.002, 0, w, 0.002, 0, w, 0.002, 0, w, 0.002, d, w, 0.002, d, 0, 0.002, d, 0, 0.002, d, 0, 0.002, 0], lineMat('--muted')));
racks.forEach((r, i) => {
const f = footprint(r), g = new T.Group(), H = r.height || 42, h = PLINTH + H * U_M + TOPCAP, sel = SITE.sel === r.name;
g.position.set((r.x + f.w / 2) * TILE, 0, (r.y + f.h / 2) * TILE);
g.rotation.y = { N: 0, S: Math.PI, E: -Math.PI / 2, W: Math.PI / 2 }[r.facing]; // the front is local -z
const st = rackState(site, r);
const body = new T.Mesh(box(TILE - 0.02, h, 2 * TILE - 0.02), mat('rack' + r.auto, () => new T.MeshStandardMaterial({ color: 0x2a2f36, roughness: 0.8, metalness: 0.2, transparent: r.auto, opacity: r.auto ? 0.5 : 1 })));
body.position.y = h / 2;
body.userData = { rack: r.name, tip: `${r.name} · ${st.ms.length} machines · ${st.used}/${H}U used${r.auto ? ' · not placed yet' : ''}` };
const edges = new T.LineSegments(keep(new T.EdgesGeometry(body.geometry)), lineMat(sel ? '--accent' : '--muted'));
edges.position.copy(body.position);
// the rails' face, lighter than the cabinet: where the front is and what is empty
const face = new T.Mesh(box(RAIL, H * U_M, 0.004), mat('face', () => new T.MeshStandardMaterial({ color: 0x3c434c, roughness: 0.9 })));
face.position.set(0, PLINTH + H * U_M / 2, -TILE + 0.008);
g.add(body, edges, face); R3.pick.push(body);
for (const b of Object.values(blocks[i].top)) {
const span = Math.min(H, b.unit + b.h - 1) - b.unit + 1, hh = span * U_M - 0.004, y = PLINTH + (b.unit - 1) * U_M + 0.002 + hh / 2;
const n = b.node ? b.ms.length : 1, sw = RAIL / n;
b.ms.slice(0, n).forEach((m, k) => {
const s = new T.Mesh(box(sw - 0.006, hh, 0.03), stateMat(stateClass(m.state), b.known));
s.position.set(-RAIL / 2 + sw * (k + 0.5), y, -TILE - 0.006);
s.userData = { rack: r.name, id: m.id, tip: `${nameOf(m)} · ${m.state} · U${b.unit}${span > 1 ? '–' + (b.unit + span - 1) : ''}${b.known ? '' : ' (height unknown)'} · ${[m.manufacturer, m.product].filter(Boolean).join(' ')}` };
g.add(s); R3.pick.push(s);
});
}
if (sel) { // the selected rack's footprint, in the accent colour
const p = new T.Mesh(keep(new T.PlaneGeometry(TILE + 0.1, 2 * TILE + 0.1)), mat('selp', () => new T.MeshBasicMaterial({ color: cv('--accent'), transparent: true, opacity: 0.35 })));
p.rotation.x = -Math.PI / 2; p.position.y = 0.003; g.add(p);
}
const label = labelSprite(r.name, css.getPropertyValue(sel ? '--accent' : '--fg').trim(), css.getPropertyValue('--panel').trim());
label.position.y = h + 0.22; g.add(label);
sc.add(g);
});
}
// labelSprite: a rack's name on a pill, drawn over everything so a rack in
// front never hides it
function labelSprite(text, color, bg) {
const T = R3.T, c = document.createElement('canvas'); c.width = 256; c.height = 64;
const x = c.getContext('2d'), t = text.length > 12 ? '…' + text.slice(-11) : text;
x.font = '600 34px ui-monospace, Menlo, Consolas, monospace';
const w = Math.min(248, x.measureText(t).width + 28);
x.globalAlpha = 0.85; x.fillStyle = bg; x.beginPath(); x.roundRect(128 - w / 2, 8, w, 48, 12); x.fill();
x.globalAlpha = 1; x.fillStyle = color; x.textAlign = 'center'; x.textBaseline = 'middle'; x.fillText(t, 128, 33);
const tex = new T.CanvasTexture(c); tex.colorSpace = T.SRGBColorSpace; R3.trash.push(tex);
const m = new T.SpriteMaterial({ map: tex, transparent: true, depthTest: false, depthWrite: false }); R3.trash.push(m);
const s = new T.Sprite(m); s.scale.set(0.9, 0.225, 1); s.renderOrder = 10;
return s;
}
// ---------------------------------------------------------------- camera
// orbit around a target on the floor: theta 0 looks from the south (+z)
// fit: the racks in view (the room when it has none)
function fit() {
const { w, d, racks } = R3.room || { w: 5, d: 4 };
const b = racks || [0, 0, w, d], sw = b[2] - b[0], sd = b[3] - b[1];
R3.orb = { theta: 0.35, phi: 0.95, r: Math.max(sw, sd, 2) * 1.25 + 2.5, t: new R3.T.Vector3((b[0] + b[2]) / 2, 0.8, (b[1] + b[3]) / 2) };
R3.maxR = Math.max(w, d) * 4 + 10;
}
function size() {
const el = R3.gl && R3.gl.domElement.parentElement; if (!el) return;
const w = el.clientWidth, h = el.clientHeight; if (!w || !h) return;
R3.gl.setSize(w, h); R3.camera.aspect = w / h; R3.camera.updateProjectionMatrix();
}
function draw() {
if (R3.queued || !R3.gl) return;
R3.queued = true;
requestAnimationFrame(() => {
R3.queued = false; if (!R3.gl || !R3.orb) return;
const o = R3.orb, c = R3.camera;
c.position.set(o.t.x + o.r * Math.sin(o.phi) * Math.sin(o.theta), o.t.y + o.r * Math.cos(o.phi), o.t.z + o.r * Math.sin(o.phi) * Math.cos(o.theta));
c.lookAt(o.t);
R3.gl.render(R3.scene, c);
});
}
function hitAt(ev) {
const rc = R3.gl.domElement.getBoundingClientRect();
R3.ray.setFromCamera(new R3.T.Vector2((ev.clientX - rc.left) / rc.width * 2 - 1, -(ev.clientY - rc.top) / rc.height * 2 + 1), R3.camera);
const h = R3.ray.intersectObjects(R3.pick, false)[0];
return h ? { ...h.object.userData, point: h.point, obj: h.object } : null;
}
// controls: drag turns, right-drag or shift-drag moves, wheel or pinch zooms;
// a click selects a rack (and on the selected rack's servers opens the
// machine), a double click brings the rack close
function controls(cv) {
const pts = new Map(); let drag = null, hoverQ = false;
const clampPhi = p => Math.min(1.5, Math.max(0.08, p));
const spread = () => { const [a, b] = [...pts.values()]; return Math.hypot(a.x - b.x, a.y - b.y); };
cv.style.touchAction = 'none';
cv.addEventListener('contextmenu', ev => ev.preventDefault());
cv.addEventListener('pointerdown', ev => {
try { cv.setPointerCapture(ev.pointerId); } catch (e) { /* not a live pointer */ }
pts.set(ev.pointerId, { x: ev.clientX, y: ev.clientY });
if (pts.size === 1) drag = { moved: 0, pan: ev.button === 2 || ev.shiftKey || ev.ctrlKey || ev.metaKey, pinch: 0 };
else if (drag) { drag.pinch = spread(); drag.moved = 99; }
R3.tip.hidden = true;
});
cv.addEventListener('pointermove', ev => {
const p = pts.get(ev.pointerId);
if (!p) { // hover: what is under the pointer
if (hoverQ) return; hoverQ = true;
requestAnimationFrame(() => {
hoverQ = false; if (!R3.gl || !R3.orb) return;
const h = hitAt(ev), rc = cv.getBoundingClientRect();
cv.style.cursor = h ? 'pointer' : 'grab';
R3.tip.hidden = !h;
if (h) { R3.tip.textContent = h.tip; R3.tip.style.left = (ev.clientX - rc.left + 14) + 'px'; R3.tip.style.top = (ev.clientY - rc.top + 14) + 'px'; }
});
return;
}
const dx = ev.clientX - p.x, dy = ev.clientY - p.y, o = R3.orb; if (!o) return;
p.x = ev.clientX; p.y = ev.clientY; drag.moved += Math.abs(dx) + Math.abs(dy);
if (pts.size >= 2) { const s = spread(); if (drag.pinch) o.r = Math.min(R3.maxR, Math.max(0.8, o.r * drag.pinch / s)); drag.pinch = s; }
else if (drag.pan) {
const k = o.r * 0.0016, st = Math.sin(o.theta), ct = Math.cos(o.theta);
o.t.x += -ct * dx * k - st * dy * k; o.t.z += st * dx * k - ct * dy * k;
} else { o.theta -= dx * 0.008; o.phi = clampPhi(o.phi - dy * 0.008); }
draw();
});
const up = ev => {
if (!pts.delete(ev.pointerId)) return;
if (pts.size || !drag) return;
const click = drag.moved < 6 && ev.type === 'pointerup' && ev.button === 0; drag = null;
if (!click) return;
const at = { clientX: ev.clientX, clientY: ev.clientY }; // a double click is not two clicks
clearTimeout(R3.clickT); R3.clickT = setTimeout(() => { if (R3.gl) clicked(at); }, 240);
};
cv.addEventListener('pointerup', up); cv.addEventListener('pointercancel', up);
cv.addEventListener('pointerleave', () => { if (!pts.size) R3.tip.hidden = true; });
cv.addEventListener('wheel', ev => {
ev.preventDefault(); const o = R3.orb; if (!o) return;
o.r = Math.min(R3.maxR, Math.max(0.8, o.r * Math.exp(ev.deltaY * 0.0015))); draw();
}, { passive: false });
cv.addEventListener('dblclick', ev => {
clearTimeout(R3.clickT);
const h = hitAt(ev), o = R3.orb; if (!h || !o) return;
const p = new R3.T.Vector3(); h.obj.parent.getWorldPosition(p);
o.t.set(p.x, 1, p.z); o.r = 3.2; draw();
});
}
function clicked(ev) {
const h = hitAt(ev), c = R3.ctx; if (!c) return;
const base = '#/sites/' + encodeURIComponent(c.site) + '/' + encodeURIComponent(c.roomArg);
if (!h) { if (SITE.sel) location.hash = base; return; }
if (h.id && SITE.sel === h.rack) { location.hash = '#/machine/' + h.id; return; }
location.hash = SITE.sel === h.rack ? base : base + '/' + encodeURIComponent(h.rack);
}
function room3dReset() { R3.orb = null; fit(); draw(); }
+22 -9
View File
@@ -177,12 +177,17 @@ function rackState(site, r) {
return { ms, used, worst };
}
// roomSize: the room's floor in tiles, as set or as far as its racks go
function roomSize(site, room, racks) {
const rm = S.rooms.find(r => inSite(site, r.building) && sameRoom(r.name, room)) || {};
return { W: Math.max(rm.width || 0, ...racks.map(r => r.x + footprint(r).w + 1), 8), D: Math.max(rm.depth || 0, ...racks.map(r => r.y + footprint(r).h + 1), 6) };
}
// floorSVG draws the room; opt.mini: a thumbnail for the site page
function floorSVG(site, room, opt = {}) {
const racks = SITE.edit && !opt.mini ? SITE.edit.racks : racksOnFloor(site, room);
const rm = S.rooms.find(r => inSite(site, r.building) && sameRoom(r.name, room)) || {};
const T = opt.mini ? 9 : 40;
const W = Math.max(rm.width || 0, ...racks.map(r => r.x + footprint(r).w + 1), 8), D = Math.max(rm.depth || 0, ...racks.map(r => r.y + footprint(r).h + 1), 6);
const { W, D } = roomSize(site, room, racks);
const o = [`<svg class="floor${opt.mini ? ' mini' : ''}" viewBox="0 0 ${W * T} ${D * T}" width="${W * T}" height="${D * T}"${opt.mini ? ' style="max-width:100%;height:auto"' : ''}>`];
o.push(`<rect class="room" x="0.5" y="0.5" width="${W * T - 1}" height="${D * T - 1}"/>`);
if (!opt.mini) { for (let x = 1; x < W; x++) o.push(`<line class="tile" x1="${x * T}" y1="0" x2="${x * T}" y2="${D * T}"/>`); for (let y = 1; y < D; y++) o.push(`<line class="tile" x1="0" y1="${y * T}" x2="${W * T}" y2="${y * T}"/>`); }
@@ -206,22 +211,31 @@ function pageRoom(siteName, roomArg) {
if (!site) return `<div class="empty">No site ${esc(siteName)}.</div>`;
const room = roomArg === '-' ? '' : roomArg;
const racks = racksOnFloor(site, room);
const autoN = racks.filter(r => r.auto).length;
const autoN = racks.filter(r => r.auto).length, v3 = !SITE.edit && roomView.get() === '3d';
const selRack = racks.find(r => r.name === SITE.sel);
const panel = selRack ? `<div class="card floor-side"><h3>${esc(selRack.name)} <span class="muted">${selRack.height}U · front ${({ N: 'north', S: 'south', E: 'east', W: 'west' })[selRack.facing]}</span></h3>
${SITE.edit ? `<div class="actions" style="margin-bottom:8px"><button class="btn sm" id="rk-rotate">Rotate</button></div>` : ''}
${rackElev(selRack)}</div>`
: `<div class="card floor-side muted">Click a rack for its front.${autoN ? `<br><br>${autoN} rack(s) have no place yet and are laid out automatically (dashed): Edit layout to place them.` : ''}</div>`;
: `<div class="card floor-side muted">Click a rack for its front.${autoN ? `<br><br>${autoN} rack(s) have no place yet and are laid out automatically (${v3 ? 'see-through' : 'dashed'}): Edit layout to place them.` : ''}</div>`;
const legend = v3 ? '<span>drag: turn · right or shift drag: move · wheel: zoom · double click: go to a rack · a click on a selected rack\'s server opens it · see-through: height unknown</span>'
: `<span><b class="lg vacant"></b>empty</span><span>thick edge: the front · bar: units used${SITE.edit ? ' · drag to move, select and Rotate' : ''}</span>`;
return `<div class="page-head"><h1><a href="#/sites" class="muted" style="font-weight:400">Sites</a> / <a href="#/sites/${encodeURIComponent(site.name)}" class="muted" style="font-weight:400">${esc(site.name)}</a> / ${esc(room || '(no room)')}</h1>
<span class="sub">${racks.length} racks · floor tiles of 600 mm</span>
<div class="right">${SITE.edit ? '<button class="btn" id="fl-cancel">Cancel</button><button class="btn" id="fl-auto">Automatic again</button><button class="btn primary" id="fl-save">Save layout</button>' : '<button class="btn" id="fl-edit">Edit layout</button>'}</div></div>
<div class="floor-wrap"><div class="card floor-card">${floorSVG(site, room)}
<div class="legend"><span><b class="lg ok"></b>deployed / ready</span><span><b class="lg warn"></b>busy / new</span><span><b class="lg bad"></b>failed</span><span><b class="lg vacant"></b>empty</span><span>thick edge: the front · bar: units used${SITE.edit ? ' · drag to move, select and Rotate' : ''}</span></div></div>${panel}</div>`;
<div class="right">${SITE.edit ? '<button class="btn" id="fl-cancel">Cancel</button><button class="btn" id="fl-auto">Automatic again</button><button class="btn primary" id="fl-save">Save layout</button>'
: `<span class="seg-btns"><button class="btn${v3 ? '' : ' on'}" data-roomview="2d">2D</button><button class="btn${v3 ? ' on' : ''}" data-roomview="3d">3D</button></span>${v3 ? '<button class="btn" id="r3-reset">Reset view</button>' : ''}<button class="btn" id="fl-edit">Edit layout</button>`}</div></div>
<div class="floor-wrap"><div class="card floor-card">${v3 ? '<div id="room3d" class="room3d"></div>' : floorSVG(site, room)}
<div class="legend"><span><b class="lg ok"></b>deployed / ready</span><span><b class="lg warn"></b>busy / new</span><span><b class="lg bad"></b>failed</span>${legend}</div></div>${panel}</div>`;
}
function wireRoom(siteName, roomArg) {
const site = siteList().find(s => s.name === siteName); if (!site) return;
const room = roomArg === '-' ? '' : roomArg;
$$('[data-roomview]').forEach(b => b.onclick = () => { roomView.set(b.dataset.roomview); render(); });
$$('.floor-side .elev .slot.m').forEach(s => s.onclick = () => { location.hash = '#/machine/' + s.dataset.id; });
const e = $('#fl-edit'); if (e) e.onclick = () => { SITE.edit = { racks: racksOnFloor(site, room).map(r => ({ ...r })) }; render(); };
const rs = $('#r3-reset'); if (rs) rs.onclick = () => room3dReset();
if ($('#room3d')) { room3d(site, roomArg, racksOnFloor(site, room)); return; }
room3dStop();
const svg = $('svg.floor'); if (!svg) return;
// the selected rack is part of the address (#/sites/SITE/ROOM/RACK): a rack can be linked to
$$('svg.floor .rk').forEach(g => g.onclick = () => {
@@ -230,7 +244,6 @@ function wireRoom(siteName, roomArg) {
if (SITE.edit) { SITE.sel = SITE.sel === g.dataset.rack ? '' : g.dataset.rack; render(); return; }
location.hash = SITE.sel === g.dataset.rack ? base : base + '/' + encodeURIComponent(g.dataset.rack);
});
const e = $('#fl-edit'); if (e) e.onclick = () => { SITE.edit = { racks: racksOnFloor(site, room).map(r => ({ ...r })) }; render(); };
const c = $('#fl-cancel'); if (c) c.onclick = () => { SITE.edit = null; render(); };
const save = async (auto) => {
const body = SITE.edit.racks.map(r => {
@@ -272,7 +285,7 @@ function renderSites() {
if (r.arg2) {
if (SITE.edit && SITE.drag) return;
if (!SITE.edit) SITE.sel = r.arg3 ? decodeURIComponent(r.arg3) : ''; main.innerHTML = pageRoom(decodeURIComponent(r.arg), decodeURIComponent(r.arg2)); wireRoom(decodeURIComponent(r.arg), decodeURIComponent(r.arg2)); return; }
SITE.edit = null;
SITE.edit = null; room3dStop();
if (r.arg) { main.innerHTML = pageSite(decodeURIComponent(r.arg)); wireSite(decodeURIComponent(r.arg)); return; }
if (main.dataset.view === 'sites' && refreshSites()) return;
main.innerHTML = pageSites(); main.dataset.view = 'sites'; wireSites();
+3
View File
@@ -234,3 +234,6 @@ svg.floor .rk text { font-size: 9px; fill: var(--fg); pointer-events: none; font
.legend b.lg.warn { background: color-mix(in srgb, var(--warn) 28%, var(--panel)); border-color: var(--warn); }
.legend b.lg.bad { background: color-mix(in srgb, var(--danger) 32%, var(--panel)); border-color: var(--danger); }
.legend b.lg.vacant { background: var(--pill); }
.room3d { position: relative; height: min(72vh, 680px); min-height: 360px; border-radius: 6px; overflow: hidden; }
.room3d canvas { display: block; cursor: grab; } .room3d canvas:active { cursor: grabbing; }
.r3-tip { position: absolute; pointer-events: none; background: var(--panel); border: 1px solid var(--line2); border-radius: 6px; padding: 4px 8px; font-size: 12px; white-space: nowrap; box-shadow: 0 4px 14px rgba(0,0,0,.18); }
+21
View File
@@ -0,0 +1,21 @@
The MIT License
Copyright © 2010-2023 three.js authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
+6
View File
@@ -0,0 +1,6 @@
/**
* @license
* Copyright 2010-2023 Three.js Authors
* SPDX-License-Identifier: MIT
*/
const t="160",e={LEFT:0,MIDDLE:1,RIGHT:2,ROTATE:0,DOLLY:1,PAN:2},n={ROTATE:0,PAN:1,DOLLY_PAN:2,DOLLY_ROTATE:3},i=0,r=1,s=2,a=3,o=0,l=1,c=2,h=3,u=0,d=1,p=2,m=2,f=0,g=1,_=2,v=3,x=4,y=5,M=100,S=101,b=102,E=103,T=104,w=200,A=201,R=202,C=203,P=204,L=205,I=206,U=207,N=208,D=209,O=210,F=211,B=212,z=213,H=214,V=0,k=1,G=2,W=3,X=4,j=5,q=6,Y=7,Z=0,J=1,K=2,$=0,Q=1,tt=2,et=3,nt=4,it=5,rt=6,st="attached",at="detached",ot=300,lt=301,ct=302,ht=303,ut=304,dt=306,pt=1e3,mt=1001,ft=1002,gt=1003,_t=1004,vt=1004,xt=1005,yt=1005,Mt=1006,St=1007,bt=1007,Et=1008,Tt=1008,wt=1009,At=1010,Rt=1011,Ct=1012,Pt=1013,Lt=1014,It=1015,Ut=1016,Nt=1017,Dt=1018,Ot=1020,Ft=1021,Bt=1023,zt=1024,Ht=1025,Vt=1026,kt=1027,Gt=1028,Wt=1029,Xt=1030,jt=1031,qt=1033,Yt=33776,Zt=33777,Jt=33778,Kt=33779,$t=35840,Qt=35841,te=35842,ee=35843,ne=36196,ie=37492,re=37496,se=37808,ae=37809,oe=37810,le=37811,ce=37812,he=37813,ue=37814,de=37815,pe=37816,me=37817,fe=37818,ge=37819,_e=37820,ve=37821,xe=36492,ye=36494,Me=36495,Se=36283,be=36284,Ee=36285,Te=36286,we=2200,Ae=2201,Re=2202,Ce=2300,Pe=2301,Le=2302,Ie=2400,Ue=2401,Ne=2402,De=2500,Oe=2501,Fe=0,Be=1,ze=2,He=3e3,Ve=3001,ke=3200,Ge=3201,We=0,Xe=1,je="",qe="srgb",Ye="srgb-linear",Ze="display-p3",Je="display-p3-linear",Ke="linear",$e="srgb",Qe="rec709",tn="p3",en=0,nn=7680,rn=7681,sn=7682,an=7683,on=34055,ln=34056,cn=5386,hn=512,un=513,dn=514,pn=515,mn=516,fn=517,gn=518,_n=519,vn=512,xn=513,yn=514,Mn=515,Sn=516,bn=517,En=518,Tn=519,wn=35044,An=35048,Rn=35040,Cn=35045,Pn=35049,Ln=35041,In=35046,Un=35050,Nn=35042,Dn="100",On="300 es",Fn=1035,Bn=2e3,zn=2001;class Hn{addEventListener(t,e){void 0===this._listeners&&(this._listeners={});const n=this._listeners;void 0===n[t]&&(n[t]=[]),-1===n[t].indexOf(e)&&n[t].push(e)}hasEventListener(t,e){if(void 0===this._listeners)return!1;const n=this._listeners;return void 0!==n[t]&&-1!==n[t].indexOf(e)}removeEventListener(t,e){if(void 0===this._listeners)return;const n=this._listeners[t];if(void 0!==n){const t=n.indexOf(e);-1!==t&&n.splice(t,1)}}dispatchEvent(t){if(void 0===this._listeners)return;const e=this._listeners[t.type];if(void 0!==e){t.target=this;const n=e.slice(0);for(let e=0,i=n.length;e<i;e++)n[e].call(this,t);t.target=null}}}const Vn=["00","01","02","03","04","05","06","07","08","09","0a","0b","0c","0d","0e","0f","10","11","12","13","14","15","16","17","18","19","1a","1b","1c","1d","1e","1f","20","21","22","23","24","25","26","27","28","29","2a","2b","2c","2d","2e","2f","30","31","32","33","34","35","36","37","38","39","3a","3b","3c","3d","3e","3f","40","41","42","43","44","45","46","47","48","49","4a","4b","4c","4d","4e","4f","50","51","52","53","54","55","56","57","58","59","5a","5b","5c","5d","5e","5f","60","61","62","63","64","65","66","67","68","69","6a","6b","6c","6d","6e","6f","70","71","72","73","74","75","76","77","78","79","7a","7b","7c","7d","7e","7f","80","81","82","83","84","85","86","87","88","89","8a","8b","8c","8d","8e","8f","90","91","92","93","94","95","96","97","98","99","9a","9b","9c","9d","9e","9f","a0","a1","a2","a3","a4","a5","a6","a7","a8","a9","aa","ab","ac","ad","ae","af","b0","b1","b2","b3","b4","b5","b6","b7","b8","b9","ba","bb","bc","bd","be","bf","c0","c1","c2","c3","c4","c5","c6","c7","c8","c9","ca","cb","cc","cd","ce","cf","d0","d1","d2","d3","d4","d5","d6","d7","d8","d9","da","db","dc","dd","de","df","e0","e1","e2","e3","e4","e5","e6","e7","e8","e9","ea","eb","ec","ed","ee","ef","f0","f1","f2","f3","f4","f5","f6","f7","f8","f9","fa","fb","fc","fd","fe","ff"];let kn=1234567;const Gn=Math.PI/180,Wn=180/Math.PI;function Xn(){const t=4294967295*Math.random()|0,e=4294967295*Math.random()|0,n=4294967295*Math.random()|0,i=4294967295*Math.random()|0;return(Vn[255&t]+Vn[t>>8&255]+Vn[t>>16&255]+Vn[t>>24&255]+"-"+Vn[255&e]+Vn[e>>8&255]+"-"+Vn[e>>16&15|64]+Vn[e>>24&255]+"-"+Vn[63&n|128]+Vn[n>>8&255]+"-"+Vn[n>>16&255]+Vn[n>>24&255]+Vn[255&i]+Vn[i>>8&255]+Vn[i>>16&255]+Vn[i>>24&255]).toLowerCase()}function jn(t,e,n){return Math.max(e,Math.min(n,t))}function qn(t,e){return(t%e+e)%e}function Yn(t,e,n){return(1-n)*t+n*e}function Zn(t){return 0==(t&t-1)&&0!==t}function Jn(t){return Math.pow(2,Math.floor(Math.log(t)/Math.LN2))}function Kn(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return t/4294967295;case Uint16Array:return t/65535;case Uint8Array:return t/255;case Int32Array:return Math.max(t/2147483647,-1);case Int16Array:return Math.max(t/32767,-1);case Int8Array:return Math.max(t/127,-1);default:throw new Error("Invalid component type.")}}function $n(t,e){switch(e.constructor){case Float32Array:return t;case Uint32Array:return Math.round(4294967295*t);case Uint16Array:return Math.round(65535*t);case Uint8Array:return Math.round(255*t);case Int32Array:return Math.round(2147483647*t);case Int16Array:return Math.round(32767*t);case Int8Array:return Math.round(127*t);default:throw new Error("Invalid component type.")}}const Qn={DEG2RAD:Gn,RAD2DEG:Wn,generateUUID:Xn,clamp:jn,euclideanModulo:qn,mapLinear:function(t,e,n,i,r){Line truncated