A To do card on server pages and in a device's drawer
- The open jobs about a server (or device) are listed on its page, with a line to add another already about it and a box to tick one off with Undo - GET /api/todos takes ?targetType=&targetId= to list only those about one thing - README and ROLES updated Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
18ceed62e8
commit
788b3e073c
10 files changed
+164
-9
No files matched your search
@@ -861,7 +861,7 @@ support has ended, a note while it is only coming. The dates are a static table
|
||||
**Suggested dependencies.** Under **Map → Dependencies**, a *Suggested* card offers what the app can work out without being told: a service (Gitea, Semaphore, Uptime Kuma, phpIPAM, Home Assistant…) that is reached at a
|
||||
server's own address most likely runs there, so it needs that server. *Add* writes it as an ordinary dependency; *Not that* hides the suggestion (*Show the N you said no to* brings them back). Nothing is written until you add it.
|
||||
|
||||
**Notes and a to-do list.** Every server's page has a *Notes* card, and every network device a *Notes* button (operators), for what is worth remembering: free text with the same small formatting as runbooks
|
||||
**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.
|
||||
|
||||
@@ -105,7 +105,7 @@ even further, to admin only:
|
||||
- **Network devices** (Network → Network devices): everyone can see the devices, networks and Wi-Fi names read from UniFi controllers; **Read now** and putting a device under maintenance need operator; adding the UniFi
|
||||
integration itself (a key or login) is an administrator's job, like any integration.
|
||||
- **Dependencies**: everyone can see what needs what; adding and removing one needs operator. So does adding or hiding a *suggested* one.
|
||||
- **To do and Notes** (Operations → To do, a server's *Notes*, a device's *Notes*): everyone signed in reads them; adding, editing, ticking off and removing a job, and writing a note, need operator.
|
||||
- **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, 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** (Monitoring → 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
|
||||
|
||||
@@ -22,8 +22,11 @@ const fields = {
|
||||
targetId: z.number().int().positive().nullable().optional(),
|
||||
};
|
||||
|
||||
todosRouter.get("/", asyncHandler(async (_req, res) => {
|
||||
res.json({ todos: await listTodos(), people: await assignableUsers() });
|
||||
// `?targetType=server&targetId=3` lists only the jobs about that one (a server's page shows its own).
|
||||
todosRouter.get("/", asyncHandler(async (req, res) => {
|
||||
const type = TARGET_TYPES.find((t) => t === req.query.targetType);
|
||||
const id = /^\d+$/.test(String(req.query.targetId ?? "")) ? Number(req.query.targetId) : NaN;
|
||||
res.json({ todos: await listTodos(type && Number.isInteger(id) ? { type, id } : undefined), people: await assignableUsers() });
|
||||
}));
|
||||
|
||||
todosRouter.post("/", requireRole("operator"), asyncHandler(async (req, res) => {
|
||||
|
||||
@@ -68,10 +68,11 @@ async function shape(rows: Row[]): Promise<TodoItem[]> {
|
||||
}
|
||||
|
||||
/** Open ones first, the soonest due first (those with no day last); done ones after, the latest done first. */
|
||||
export async function listTodos(): Promise<TodoItem[]> {
|
||||
const open = await shape(await db.select().from(todos).where(isNull(todos.doneAt)));
|
||||
export async function listTodos(about?: { type: TargetType; id: number }): Promise<TodoItem[]> {
|
||||
const only = about ? and(eq(todos.targetType, about.type), eq(todos.targetId, about.id)) : undefined;
|
||||
const open = await shape(await db.select().from(todos).where(and(isNull(todos.doneAt), only)));
|
||||
open.sort((a, b) => (a.dueDate ?? "9999-99-99").localeCompare(b.dueDate ?? "9999-99-99") || a.createdAt.localeCompare(b.createdAt) || a.id - b.id);
|
||||
const done = await shape(await db.select().from(todos).where(isNotNull(todos.doneAt)).orderBy(desc(todos.doneAt)).limit(200));
|
||||
const done = await shape(await db.select().from(todos).where(and(isNotNull(todos.doneAt), only)).orderBy(desc(todos.doneAt)).limit(200));
|
||||
return [...open, ...done];
|
||||
}
|
||||
|
||||
|
||||
@@ -115,6 +115,13 @@ describe("the to-do list", () => {
|
||||
assert.equal(back.body.todo.doneAt, null);
|
||||
});
|
||||
|
||||
test("a server's page asks for just the jobs about it", async () => {
|
||||
const mine = (await send("GET", `/todos?targetType=server&targetId=${ids.web}`)).body.todos.map((t: any) => t.title);
|
||||
assert.deepEqual(mine, ["Replace the UPS battery"], "the two with nothing to do with it are left out");
|
||||
assert.equal((await send("GET", `/todos?targetType=server&targetId=999999`)).body.todos.length, 0);
|
||||
assert.equal((await send("GET", `/todos?targetType=bogus&targetId=${ids.web}`)).body.todos.length >= 3, true, "an unknown kind is no filter");
|
||||
});
|
||||
|
||||
test("a job can be changed, and removed; one that is not there is a 404", async () => {
|
||||
const changed = await send("PATCH", `/todos/${jobId}`, { title: "Replace the UPS battery (APC)", dueDate: null, assigneeId: null });
|
||||
assert.deepEqual([changed.body.todo.title, changed.body.todo.dueDate, changed.body.todo.assignee], ["Replace the UPS battery (APC)", null, null]);
|
||||
|
||||
@@ -2388,7 +2388,8 @@ export const api = {
|
||||
get: () => request<MyWork>("/api/my-work"),
|
||||
},
|
||||
todos: {
|
||||
list: () => request<{ todos: TodoItem[]; people: { id: number; name: string; role: string }[] }>("/api/todos"),
|
||||
list: (about?: { type: "server" | "device"; id: number }) =>
|
||||
request<{ todos: TodoItem[]; people: { id: number; name: string; role: string }[] }>(`/api/todos${about ? `?targetType=${about.type}&targetId=${about.id}` : ""}`),
|
||||
create: (data: TodoInput) => request<{ todo: TodoItem }>("/api/todos", { method: "POST", body: JSON.stringify(data) }),
|
||||
update: (id: number, data: Partial<TodoInput> & { done?: boolean }) => request<{ todo: TodoItem }>(`/api/todos/${id}`, { method: "PATCH", body: JSON.stringify(data) }),
|
||||
remove: (id: number) => request<void>(`/api/todos/${id}`, { method: "DELETE" }),
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
import { useCallback, useEffect, useState } 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";
|
||||
|
||||
/**
|
||||
* The open jobs on the to-do list that are about this server or device, with a box to tick one off and (for operators) a line to add another that is already about it.
|
||||
* The full list, with who each is handed to and the finished ones, is on the To do page.
|
||||
*/
|
||||
export default function TodosCard({ targetType, targetId, canEdit, bare = false }: { targetType: "server" | "device"; targetId: number; canEdit: boolean; /** Without the card round it (inside a drawer). */ bare?: boolean }) {
|
||||
const [jobs, setJobs] = useState<TodoItem[] | null>(null);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const [title, setTitle] = useState("");
|
||||
const [due, setDue] = useState("");
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
const load = useCallback(() => {
|
||||
return api.todos
|
||||
.list({ type: targetType, id: targetId })
|
||||
.then((res) => {
|
||||
setJobs(res.todos.filter((t) => !t.doneAt));
|
||||
setFailed(false);
|
||||
})
|
||||
.catch(() => setFailed(true));
|
||||
}, [targetType, targetId]);
|
||||
|
||||
useEffect(() => {
|
||||
setJobs(null);
|
||||
void load();
|
||||
}, [load]);
|
||||
|
||||
async function add(e: React.FormEvent) {
|
||||
e.preventDefault();
|
||||
if (title.trim() === "") return;
|
||||
setBusy(true);
|
||||
try {
|
||||
await api.todos.create({ title: title.trim(), dueDate: due || null, targetType, targetId });
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
const content = (
|
||||
<>
|
||||
{failed ? (
|
||||
<div className="text-secondary">Couldn’t load the jobs.</div>
|
||||
) : jobs === null ? (
|
||||
<BlockSkeleton lines={2} />
|
||||
) : jobs.length === 0 ? (
|
||||
<div className="text-secondary">Nothing to do about this.</div>
|
||||
) : (
|
||||
<ul className="list-group list-group-flush mb-2">
|
||||
{jobs.map((t) => {
|
||||
const d = dueWords(t);
|
||||
return (
|
||||
<li key={t.id} className="list-group-item px-0 d-flex gap-3 align-items-start">
|
||||
<input type="checkbox" className="form-check-input mt-1" aria-label={`Done: ${t.title}`} disabled={!canEdit} checked={false} onChange={() => void tick(t)} />
|
||||
<div className="me-auto">
|
||||
<div className="fw-bold">{t.title}</div>
|
||||
{t.detail && (
|
||||
<div className="text-secondary small" style={{ whiteSpace: "pre-wrap" }}>
|
||||
{t.detail}
|
||||
</div>
|
||||
)}
|
||||
<div className="small d-flex flex-wrap gap-2 mt-1">
|
||||
{d && <span className={d.className}>{d.text}</span>}
|
||||
{t.assignee && <span className="badge bg-blue-lt text-blue">{t.assignee.name}</span>}
|
||||
</div>
|
||||
</div>
|
||||
</li>
|
||||
);
|
||||
})}
|
||||
</ul>
|
||||
)}
|
||||
{canEdit && (
|
||||
<form className="d-flex flex-wrap gap-2" onSubmit={(e) => void add(e)}>
|
||||
<input className="form-control flex-fill" style={{ minWidth: "12rem", width: "auto" }} maxLength={160} value={title} onChange={(e) => setTitle(e.target.value)} placeholder="Add a job about this…" aria-label="A job about this" />
|
||||
<input type="date" className="form-control w-auto" value={due} onChange={(e) => setDue(e.target.value)} aria-label="Due day (optional)" />
|
||||
<button type="submit" className="btn btn-primary" disabled={busy || title.trim() === ""}>
|
||||
Add
|
||||
</button>
|
||||
</form>
|
||||
)}
|
||||
<div className="small mt-2">
|
||||
<Link to="/todo">All jobs</Link>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
|
||||
if (bare)
|
||||
return (
|
||||
<>
|
||||
<h4 className="mb-2">To do</h4>
|
||||
{content}
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
<h3 className="card-title">To do{jobs && jobs.length > 0 ? ` (${jobs.length})` : ""}</h3>
|
||||
</div>
|
||||
<div className="card-body">{content}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import SilenceButton from "../components/SilenceButton";
|
||||
import RunbookEntry from "../components/RunbookEntry";
|
||||
import NetworkDiagram from "../components/NetworkDiagram";
|
||||
import NotesCard from "../components/NotesCard";
|
||||
import TodosCard from "../components/TodosCard";
|
||||
import DetailDrawer from "../components/DetailDrawer";
|
||||
import CopyButton from "../components/CopyButton";
|
||||
import EmptyState, { EmptyRow } from "../components/EmptyState";
|
||||
@@ -368,6 +369,8 @@ export default function NetworkDevices({ user }: { user: CurrentUser }) {
|
||||
{noting && (
|
||||
<DetailDrawer title={noting.name} subtitle="Notes" onClose={() => setNoting(null)}>
|
||||
<NotesCard targetType="device" targetId={noting.id} canEdit={canAct} bare />
|
||||
<hr />
|
||||
<TodosCard targetType="device" targetId={noting.id} canEdit={canAct} bare />
|
||||
</DetailDrawer>
|
||||
)}
|
||||
</>
|
||||
|
||||
@@ -16,6 +16,7 @@ import ServerPorts from "../components/ServerPorts";
|
||||
import ServerTrends from "../components/ServerTrends";
|
||||
import UptimeHistory from "../components/UptimeHistory";
|
||||
import NotesCard from "../components/NotesCard";
|
||||
import TodosCard from "../components/TodosCard";
|
||||
import ServerActivity from "../components/ServerActivity";
|
||||
import TimeAgo from "../components/TimeAgo";
|
||||
import UptimeRibbon from "../components/UptimeRibbon";
|
||||
@@ -764,6 +765,7 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<TodosCard targetType="server" targetId={server.id} canEdit={canEditTasks} />
|
||||
<NotesCard targetType="server" targetId={server.id} canEdit={canEditTasks} />
|
||||
<div className="card mb-3">
|
||||
<div className="card-header">
|
||||
|
||||
@@ -17,7 +17,7 @@ type Place = { type: "server" | "device"; id: number; name: string };
|
||||
|
||||
const today = () => new Date().toISOString().slice(0, 10);
|
||||
|
||||
function dueWords(t: TodoItem): { text: string; className: string } | null {
|
||||
export function dueWords(t: TodoItem): { text: string; className: string } | null {
|
||||
if (!t.dueDate) return null;
|
||||
const days = Math.round((Date.parse(`${t.dueDate}T00:00:00Z`) - Date.parse(`${today()}T00:00:00Z`)) / 86_400_000);
|
||||
if (t.doneAt) return { text: formatDate(new Date(`${t.dueDate}T12:00:00Z`)), className: "text-secondary" };
|
||||
|
||||
Reference in new issue
Block a user