diff --git a/README.md b/README.md index c537917..84f3b32 100644 --- a/README.md +++ b/README.md @@ -950,7 +950,7 @@ server's own address most likely runs there, so it needs that server. *Add* writ **Notes and a to-do list.** Every server's page has a *To do* card (the open jobs about it, with a line to add another and a box to tick one off) and a *Notes* card, and every network device a *Notes* button (operators; its drawer shows the device's jobs too), for what is worth remembering: free text with the same small formatting as runbooks (bold, lists, links). **Operations → To do** is a list of the small jobs — "replace the UPS battery", "move the NAS to the new switch" — each with a day it is due, a person it is handed to and a server or device it is about. A job with a day shows in **Coming up**, a job handed to someone in their **My work** (and its badge), and ticking it off, editing and removing it go in the change log. Operators and administrators write, -everyone signed in reads. +everyone signed in reads. The **dashboard** shows every open job in a **To do** card down its right-hand side (beside the attention, since-you-last-looked and getting-started cards on a wide screen, under them on a narrow one): soonest due first, overdue ones in red, a box to tick one off (with an undo) and, for operators, a line to add another; it scrolls when the list is long and is read again every minute. **Photos on a note.** A note can carry up to **12 photos** — the rack as it is, a cable's label, the back of the NAS: *Add photo* on the Notes card (from the camera on a phone, or from the files), a click to see one large (arrow keys move between them), a caption, and *Remove*. The browser makes each one small first (1600 pixels on the long side, as a JPEG — a few hundred kilobytes; a small PNG or a GIF is sent as it is) and draws it again, which also leaves out where the photo was taken. The server takes only a **JPEG, PNG, GIF or WebP, told by the picture's own first bytes** (an SVG, which can carry script, is refused diff --git a/ROLES.md b/ROLES.md index 6d5f43f..47e0f8e 100644 --- a/ROLES.md +++ b/ROLES.md @@ -146,7 +146,7 @@ even further, to admin only: woken up). **Snooze** an alert, wake it, **close** it and open it again need operator, like acknowledging. The storage forecast beside Proxmox storages and Synology volumes is for everyone who can see those pages. - **What changed before this?** (on an incident's page, and `GET /api/v1/incidents/:id/before`): everyone signed in, like the incident record it is made from. - **Dependencies**: everyone can see what needs what (including what needs the Internet); adding and removing one needs operator. So does adding or hiding a *suggested* one. -- **To do and Notes** (Operations → To do, the *To do* and *Notes* cards on a server's page, a device's *Notes* drawer): everyone signed in reads them; adding, editing, ticking off and removing a job, and writing a note, and adding, captioning and removing a photo on one, need operator. +- **To do and Notes** (Operations → To do, the *To do* card on the dashboard, the *To do* and *Notes* cards on a server's page, a device's *Notes* drawer): everyone signed in reads them; adding, editing, ticking off and removing a job, and writing a note, and adding, captioning and removing a photo on one, need operator. - **Racks** (Inventory → Racks) and the **network diagram**: everyone signed in. A rack is made from the hardware's *where* and *rack unit*, which operators edit on the inventory page. - **Proxy hosts** (Network → Proxy hosts): everyone signed in sees what Nginx Proxy Manager serves; **Read now** needs operator; adding the integration (its login) is an administrator's job. - **Home Assistant** (Apps → Home Assistant): everyone signed in sees what is watched, its state and history; choosing what to watch, its limits, stopping and **Read now** need operator (the list of all diff --git a/web/src/components/DashboardTodos.tsx b/web/src/components/DashboardTodos.tsx new file mode 100644 index 0000000..48ea83f --- /dev/null +++ b/web/src/components/DashboardTodos.tsx @@ -0,0 +1,133 @@ +import { useCallback, useEffect, useState, type FormEvent } from "react"; +import { Link } from "react-router-dom"; +import { api, type TodoItem } from "../api/client"; +import { dueWords } from "../pages/Todo"; +import { BlockSkeleton } from "./Skeleton"; +import { refreshMyWork } from "../hooks/useMyWork"; +import { readableError } from "../utils/errors"; +import { toast } from "../utils/toast"; + +/** + * Every open job on the to-do list, soonest due first, beside the cards at the top of the dashboard: a box to tick one off (with an undo) and, for operators, a line to add another. It is the + * same list as the To do page — which has who each is handed to, the details and the finished ones — and is read again every minute, and after anything done here. + */ +export default function DashboardTodos({ canEdit }: { canEdit: boolean }) { + const [jobs, setJobs] = useState(null); + const [failed, setFailed] = useState(false); + const [title, setTitle] = useState(""); + const [due, setDue] = useState(""); + const [busy, setBusy] = useState(false); + + const load = useCallback( + () => + api.todos + .list() + .then((res) => { + setJobs(res.todos.filter((t) => !t.doneAt)); + setFailed(false); + }) + .catch(() => setFailed(true)), + [], + ); + + useEffect(() => { + void load(); + const t = setInterval(() => void load(), 60_000); + return () => clearInterval(t); + }, [load]); + + async function add(e: FormEvent) { + e.preventDefault(); + if (title.trim() === "" || busy) return; + setBusy(true); + try { + await api.todos.create({ title: title.trim(), dueDate: due || null }); + setTitle(""); + setDue(""); + await load(); + refreshMyWork(); + } catch (err) { + toast.error(readableError(err)); + } finally { + setBusy(false); + } + } + + async function tick(t: TodoItem) { + try { + await api.todos.update(t.id, { done: true }); + toast.success(`Done: ${t.title}`, { + label: "Undo", + onClick: async () => { + try { + await api.todos.update(t.id, { done: false }); + } catch (err) { + toast.error(readableError(err)); + } finally { + void load(); + refreshMyWork(); + } + }, + }); + await load(); + refreshMyWork(); + } catch (err) { + toast.error(readableError(err)); + } + } + + return ( +
+
+

To do{jobs && jobs.length > 0 ? ` (${jobs.length})` : ""}

+
+ All jobs +
+
+
+ {failed && jobs === null ? ( +
Couldn’t load the jobs.
+ ) : jobs === null ? ( +
+ +
+ ) : jobs.length === 0 ? ( +
Nothing to do.{canEdit ? " Add a job below." : ""}
+ ) : ( +
    + {jobs.map((t) => { + const d = dueWords(t); + return ( +
  • + void tick(t)} /> +
    +
    {t.title}
    + {t.detail && ( +
    + {t.detail} +
    + )} +
    + {d && {d.text}} + {t.assignee && {t.assignee.name}} + {t.target && {t.target.name}} +
    +
    +
  • + ); + })} +
+ )} +
+ {canEdit && ( +
void add(e)}> + setTitle(e.target.value)} placeholder="Add a job…" aria-label="A job to add" /> + setDue(e.target.value)} aria-label="Due day (optional)" /> + +
+ )} +
+ ); +} diff --git a/web/src/pages/Dashboard.tsx b/web/src/pages/Dashboard.tsx index dc907b1..c490e7a 100644 --- a/web/src/pages/Dashboard.tsx +++ b/web/src/pages/Dashboard.tsx @@ -3,6 +3,7 @@ import { Fragment, isValidElement, useEffect, useState, type ReactNode } from "r import { IconArrowLeft, IconArrowRight, IconEye, IconEyeOff } from "@tabler/icons-react"; import TimeAgo from "../components/TimeAgo"; import WhatChanged from "../components/WhatChanged"; +import DashboardTodos from "../components/DashboardTodos"; import { setProblemsFirst, useProblemsFirst } from "../utils/problemsFirst"; import { UNPLACED, moveCard, resetDashboardLayout, setCardHidden, setEditingDashboard, useDashboardLayout } from "../utils/dashboardLayout"; import { Link } from "react-router-dom"; @@ -730,6 +731,11 @@ export default function Dashboard({ user }: { user: CurrentUser }) {

Welcome back, {user.name ?? user.email ?? user.sub}.

+ + + +
+
{(user.role === "admin" || user.role === "operator") && } @@ -737,6 +743,9 @@ export default function Dashboard({ user }: { user: CurrentUser }) { )}
+
+ +
diff --git a/web/src/styles.css b/web/src/styles.css index 1426abe..5d0681e 100644 --- a/web/src/styles.css +++ b/web/src/styles.css @@ -1986,3 +1986,32 @@ tr.alert-row-child > td:first-child { font-size: 0.875rem; color: var(--tblr-secondary); } + +/* ── The dashboard's right-hand column: the to-do list as tall as the cards beside it (wide screens), a scrolling card of its own under them (narrow ones). ── */ +.dash-side { + min-height: 24rem; +} + +.dash-todos { + max-height: 32rem; + margin-bottom: 1rem; +} + +.dash-todos-list { + flex: 1 1 auto; + min-height: 0; + overflow-y: auto; +} + +@media (min-width: 1200px) { + .dash-side { + position: relative; + } + + .dash-todos { + position: absolute; + inset: 0 calc(var(--tblr-gutter-x, 1.5rem) / 2) 0; + max-height: none; + margin-bottom: 0; + } +}