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

+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;
}