Wall displays: a night schedule that dims or blanks the board
A named display can dim the board or blank it (so a tablet or computer may sleep) between two times on the screen's own clock. A critical alert brings the board back unless told not to, and a touch or key press brings it back for two minutes. A share link that opens the display follows the same schedule. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
168d01dc7b
commit
a69d0a611d
17 files changed
+9948
-22
No files matched your search
@@ -1596,6 +1596,7 @@ Named wall displays (services/wallDisplays.ts): which pages the board rotates th
|
||||
| `slug` | text NOT NULL, unique | The address: `/wall/<slug>`; lower case letters, digits and single hyphens. Made from the name; kept when the name is changed. |
|
||||
| `pages` | text NOT NULL, default `[]` | JSON: page ids in the order they are shown — `overview`, `alerts`, `group:<id>`; empty = every page the board has. |
|
||||
| `rotate_seconds` | integer | 10–600; null = not set (the address or the browser decides). |
|
||||
| `night_from`, `night_to`, `night_mode`, `night_wake_critical` | text, text, text, bool NOT NULL default 1 | A night schedule on the screen's own clock: `HH:MM` to `HH:MM` (past midnight when `to` is earlier), `dim` or `off`, and whether a critical alert shows the board anyway. Null times = no night. |
|
||||
| `created_by`, `created_at` | | |
|
||||
|
||||
#### `status_items`
|
||||
|
||||
@@ -437,7 +437,7 @@ The Map's second view, **Dependencies**, draws what needs what with the foundati
|
||||
a dependency or a "runs on" link, each with its status). Pick a box and what would go down with it turns red and what it relies on blue,
|
||||
with a sentence underneath — "If it goes down, 4 things go with it: …" — so the answer to "what breaks if I reboot this?" is there before you do it.
|
||||
|
||||
**Named wall displays** (Settings → Share links → *Wall displays*, administrators). One board for every screen is rarely right: the hall TV wants the overview and what needs attention, the office monitor the apps and the network. A display is a **name**, an **address of its own** (`/wall/hall-tv`, made from the name unless you give one — it stays put if you later correct the name, so a bookmark on a screen keeps working), **which pages it rotates through and in what order** (the overview, *Needs attention*, and a page for each group of integrations; none ticked is every page) and **how fast**. A page that has nothing to show just now (*Needs attention* with nothing wrong, a group with no integrations) is left out, and a display none of whose pages exist shows the overview. The signed-in wall opens one from its address and has a *Display* choice in its footer; the footer says which display it is; an unknown address says so and shows everything. How fast is decided by the address (`?rotate=45`) first, then the display, then what this browser last chose. A **wall share link** can open a display too (choose it when making the link): the public board then rotates through that display's pages at its speed; remove the display and the link goes on opening the whole board. Up to twenty displays; each change is in the audit log and the change log. A display only chooses among the board's pages — what the board shows (and, for a share link, how much: numbers only or with names) is unchanged.
|
||||
**Named wall displays** (Settings → Share links → *Wall displays*, administrators). One board for every screen is rarely right: the hall TV wants the overview and what needs attention, the office monitor the apps and the network. A display is a **name**, an **address of its own** (`/wall/hall-tv`, made from the name unless you give one — it stays put if you later correct the name, so a bookmark on a screen keeps working), **which pages it rotates through and in what order** (the overview, *Needs attention*, and a page for each group of integrations; none ticked is every page) and **how fast**. A page that has nothing to show just now (*Needs attention* with nothing wrong, a group with no integrations) is left out, and a display none of whose pages exist shows the overview. The signed-in wall opens one from its address and has a *Display* choice in its footer; the footer says which display it is; an unknown address says so and shows everything. How fast is decided by the address (`?rotate=45`) first, then the display, then what this browser last chose. A **wall share link** can open a display too (choose it when making the link): the public board then rotates through that display's pages at its speed; remove the display and the link goes on opening the whole board. Up to twenty displays; each change is in the audit log and the change log. **A night schedule** can dim or blank a display: from a time to a time on **the screen's own clock** (every day; an end earlier than the start runs past midnight), the board is either **dimmed** (the same picture at about a quarter of its brightness) or **blank** (black, with a faint note; the screen is no longer held awake, so a tablet or computer may go to sleep). A page cannot switch a TV off, so these are the two things it can do. By default **a critical alert brings the board back** whatever the hour (switch that off per display), and **a touch or a key press brings it back for two minutes**. It works the same for a share link that opens the display. A display only chooses among the board's pages — what the board shows (and, for a share link, how much: numbers only or with names) is unchanged.
|
||||
|
||||
**Wall display** (`/wall`, also on the dashboard and the user menu) is a
|
||||
full-screen status board for a spare monitor or tablet: the overall state in
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
ALTER TABLE `wall_displays` ADD `night_from` text;--> statement-breakpoint
|
||||
ALTER TABLE `wall_displays` ADD `night_to` text;--> statement-breakpoint
|
||||
ALTER TABLE `wall_displays` ADD `night_mode` text;--> statement-breakpoint
|
||||
ALTER TABLE `wall_displays` ADD `night_wake_critical` integer DEFAULT true NOT NULL;
|
||||
File diff suppressed because it is too large.
Load diff
@@ -687,6 +687,13 @@
|
||||
"when": 1794521526082,
|
||||
"tag": "0097_duplicati_followups",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 98,
|
||||
"version": "6",
|
||||
"when": 1794522492798,
|
||||
"tag": "0098_wall_display_night",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -857,6 +857,11 @@ export const wallDisplays = sqliteTable("wall_displays", {
|
||||
slug: text("slug").notNull().unique(), // the address: /wall/<slug>
|
||||
pages: text("pages").notNull().default("[]"), // JSON: page ids in order ("overview", "alerts", "group:apps" …); empty = every page the board has
|
||||
rotateSeconds: integer("rotate_seconds"), // how long each page stays; null = not set (the address or the browser decides, else the board does not rotate)
|
||||
// A night schedule on the screen's own clock: from this time to that (HH:MM, and past midnight when "to" is earlier), the board is dimmed or blanked. All null = none.
|
||||
nightFrom: text("night_from"),
|
||||
nightTo: text("night_to"),
|
||||
nightMode: text("night_mode"), // dim | off
|
||||
nightWakeCritical: integer("night_wake_critical", { mode: "boolean" }).notNull().default(true), // show the board again while something is critical
|
||||
createdBy: text("created_by"),
|
||||
createdAt: text("created_at")
|
||||
.notNull()
|
||||
|
||||
@@ -5,7 +5,7 @@ import { db } from "../db/client.js";
|
||||
import { shareLinks, wallDisplays } from "../db/schema.js";
|
||||
import { requireAuth, requireRole } from "../auth/middleware.js";
|
||||
import { recordAudit } from "../services/audit.js";
|
||||
import { freeSlug, listDisplays, MAX_DISPLAYS, MAX_SLUG, PAGE_ID, ROTATE_MAX, ROTATE_MIN, shapeDisplay, SLUG, slugOf } from "../services/wallDisplays.js";
|
||||
import { freeSlug, listDisplays, MAX_DISPLAYS, MAX_SLUG, NIGHT_MODES, PAGE_ID, ROTATE_MAX, ROTATE_MIN, shapeDisplay, SLUG, slugOf, TIME } from "../services/wallDisplays.js";
|
||||
import { asyncHandler } from "../utils/asyncHandler.js";
|
||||
|
||||
export const wallDisplaysRouter = Router();
|
||||
@@ -20,8 +20,22 @@ const displaySchema = z.object({
|
||||
// The pages in the order the board rotates through them; empty is every page it has.
|
||||
pages: z.array(z.string().regex(PAGE_ID, "That is not a page of the board.")).max(20).default([]),
|
||||
rotateSeconds: z.number().int().min(ROTATE_MIN).max(ROTATE_MAX).nullable().default(null),
|
||||
// A night schedule on the screen's own clock, or none. From and to are times of day; "to" earlier than "from" runs past midnight.
|
||||
night: z
|
||||
.object({
|
||||
from: z.string().regex(TIME, "Use a time like 22:00."),
|
||||
to: z.string().regex(TIME, "Use a time like 07:00."),
|
||||
mode: z.enum(NIGHT_MODES),
|
||||
wakeOnCritical: z.boolean().default(true),
|
||||
})
|
||||
.refine((n) => n.from !== n.to, { message: "The night needs a start and an end that differ.", path: ["to"] })
|
||||
.nullable()
|
||||
.default(null),
|
||||
});
|
||||
|
||||
/** The columns a night schedule is kept in. */
|
||||
const nightColumns = (n: z.infer<typeof displaySchema>["night"]) => ({ nightFrom: n?.from ?? null, nightTo: n?.to ?? null, nightMode: n?.mode ?? null, nightWakeCritical: n?.wakeOnCritical ?? true });
|
||||
|
||||
const idOf = (v: string) => (/^\d+$/.test(v) ? Number(v) : NaN);
|
||||
const addressOf = (slug: string) => `/wall/${slug}`;
|
||||
|
||||
@@ -40,7 +54,7 @@ wallDisplaysRouter.post("/", requireRole("admin"), asyncHandler(async (req, res)
|
||||
const actor = req.currentUser!;
|
||||
const [row] = await db
|
||||
.insert(wallDisplays)
|
||||
.values({ name: parsed.data.name, slug, pages: JSON.stringify([...new Set(parsed.data.pages)]), rotateSeconds: parsed.data.rotateSeconds, createdBy: actor.name ?? actor.email ?? actor.oidcSub })
|
||||
.values({ name: parsed.data.name, slug, pages: JSON.stringify([...new Set(parsed.data.pages)]), rotateSeconds: parsed.data.rotateSeconds, ...nightColumns(parsed.data.night), createdBy: actor.name ?? actor.email ?? actor.oidcSub })
|
||||
.returning();
|
||||
await recordAudit({ actor, category: "wall_display", action: "create", targetType: "wall_display", targetId: row.id, detail: { name: row.name, address: addressOf(row.slug) } });
|
||||
res.status(201).json({ display: shapeDisplay(row) });
|
||||
@@ -59,7 +73,7 @@ wallDisplaysRouter.put("/:id", requireRole("admin"), asyncHandler(async (req, re
|
||||
if (all.some((d) => d.id !== id && d.slug === slug)) return res.status(409).json({ error: "slug_taken", message: `Another display already has the address ${addressOf(slug)}.` });
|
||||
const [row] = await db
|
||||
.update(wallDisplays)
|
||||
.set({ name: parsed.data.name, slug, pages: JSON.stringify([...new Set(parsed.data.pages)]), rotateSeconds: parsed.data.rotateSeconds })
|
||||
.set({ name: parsed.data.name, slug, pages: JSON.stringify([...new Set(parsed.data.pages)]), rotateSeconds: parsed.data.rotateSeconds, ...nightColumns(parsed.data.night) })
|
||||
.where(eq(wallDisplays.id, id))
|
||||
.returning();
|
||||
await recordAudit({ actor: req.currentUser!, category: "wall_display", action: "update", targetType: "wall_display", targetId: id, detail: { name: row.name, address: addressOf(row.slug) } });
|
||||
|
||||
@@ -19,6 +19,26 @@ export const PAGE_ID = /^(overview|alerts|group:[a-z0-9-]{1,40})$/;
|
||||
/** The address part of a display: lower case letters, digits and single hyphens. */
|
||||
export const SLUG = /^[a-z0-9]+(-[a-z0-9]+)*$/;
|
||||
export const MAX_SLUG = 40;
|
||||
/** A time of day, 00:00 to 23:59. */
|
||||
export const TIME = /^([01]\d|2[0-3]):[0-5]\d$/;
|
||||
export const NIGHT_MODES = ["dim", "off"] as const;
|
||||
export type NightMode = (typeof NIGHT_MODES)[number];
|
||||
|
||||
export interface Night {
|
||||
from: string;
|
||||
to: string;
|
||||
mode: NightMode;
|
||||
/** Show the board again, whatever the hour, while something is critical. */
|
||||
wakeOnCritical: boolean;
|
||||
}
|
||||
|
||||
/** What is stored of a night schedule, read back as one; none unless all three of its parts are there and make sense. */
|
||||
export function nightOf(row: Pick<WallDisplayRow, "nightFrom" | "nightTo" | "nightMode" | "nightWakeCritical">): Night | null {
|
||||
if (!row.nightFrom || !row.nightTo || !row.nightMode) return null;
|
||||
if (!TIME.test(row.nightFrom) || !TIME.test(row.nightTo) || row.nightFrom === row.nightTo) return null;
|
||||
if (!(NIGHT_MODES as readonly string[]).includes(row.nightMode)) return null;
|
||||
return { from: row.nightFrom, to: row.nightTo, mode: row.nightMode as NightMode, wakeOnCritical: row.nightWakeCritical };
|
||||
}
|
||||
|
||||
/** Pure: a name as an address part — "Hall TV (upstairs)" → "hall-tv-upstairs"; Swedish letters are folded (å, ä → a, ö → o) so the address is plain. */
|
||||
export function slugOf(name: string): string {
|
||||
@@ -56,7 +76,7 @@ export function parsePages(stored: string | null | undefined): string[] {
|
||||
|
||||
/** A display as everyone signed in sees it. */
|
||||
export function shapeDisplay(row: WallDisplayRow) {
|
||||
return { id: row.id, name: row.name, slug: row.slug, pages: parsePages(row.pages), rotateSeconds: row.rotateSeconds, createdBy: row.createdBy, createdAt: row.createdAt };
|
||||
return { id: row.id, name: row.name, slug: row.slug, pages: parsePages(row.pages), rotateSeconds: row.rotateSeconds, night: nightOf(row), createdBy: row.createdBy, createdAt: row.createdAt };
|
||||
}
|
||||
|
||||
export async function listDisplays(): Promise<WallDisplayRow[]> {
|
||||
@@ -64,8 +84,8 @@ export async function listDisplays(): Promise<WallDisplayRow[]> {
|
||||
}
|
||||
|
||||
/** The display a share link points at, as the public board needs it (name, pages, speed) — null when there is none or it was taken away. */
|
||||
export async function displayForLink(displayId: number | null): Promise<{ name: string; pages: string[]; rotateSeconds: number | null } | null> {
|
||||
export async function displayForLink(displayId: number | null): Promise<{ name: string; pages: string[]; rotateSeconds: number | null; night: Night | null } | null> {
|
||||
if (displayId === null) return null;
|
||||
const [row] = await db.select().from(wallDisplays).where(eq(wallDisplays.id, displayId)).limit(1);
|
||||
return row ? { name: row.name, pages: parsePages(row.pages), rotateSeconds: row.rotateSeconds } : null;
|
||||
return row ? { name: row.name, pages: parsePages(row.pages), rotateSeconds: row.rotateSeconds, night: nightOf(row) } : null;
|
||||
}
|
||||
@@ -96,6 +96,49 @@ describe("what a display shows, and how fast", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("the night", () => {
|
||||
const at = (hh: number, mm = 0) => new Date(2026, 10, 10, hh, mm, 0);
|
||||
const night = { from: "22:00", to: "07:00", mode: "dim" as const, wakeOnCritical: true };
|
||||
|
||||
test("a night across midnight is from the start up to, not including, the end; one within a day is plain", () => {
|
||||
assert.equal(P.inNight(at(21, 59), night), false);
|
||||
assert.equal(P.inNight(at(22, 0), night), true);
|
||||
assert.equal(P.inNight(at(23, 59), night), true);
|
||||
assert.equal(P.inNight(at(0, 0), night), true);
|
||||
assert.equal(P.inNight(at(6, 59), night), true);
|
||||
assert.equal(P.inNight(at(7, 0), night), false, "the end is the morning");
|
||||
assert.equal(P.inNight(at(12, 0), night), false);
|
||||
const nap = { from: "13:00", to: "15:30" };
|
||||
assert.deepEqual([at(12, 59), at(13, 0), at(15, 29), at(15, 30)].map((d) => P.inNight(d, nap)), [false, true, true, false]);
|
||||
assert.equal(P.inNight(at(3), { from: "05:00", to: "05:00" }), false, "no length, no night");
|
||||
});
|
||||
|
||||
test("at night it is dimmed or blank; by day, with no schedule, or when something is critical (if told to) it is the board", () => {
|
||||
const quiet = { critical: false, wokenUntil: null };
|
||||
assert.equal(P.nightState(at(12), night, quiet), "day");
|
||||
assert.equal(P.nightState(at(23), night, quiet), "dim");
|
||||
assert.equal(P.nightState(at(23), { ...night, mode: "off" }, quiet), "off");
|
||||
assert.equal(P.nightState(at(23), null, quiet), "day");
|
||||
assert.equal(P.nightState(at(23), undefined, quiet), "day");
|
||||
assert.equal(P.nightState(at(23), night, { critical: true, wokenUntil: null }), "day", "something is critical");
|
||||
assert.equal(P.nightState(at(23), { ...night, mode: "off", wakeOnCritical: false }, { critical: true, wokenUntil: null }), "off", "told not to");
|
||||
});
|
||||
|
||||
test("a touch brings the board back for two minutes, then the night returns", () => {
|
||||
const now = at(23);
|
||||
const touched = now.getTime() + P.WAKE_FOR_MS;
|
||||
assert.equal(P.WAKE_FOR_MS, 120_000);
|
||||
assert.equal(P.nightState(now, night, { critical: false, wokenUntil: touched }), "day");
|
||||
assert.equal(P.nightState(new Date(touched + 1), night, { critical: false, wokenUntil: touched }), "dim");
|
||||
});
|
||||
|
||||
test("what is stored is a night only when all of it is there and makes sense", () => {
|
||||
const row = { nightFrom: "22:00", nightTo: "07:00", nightMode: "off", nightWakeCritical: false };
|
||||
assert.deepEqual(W.nightOf(row), { from: "22:00", to: "07:00", mode: "off", wakeOnCritical: false });
|
||||
for (const bad of [{ nightFrom: null }, { nightTo: null }, { nightMode: null }, { nightFrom: "7:00" }, { nightTo: "24:00" }, { nightMode: "sleep" }, { nightTo: "22:00" }]) assert.equal(W.nightOf({ ...row, ...bad }), null, JSON.stringify(bad));
|
||||
});
|
||||
});
|
||||
|
||||
describe("the routes", () => {
|
||||
let app: Server;
|
||||
let base = "";
|
||||
@@ -184,7 +227,7 @@ describe("the routes", () => {
|
||||
assert.equal(link.displayId, id);
|
||||
|
||||
const board = await (await call("GET", `/public/wall/${token}`)).json();
|
||||
assert.deepEqual(board.displayConfig, { name: "Hall TV", pages: ["overview", "group:apps"], rotateSeconds: 30 });
|
||||
assert.deepEqual(board.displayConfig, { name: "Hall TV", pages: ["overview", "group:apps"], rotateSeconds: 30, night: null });
|
||||
|
||||
// a link with no display says none
|
||||
const plain = (await (await call("POST", "/share-links", { label: "Whole board", kind: "wall", expiresInDays: null })).json()).token;
|
||||
@@ -216,6 +259,33 @@ describe("the routes", () => {
|
||||
assert.equal(describeChange("wall_display", "delete", { name: "Hall TV" }).title, "Wall display removed: Hall TV");
|
||||
});
|
||||
|
||||
test("a display can have a night schedule; it is read back, given to the public board, and taken away by saving without one", async () => {
|
||||
const made = await call("POST", "/wall-displays", { name: "Bedroom", night: { from: "23:00", to: "06:30", mode: "off", wakeOnCritical: false } });
|
||||
assert.equal(made.status, 201);
|
||||
const display = (await made.json()).display;
|
||||
assert.deepEqual(display.night, { from: "23:00", to: "06:30", mode: "off", wakeOnCritical: false });
|
||||
|
||||
const link = await (await call("POST", "/share-links", { label: "Bedroom screen", kind: "wall", displayId: display.id, expiresInDays: null })).json();
|
||||
const board = await (await call("GET", `/public/wall/${link.token}`)).json();
|
||||
assert.deepEqual(board.displayConfig.night, { from: "23:00", to: "06:30", mode: "off", wakeOnCritical: false });
|
||||
|
||||
const without = (await (await call("PUT", `/wall-displays/${display.id}`, { name: "Bedroom" })).json()).display;
|
||||
assert.equal(without.night, null);
|
||||
assert.equal((await (await call("GET", `/public/wall/${link.token}`)).json()).displayConfig.night, null);
|
||||
|
||||
const defaults = (await (await call("PUT", `/wall-displays/${display.id}`, { name: "Bedroom", night: { from: "22:00", to: "07:00", mode: "dim" } })).json()).display;
|
||||
assert.equal(defaults.night.wakeOnCritical, true, "a critical alert brings it back unless it is told not to");
|
||||
await call("DELETE", `/wall-displays/${display.id}`);
|
||||
});
|
||||
|
||||
test("a night needs real times, two that differ, and a way", async () => {
|
||||
const bad = (night: unknown) => call("POST", "/wall-displays", { name: "Nope", night });
|
||||
for (const n of [{ from: "7:00", to: "22:00", mode: "dim" }, { from: "22:00", to: "25:00", mode: "dim" }, { from: "22:00", to: "22:00", mode: "dim" }, { from: "22:00", to: "07:00", mode: "sleep" }, { from: "22:00", to: "07:00" }, { from: "22:00" }, "night"]) {
|
||||
assert.equal((await bad(n)).status, 400, JSON.stringify(n));
|
||||
}
|
||||
assert.match((await (await bad({ from: "22:00", to: "22:00", mode: "dim" })).json()).message, /start and an end that differ/);
|
||||
});
|
||||
|
||||
test("no more than twenty", async () => {
|
||||
for (let i = 0; i < 25; i++) {
|
||||
const r = await call("POST", "/wall-displays", { name: `Screen ${i}` });
|
||||
|
||||
@@ -61,6 +61,8 @@ export interface WallDisplay {
|
||||
slug: string;
|
||||
pages: string[];
|
||||
rotateSeconds: number | null;
|
||||
/** A night schedule on the screen's own clock; null = none. */
|
||||
night: { from: string; to: string; mode: "dim" | "off"; wakeOnCritical: boolean } | null;
|
||||
createdBy: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
@@ -69,6 +71,7 @@ export interface WallDisplayInput {
|
||||
slug?: string;
|
||||
pages: string[];
|
||||
rotateSeconds: number | null;
|
||||
night: { from: string; to: string; mode: "dim" | "off"; wakeOnCritical: boolean } | null;
|
||||
}
|
||||
|
||||
export interface ShareLink {
|
||||
@@ -111,7 +114,7 @@ export interface WallGroup {
|
||||
|
||||
export interface PublicWall {
|
||||
/** The named display this link opens, if any. */
|
||||
displayConfig?: { name: string; pages: string[]; rotateSeconds: number | null } | null;
|
||||
displayConfig?: { name: string; pages: string[]; rotateSeconds: number | null; night: { from: string; to: string; mode: "dim" | "off"; wakeOnCritical: boolean } | null } | null;
|
||||
detail: ShareLinkDetail;
|
||||
level: "ok" | "warning" | "critical" | "unsure";
|
||||
environment: string | null;
|
||||
|
||||
@@ -14,9 +14,21 @@ interface Draft {
|
||||
slug: string;
|
||||
pages: string[];
|
||||
rotateSeconds: number | null;
|
||||
/** A night schedule: switched on, from, to (screen's own clock), how, and whether a critical alert brings the board back. */
|
||||
night: boolean;
|
||||
nightFrom: string;
|
||||
nightTo: string;
|
||||
nightMode: "dim" | "off";
|
||||
nightWake: boolean;
|
||||
}
|
||||
|
||||
const EMPTY: Draft = { id: null, name: "", slug: "", pages: [], rotateSeconds: null };
|
||||
const EMPTY: Draft = { id: null, name: "", slug: "", pages: [], rotateSeconds: null, night: false, nightFrom: "22:00", nightTo: "07:00", nightMode: "dim", nightWake: true };
|
||||
|
||||
/** The night in words: "22:00–07:00, dimmed". */
|
||||
function nightWords(n: WallDisplay["night"]): string {
|
||||
if (!n) return t("none");
|
||||
return `${n.from}–${n.to}, ${n.mode === "dim" ? t("dimmed") : t("blank")}${n.wakeOnCritical ? "" : ` · ${t("even if something is critical")}`}`;
|
||||
}
|
||||
|
||||
/** What a display shows, in words: "every page", or the pages it lists. */
|
||||
function pagesWords(pages: string[]): string {
|
||||
@@ -36,7 +48,7 @@ export default function WallDisplays({ displays, onChanged }: { displays: WallDi
|
||||
const choices = displayPageChoices();
|
||||
|
||||
function edit(d: WallDisplay) {
|
||||
setDraft({ id: d.id, name: d.name, slug: d.slug, pages: d.pages, rotateSeconds: d.rotateSeconds });
|
||||
setDraft({ id: d.id, name: d.name, slug: d.slug, pages: d.pages, rotateSeconds: d.rotateSeconds, night: d.night !== null, nightFrom: d.night?.from ?? "22:00", nightTo: d.night?.to ?? "07:00", nightMode: d.night?.mode ?? "dim", nightWake: d.night?.wakeOnCritical ?? true });
|
||||
setError(null);
|
||||
}
|
||||
|
||||
@@ -54,7 +66,7 @@ export default function WallDisplays({ displays, onChanged }: { displays: WallDi
|
||||
setBusy(true);
|
||||
setError(null);
|
||||
try {
|
||||
const input = { name: draft.name.trim(), slug: draft.slug.trim() || undefined, pages: draft.pages, rotateSeconds: draft.rotateSeconds };
|
||||
const input = { name: draft.name.trim(), slug: draft.slug.trim() || undefined, pages: draft.pages, rotateSeconds: draft.rotateSeconds, night: draft.night ? { from: draft.nightFrom, to: draft.nightTo, mode: draft.nightMode, wakeOnCritical: draft.nightWake } : null };
|
||||
if (draft.id === null) await api.wallDisplays.create(input);
|
||||
else await api.wallDisplays.update(draft.id, input);
|
||||
toast.success(draft.id === null ? t("Added {name}.", { name: draft.name.trim() }) : t("Saved."));
|
||||
@@ -139,8 +151,48 @@ export default function WallDisplays({ displays, onChanged }: { displays: WallDi
|
||||
{t("Tick none for every page the board has. A page only appears while it has something to show: “Needs attention” only while something does, a group only if you have an integration in it.")}
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<label className="form-check mb-2">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.night} onChange={(e) => setDraft({ ...draft, night: e.target.checked })} />
|
||||
<span className="form-check-label">{t("Dim or blank it at night")}</span>
|
||||
</label>
|
||||
{draft.night && (
|
||||
<div className="row g-3 ms-1">
|
||||
<div className="col-sm-3 col-md-2">
|
||||
<label className="form-label" htmlFor="wd-from">
|
||||
{t("From")}
|
||||
</label>
|
||||
<input id="wd-from" type="time" className="form-control" required value={draft.nightFrom} onChange={(e) => setDraft({ ...draft, nightFrom: e.target.value })} />
|
||||
</div>
|
||||
<div className="col-sm-3 col-md-2">
|
||||
<label className="form-label" htmlFor="wd-to">
|
||||
{t("To")}
|
||||
</label>
|
||||
<input id="wd-to" type="time" className="form-control" required value={draft.nightTo} onChange={(e) => setDraft({ ...draft, nightTo: e.target.value })} />
|
||||
</div>
|
||||
<div className="col-sm-6 col-md-4">
|
||||
<label className="form-label" htmlFor="wd-nightmode">
|
||||
{t("At night")}
|
||||
</label>
|
||||
<select id="wd-nightmode" className="form-select" value={draft.nightMode} onChange={(e) => setDraft({ ...draft, nightMode: e.target.value as "dim" | "off" })}>
|
||||
<option value="dim">{t("Dim the board")}</option>
|
||||
<option value="off">{t("Blank the screen (the device may sleep)")}</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="col-12">
|
||||
<label className="form-check mb-1">
|
||||
<input type="checkbox" className="form-check-input" checked={draft.nightWake} onChange={(e) => setDraft({ ...draft, nightWake: e.target.checked })} />
|
||||
<span className="form-check-label">{t("Show the board again while something is critical")}</span>
|
||||
</label>
|
||||
<div className="form-hint text-secondary small">
|
||||
{t("By the clock of the screen itself, every day; an end earlier than the start runs past midnight. A page that cannot switch a TV off can only dim the picture or show black — a blank screen lets a tablet or a computer go to sleep, and a touch or a key brings the board back for two minutes.")}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
<div className="col-12 d-flex gap-2">
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || draft.name.trim() === ""}>
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || draft.name.trim() === "" || (draft.night && draft.nightFrom === draft.nightTo)}>
|
||||
{busy ? t("Saving…") : t("Save")}
|
||||
</button>
|
||||
<button type="button" className="btn" onClick={() => setDraft(null)}>
|
||||
@@ -159,6 +211,7 @@ export default function WallDisplays({ displays, onChanged }: { displays: WallDi
|
||||
<th>{t("Address")}</th>
|
||||
<th>{t("Pages")}</th>
|
||||
<th>{t("Rotates")}</th>
|
||||
<th>{t("Night")}</th>
|
||||
<th className="w-1">{t("Actions")}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -174,6 +227,7 @@ export default function WallDisplays({ displays, onChanged }: { displays: WallDi
|
||||
</td>
|
||||
<td className="text-secondary">{pagesWords(d.pages)}</td>
|
||||
<td className="text-secondary">{d.rotateSeconds === null ? t("not set") : t("every {n} s", { n: d.rotateSeconds })}</td>
|
||||
<td className="text-secondary">{nightWords(d.night)}</td>
|
||||
<td>
|
||||
<div className="btn-list flex-nowrap">
|
||||
<button type="button" className="btn btn-sm" onClick={() => edit(d)}>
|
||||
|
||||
@@ -2,7 +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 { applyDisplay, groupMembers, pageOrOverview, ROTATE_CHOICES, stepPage, wallPages } from "../utils/wallPages";
|
||||
import { applyDisplay, groupMembers, nightState, pageOrOverview, ROTATE_CHOICES, stepPage, WAKE_FOR_MS, wallPages, type WallNight } from "../utils/wallPages";
|
||||
import { t } from "../i18n";
|
||||
|
||||
export const REFRESH_MS = 30_000;
|
||||
@@ -82,9 +82,10 @@ function useClock(): Date {
|
||||
return now;
|
||||
}
|
||||
|
||||
/** Keeps the screen awake while the page is open, where the browser allows it. */
|
||||
function useWakeLock() {
|
||||
/** Keeps the screen awake while the page is open, where the browser allows it — and lets go while `enabled` is false (a blank night screen, so the device may sleep). */
|
||||
function useWakeLock(enabled = true) {
|
||||
useEffect(() => {
|
||||
if (!enabled) return;
|
||||
let lock: { release: () => Promise<void> } | null = null;
|
||||
let gone = false;
|
||||
const request = async () => {
|
||||
@@ -103,7 +104,7 @@ function useWakeLock() {
|
||||
document.removeEventListener("visibilitychange", onVisible);
|
||||
void lock?.release().catch(() => {});
|
||||
};
|
||||
}, []);
|
||||
}, [enabled]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,12 +122,26 @@ export default function WallView({
|
||||
idle: boolean;
|
||||
footerActions: ReactNode;
|
||||
/** A named display: its name (shown in the footer) and which pages it rotates through, in order; none listed is every page. */
|
||||
display?: { name: string; pages: string[] } | null;
|
||||
display?: { name: string; pages: string[]; night?: WallNight | null } | null;
|
||||
/** 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 night: dimmed or blank by the screen's own clock, unless something is critical (and the schedule says to show it) or somebody has just touched the screen.
|
||||
const [wokenUntil, setWokenUntil] = useState<number | null>(null);
|
||||
const night = nightState(now, display?.night, { critical: data.level === "critical", wokenUntil });
|
||||
useWakeLock(night !== "off");
|
||||
useEffect(() => {
|
||||
if (!display?.night) return;
|
||||
const wake = () => setWokenUntil(Date.now() + WAKE_FOR_MS);
|
||||
window.addEventListener("pointerdown", wake);
|
||||
window.addEventListener("keydown", wake);
|
||||
return () => {
|
||||
window.removeEventListener("pointerdown", wake);
|
||||
window.removeEventListener("keydown", wake);
|
||||
};
|
||||
}, [display?.night]);
|
||||
|
||||
// The pages: the overview, what needs attention (while something does), and one for each group of integrations.
|
||||
const rotating = !!rotation && rotation.seconds !== null;
|
||||
@@ -162,7 +177,8 @@ export default function WallView({
|
||||
const showsDetail = data.problems !== null || data.windows !== null || data.integrations !== null;
|
||||
|
||||
return (
|
||||
<div className={`wall ${idle ? "wall-idle" : ""}`} data-bs-theme="dark">
|
||||
<div className={`wall ${idle ? "wall-idle" : ""} ${night !== "day" ? `wall-night-${night}` : ""}`} data-bs-theme="dark" aria-hidden={night === "off" ? true : undefined}>
|
||||
{night === "off" && <div className="wall-night-note">{t("Night — touch the screen to wake it")}</div>}
|
||||
<header className="wall-header">
|
||||
<img src="/logo.webp" alt="Homelab Manager" width={901} height={460} className="wall-logo" />
|
||||
{data.environmentName && <span className="badge env-badge">{data.environmentName}</span>}
|
||||
|
||||
@@ -140,6 +140,7 @@ export const sv: Record<string, string> = {
|
||||
"Apply this server's updates through a Semaphore playbook": "Installera serverns uppdateringar via en Semaphore-playbook",
|
||||
"approved in Semaphore": "godkänd i Semaphore",
|
||||
"Apps": "Appar",
|
||||
"At night": "På natten",
|
||||
"Automation": "Automation",
|
||||
"Awaiting reply": "Väntar på svar",
|
||||
"Awake again.": "Vaken igen.",
|
||||
@@ -153,10 +154,13 @@ export const sv: Record<string, string> = {
|
||||
"Belongs to": "Tillhör",
|
||||
"between {low} and {high}": "mellan {low} och {high}",
|
||||
"Between 5 and 500.": "Mellan 5 och 500.",
|
||||
"blank": "svart",
|
||||
"Blank the screen (the device may sleep)": "Släck skärmen (enheten får sova)",
|
||||
"Blocking is switched off.": "Blockering är avstängd.",
|
||||
"Bound to localhost only — other machines can't connect, but the port is still taken": "Bunden bara till localhost — andra maskiner kan inte ansluta, men porten är ändå upptagen",
|
||||
"breadcrumb": "sökväg",
|
||||
"by {name}": "av {name}",
|
||||
"By the clock of the screen itself, every day; an end earlier than the start runs past midnight. A page that cannot switch a TV off can only dim the picture or show black — a blank screen lets a tablet or a computer go to sleep, and a touch or a key brings the board back for two minutes.": "Efter skärmens egen klocka, varje dag; ett slut som är tidigare än starten går förbi midnatt. En sida kan inte stänga av en TV, bara dämpa bilden eller visa svart — en svart skärm låter en surfplatta eller dator gå i vila, och en tryckning eller tangent tar tillbaka tavlan i två minuter.",
|
||||
"Can’t be read": "Kan inte läsas",
|
||||
"Cancel": "Avbryt",
|
||||
"Cards": "Kort",
|
||||
@@ -216,6 +220,9 @@ export const sv: Record<string, string> = {
|
||||
"Description": "Beskrivning",
|
||||
"Details": "Detaljer",
|
||||
"didn't finish": "blev inte klar",
|
||||
"Dim or blank it at night": "Dämpa eller släck den på natten",
|
||||
"Dim the board": "Dämpa tavlan",
|
||||
"dimmed": "dämpad",
|
||||
"Disable": "Stäng av",
|
||||
"Disabled": "Avstängd",
|
||||
"Disk": "Disk",
|
||||
@@ -246,6 +253,7 @@ export const sv: Record<string, string> = {
|
||||
"Ends": "Slutar",
|
||||
"Ends in": "Slutar om",
|
||||
"Enter a value": "Ange ett värde",
|
||||
"even if something is critical": "även om något är kritiskt",
|
||||
"every {n} s": "var {n} s",
|
||||
"Every alert is live. Start a window above before you work on something, so it doesn't raise alarms while you do.": "Alla larm är aktiva. Starta ett fönster ovan innan du jobbar med något, så att det inte larmar medan du gör det.",
|
||||
"Every container is on its latest image, as far as the last check could tell.": "Alla containrar kör sin senaste avbild, så vitt den senaste kontrollen kunde se.",
|
||||
@@ -273,6 +281,7 @@ export const sv: Record<string, string> = {
|
||||
"First port": "Första port",
|
||||
"Fold the cards you do not need and put the others in the order you like — for every server": "Fäll ihop korten du inte behöver och lägg de andra i den ordning du vill — för alla servrar",
|
||||
"Follow Settings again": "Följ Inställningar igen",
|
||||
"From": "Från",
|
||||
"From now": "Från nu",
|
||||
"full in about {n} days": "full om cirka {n} dagar",
|
||||
"Full screen": "Helskärm",
|
||||
@@ -399,6 +408,8 @@ export const sv: Record<string, string> = {
|
||||
"Next →": "Nästa →",
|
||||
"Next run": "Nästa körning",
|
||||
"Next to expire:": "Nästa som löper ut:",
|
||||
"Night": "Natt",
|
||||
"Night — touch the screen to wake it": "Natt — rör vid skärmen för att väcka den",
|
||||
"No active alerts, but some checks couldn't run": "Inga aktiva larm, men vissa kontroller kunde inte köras",
|
||||
"No active alerts.": "Inga aktiva larm.",
|
||||
"No admin links added yet — e.g. Dockge, Webmin, or Cockpit for this server.": "Inga adminlänkar tillagda än — till exempel Dockge, Webmin eller Cockpit för den här servern.",
|
||||
@@ -428,6 +439,7 @@ export const sv: Record<string, string> = {
|
||||
"No templates found in Semaphore.": "Inga mallar hittades i Semaphore.",
|
||||
"Nobody in particular": "Ingen särskild",
|
||||
"Nobody is on it": "Ingen jobbar med det",
|
||||
"none": "ingen",
|
||||
"Normal": "Normal",
|
||||
"Not a VM? Hide this": "Ingen VM? Dölj det här",
|
||||
"Not checked yet": "Inte kontrollerad än",
|
||||
@@ -602,6 +614,7 @@ export const sv: Record<string, string> = {
|
||||
"Show servers that are": "Visa servrar som är",
|
||||
"Show silenced": "Visa tystade",
|
||||
"Show silenced and grouped": "Visa tystade och grupperade",
|
||||
"Show the board again while something is critical": "Visa tavlan igen medan något är kritiskt",
|
||||
"Show the history": "Visa historiken",
|
||||
"Shutdown": "Stäng av",
|
||||
"Sign in with Authentik": "Logga in med Authentik",
|
||||
@@ -671,6 +684,7 @@ export const sv: Record<string, string> = {
|
||||
"Time in total": "Tid totalt",
|
||||
"Time range": "Tidsperiod",
|
||||
"Title": "Titel",
|
||||
"To": "Till",
|
||||
"To do": "Att göra",
|
||||
"Today": "Idag",
|
||||
"Toggle navigation": "Visa eller dölj menyn",
|
||||
|
||||
@@ -107,7 +107,7 @@ export default function SharedWall() {
|
||||
<WallView
|
||||
data={data}
|
||||
idle={idle}
|
||||
display={displayConfig ? { name: displayConfig.name, pages: displayConfig.pages } : null}
|
||||
display={displayConfig ? { name: displayConfig.name, pages: displayConfig.pages, night: displayConfig.night } : null}
|
||||
rotation={{ seconds: rotation.seconds, onChange: rotation.setSeconds }}
|
||||
footerActions={
|
||||
<button type="button" className="wall-link" onClick={() => void document.documentElement.requestFullscreen?.().catch(() => {})}>
|
||||
|
||||
@@ -104,7 +104,7 @@ export default function Wall() {
|
||||
<WallView
|
||||
data={data}
|
||||
idle={idle}
|
||||
display={display ? { name: display.name, pages: display.pages } : slug && displays !== null ? { name: t("No display called “{slug}” — showing everything", { slug }), pages: [] } : null}
|
||||
display={display ? { name: display.name, pages: display.pages, night: display.night } : slug && displays !== null ? { name: t("No display called “{slug}” — showing everything", { slug }), pages: [] } : null}
|
||||
rotation={{ seconds: rotation.seconds, onChange: rotation.setSeconds }}
|
||||
footerActions={
|
||||
<>
|
||||
|
||||
@@ -2354,3 +2354,26 @@ select,
|
||||
.sparkline-orange { --sparkline-color: var(--tblr-orange); }
|
||||
.sparkline-red { --sparkline-color: var(--tblr-red); }
|
||||
.sparkline-secondary { --sparkline-color: var(--tblr-secondary); }
|
||||
|
||||
/* ── A wall display at night (named displays, night schedule): dimmed, or blank so the screen can sleep ── */
|
||||
.wall-night-dim {
|
||||
filter: brightness(0.28) saturate(0.7);
|
||||
}
|
||||
|
||||
.wall-night-off {
|
||||
background: #000;
|
||||
cursor: none;
|
||||
}
|
||||
|
||||
.wall-night-off > :not(.wall-night-note) {
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
.wall-night-note {
|
||||
position: fixed;
|
||||
inset: auto 0 1.5rem 0;
|
||||
text-align: center;
|
||||
font-size: 0.9rem;
|
||||
color: #e6edf7;
|
||||
opacity: 0.18;
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { IntegrationType } from "../api/client";
|
||||
import { groupOfType, TYPE_GROUPS } from "./integrationTypes";
|
||||
import { } from "../i18n";
|
||||
|
||||
/** One screen of the rotating wall display: the overview, the list of what needs attention, or one group of integrations. */
|
||||
export interface WallPage {
|
||||
@@ -16,6 +17,44 @@ export interface WallPagesInput {
|
||||
integrations: { type: string }[] | null;
|
||||
}
|
||||
|
||||
/** A night schedule: from this time to that on the screen's own clock (past midnight when `to` is earlier), the board is dimmed, or blanked so the screen can sleep. */
|
||||
export interface WallNight {
|
||||
from: string;
|
||||
to: string;
|
||||
mode: "dim" | "off";
|
||||
/** Show the board again, whatever the hour, while something is critical. */
|
||||
wakeOnCritical: boolean;
|
||||
}
|
||||
export type NightState = "day" | "dim" | "off";
|
||||
|
||||
/** How long a touch or a key press brings the board back at night. */
|
||||
export const WAKE_FOR_MS = 2 * 60_000;
|
||||
|
||||
const minutesOf = (hhmm: string): number => {
|
||||
const [h, m] = hhmm.split(":").map(Number);
|
||||
return h * 60 + m;
|
||||
};
|
||||
|
||||
/** Pure: whether a moment (by the clock of the Date it is given, which is the screen's) falls in the night: from the start up to, not including, the end — and across midnight when the end is earlier. */
|
||||
export function inNight(now: Date, night: Pick<WallNight, "from" | "to">): boolean {
|
||||
const t = now.getHours() * 60 + now.getMinutes();
|
||||
const from = minutesOf(night.from);
|
||||
const to = minutesOf(night.to);
|
||||
if (from === to) return false;
|
||||
return from < to ? t >= from && t < to : t >= from || t < to;
|
||||
}
|
||||
|
||||
/**
|
||||
* Pure: what the board should look like now. The day, unless it is night; and at night, unless something is critical and the schedule says to show the board then, or somebody touched the
|
||||
* screen a little while ago (`wokenUntil`, epoch ms). Otherwise the night's way: dimmed, or blank.
|
||||
*/
|
||||
export function nightState(now: Date, night: WallNight | null | undefined, opts: { critical: boolean; wokenUntil: number | null }): NightState {
|
||||
if (!night || !inNight(now, night)) return "day";
|
||||
if (night.wakeOnCritical && opts.critical) return "day";
|
||||
if (opts.wokenUntil !== null && opts.wokenUntil > now.getTime()) return "day";
|
||||
return night.mode;
|
||||
}
|
||||
|
||||
/** The longest and shortest a page may stay, in seconds. */
|
||||
export const ROTATE_MIN = 10;
|
||||
export const ROTATE_MAX = 600;
|
||||
|
||||
Reference in new issue
Block a user