3D rooms: switches show from the front; UI files revalidate
Switches stood only at the back of the rack and read as a dark slab from the cold aisle. Each now has a front at its unit on the front rails, with its name on a label in its cable colour, LEDs and fans, and clicks and hovers like the rest of it. The web UI's files carry Cache-Control: no-cache and an ETag per build (and start), so a browser asks each time, gets 304 while nothing changed, and the new files right after a deploy. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7111327dd7
commit
1d41a83f27
4 files changed
+60
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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 }
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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) }; };
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user