diff options
| author | tv <tv@krebsco.de> | 2026-10-30 19:10:11 +0100 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-10-30 19:10:11 +0100 |
| commit | 7d3d8031d2301f24b32ee08215a8d004fb81493b (patch) | |
| tree | 5435598c930e2fae34feedca524ce55322615f07 /src/api/dashboard/dashboard.html | |
| parent | f5fa9b16fe5505e0058723835d550d73c11391f7 (diff) | |
dashboard: reload new version
Diffstat (limited to 'src/api/dashboard/dashboard.html')
| -rw-r--r-- | src/api/dashboard/dashboard.html | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/api/dashboard/dashboard.html b/src/api/dashboard/dashboard.html index 11e53d2..a5181ca 100644 --- a/src/api/dashboard/dashboard.html +++ b/src/api/dashboard/dashboard.html @@ -113,6 +113,9 @@ </main> <script> "use strict"; +// Which page this is (the node fills it in); a snapshot naming another came from +// another build: reloaded then, to get its page. +const PAGE_VERSION = "__PAGE_VERSION__"; // The state as the node published it, and when it did (the last event). let state = null; let stateAt = 0; @@ -167,11 +170,18 @@ function age(secs) { // What is in focus, its figures shown: a node's ID, or a link's pair key (`pairKey`, // two IDs). null: this node's (`/admin/stats`). -let focused = null; +let focused = (() => { + try { return decodeURIComponent(location.hash.slice(1)) || null; } catch { return null; } +})(); const pairKey = (a, b) => a < b ? a + " " + b : b + " " + a; const isPair = key => key !== null && key.includes(" "); function focus(id) { focused = id === null || id === state.node.id ? null : id; + // In the URL too, so a reload (a new version) keeps it. + try { + history.replaceState(null, "", focused === null ? location.pathname + : "#" + encodeURIComponent(focused)); + } catch { /* not where history works */ } render(); } @@ -536,7 +546,14 @@ let events = null; function connect() { events = new EventSource("dashboard/events"); events.addEventListener("snapshot", event => { - state = JSON.parse(event.data); stateAt = Date.now(); live = true; + const snapshot = JSON.parse(event.data); + if (snapshot.page !== PAGE_VERSION) { + events.close(); + status("new version; reloading…", false); + location.reload(); + return; + } + state = snapshot; stateAt = Date.now(); live = true; status("live", true); render(); }); events.addEventListener("patch", event => { |
