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:
bobbanandClaude Sonnet 5.5 committed 2026-11-13 18:47:53 +01:00
1 parent 168d01dc7b
commit a69d0a611d
17 files changed
+9948 -22

No files matched your search

+5
View File
@@ -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()
+17 -3
View File
@@ -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) } });
+23 -3
View File
@@ -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;
}