diff --git a/cmd/rollcall/server.go b/cmd/rollcall/server.go index b70b2c7..ec73d6b 100644 --- a/cmd/rollcall/server.go +++ b/cmd/rollcall/server.go @@ -336,10 +336,17 @@ func uiHeaders(next http.Handler) http.Handler { h.Set("X-Content-Type-Options", "nosniff") h.Set("X-Frame-Options", "DENY") h.Set("Referrer-Policy", "no-referrer") + // the files are the binary's: browsers ask each time and get 304 until + // another build runs (FileServer answers If-None-Match from this ETag) + h.Set("Cache-Control", "no-cache") + h.Set("ETag", uiETag) next.ServeHTTP(w, r) }) } +// uiETag: one per build and start (a "dev" build changes without a new version) +var uiETag = fmt.Sprintf(`"%s-%x"`, version, time.Now().Unix()) + // ---------------------------------------------------------------- helpers over inventory JSON type obj = map[string]any diff --git a/cmd/rollcall/server_uietag_test.go b/cmd/rollcall/server_uietag_test.go new file mode 100644 index 0000000..b24373e --- /dev/null +++ b/cmd/rollcall/server_uietag_test.go @@ -0,0 +1,27 @@ +package main + +import ( + "io/fs" + "net/http" + "net/http/httptest" + "testing" +) + +// UI files are revalidated every time and come back 304 while the build is the same +func TestUIRevalidates(t *testing.T) { + h := uiHeaders(http.FileServer(http.FS(mustSub()))) + rec := httptest.NewRecorder() + h.ServeHTTP(rec, httptest.NewRequest("GET", "/room3d.js", nil)) + if rec.Code != 200 || rec.Header().Get("Cache-Control") != "no-cache" || rec.Header().Get("ETag") != uiETag { + t.Fatalf("%d %q %q", rec.Code, rec.Header().Get("Cache-Control"), rec.Header().Get("ETag")) + } + req := httptest.NewRequest("GET", "/room3d.js", nil) + req.Header.Set("If-None-Match", uiETag) + rec = httptest.NewRecorder() + h.ServeHTTP(rec, req) + if rec.Code != http.StatusNotModified { + t.Fatalf("revalidation: %d", rec.Code) + } +} + +func mustSub() fs.FS { sub, _ := fs.Sub(webFS, "web"); return sub } diff --git a/cmd/rollcall/web/fronts.js b/cmd/rollcall/web/fronts.js index 1397786..f11a196 100644 --- a/cmd/rollcall/web/fronts.js +++ b/cmd/rollcall/web/fronts.js @@ -203,3 +203,23 @@ function drawSwitch(count, colors, px = 768) { x.fillStyle = colors.ok; x.beginPath(); x.arc(MM.W - 10, 8, 1.2, 0, 7); x.fill(); return { canvas: c, at }; } + +// drawSwitchFront: the side of a switch towards the cold aisle, at its unit +// on the front rails: its name on a label strip in the switch's colour (the +// colour of its cables), status LEDs and fan grilles, so it reads from the front +function drawSwitchFront(name, color, colors, px = 768) { + const H = MM.U - 1, k = px / MM.W, c = document.createElement('canvas'); + c.width = px; c.height = Math.round(H * k); + const x = c.getContext('2d'); x.scale(k, k); + x.fillStyle = '#1f2226'; x.fillRect(0, 0, MM.W, H); + x.fillStyle = '#3a3e43'; x.fillRect(0, 0, 18, H); x.fillRect(MM.W - 18, 0, 18, H); + x.fillStyle = color; x.fillRect(22, 4, 150, H - 8); // the label strip + x.fillStyle = '#101214'; x.font = '600 22px ui-monospace, Menlo, Consolas, monospace'; x.textBaseline = 'middle'; + const t = name.split('.')[0]; x.fillText(t.length > 14 ? t.slice(0, 13) + '…' : t, 28, H / 2 + 1, 140); + for (let i = 0; i < 4; i++) { x.fillStyle = i ? '#2a2d31' : colors.ok; x.beginPath(); x.arc(186 + i * 7, H / 2, 1.4, 0, 7); x.fill(); } + for (let f = 0; f < 4; f++) { // fans + const cx = MM.W - 50 - f * 40; x.fillStyle = 'rgba(0,0,0,.6)'; x.beginPath(); x.arc(cx, H / 2, 16, 0, 7); x.fill(); + x.strokeStyle = 'rgba(255,255,255,.12)'; x.lineWidth = 0.6; for (let q = 1; q < 4; q++) { x.beginPath(); x.arc(cx, H / 2, q * 4.5, 0, 7); x.stroke(); } + } + return c; +} diff --git a/cmd/rollcall/web/room3d.js b/cmd/rollcall/web/room3d.js index 5d94f44..ef81844 100644 --- a/cmd/rollcall/web/room3d.js +++ b/cmd/rollcall/web/room3d.js @@ -244,7 +244,12 @@ function drawSwitchIn(sw, ra, keep, mat, colorOf) { const edge = new T.LineSegments(keep(new T.EdgesGeometry(m.geometry)), mat('swl' + sw.color, () => new T.LineBasicMaterial({ color: new T.Color(sw.color) }))); edge.position.copy(m.position); m.userData = { rack: ra.r.name, tip: `${sw.name}${sw.role === 'oob' ? ' (out-of-band)' : ''}${sw.model ? ' · ' + sw.model : ''} · ${sw.here} cables here · ${sw.at.estimated ? 'place estimated: ' + (sw.source ? 'no unit' : 'not in NetBox') + ', set it in the panel' : 'U' + sw.at.unit + ' (' + sw.source + ')'}` }; - ra.g.add(m, edge); R3.pick.push(m); + // its front at its unit on the front rails, named, so the switch reads from the cold aisle too + const ftex = keep(new T.CanvasTexture(drawSwitchFront(sw.name, sw.color, colorOf))); ftex.colorSpace = T.SRGBColorSpace; ftex.anisotropy = R3.gl.capabilities.getMaxAnisotropy(); + const fm = keep(new T.MeshStandardMaterial({ map: ftex, emissiveMap: ftex, emissive: 0xffffff, emissiveIntensity: 0.35, roughness: 0.6 })); + const front = new T.Mesh(keep(new T.BoxGeometry(RAIL - 0.001, U_M - 0.004, 0.03)), [side, side, side, side, side, fm]); + front.position.set(0, y, -TILE - 0.006); front.userData = m.userData; + ra.g.add(m, edge, front); R3.pick.push(m, front); sw.y = y; sw.port = name => { const n = switchPortNo(name), p = d.at[n] || d.at['u' + (n % 6)]; return { lx: -RAIL / 2 + RAIL * p.x / MM.W, ly: y + (U_M - 0.004) / 2 - (U_M - 0.004) * p.y / (MM.U - 1) }; }; }