Add named wall displays: pages, order and speed per screen
An administrator can make named displays (Hall TV, Office monitor) under Settings -> Share links, each with an address of its own (/wall/hall-tv), the pages it rotates through in the board's order, and a rotation speed. The signed-in wall opens one from its address and can switch between them, and a wall share link can open one too. The address still wins over the display's speed, then the browser's choice. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
639408c0d0
commit
333146e8e3
24 files changed
+10411
-22
No files matched your search
@@ -38,6 +38,7 @@ const KIND_OF_CATEGORY: Record<string, ChangeKind> = {
|
||||
user: "settings",
|
||||
push: "settings",
|
||||
share_link: "settings",
|
||||
wall_display: "settings",
|
||||
metrics_token: "settings",
|
||||
api_token: "settings",
|
||||
alert_rule: "alerts",
|
||||
@@ -259,6 +260,12 @@ export function describeChange(category: string, action: string, detail: Record<
|
||||
return { title: `Alert settled${str(detail.message) ? `: ${str(detail.message)}` : ""}`, tone: detail.active === true ? "bad" : "good", detail: detail.active === true ? "steady for an hour, and still active" : "steady for an hour, and cleared" };
|
||||
case "report/send_monthly":
|
||||
return { title: `Monthly report sent${str(detail.month) ? ` (${str(detail.month)})` : ""}`, tone: "neutral", detail: null };
|
||||
case "wall_display/create":
|
||||
return { title: `Wall display added${name ? `: ${name}` : ""}`, tone: "neutral", detail: str(detail.address) };
|
||||
case "wall_display/update":
|
||||
return { title: `Wall display changed${name ? `: ${name}` : ""}`, tone: "neutral", detail: str(detail.address) };
|
||||
case "wall_display/delete":
|
||||
return { title: `Wall display removed${name ? `: ${name}` : ""}`, tone: "neutral", detail: null };
|
||||
case "patch_plan/create":
|
||||
return { title: `Patch plan added${name ? `: ${name}` : ""}`, tone: "neutral", detail: null };
|
||||
case "patch_plan/update":
|
||||
|
||||
@@ -17,7 +17,7 @@ const hash = (token: string) => createHash("sha256").update(token).digest("hex")
|
||||
/** A link isn't recorded as used more than once in this time, so a screen refreshing every few seconds doesn't write the database each time. */
|
||||
const USED_WRITE_GAP_MS = 60_000;
|
||||
|
||||
export async function createShareLink(params: { label: string; detail: ShareLinkDetail; kind?: ShareLinkKind; title?: string | null; message?: string | null; expiresInDays: number | null; createdBy: string; now?: Date }): Promise<{ link: ShareLinkRow; token: string }> {
|
||||
export async function createShareLink(params: { label: string; detail: ShareLinkDetail; kind?: ShareLinkKind; displayId?: number | null; title?: string | null; message?: string | null; expiresInDays: number | null; createdBy: string; now?: Date }): Promise<{ link: ShareLinkRow; token: string }> {
|
||||
const now = params.now ?? new Date();
|
||||
const token = randomBytes(24).toString("base64url");
|
||||
const [link] = await db
|
||||
@@ -28,6 +28,7 @@ export async function createShareLink(params: { label: string; detail: ShareLink
|
||||
tokenPrefix: token.slice(0, 6),
|
||||
detail: params.detail,
|
||||
kind: params.kind ?? "wall",
|
||||
displayId: (params.kind ?? "wall") === "wall" ? (params.displayId ?? null) : null,
|
||||
title: params.title?.trim() || null,
|
||||
message: params.message?.trim() || null,
|
||||
createdBy: params.createdBy,
|
||||
@@ -57,6 +58,7 @@ export function publicShareLink(link: ShareLinkRow, now: Date = new Date()) {
|
||||
tokenPrefix: link.tokenPrefix,
|
||||
detail: link.detail,
|
||||
kind: link.kind,
|
||||
displayId: link.displayId,
|
||||
title: link.title,
|
||||
message: link.message,
|
||||
createdBy: link.createdBy,
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/**
|
||||
* Named wall displays: "Hall TV", "Office monitor", "Rack tablet". Each is a saved choice of which pages the board rotates through (and in which order) and how fast, with an address of its own
|
||||
* (`/wall/hall-tv`) that can be bookmarked on the screen it is for, and a share link can open one too. Nothing about what the board shows changes: a display only chooses among the pages the
|
||||
* board has (the overview, what needs attention, and one for each group of integrations) — see web/src/utils/wallPages.ts.
|
||||
*/
|
||||
import { eq } from "drizzle-orm";
|
||||
import { db } from "../db/client.js";
|
||||
import { wallDisplays } from "../db/schema.js";
|
||||
|
||||
export type WallDisplayRow = typeof wallDisplays.$inferSelect;
|
||||
|
||||
/** More displays than there are screens in a house. */
|
||||
export const MAX_DISPLAYS = 20;
|
||||
export const ROTATE_MIN = 10;
|
||||
export const ROTATE_MAX = 600;
|
||||
|
||||
/** A page of the board: "overview", "alerts", or "group:<id>" for a group of integrations (infrastructure, apps, backups, network, monitoring, automation, other …). */
|
||||
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;
|
||||
|
||||
/** 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 {
|
||||
const folded = name
|
||||
.toLowerCase()
|
||||
.replace(/[åä]/g, "a")
|
||||
.replace(/ö/g, "o")
|
||||
.normalize("NFD")
|
||||
.replace(/[̀-ͯ]/g, "");
|
||||
const slug = folded.replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, MAX_SLUG).replace(/-+$/g, "");
|
||||
return slug || "display";
|
||||
}
|
||||
|
||||
/** Pure: a slug nobody else has, by adding -2, -3 … (the display being edited does not count against itself). */
|
||||
export function freeSlug(wanted: string, taken: Iterable<string>): string {
|
||||
const used = new Set(taken);
|
||||
if (!used.has(wanted)) return wanted;
|
||||
for (let n = 2; ; n++) {
|
||||
const tail = `-${n}`;
|
||||
const candidate = `${wanted.slice(0, MAX_SLUG - tail.length)}${tail}`;
|
||||
if (!used.has(candidate)) return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
/** What is stored for the pages, read back as a list of page ids; anything that is not one is none (which means every page). */
|
||||
export function parsePages(stored: string | null | undefined): string[] {
|
||||
if (!stored) return [];
|
||||
try {
|
||||
const v = JSON.parse(stored);
|
||||
return Array.isArray(v) ? [...new Set(v.filter((p): p is string => typeof p === "string" && PAGE_ID.test(p)))] : [];
|
||||
} catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/** 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 };
|
||||
}
|
||||
|
||||
export async function listDisplays(): Promise<WallDisplayRow[]> {
|
||||
return db.select().from(wallDisplays).orderBy(wallDisplays.name);
|
||||
}
|
||||
|
||||
/** 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> {
|
||||
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;
|
||||
}
|
||||
Reference in new issue
Block a user