Racks, notes and to-do, OS support, suggested dependencies, Nginx Proxy Manager and Home Assistant

- Racks page and a network diagram (UniFi tree with servers, printable)
- Notes on servers and devices; To do list shown in Coming up and My work
- Agents report the operating system (Linux 7, Windows 6); end-of-life badge and alert
- Suggested dependencies from where a service is reached
- Nginx Proxy Manager integration: proxy hosts page, certificate and host alerts, suggested checks
- Home Assistant integration: watch chosen entities, history chart, limit and unavailable alerts
- TimeChart gets a "value" scale that fits negatives; docs updated

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
bobbanandClaude Sonnet 5.5 committed 2026-10-20 21:47:56 +02:00
1 parent 68b41b5586
commit 18ceed62e8
77 files changed
+20432 -35

No files matched your search

+1
View File
@@ -18,6 +18,7 @@ const KINDS: { id: AgendaKind; label: string }[] = [
{ id: "maintenance", label: "Maintenance" },
{ id: "restore", label: "Restore tests" },
{ id: "updates", label: "Updates waiting" },
{ id: "todo", label: "To do" },
];
const KIND_LABEL = Object.fromEntries(KINDS.map((k) => [k.id, k.label])) as Record<AgendaKind, string>;
+1 -1
View File
@@ -332,7 +332,7 @@ function MyWorkStrip() {
return (
<div className="alert alert-info d-flex flex-wrap align-items-center gap-2 py-2" role="status">
<span>
<strong>{work.needsAttention}</strong> {work.needsAttention === 1 ? "thing" : "things"} of yours {work.needsAttention === 1 ? "wants" : "want"} a look — alerts handed to you or about to run out, maintenance about to end, update runs still going.
<strong>{work.needsAttention}</strong> {work.needsAttention === 1 ? "thing" : "things"} of yours {work.needsAttention === 1 ? "wants" : "want"} a look — alerts handed to you or about to run out, maintenance about to end, update runs still going, jobs that are due.
</span>
<Link to="/my-work" className="btn btn-sm btn-primary ms-auto">
My work
+400
View File
@@ -0,0 +1,400 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { api, type CurrentUser, type HaEntityChoice, type HaOverview, type HaWatchedEntity } from "../api/client";
import DetailDrawer from "../components/DetailDrawer";
import RangeSelect from "../components/RangeSelect";
import TimeAgo from "../components/TimeAgo";
import TimeChart from "../components/TimeChart";
import EmptyState from "../components/EmptyState";
import { BlockSkeleton } from "../components/Skeleton";
import { ErrorNotice } from "../components/Notice";
import { useChartRange } from "../utils/chartRanges";
import { readableError } from "../utils/errors";
import { toast } from "../utils/toast";
type Integration = HaOverview["integrations"][number];
const shownName = (w: HaWatchedEntity) => w.name ?? w.entity?.friendlyName ?? w.entityId;
const numberWords = (v: number, unit: string | null) => `${Math.round(v * 100) / 100}${unit ? ` ${unit}` : ""}`;
function StateCell({ w, problem }: { w: HaWatchedEntity; problem: boolean }) {
const e = w.entity;
if (!e) return <span className="text-secondary">not read yet</span>;
if (e.unavailableSince !== null || e.state === "missing") {
return (
<span className="badge bg-yellow-lt text-yellow" title={`Since ${e.unavailableSince ?? "?"}`}>
{e.state === "missing" ? "Not in Home Assistant" : e.state}
{e.unavailableSince ? <> · <TimeAgo value={e.unavailableSince} /></> : null}
</span>
);
}
return <strong className={problem ? "text-red" : ""}>{e.value !== null ? numberWords(e.value, e.unit) : e.state}</strong>;
}
function limitsWords(w: HaWatchedEntity): string {
const unit = w.entity?.unit ? ` ${w.entity.unit}` : "";
if (w.below !== null && w.above !== null) return `${w.below}–${w.above}${unit}`;
if (w.below !== null) return `not under ${w.below}${unit}`;
if (w.above !== null) return `not over ${w.above}${unit}`;
return "";
}
/** A watched number over time, from what this app has kept (up to 35 days). */
function HistoryDrawer({ integrationId, w, onClose }: { integrationId: number; w: HaWatchedEntity; onClose: () => void }) {
const [days, setDays] = useChartRange(7);
const shown = days > 30 ? 30 : days;
const [points, setPoints] = useState<{ t: string; v: number }[] | null>(null);
const [error, setError] = useState<string | null>(null);
const [to, setTo] = useState(() => Date.now());
useEffect(() => {
let alive = true;
api.homeAssistant
.history(integrationId, w.entityId, shown)
.then((res) => {
if (!alive) return;
setPoints(res.points);
setTo(Date.now());
setError(null);
})
.catch((err) => alive && setError(readableError(err)));
return () => {
alive = false;
};
}, [integrationId, w.entityId, shown]);
const unit = w.entity?.unit ?? "";
const series = useMemo(() => [{ name: shownName(w), color: "#4299e1", points: points ?? [] }], [points, w]);
return (
<DetailDrawer title={shownName(w)} subtitle={w.entityId} onClose={onClose}>
<div className="mb-3">
<RangeSelect value={shown} onChange={setDays} only={[1, 7, 30]} />
</div>
<ErrorNotice error={error} />
{!points && !error && <BlockSkeleton lines={5} />}
{points && <TimeChart series={series} unit="value" from={to - shown * 86_400_000} to={to} label={`${shownName(w)} over time`} format={(v) => numberWords(v, unit)} empty="Nothing kept for this in this stretch yet — a reading is added every few minutes." />}
<div className="text-secondary small mt-2">Readings are kept for 35 days.</div>
</DetailDrawer>
);
}
/** Change what is said about an entity already watched: its name and its limits. */
function EditDrawer({ integrationId, w, onClose, onSaved }: { integrationId: number; w: HaWatchedEntity; onClose: () => void; onSaved: () => void }) {
const numeric = w.entity?.value !== null && w.entity?.value !== undefined;
const [name, setName] = useState(w.name ?? "");
const [below, setBelow] = useState(w.below === null ? "" : String(w.below));
const [above, setAbove] = useState(w.above === null ? "" : String(w.above));
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
async function save() {
const parse = (s: string) => (s.trim() === "" ? null : Number(s));
const b = parse(below);
const a = parse(above);
if ((b !== null && !Number.isFinite(b)) || (a !== null && !Number.isFinite(a))) return setError("The limits have to be numbers.");
setBusy(true);
try {
await api.homeAssistant.watch(integrationId, { entityId: w.entityId, name: name.trim() || null, below: b, above: a });
onSaved();
onClose();
} catch (err) {
setError(readableError(err));
} finally {
setBusy(false);
}
}
return (
<DetailDrawer title={shownName(w)} subtitle={w.entityId} onClose={onClose}>
<ErrorNotice error={error} />
<div className="mb-3">
<label className="form-label" htmlFor="ha-name">
Name shown here
</label>
<input id="ha-name" className="form-control" value={name} maxLength={80} placeholder={w.entity?.friendlyName ?? w.entityId} onChange={(e) => setName(e.target.value)} />
</div>
{numeric ? (
<div className="row g-2 mb-3">
<div className="col-6">
<label className="form-label" htmlFor="ha-below">
Alert when under{w.entity?.unit ? ` (${w.entity.unit})` : ""}
</label>
<input id="ha-below" className="form-control" inputMode="decimal" value={below} onChange={(e) => setBelow(e.target.value)} placeholder="no limit" />
</div>
<div className="col-6">
<label className="form-label" htmlFor="ha-above">
Alert when over{w.entity?.unit ? ` (${w.entity.unit})` : ""}
</label>
<input id="ha-above" className="form-control" inputMode="decimal" value={above} onChange={(e) => setAbove(e.target.value)} placeholder="no limit" />
</div>
</div>
) : (
<div className="text-secondary mb-3">This one isn&rsquo;t a number, so there are no limits to set. It is an alert when it has been unavailable for 15 minutes.</div>
)}
<button className="btn btn-primary" onClick={() => void save()} disabled={busy}>
{busy ? "Saving…" : "Save"}
</button>
</DetailDrawer>
);
}
/** Pick entities to watch: search what Home Assistant has, read live. */
function PickDrawer({ integration, onClose, onChanged }: { integration: Integration; onClose: () => void; onChanged: () => void }) {
const [q, setQ] = useState("");
const [found, setFound] = useState<{ total: number; entities: HaEntityChoice[] } | null>(null);
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState<string | null>(null);
useEffect(() => {
let alive = true;
const timer = setTimeout(() => {
api.homeAssistant
.entities(integration.id, q)
.then((res) => {
if (!alive) return;
setFound(res);
setError(null);
})
.catch((err) => alive && setError(readableError(err)));
}, 250);
return () => {
alive = false;
clearTimeout(timer);
};
}, [integration.id, q]);
async function watch(e: HaEntityChoice) {
setBusy(e.entityId);
try {
await api.homeAssistant.watch(integration.id, { entityId: e.entityId });
setFound((f) => (f ? { ...f, entities: f.entities.map((x) => (x.entityId === e.entityId ? { ...x, watched: true } : x)) } : f));
onChanged();
} catch (err) {
toast.error(readableError(err));
} finally {
setBusy(null);
}
}
return (
<DetailDrawer title="Watch something" subtitle={integration.name} onClose={onClose}>
<div className="text-secondary mb-2">Search by name or id, like &ldquo;battery&rdquo; or &ldquo;freezer&rdquo;. Limits are set afterwards, from the list.</div>
<input className="form-control mb-3" type="search" value={q} onChange={(e) => setQ(e.target.value)} placeholder="Search Home Assistant…" aria-label="Search entities" autoFocus />
<ErrorNotice error={error} />
{!found && !error && <BlockSkeleton lines={4} />}
{found && (
<>
<div className="list-group list-group-flush">
{found.entities.map((e) => (
<div className="list-group-item d-flex align-items-center gap-2 px-0" key={e.entityId}>
<div className="flex-fill" style={{ minWidth: 0 }}>
<div className="text-truncate">{e.name}</div>
<div className="text-secondary small font-monospace text-truncate">
{e.entityId} · {e.state}
{e.unit ? ` ${e.unit}` : ""}
</div>
</div>
{e.watched ? (
<span className="badge bg-green-lt text-green">Watching</span>
) : (
<button className="btn btn-sm btn-outline-primary" disabled={busy === e.entityId} onClick={() => void watch(e)}>
Watch
</button>
)}
</div>
))}
</div>
{found.entities.length === 0 && <div className="text-secondary">Nothing matches.</div>}
<div className="text-secondary small mt-2">
{found.entities.length >= 60 ? "The first 60 of " : ""}
{found.total} in Home Assistant.
</div>
</>
)}
</DetailDrawer>
);
}
/**
* The few things worth watching in Home Assistant — a UPS battery, a freezer, a door sensor, a pump — chosen here, not all several hundred entities. Each is read every
* few minutes and kept with its history; it is an alert when it has said nothing for 15 minutes, or a number goes past a limit that was set. Nothing is ever written
* to Home Assistant.
*/
export default function HomeAssistant({ user }: { user: CurrentUser }) {
const canAct = user.role === "admin" || user.role === "operator";
const [data, setData] = useState<HaOverview | null>(null);
const [error, setError] = useState<string | null>(null);
const [reading, setReading] = useState(false);
const [picking, setPicking] = useState<Integration | null>(null);
const [editing, setEditing] = useState<{ id: number; w: HaWatchedEntity } | null>(null);
const [charting, setCharting] = useState<{ id: number; w: HaWatchedEntity } | null>(null);
const load = useCallback(
() =>
api.homeAssistant
.overview()
.then((res) => {
setData(res);
setError(null);
})
.catch((err) => setError(readableError(err))),
[],
);
useEffect(() => {
void load();
const timer = setInterval(() => void load(), 60_000);
return () => clearInterval(timer);
}, [load]);
async function readNow() {
setReading(true);
try {
const res = await api.homeAssistant.sync();
const failed = Object.values(res.statuses).filter((s) => !s.ok);
if (failed.length > 0) toast.error(`Couldn't read Home Assistant: ${failed[0].error ?? "no answer"}`);
else toast.success("Read from Home Assistant.");
await load();
} catch (err) {
toast.error(readableError(err));
} finally {
setReading(false);
}
}
async function stop(id: number, w: HaWatchedEntity) {
try {
await api.homeAssistant.unwatch(id, w.entityId);
toast.success(`No longer watching ${shownName(w)}.`);
await load();
} catch (err) {
toast.error(readableError(err));
}
}
const live = data?.integrations ?? [];
return (
<>
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
<h2 className="page-title mb-0">Home Assistant</h2>
{canAct && live.length > 0 && (
<div className="ms-auto btn-list">
<button className="btn btn-outline-secondary" onClick={() => void readNow()} disabled={reading}>
{reading ? "Reading…" : "Read now"}
</button>
</div>
)}
</div>
<div className="text-secondary mb-3">
The few things worth an alert in Home Assistant — a UPS battery, a freezer, a pump — chosen here rather than every entity it has. Each is read every five minutes and its history is kept for 35 days. It only
reads; nothing is ever sent to Home Assistant.
</div>
<ErrorNotice error={error} />
{data === null && !error && <BlockSkeleton lines={4} />}
{data && live.length === 0 && (
<div className="card">
<EmptyState
title="No Home Assistant connected"
hint="Add a Home Assistant integration with a long-lived access token (made at the bottom of your profile page in Home Assistant), then choose what to watch."
action={user.role === "admin" ? { label: "Add Home Assistant", to: "/integrations" } : undefined}
/>
</div>
)}
{live.map((i) => (
<div className="card mb-3" key={i.id}>
<div className="card-header">
<div>
<h3 className="card-title">{i.name}</h3>
<div className={`small ${i.status && !i.status.ok ? "text-red" : "text-secondary"}`}>
{!i.enabled ? (
"Switched off"
) : !i.status ? (
"Not read yet"
) : i.status.ok ? (
<>
Read <TimeAgo value={i.status.at} /> · watching {i.status.entities}
</>
) : (
<>
Couldn&rsquo;t be read: {i.status.error}. Showing what was read <TimeAgo value={i.status.at} />; its alerts are held until it can be read again.
</>
)}
</div>
</div>
{canAct && i.enabled && (
<div className="card-actions">
<button className="btn btn-primary btn-sm" onClick={() => setPicking(i)}>
Watch something
</button>
</div>
)}
</div>
{i.watched.length === 0 ? (
<EmptyState title="Nothing is being watched yet" hint="Pick the entities that matter — a battery level, a temperature, a switch — and set the limits that should raise an alert." action={canAct && i.enabled ? { label: "Watch something", onClick: () => setPicking(i) } : undefined} />
) : (
<div className="table-responsive">
<table className="table table-vcenter card-table table-stack">
<thead>
<tr>
<th>Name</th>
<th>Now</th>
<th>Alert when</th>
<th>Last changed</th>
<th className="w-1">
<span className="visually-hidden">Actions</span>
</th>
</tr>
</thead>
<tbody>
{i.watched.map((w) => {
const problem = i.problems.some((p) => p.key.endsWith(`:${w.entityId}`));
return (
<tr key={w.entityId}>
<td className="stack-wide">
<strong>{shownName(w)}</strong>
<div className="text-secondary small font-monospace">{w.entityId}</div>
</td>
<td className="stack-label" data-label="Now">
<StateCell w={w} problem={problem} />
</td>
<td className="stack-label" data-label="Alert when">
{limitsWords(w) || <span className="text-secondary">unavailable for 15 min</span>}
</td>
<td className="stack-label" data-label="Last changed">
{w.entity?.lastChanged ? <TimeAgo value={w.entity.lastChanged} /> : <span className="text-secondary">—</span>}
</td>
<td className="text-nowrap stack-wide">
<div className="btn-list flex-nowrap">
{w.entity?.value !== null && w.entity?.value !== undefined && (
<button className="btn btn-sm btn-outline-secondary" onClick={() => setCharting({ id: i.id, w })}>
History
</button>
)}
{canAct && (
<>
<button className="btn btn-sm btn-outline-secondary" onClick={() => setEditing({ id: i.id, w })}>
Limits
</button>
<button className="btn btn-sm btn-outline-danger" onClick={() => void stop(i.id, w)} aria-label={`Stop watching ${shownName(w)}`}>
Stop
</button>
</>
)}
</div>
</td>
</tr>
);
})}
</tbody>
</table>
</div>
)}
</div>
))}
{picking && <PickDrawer integration={picking} onClose={() => setPicking(null)} onChanged={() => void load()} />}
{editing && <EditDrawer integrationId={editing.id} w={editing.w} onClose={() => setEditing(null)} onSaved={() => void load()} />}
{charting && <HistoryDrawer integrationId={charting.id} w={charting.w} onClose={() => setCharting(null)} />}
</>
);
}
+4
View File
@@ -26,6 +26,8 @@ const TYPE_LABELS: Record<IntegrationType, string> = {
pbs: "Proxmox Backup Server",
osticket: "osTicket",
unifi: "UniFi",
npm: "Nginx Proxy Manager",
homeassistant: "Home Assistant",
};
/** The page each kind of integration gets once it is connected. */
@@ -41,6 +43,8 @@ const TYPE_PAGES: Record<IntegrationType, string> = {
pbs: "/pbs",
osticket: "/osticket",
unifi: "/network/devices",
npm: "/proxy-hosts",
homeassistant: "/home-assistant",
};
/** "pve.example.lan" out of "https://pve.example.lan:8006/", or the text itself when it isn't an address. */
+3
View File
@@ -268,6 +268,9 @@ export default function Inventory({ user }: { user: CurrentUser }) {
<div className="d-flex align-items-center mb-3">
<h2 className="page-title mb-0">Inventory</h2>
<div className="ms-auto d-flex gap-2">
<Link to="/inventory/racks" className="btn">
Racks
</Link>
<Link to="/inventory/lifecycle" className="btn">
Lifecycle
</Link>
+140
View File
@@ -0,0 +1,140 @@
import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { api } from "../api/client";
import EmptyState from "../components/EmptyState";
import { ErrorNotice } from "../components/Notice";
import { BlockSkeleton } from "../components/Skeleton";
import { readableError } from "../utils/errors";
import { KIND_LABELS } from "../utils/inventory";
type Rack = Awaited<ReturnType<typeof api.inventory.racks>>["racks"][number];
const UNIT_H = 24;
const KIND_COLOR: Record<string, string> = { server: "#4299e1", storage: "#38b2ac", network: "#48bb78", power: "#f59f00", client: "#a78bfa", other: "#8896ab" };
/** One rack, from the bottom (unit 1) up, as it stands: each piece where it says it sits, empty units between, a clash in red. */
function RackDrawing({ rack }: { rack: Rack }) {
const height = rack.units * UNIT_H;
const yOf = (unit: number) => height - unit * UNIT_H; // top edge of a unit
return (
<div className="rack-drawing">
<svg viewBox={`0 0 260 ${height + 4}`} width="100%" role="img" aria-label={`${rack.name}: ${rack.slots.length} pieces in ${rack.units} units${rack.slots.some((s) => s.clash) ? ", with a clash" : ""}`} style={{ maxWidth: 300 }}>
<rect x="26" y="1" width="228" height={height + 2} fill="none" stroke="currentColor" strokeOpacity="0.5" strokeWidth="2" rx="3" />
{Array.from({ length: rack.units }, (_, i) => i + 1).map((u) => (
<g key={u}>
<line x1="26" x2="254" y1={yOf(u) + 1} y2={yOf(u) + 1} stroke="currentColor" strokeOpacity="0.1" />
<text x="22" y={yOf(u) + UNIT_H / 2 + 4} textAnchor="end" fontSize="10" fill="currentColor" fillOpacity="0.55">
{u}
</text>
</g>
))}
{rack.slots.map((s) => {
const h = (s.to - s.from + 1) * UNIT_H;
const y = yOf(s.to);
return (
<g key={s.assetId}>
<title>{`${s.name}${s.model ? ` — ${s.model}` : ""} (${KIND_LABELS[s.kind as keyof typeof KIND_LABELS] ?? s.kind}, ${s.from === s.to ? `unit ${s.from}` : `units ${s.from}–${s.to}`}${s.powerWatts !== null ? `, ${s.powerWatts} W` : ""})${s.clash ? " — another piece is in the same unit" : ""}`}</title>
<rect x="29" y={y + 2} width="222" height={h - 3} rx="3" fill={KIND_COLOR[s.kind] ?? KIND_COLOR.other} fillOpacity="0.28" stroke={s.clash ? "#f03e3e" : KIND_COLOR[s.kind] ?? KIND_COLOR.other} strokeWidth={s.clash ? 2.5 : 1.5} />
<text x="38" y={y + Math.min(h, UNIT_H) / 2 + 4} fontSize="12" fill="currentColor" fontWeight="600">
{s.name.length > 30 ? `${s.name.slice(0, 29)}…` : s.name}
</text>
{h >= UNIT_H * 2 && s.model && (
<text x="38" y={y + UNIT_H / 2 + 20} fontSize="10.5" fill="currentColor" fillOpacity="0.75">
{s.model.length > 34 ? `${s.model.slice(0, 33)}…` : s.model}
</text>
)}
</g>
);
})}
</svg>
</div>
);
}
/**
* The racks, drawn from the inventory: each piece of hardware that says which unit it sits in (U12, or U12-13) and where (the rack's name in its location). Edit a
* piece's location and unit on the Inventory page and it moves here. Print it for the door of the cabinet.
*/
export default function InventoryRacks() {
const [racks, setRacks] = useState<Rack[] | null>(null);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
api.inventory
.racks()
.then((res) => setRacks(res.racks))
.catch((err) => setError(readableError(err)));
}, []);
return (
<>
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
<h2 className="page-title mb-0">Racks</h2>
<div className="ms-auto btn-list no-print">
<button type="button" className="btn btn-outline-secondary" onClick={() => window.print()} disabled={!racks || racks.length === 0}>
Print
</button>
<Link to="/inventory" className="btn btn-outline-secondary">
Hardware
</Link>
</div>
</div>
<div className="text-secondary mb-3 no-print">
Each piece of hardware that gives a unit (&ldquo;U12&rdquo;, or &ldquo;U12-13&rdquo; for a tall one) and the rack&rsquo;s name as its location is drawn where it sits, from the bottom up. Two pieces in the same unit are shown in red.
</div>
<ErrorNotice error={error} />
{racks === null && !error && <BlockSkeleton lines={4} />}
{racks !== null && racks.length === 0 && (
<div className="card">
<EmptyState title="No racks to draw yet" hint={<>On the <Link to="/inventory">Hardware</Link> page, give a piece a location (the rack&rsquo;s name) and a rack unit such as U12, and it appears here.</>} />
</div>
)}
<div className="row row-cards">
{racks?.map((rack) => (
<div className="col-md-6 col-xl-4" key={rack.name}>
<div className="card h-100">
<div className="card-header">
<h3 className="card-title">{rack.name}</h3>
<div className="card-actions text-secondary small">
{rack.slots.length} {rack.slots.length === 1 ? "piece" : "pieces"} · {rack.usedUnits} of {rack.units} units{rack.watts > 0 ? ` · ${rack.watts} W` : ""}
</div>
</div>
<div className="card-body">
<RackDrawing rack={rack} />
{rack.slots.some((s) => s.clash) && (
<div className="alert alert-danger mt-3 mb-0">
Clash: {rack.slots.filter((s) => s.clash).map((s) => `${s.name} (${s.from === s.to ? `U${s.from}` : `U${s.from}-${s.to}`})`).join(", ")} claim the same unit. Correct one of them on the Hardware page.
</div>
)}
{rack.unplaced.length > 0 && (
<div className="mt-3 small">
<span className="text-secondary">Named here but not in a unit: </span>
{rack.unplaced.map((u, i) => (
<span key={u.assetId}>
{i > 0 && ", "}
<Link to={`/inventory?asset=${u.assetId}`}>{u.name}</Link>
</span>
))}
</div>
)}
<ul className="list-unstyled small mt-3 mb-0 d-print-none">
{[...rack.slots].reverse().map((s) => (
<li key={s.assetId}>
<span className="text-secondary">{s.from === s.to ? `U${s.from}` : `U${s.from}–${s.to}`}</span> <Link to={`/inventory?asset=${s.assetId}`}>{s.name}</Link>
{s.serverId !== null && (
<>
{" "}
· <Link to={`/servers/${s.serverId}`}>server</Link>
</>
)}
</li>
))}
</ul>
</div>
</div>
</div>
))}
</div>
</>
);
}
+49 -2
View File
@@ -74,7 +74,28 @@ export default function MyWorkPage({ user }: { user: CurrentUser }) {
}
}
const nothing = work !== null && work.alerts.length === 0 && work.windows.length === 0 && work.updateRuns.length === 0;
const nothing = work !== null && work.alerts.length === 0 && work.windows.length === 0 && work.updateRuns.length === 0 && work.todos.length === 0;
async function finish(t: MyWork["todos"][number]) {
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 {
reload();
}
},
});
reload();
} catch (err) {
toast.error(readableError(err));
}
}
return (
<>
@@ -82,7 +103,7 @@ export default function MyWorkPage({ user }: { user: CurrentUser }) {
<h2 className="page-title mb-0">My work</h2>
</div>
<div className="text-secondary mb-3">
What has your name on it: alerts you acknowledged or were handed, maintenance you started and update runs you started. Whatever is about to run out is marked, and listed first.
What has your name on it: alerts you acknowledged or were handed, maintenance you started and update runs you started, and jobs handed to you. Whatever is about to run out is marked, and listed first.
</div>
{work === null && <BlockSkeleton lines={4} />}
@@ -146,6 +167,32 @@ export default function MyWorkPage({ user }: { user: CurrentUser }) {
</div>
)}
{work && work.todos.length > 0 && (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Jobs handed to you</h3>
<div className="card-actions">
<Link to="/todo?who=me" className="small">
To do
</Link>
</div>
</div>
<ul className="list-group list-group-flush">
{work.todos.map((t) => (
<li key={t.id} className="list-group-item d-flex gap-3 align-items-start">
<input type="checkbox" className="form-check-input mt-1" aria-label={`Done: ${t.title}`} checked={false} onChange={() => void finish(t)} />
<div className="me-auto">
<div className="fw-bold">{t.title}</div>
{t.detail && <div className="text-secondary small">{t.detail}</div>}
{t.target && <div className="small text-secondary">about {t.target.name}</div>}
</div>
{t.dueDate && <span className={`small ${t.overdue ? "text-red" : t.dueSoon ? "text-yellow" : "text-secondary"}`}>{t.overdue ? "overdue · " : ""}{t.dueDate}</span>}
</li>
))}
</ul>
</div>
)}
{work && work.windows.length > 0 && (
<div className="card mb-3">
<div className="card-header">
+25 -1
View File
@@ -8,6 +8,9 @@ import TimeAgo from "../components/TimeAgo";
import ViewTabs from "../components/ViewTabs";
import SilenceButton from "../components/SilenceButton";
import RunbookEntry from "../components/RunbookEntry";
import NetworkDiagram from "../components/NetworkDiagram";
import NotesCard from "../components/NotesCard";
import DetailDrawer from "../components/DetailDrawer";
import CopyButton from "../components/CopyButton";
import EmptyState, { EmptyRow } from "../components/EmptyState";
import { BlockSkeleton } from "../components/Skeleton";
@@ -62,12 +65,14 @@ function StateBadge({ d }: { d: NetworkDevice }) {
export default function NetworkDevices({ user }: { user: CurrentUser }) {
const canAct = user.role === "admin" || user.role === "operator";
const [params] = useSearchParams();
const view = params.get("view") === "wifi" ? "wifi" : "devices";
const asked = params.get("view");
const view = asked === "wifi" ? "wifi" : asked === "diagram" ? "diagram" : "devices";
const [data, setData] = useState<NetworkOverview | null>(null);
const [error, setError] = useState<string | null>(null);
const [reading, setReading] = useState(false);
const [kind, setKind] = useState<"all" | NetworkDeviceKind>("all");
const [status, setStatus] = useState<"all" | "problem">("all");
const [noting, setNoting] = useState<NetworkDevice | null>(null);
const load = useCallback(() => {
return api.network
@@ -120,6 +125,7 @@ export default function NetworkDevices({ user }: { user: CurrentUser }) {
label="Network devices view"
tabs={[
{ to: "/network/devices", label: "Devices", active: view === "devices" },
{ to: "/network/devices?view=diagram", label: "Diagram", active: view === "diagram" },
{ to: "/network/devices?view=wifi", label: "Networks & Wi-Fi", active: view === "wifi" },
]}
/>
@@ -324,6 +330,9 @@ export default function NetworkDevices({ user }: { user: CurrentUser }) {
<div className="btn-list flex-nowrap align-items-center">
{!d.inMaintenance && <SilenceButton target={{ type: "device", id: d.id, name: d.name }} onDone={() => void load()} />}
<RunbookEntry targetType="device" targetId={d.id} targetName={d.name} canEdit={canAct} offerAdd />
<button type="button" className="btn btn-link btn-sm p-0" onClick={() => setNoting(d)}>
Notes
</button>
</div>
</td>
)}
@@ -345,7 +354,22 @@ export default function NetworkDevices({ user }: { user: CurrentUser }) {
</>
)}
{data && data.integrations.length > 0 && view === "diagram" && (
<>
<div className="mb-2 no-print">
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => window.print()}>
Print
</button>
</div>
<NetworkDiagram devices={devices} />
</>
)}
{data && data.integrations.length > 0 && view === "wifi" && <NetworksAndWifi data={data} />}
{noting && (
<DetailDrawer title={noting.name} subtitle="Notes" onClose={() => setNoting(null)}>
<NotesCard targetType="device" targetId={noting.id} canEdit={canAct} bare />
</DetailDrawer>
)}
</>
);
}
+242
View File
@@ -0,0 +1,242 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import { Link } from "react-router-dom";
import { api, type CurrentUser, type IntegrationProblem, type NpmHost, type NpmOverview } from "../api/client";
import SortableTh from "../components/SortableTh";
import Pagination from "../components/Pagination";
import TableToolbar from "../components/TableToolbar";
import TimeAgo from "../components/TimeAgo";
import EmptyState, { EmptyRow } from "../components/EmptyState";
import { BlockSkeleton } from "../components/Skeleton";
import { ErrorNotice } from "../components/Notice";
import { useSortable } from "../hooks/useSortable";
import { useTableSearch } from "../hooks/useTableSearch";
import { usePagination } from "../hooks/usePagination";
import { downloadCsv } from "../utils/csv";
import { formatDate } from "../utils/date";
import { readableError } from "../utils/errors";
import { toast } from "../utils/toast";
type Row = NpmHost & { integrationName: string; domain: string; target: string; certDays: number | null; certName: string; statusRank: number; serverName: string };
const DAY_MS = 86_400_000;
const daysLeft = (iso: string | null): number | null => (iso && Number.isFinite(Date.parse(iso)) ? Math.floor((Date.parse(iso) - Date.now()) / DAY_MS) : null);
function StatusBadge({ h }: { h: Row }) {
if (!h.enabled) return <span className="badge bg-secondary-lt text-secondary">Switched off</span>;
if (!h.online)
return (
<span className="badge bg-red-lt text-red" title={h.error ?? "Nginx Proxy Manager could not set this host up"}>
Not working
</span>
);
return <span className="badge bg-green-lt text-green">Working</span>;
}
function CertBadge({ h }: { h: Row }) {
if (!h.certificate) return <span className="text-secondary">{h.sslForced ? "—" : "No certificate"}</span>;
const d = h.certDays;
const color = d === null ? "secondary" : d < 0 ? "red" : d <= 3 ? "red" : d <= 14 ? "yellow" : "green";
const words = d === null ? "no end date" : d < 0 ? `ran out ${-d} ${d === -1 ? "day" : "days"} ago` : d === 0 ? "ends today" : `${d} ${d === 1 ? "day" : "days"} left`;
return (
<span title={h.certificate.expiresAt ? `${h.certificate.name} — ends ${formatDate(new Date(h.certificate.expiresAt))}` : h.certificate.name}>
<span className={`badge bg-${color}-lt text-${color}`}>{words}</span>
<div className="text-secondary small">{h.certificate.name}</div>
</span>
);
}
/**
* What Nginx Proxy Manager proxies: each name people use, where it forwards to (and which server that is), its certificate and whether NPM could set it up. Read
* from NPM when the page is opened (and at most once a minute); nothing here changes anything in NPM.
*/
export default function ProxyHosts({ user }: { user: CurrentUser }) {
const [data, setData] = useState<NpmOverview | null>(null);
const [error, setError] = useState<string | null>(null);
const [reading, setReading] = useState(false);
const load = useCallback(
(refresh = false) =>
api.npm
.overview(refresh)
.then((res) => {
setData(res);
setError(null);
})
.catch((err) => setError(readableError(err))),
[],
);
useEffect(() => {
void load();
const timer = setInterval(() => void load(), 60_000);
return () => clearInterval(timer);
}, [load]);
async function readNow() {
setReading(true);
await load(true);
setReading(false);
toast.success("Read from Nginx Proxy Manager.");
}
const rows: Row[] = useMemo(
() =>
(data?.integrations ?? []).flatMap((i) =>
i.hosts.map((h) => ({
...h,
integrationName: i.name,
domain: h.domains.join(", "),
target: `${h.forwardScheme}://${h.forwardHost}${h.forwardPort !== null ? `:${h.forwardPort}` : ""}`,
certDays: daysLeft(h.certificate?.expiresAt ?? null),
certName: h.certificate?.name ?? "",
statusRank: !h.enabled ? 2 : h.online ? 1 : 0,
serverName: h.server?.name ?? "",
})),
),
[data],
);
const tableSearch = useTableSearch(rows);
const { sorted, sortKey, sortDir, requestSort } = useSortable(tableSearch.filtered, "statusRank", "asc", { url: true });
const { pageItems, page, setPage, pageCount, totalCount } = usePagination(sorted);
const problems: (IntegrationProblem & { integration: string })[] = (data?.integrations ?? []).flatMap((i) => i.problems.map((p) => ({ ...p, integration: i.name })));
const soon = rows.filter((h) => h.enabled && h.certDays !== null && h.certDays <= 14).length;
const noNpm = data !== null && data.integrations.length === 0;
function exportCsv() {
downloadCsv(
"proxy-hosts.csv",
["Names", "Forwards to", "Server", "Status", "Certificate", "Certificate ends", "Force HTTPS", "Nginx Proxy Manager"],
(sorted ?? []).map((h) => [h.domain, h.target, h.serverName, !h.enabled ? "switched off" : h.online ? "working" : "not working", h.certName, h.certificate?.expiresAt ?? "", h.sslForced ? "yes" : "no", h.integrationName]),
);
}
return (
<>
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
<h2 className="page-title mb-0">Proxy hosts</h2>
{(user.role === "admin" || user.role === "operator") && data && data.integrations.length > 0 && (
<div className="ms-auto btn-list">
<button className="btn btn-outline-secondary" onClick={() => void readNow()} disabled={reading}>
{reading ? "Reading…" : "Read now"}
</button>
</div>
)}
</div>
<div className="text-secondary mb-3">
What Nginx Proxy Manager serves: the name, where it forwards to, the certificate and whether NPM could set it up. It only reads — nothing here changes anything in NPM. A certificate in its last
two weeks, or a host NPM can&rsquo;t set up, is an alert.
</div>
<ErrorNotice error={error} />
{data === null && !error && <BlockSkeleton lines={4} />}
{noNpm && (
<div className="card">
<EmptyState
title="No Nginx Proxy Manager connected"
hint="Add an Nginx Proxy Manager integration — a user that may only view proxy hosts and certificates is enough — and what it serves appears here."
action={user.role === "admin" ? { label: "Add Nginx Proxy Manager", to: "/integrations" } : undefined}
/>
</div>
)}
{data && data.integrations.length > 0 && (
<div className="mb-3 small">
{data.integrations.map((i) => (
<div key={i.id} className={i.error ? "text-red" : "text-secondary"}>
<strong>{i.name}</strong>
{i.error ? <> — couldn&rsquo;t be read: {i.error}</> : <> — read <TimeAgo value={i.readAt} />{i.version ? ` · version ${i.version}` : ""} · {i.hosts.length} {i.hosts.length === 1 ? "host" : "hosts"}</>}
</div>
))}
</div>
)}
{data && data.integrations.some((i) => !i.error) && (
<>
<div className="row row-cards mb-3">
{[
{ label: "Proxy hosts", value: rows.length, color: "" },
{ label: "Not working", value: rows.filter((h) => h.enabled && !h.online).length, color: rows.some((h) => h.enabled && !h.online) ? "text-red" : "text-green" },
{ label: "Certificates ending within 14 days", value: soon, color: soon > 0 ? "text-yellow" : "text-green" },
{ label: "Switched off", value: rows.filter((h) => !h.enabled).length, color: "" },
].map((c) => (
<div className="col-6 col-lg-3" key={c.label}>
<div className="card card-sm">
<div className="card-body">
<div className={`h2 mb-0 ${c.color}`}>{c.value}</div>
<div className="text-secondary">{c.label}</div>
</div>
</div>
</div>
))}
</div>
{problems.length > 0 && (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Needs attention</h3>
</div>
<div className="list-group list-group-flush">
{problems.map((p) => (
<div className="list-group-item d-flex align-items-center gap-2" key={p.key}>
<span className={`badge ${p.severity === "critical" ? "bg-red-lt text-red" : "bg-yellow-lt text-yellow"}`}>{p.severity === "critical" ? "Critical" : "Warning"}</span>
<span>{p.message}</span>
</div>
))}
</div>
</div>
)}
<div className="card">
<TableToolbar search={tableSearch.query} onSearch={tableSearch.setQuery} placeholder="Search names, targets, servers…" shown={sorted?.length} total={rows.length} onExport={exportCsv} exportDisabled={!sorted || sorted.length === 0} />
<div className="table-responsive">
<table className="table table-vcenter card-table table-stack">
<thead>
<tr>
<SortableTh<Row> label="Status" sortKeyName="statusRank" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<Row> label="Name" sortKeyName="domain" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<Row> label="Forwards to" sortKeyName="target" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
<SortableTh<Row> label="Certificate" sortKeyName="certDays" activeKey={sortKey} direction={sortDir} onSort={requestSort} />
</tr>
</thead>
<tbody>
{(pageItems ?? []).length === 0 && <EmptyRow colSpan={4} title="No proxy hosts" filtered={tableSearch.active ? () => tableSearch.setQuery("") : undefined} />}
{(pageItems ?? []).map((h) => (
<tr key={`${h.integrationName}-${h.id}`}>
<td>
<StatusBadge h={h} />
{h.error && h.enabled && <div className="text-secondary small">{h.error.slice(0, 120)}</div>}
</td>
<td className="stack-wide">
{h.domains.map((d, i) => (
<div key={i}>
<a href={`${h.sslForced || h.certificate ? "https" : "http"}://${d}`} target="_blank" rel="noopener noreferrer">
<strong>{d}</strong>
</a>
</div>
))}
{data && data.integrations.length > 1 && <div className="text-secondary small">{h.integrationName}</div>}
</td>
<td className="stack-label" data-label="Forwards to">
<span className="font-monospace">{h.target}</span>
{h.server && (
<div className="small">
<Link to={`/servers/${h.server.id}`}>{h.server.name}</Link>
</div>
)}
</td>
<td className="stack-label" data-label="Certificate">
<CertBadge h={h} />
</td>
</tr>
))}
</tbody>
</table>
</div>
<Pagination page={page} pageCount={pageCount} totalCount={totalCount} onPageChange={setPage} />
</div>
</>
)}
</>
);
}
+13
View File
@@ -15,6 +15,7 @@ import {
import ServerPorts from "../components/ServerPorts";
import ServerTrends from "../components/ServerTrends";
import UptimeHistory from "../components/UptimeHistory";
import NotesCard from "../components/NotesCard";
import ServerActivity from "../components/ServerActivity";
import TimeAgo from "../components/TimeAgo";
import UptimeRibbon from "../components/UptimeRibbon";
@@ -705,6 +706,17 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
<dd className="col-7">
<UptimeRibbon kind="servers" id={server.id} name={server.name} />
</dd>
{detail.os && (
<>
<dt className="col-5">System</dt>
<dd className="col-7">
{detail.os.product}
{detail.os.state === "ended" && <span className="badge bg-red-lt text-red ms-2" title={`Support ended on ${detail.os.endsOn}`}>support ended</span>}
{detail.os.state === "soon" && <span className="badge bg-yellow-lt text-yellow ms-2" title={`Support ends on ${detail.os.endsOn}`}>support ends in {detail.os.daysLeft} {detail.os.daysLeft === 1 ? "day" : "days"}</span>}
{detail.os.state === "ok" && detail.os.endsOn && <div className="text-secondary small">supported until {detail.os.endsOn}</div>}
</dd>
</>
)}
<dt className="col-5">Runs on</dt>
<dd className="col-7">
<RunsOn serverId={server.id} parent={detail.relations.parent} noParent={server.noParent} canEdit={isAdmin} onChanged={() => void loadDetail()} />
@@ -752,6 +764,7 @@ export default function ServerDetail({ user }: { user: CurrentUser }) {
</div>
</div>
<NotesCard targetType="server" targetId={server.id} canEdit={canEditTasks} />
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Runbooks</h3>
+320
View File
@@ -0,0 +1,320 @@
import { useEffect, useMemo, useState } from "react";
import { Link, useSearchParams } from "react-router-dom";
import { api, type CurrentUser, type TodoInput, type TodoItem } from "../api/client";
import DetailDrawer from "../components/DetailDrawer";
import EmptyState from "../components/EmptyState";
import { ErrorNotice } from "../components/Notice";
import { BlockSkeleton } from "../components/Skeleton";
import TimeAgo from "../components/TimeAgo";
import { refreshMyWork } from "../hooks/useMyWork";
import { formatDate } from "../utils/date";
import { readableError } from "../utils/errors";
import { toast } from "../utils/toast";
import { removeWithUndo } from "../utils/undoable";
type Person = { id: number; name: string; role: string };
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 {
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" };
if (days < 0) return { text: `${-days} ${days === -1 ? "day" : "days"} overdue`, className: "text-red" };
if (days === 0) return { text: "due today", className: "text-yellow" };
if (days === 1) return { text: "due tomorrow", className: "text-yellow" };
return { text: `due ${formatDate(new Date(`${t.dueDate}T12:00:00Z`))}`, className: days <= 7 ? "text-yellow" : "text-secondary" };
}
/** The same form to make a job and to change one. */
function JobForm({ initial, people, places, busy, submitLabel, onSubmit, onCancel }: { initial: TodoInput & { targetKey?: string }; people: Person[]; places: Place[]; busy: boolean; submitLabel: string; onSubmit: (v: TodoInput) => void; onCancel?: () => void }) {
const [title, setTitle] = useState(initial.title);
const [detail, setDetail] = useState(initial.detail ?? "");
const [due, setDue] = useState(initial.dueDate ?? "");
const [who, setWho] = useState(initial.assigneeId ? String(initial.assigneeId) : "");
const [about, setAbout] = useState(initial.targetType && initial.targetId ? `${initial.targetType}:${initial.targetId}` : "");
return (
<form
onSubmit={(e) => {
e.preventDefault();
const [type, id] = about.split(":");
onSubmit({ title: title.trim(), detail: detail.trim() || null, dueDate: due || null, assigneeId: who ? Number(who) : null, targetType: about ? (type as "server" | "device") : null, targetId: about ? Number(id) : null });
}}
>
<div className="row g-3">
<div className="col-12">
<label className="form-label" htmlFor="todo-title">
What is to be done
</label>
<input id="todo-title" className="form-control" maxLength={160} required value={title} onChange={(e) => setTitle(e.target.value)} placeholder="e.g. Replace the UPS battery" autoFocus />
</div>
<div className="col-md-4">
<label className="form-label" htmlFor="todo-due">
By <span className="text-secondary">(optional)</span>
</label>
<input id="todo-due" type="date" className="form-control" value={due} onChange={(e) => setDue(e.target.value)} />
</div>
<div className="col-md-4">
<label className="form-label" htmlFor="todo-who">
For <span className="text-secondary">(optional)</span>
</label>
<select id="todo-who" className="form-select" value={who} onChange={(e) => setWho(e.target.value)}>
<option value="">Nobody in particular</option>
{people.map((p) => (
<option key={p.id} value={p.id}>
{p.name}
</option>
))}
</select>
</div>
<div className="col-md-4">
<label className="form-label" htmlFor="todo-about">
About <span className="text-secondary">(optional)</span>
</label>
<select id="todo-about" className="form-select" value={about} onChange={(e) => setAbout(e.target.value)}>
<option value="">Nothing in particular</option>
<optgroup label="Servers">
{places.filter((p) => p.type === "server").map((p) => (
<option key={`s${p.id}`} value={`server:${p.id}`}>
{p.name}
</option>
))}
</optgroup>
{places.some((p) => p.type === "device") && (
<optgroup label="Network devices">
{places.filter((p) => p.type === "device").map((p) => (
<option key={`d${p.id}`} value={`device:${p.id}`}>
{p.name}
</option>
))}
</optgroup>
)}
</select>
</div>
<div className="col-12">
<label className="form-label" htmlFor="todo-detail">
Details <span className="text-secondary">(optional)</span>
</label>
<textarea id="todo-detail" className="form-control" rows={3} maxLength={2000} value={detail} onChange={(e) => setDetail(e.target.value)} />
</div>
</div>
<div className="d-flex gap-2 mt-3">
<button type="submit" className="btn btn-primary" disabled={busy || title.trim() === ""}>
{busy ? "Saving…" : submitLabel}
</button>
{onCancel && (
<button type="button" className="btn" onClick={onCancel}>
Cancel
</button>
)}
</div>
</form>
);
}
/**
* The small jobs of a homelab, written down: what, by when, for whom and about which server or device. A job with a day is in Coming up; one handed to somebody is in
* their My work. Ticking one off keeps it (under Done), and it can be brought back.
*/
export default function Todo({ user }: { user: CurrentUser }) {
const canEdit = user.role === "admin" || user.role === "operator";
const [params, setParams] = useSearchParams();
const mineOnly = params.get("who") === "me";
const [list, setList] = useState<TodoItem[] | null>(null);
const [people, setPeople] = useState<Person[]>([]);
const [places, setPlaces] = useState<Place[]>([]);
const [error, setError] = useState<string | null>(null);
const [busy, setBusy] = useState(false);
const [editing, setEditing] = useState<TodoItem | null>(null);
const [showDone, setShowDone] = useState(false);
function load() {
api.todos
.list()
.then((res) => {
setList(res.todos);
setPeople(res.people);
})
.catch((err) => setError(readableError(err)));
refreshMyWork();
}
useEffect(load, []);
useEffect(() => {
// What a job can be about: the servers, and the network devices when there are any.
Promise.all([api.servers.list().catch(() => null), api.network.overview().catch(() => null)]).then(([s, n]) =>
setPlaces([...(s?.servers ?? []).map((x) => ({ type: "server" as const, id: x.id, name: x.name })), ...(n?.devices ?? []).map((x) => ({ type: "device" as const, id: x.id, name: x.name }))]),
);
}, []);
const visible = useMemo(() => (list ?? []).filter((t) => !mineOnly || t.assignee?.id === user.id), [list, mineOnly, user.id]);
const open = visible.filter((t) => !t.doneAt);
const done = visible.filter((t) => t.doneAt);
async function create(v: TodoInput) {
setBusy(true);
setError(null);
try {
await api.todos.create(v);
toast.success("Added.");
load();
} catch (err) {
setError(readableError(err));
} finally {
setBusy(false);
}
}
async function save(t: TodoItem, v: TodoInput) {
setBusy(true);
try {
await api.todos.update(t.id, v);
setEditing(null);
toast.success("Saved.");
load();
} catch (err) {
toast.error(readableError(err));
} finally {
setBusy(false);
}
}
async function tick(t: TodoItem, finished: boolean) {
try {
await api.todos.update(t.id, { done: finished });
if (finished) {
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 {
load();
}
},
});
}
load();
} catch (err) {
toast.error(readableError(err));
}
}
async function remove(t: TodoItem) {
setEditing(null);
await removeWithUndo({
remove: () => api.todos.remove(t.id),
restore: () => api.todos.create({ title: t.title, detail: t.detail, dueDate: t.dueDate, assigneeId: t.assignee?.id ?? null, targetType: t.target?.type ?? null, targetId: t.target?.id ?? null }).then((r) => (t.doneAt ? api.todos.update(r.todo.id, { done: true }) : r)),
message: `Removed "${t.title}".`,
reload: load,
});
}
const row = (t: TodoItem) => {
const due = dueWords(t);
return (
<li key={t.id} className="list-group-item d-flex gap-3 align-items-start">
<input type="checkbox" className="form-check-input mt-1" aria-label={t.doneAt ? `Bring back: ${t.title}` : `Done: ${t.title}`} checked={!!t.doneAt} disabled={!canEdit} onChange={() => void tick(t, !t.doneAt)} />
<div className="me-auto">
<div className={t.doneAt ? "text-decoration-line-through text-secondary" : "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">
{due && <span className={due.className}>{due.text}</span>}
{t.assignee && <span className="badge bg-blue-lt text-blue">{t.assignee.name}</span>}
{t.target && <Link to={t.target.type === "server" ? `/servers/${t.target.id}` : "/network/devices"}>{t.target.name}</Link>}
{t.doneAt && (
<span className="text-secondary">
done <TimeAgo value={t.doneAt} />
{t.doneBy ? ` by ${t.doneBy}` : ""}
</span>
)}
</div>
</div>
{canEdit && (
<button type="button" className="btn btn-sm btn-outline-secondary" onClick={() => setEditing(t)}>
Edit
</button>
)}
</li>
);
};
return (
<>
<div className="d-flex flex-wrap align-items-center gap-2 mb-1">
<h2 className="page-title mb-0">To do</h2>
<div className="ms-auto btn-group btn-group-sm" role="group" aria-label="Whose jobs">
<button type="button" className={`btn ${!mineOnly ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={!mineOnly} onClick={() => setParams({})}>
Everyone&rsquo;s
</button>
<button type="button" className={`btn ${mineOnly ? "btn-primary" : "btn-outline-secondary"}`} aria-pressed={mineOnly} onClick={() => setParams({ who: "me" })}>
Handed to me
</button>
</div>
</div>
<div className="text-secondary mb-3">
The small jobs: replace the battery, move the NAS to the new switch. A job with a day is in <Link to="/coming-up?kinds=todo">Coming up</Link>; one handed to somebody is in their <Link to="/my-work">My work</Link>.
</div>
<ErrorNotice error={error} />
{canEdit && (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">Add a job</h3>
</div>
<div className="card-body">
<JobForm key={list?.length ?? 0} initial={{ title: "" }} people={people} places={places} busy={busy} submitLabel="Add" onSubmit={(v) => void create(v)} />
</div>
</div>
)}
{list === null && !error && <BlockSkeleton lines={3} />}
{list !== null && open.length === 0 && (
<div className="card mb-3">
<EmptyState title={mineOnly ? "Nothing is handed to you" : "Nothing to do"} hint={canEdit ? "Add a job above, and give it a day if it has one." : "Nothing has been written down."} />
</div>
)}
{open.length > 0 && (
<div className="card mb-3">
<div className="card-header">
<h3 className="card-title">To do ({open.length})</h3>
</div>
<ul className="list-group list-group-flush">{open.map(row)}</ul>
</div>
)}
{done.length > 0 && (
<div className="card">
<div className="card-header">
<h3 className="card-title">Done ({done.length})</h3>
<div className="card-actions">
<button type="button" className="btn btn-sm" onClick={() => setShowDone((v) => !v)}>
{showDone ? "Hide" : "Show"}
</button>
</div>
</div>
{showDone && <ul className="list-group list-group-flush">{done.map(row)}</ul>}
</div>
)}
{editing && (
<DetailDrawer title="Edit the job" subtitle={editing.title} onClose={() => setEditing(null)}>
<JobForm
initial={{ title: editing.title, detail: editing.detail, dueDate: editing.dueDate, assigneeId: editing.assignee?.id ?? null, targetType: editing.target?.type ?? null, targetId: editing.target?.id ?? null }}
people={people}
places={places}
busy={busy}
submitLabel="Save"
onSubmit={(v) => void save(editing, v)}
onCancel={() => setEditing(null)}
/>
<hr />
<button type="button" className="btn btn-outline-danger" onClick={() => void remove(editing)}>
Remove it
</button>
</DetailDrawer>
)}
</>
);
}
+2
View File
@@ -24,6 +24,8 @@ const INTEGRATION_NAMES: Record<string, string> = {
pbs: "Proxmox Backup Server",
osticket: "osTicket",
unifi: "UniFi",
npm: "Nginx Proxy Manager",
homeassistant: "Home Assistant",
};
function ColorList({
@@ -82,7 +82,7 @@ const DIGEST_DAYS: { value: number; label: string }[] = [
{ value: 6, label: "Saturday" },
{ value: 0, label: "Sunday" },
];
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true, flapRaises: 3, deviceOfflineMinutes: 10 };
const DEFAULT_HEALTH_CHECKS: HealthCheckSettings = { serverOfflineMinutes: 60, diskUsagePercent: 90, domainWarnDays: 30, diskForecastDays: 14, backupStaleHours: 48, restoreTestDays: 0, newPortAlerts: true, flapRaises: 3, deviceOfflineMinutes: 10, osSupportWarnDays: 90 };
const DEFAULT_MONTHLY: MonthlyReportSettings = { enabled: false, day: 1, time: "08:00" };
type TestResult = { ok: boolean; message: string } | null;
@@ -735,6 +735,15 @@ export default function NotificationSettings() {
hint="From each agent server's own history, shown on the Alerts page and dashboard (not sent as a notification). Needs a few days of steady growth to say anything. 0 turns it off."
onChange={(v) => setHealthChecks((h) => ({ ...h, diskForecastDays: v }))}
/>
<NumberField
label="Flag an operating system whose support ends within"
value={healthChecks.osSupportWarnDays}
min={0}
max={365}
unit="days"
hint="From what each agent says it runs (Linux agent 7, Windows agent 6, or later) and the vendors' published end-of-support dates. Shown on the Alerts page and the server's page (not sent as a notification); one whose support has ended is a warning. 0 turns it off."
onChange={(v) => setHealthChecks((h) => ({ ...h, osSupportWarnDays: v }))}
/>
<NumberField
label="Alert when a network device is offline for"
value={healthChecks.deviceOfflineMinutes}