From d980c12a0444bab9e60f7b65816de9850e473918 Mon Sep 17 00:00:00 2001 From: Bobban Rydh Date: Sat, 7 Nov 2026 01:44:27 +0100 Subject: [PATCH] Add rotation to the wall display: overview, what needs attention, and one page per group of integrations Co-Authored-By: Claude Sonnet 5.5 --- README.md | 2 + server/test/wallPages.test.ts | 87 +++++++++++++++++ web/src/components/WallView.tsx | 159 ++++++++++++++++++++++++++++++- web/src/hooks/useWallRotation.ts | 41 ++++++++ web/src/pages/SharedWall.tsx | 3 + web/src/pages/Wall.tsx | 3 + web/src/styles.css | 29 ++++++ web/src/utils/wallPages.ts | 78 +++++++++++++++ 8 files changed, 398 insertions(+), 4 deletions(-) create mode 100644 server/test/wallPages.test.ts create mode 100644 web/src/hooks/useWallRotation.ts create mode 100644 web/src/utils/wallPages.ts diff --git a/README.md b/README.md index a422508..6e4e6aa 100644 --- a/README.md +++ b/README.md @@ -444,6 +444,8 @@ the problems themselves, and each integration's status, refreshing every 30 seconds with the screen kept awake where the browser allows. Esc returns to the app. +**Rotating the wall display.** A spare screen can show more than one board: choose **Rotate → every 15 / 30 / 60 / 120 s** in the footer (or open `/wall?rotate=45`; `?rotate=on` is 30 s, `?rotate=off` stops it) and the lower half of the board changes page by page while the status line, the clock and the figures at the top stay put. The pages are the **Overview** (as before), **Needs attention** (the open alerts and what is in maintenance, in full — only while there is something), and one page for each group of the menu that has integrations (Infrastructure, Apps …) listing them, the failing ones first. The footer says which page it is on and **Pause** / **Resume** holds one on screen; the left and right arrow keys step by hand. The choice is in the address, so a TV's bookmark carries it, and this browser remembers the last one chosen on the board itself; without either the wall stays on the overview, as it always was. A share link's wall rotates the same way (add `?rotate=30` to its address) when it shows names; one that shows numbers only has a single page and offers nothing to rotate. + **Alerts folded under their host.** A server can say which server it runs on (a virtual machine on its Proxmox host): on its page, "Runs on" — and left alone it is worked out when the server is linked to a Proxmox guest and exactly one diff --git a/server/test/wallPages.test.ts b/server/test/wallPages.test.ts new file mode 100644 index 0000000..e069c54 --- /dev/null +++ b/server/test/wallPages.test.ts @@ -0,0 +1,87 @@ +import { test } from "node:test"; +import assert from "node:assert/strict"; +import { groupMembers, pageOrOverview, rotateSeconds, ROTATE_DEFAULT, ROTATE_MAX, ROTATE_MIN, stepPage, wallPages } from "../../web/src/utils/wallPages.js"; + +const integ = (type: string, name = type, status = "ok") => ({ id: name, type, name, status }); + +test("the overview is always the first page, and the only one when there is nothing by name", () => { + assert.deepEqual(wallPages({ problems: null, integrations: null }).map((p) => p.id), ["overview"]); + assert.deepEqual(wallPages({ problems: [], integrations: [] }).map((p) => p.id), ["overview"]); +}); + +test("the attention page exists only while something needs attention", () => { + assert.deepEqual(wallPages({ problems: [{}], integrations: [] }).map((p) => p.id), ["overview", "alerts"]); + assert.ok(!wallPages({ problems: [], integrations: [integ("proxmox")] }).some((p) => p.id === "alerts")); +}); + +test("a page for each group that has integrations, in the order of the menu, skipping empty ones", () => { + const pages = wallPages({ problems: [], integrations: [integ("grafana"), integ("proxmox"), integ("jellyfin"), integ("proxmox", "pve2")] }); + assert.deepEqual(pages.map((p) => p.id), ["overview", "group:infrastructure", "group:apps", "group:monitoring"]); + assert.deepEqual(pages.map((p) => p.label), ["Overview", "Infrastructure", "Apps", "Monitoring"]); + assert.equal(pages[1].groupId, "infrastructure"); +}); + +test("a kind in no group gets an Other page last", () => { + const pages = wallPages({ problems: [], integrations: [integ("proxmox"), integ("mystery")] }); + assert.deepEqual(pages.map((p) => p.id), ["overview", "group:infrastructure", "group:other"]); +}); + +test("stepping goes on and wraps round, both ways", () => { + const pages = wallPages({ problems: [{}], integrations: [integ("proxmox")] }); // overview, alerts, infrastructure + assert.equal(stepPage(pages, "overview", 1).id, "alerts"); + assert.equal(stepPage(pages, "group:infrastructure", 1).id, "overview"); + assert.equal(stepPage(pages, "overview", -1).id, "group:infrastructure"); + assert.equal(stepPage(pages, "alerts", -1).id, "overview"); +}); + +test("a page that has gone sends the board to the overview", () => { + const pages = wallPages({ problems: [], integrations: [integ("proxmox")] }); + assert.equal(stepPage(pages, "alerts", 1).id, "overview"); + assert.equal(pageOrOverview(pages, "alerts").id, "overview"); + assert.equal(pageOrOverview(pages, "group:infrastructure").id, "group:infrastructure"); +}); + +test("a board with one page stays on it", () => { + const pages = wallPages({ problems: null, integrations: null }); + assert.equal(stepPage(pages, "overview", 1).id, "overview"); + assert.equal(stepPage(pages, "overview", -1).id, "overview"); +}); + +test("rotation is off unless asked for", () => { + assert.equal(rotateSeconds(null, null), null); + assert.equal(rotateSeconds("", ""), null); +}); + +test("the address says how long each page stays, and beats what the browser remembered", () => { + assert.equal(rotateSeconds("45", "15"), 45); + assert.equal(rotateSeconds("on", null), ROTATE_DEFAULT); + assert.equal(rotateSeconds("true", null), ROTATE_DEFAULT); + assert.equal(rotateSeconds("off", "30"), null); + assert.equal(rotateSeconds("0", "30"), null); +}); + +test("without an address, the browser's last choice is used", () => { + assert.equal(rotateSeconds(null, "60"), 60); + assert.equal(rotateSeconds(null, "off"), null); +}); + +test("a number out of range is brought into it, and anything else means off", () => { + assert.equal(rotateSeconds("2", null), ROTATE_MIN); + assert.equal(rotateSeconds("99999", null), ROTATE_MAX); + assert.equal(rotateSeconds("abc", "30"), null); + assert.equal(rotateSeconds("-5", null), null); + assert.equal(rotateSeconds("1e3", null), null); +}); + +test("a group's page lists the failing ones first, then by name, and only its own", () => { + const list = [integ("proxmox", "pve-b", "ok"), integ("synology", "nas", "failing"), integ("jellyfin", "media"), integ("proxmox", "pve-a", "ok"), integ("tailscale", "ts", "unknown")]; + assert.deepEqual(groupMembers(list, "infrastructure").map((i) => i.name), ["nas", "pve-a", "pve-b", "ts"]); + assert.deepEqual(groupMembers(list, "apps").map((i) => i.name), ["media"]); + assert.deepEqual(groupMembers(list, "backups"), []); +}); + +test("grouping does not change the list it is given", () => { + const list = [integ("proxmox", "b"), integ("proxmox", "a")]; + groupMembers(list, "infrastructure"); + assert.deepEqual(list.map((i) => i.name), ["b", "a"]); +}); diff --git a/web/src/components/WallView.tsx b/web/src/components/WallView.tsx index 456927d..1dcf92f 100644 --- a/web/src/components/WallView.tsx +++ b/web/src/components/WallView.tsx @@ -2,6 +2,7 @@ import { useEffect, useState, type ReactNode } from "react"; import type { WallGroup, WallTile } from "../api/client"; import { formatDate, formatTime } from "../utils/date"; import { formatRemaining } from "../utils/duration"; +import { groupMembers, pageOrOverview, ROTATE_CHOICES, stepPage, wallPages } from "../utils/wallPages"; export const REFRESH_MS = 30_000; @@ -108,9 +109,49 @@ function useWakeLock() { * The board itself: a full-screen status picture in type big enough to read across a room. It only draws what it is given, so the * signed-in wall and the one a share link opens look the same and can't drift apart. */ -export default function WallView({ data, idle, footerActions }: { data: WallData; idle: boolean; footerActions: ReactNode }) { +export default function WallView({ + data, + idle, + footerActions, + rotation, +}: { + data: WallData; + idle: boolean; + footerActions: ReactNode; + /** How the pages rotate (seconds each, null for the overview alone) and how to change it; absent on a board that does not rotate. */ + rotation?: { seconds: number | null; onChange: (seconds: number | null) => void }; +}) { const now = useClock(); useWakeLock(); + + // The pages: the overview, what needs attention (while something does), and one for each group of integrations. + const rotating = !!rotation && rotation.seconds !== null; + const pages = wallPages(data); + const pagesKey = pages.map((p) => p.id).join(","); + const [pageId, setPageId] = useState("overview"); + const [paused, setPaused] = useState(false); + const page = rotating ? pageOrOverview(pages, pageId) : pages[0]; + const seconds = rotation?.seconds ?? null; + useEffect(() => { + if (!rotating || paused || pages.length < 2 || seconds === null) return; + const t = setTimeout(() => setPageId(stepPage(pages, page.id, 1).id), seconds * 1000); + return () => clearTimeout(t); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [rotating, paused, seconds, page.id, pagesKey]); + // The arrow keys step through the pages by hand (and start the wait again). + useEffect(() => { + if (!rotating) return; + const onKey = (e: KeyboardEvent) => { + const el = e.target as HTMLElement | null; + if (el && (el.tagName === "SELECT" || el.tagName === "INPUT")) return; + if (e.key === "ArrowRight") setPageId(stepPage(pages, page.id, 1).id); + else if (e.key === "ArrowLeft") setPageId(stepPage(pages, page.id, -1).id); + }; + window.addEventListener("keydown", onKey); + return () => window.removeEventListener("keydown", onKey); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [rotating, page.id, pagesKey]); + const { level } = data; const offline = data.servers ? data.servers.total - data.servers.online : 0; const alertCount = data.alerts ? data.alerts.critical + data.alerts.warning : 0; @@ -161,7 +202,10 @@ export default function WallView({ data, idle, footerActions }: { data: WallData ))} - {(data.groups ?? []).length > 0 && ( + {page.kind === "alerts" && } + {page.kind === "group" && } + + {page.kind === "overview" && (data.groups ?? []).length > 0 && (
{(data.groups ?? []).map((g) => { const alerts = g.alerts.critical + g.alerts.warning; @@ -177,7 +221,7 @@ export default function WallView({ data, idle, footerActions }: { data: WallData
)} - {showsDetail ? ( + {page.kind !== "overview" ? null : showsDetail ? (
{data.problems && ( @@ -243,9 +287,116 @@ export default function WallView({ data, idle, footerActions }: { data: WallData
{data.updatedAt ? `Updated ${formatTime(data.updatedAt)}` : "Loading…"} · refreshes every {REFRESH_MS / 1000} s + {rotating && pages.length > 1 && ( + p.id === page.id) + 1} of ${pages.length}: ${page.label}`}> + {" "} + · {page.label}{" "} + {pages.map((p) => ( + + ))} + + )} + + + {rotation && pages.length > 1 && ( + <> + + {rotating && pages.length > 1 && ( + + )} + + )} + {footerActions} - {footerActions}
); } + +/** What needs attention, in the whole screen's type: the open alerts, and what is in maintenance. */ +function AlertsPage({ data, now }: { data: WallData; now: Date }) { + const problems = data.problems ?? []; + const alertCount = data.alerts ? data.alerts.critical + data.alerts.warning : problems.length; + const shown = problems.slice(0, 12); + return ( +
+

Needs attention

+
    + {shown.map((a) => ( +
  • + {a.severity}: + {a.message} +
  • + ))} + {alertCount > shown.length &&
  • and {alertCount - shown.length} more
  • } +
+ {data.windows && data.windows.length > 0 && ( + <> +

In maintenance

+
    + {data.windows.slice(0, 8).map((w) => ( +
  • + {w.name} · {formatRemaining(w.endsAt, now.getTime())} left +
  • + ))} +
+ + )} +
+ ); +} + +/** One group of integrations (Infrastructure, Apps …): how it is, and each of them with its status. */ +function GroupPage({ data, groupId, label }: { data: WallData; groupId: string; label: string }) { + const members = groupMembers(data.integrations ?? [], groupId); + const summary = (data.groups ?? []).find((g) => g.id === groupId); + const alerts = summary ? summary.alerts.critical + summary.alerts.warning : 0; + const failing = members.filter((m) => m.status === "failing").length; + const level = failing > 0 || (summary?.alerts.critical ?? 0) > 0 ? "bad" : alerts > 0 ? "warn" : "ok"; + return ( +
+

+ {label}{" "} + + {" "} + {failing > 0 ? `${failing} of ${members.length} failing` : `${members.length} connected`} + {alerts > 0 ? ` · ${alerts} ${alerts === 1 ? "alert" : "alerts"}` : ""} + +

+
    + {members.map((i) => ( +
  • + {i.name}{" "} + + {TYPE_LABELS[i.type] ?? i.type} — {i.status === "failing" ? "failing" : i.status === "ok" ? "working" : "not checked yet"} + +
  • + ))} +
+
+ ); +} diff --git a/web/src/hooks/useWallRotation.ts b/web/src/hooks/useWallRotation.ts new file mode 100644 index 0000000..53590c0 --- /dev/null +++ b/web/src/hooks/useWallRotation.ts @@ -0,0 +1,41 @@ +import { useCallback } from "react"; +import { useSearchParams } from "react-router-dom"; +import { rotateSeconds } from "../utils/wallPages"; + +const KEY = "wall.rotate"; + +function stored(): string | null { + try { + return localStorage.getItem(KEY); + } catch { + return null; + } +} + +/** + * How the wall display rotates: how many seconds each page stays, or null for the overview alone. It lives in the address (`?rotate=30`), + * so a TV's bookmark carries it, and this browser remembers the last choice made on the board itself. + */ +export function useWallRotation() { + const [params, setParams] = useSearchParams(); + const seconds = rotateSeconds(params.get("rotate"), stored()); + const setSeconds = useCallback( + (next: number | null) => { + try { + localStorage.setItem(KEY, next === null ? "off" : String(next)); + } catch { + /* a private window: the address alone carries it */ + } + setParams( + (prev) => { + const p = new URLSearchParams(prev); + p.set("rotate", next === null ? "off" : String(next)); + return p; + }, + { replace: true }, + ); + }, + [setParams], + ); + return { seconds, setSeconds }; +} diff --git a/web/src/pages/SharedWall.tsx b/web/src/pages/SharedWall.tsx index a9ed9b7..926364a 100644 --- a/web/src/pages/SharedWall.tsx +++ b/web/src/pages/SharedWall.tsx @@ -3,6 +3,7 @@ import { useParams } from "react-router-dom"; import { api, type PublicWall } from "../api/client"; import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView"; import { setDateTimeSettings } from "../utils/date"; +import { useWallRotation } from "../hooks/useWallRotation"; /** * The wall display behind a share link: the same board, read-only and without signing in. The address carries the secret, and the @@ -15,6 +16,7 @@ export default function SharedWall() { const [state, setState] = useState<"loading" | "ok" | "dead" | "unreachable">("loading"); const [updatedAt, setUpdatedAt] = useState(null); const [idle, setIdle] = useState(false); + const rotation = useWallRotation(); useEffect(() => { let alive = true; @@ -101,6 +103,7 @@ export default function SharedWall() { void document.documentElement.requestFullscreen?.().catch(() => {})}> Full screen diff --git a/web/src/pages/Wall.tsx b/web/src/pages/Wall.tsx index 9c14aab..9682e74 100644 --- a/web/src/pages/Wall.tsx +++ b/web/src/pages/Wall.tsx @@ -3,6 +3,7 @@ import { Link, useNavigate } from "react-router-dom"; import { api, type IntegrationSummary, type MaintenanceWindow, type ServerSummary, type WallGroup, type WallTile } from "../api/client"; import { alertBadge, useAlertsReport } from "../hooks/useAlertsReport"; import { useEnvironment } from "../utils/environment"; +import { useWallRotation } from "../hooks/useWallRotation"; import WallView, { REFRESH_MS, wallHeadline, type WallData } from "../components/WallView"; /** @@ -19,6 +20,7 @@ export default function Wall() { const [extras, setExtras] = useState<{ tiles: WallTile[]; groups: WallGroup[] } | null>(null); const [updatedAt, setUpdatedAt] = useState(null); const [idle, setIdle] = useState(false); + const rotation = useWallRotation(); useEffect(() => { let alive = true; @@ -91,6 +93,7 @@ export default function Wall() {