From 13602272fc82c8879815ce61292e5387f572e9eb Mon Sep 17 00:00:00 2001 From: Adam French Date: Wed, 14 Oct 2026 21:32:57 +0100 Subject: [PATCH] Tidy the dashboard and setup pages, add one-click API keys Both pages share style.css and a top bar with Dashboard and Setup tabs. The dashboard gains summary tiles, card sections and friendly kind names. The setup page puts each collector in a collapsible section with its own Generate key button, which picks a free name, copies the key and fills it into that collector's steps. Command blocks get Copy buttons. Co-Authored-By: Claude Opus 5.5 --- README.md | 4 +- internal/api/api.go | 1 + internal/web/index.html | 94 ++++++------ internal/web/setup.html | 315 ++++++++++++++++++++++++---------------- internal/web/style.css | 82 +++++++++++ internal/web/web.go | 10 ++ 6 files changed, 337 insertions(+), 169 deletions(-) create mode 100644 internal/web/style.css diff --git a/README.md b/README.md index 75966fb..878a134 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ tracker goal rm --id 2 The dashboard (`/`) and the setup page (`/setup`) have no login of their own. As in job-tracker, the tracker borrows the main site's session. It forwards the browser's cookies to the site backend's `GET /auth/validate-admin` and treats a 2xx as admin (`internal/auth`). A visitor who isn't signed in is sent to the site's `/admin/login?redirect=/tracker/`, which returns them afterwards. A "yes" is cached for 30 seconds per cookie, so signing out takes up to 30 seconds to reach the tracker. If the backend refreshes an expired token, its new cookies are passed back to the browser. -Signed in, the dashboard shows every device's data without asking for a key. The setup page has step-by-step instructions for each collector, with your server URL filled in. It also lists devices and creates and revokes their API keys, so you don't need `docker exec` for keys. +Signed in, the dashboard shows every device's data without asking for a key. The setup page has step-by-step instructions for each collector, with your server URL filled in. It also lists devices and creates and revokes their API keys, so you don't need `docker exec` for keys. Each collector's section has a **Generate key** button that names the device (for example `firefox`, or `hyprland-2` if that's taken), copies the key to the clipboard and fills it into that collector's steps. Collectors never use the site login. Each one sends its own bearer key. @@ -104,7 +104,7 @@ Collectors never use the site login. Each one sends its own bearer key. | GET, POST | `/api/v1/devices` | admin | list devices; create one with `{"name","kind"}`, which returns its key once | | DELETE | `/api/v1/devices/{name}` | admin | revoke a device's key | | GET | `/`, `/setup` | admin | dashboard and setup pages | -| GET | `/tracker.user.js`, `/healthz`, `/readyz` | none | the browser userscript holds no secrets | +| GET | `/tracker.user.js`, `/style.css`, `/healthz`, `/readyz` | none | the browser userscript holds no secrets | The event batch format is shared by all `*/events` endpoints. A batch holds at most 1000 events. diff --git a/internal/api/api.go b/internal/api/api.go index c5a6783..ef3e2af 100644 --- a/internal/api/api.go +++ b/internal/api/api.go @@ -45,6 +45,7 @@ func New(s *store.Store, admin auth.Checker, loc *time.Location, log *slog.Logge }) mux.HandleFunc("GET /readyz", srv.ready) mux.HandleFunc("GET /tracker.user.js", web.UserScript) + mux.HandleFunc("GET /style.css", web.Style) mux.Handle("GET /{$}", srv.adminPage(web.Page(web.Index))) mux.Handle("GET /setup", srv.adminPage(web.Page(web.Setup))) diff --git a/internal/web/index.html b/internal/web/index.html index 5a0fee6..a0a35d1 100644 --- a/internal/web/index.html +++ b/internal/web/index.html @@ -4,49 +4,40 @@ Activity Tracker - +
-
-

Activity Tracker

-
+ + +
+

Today

+
+ + + + +
+

diff --git a/internal/web/style.css b/internal/web/style.css new file mode 100644 index 0000000..59ea395 --- /dev/null +++ b/internal/web/style.css @@ -0,0 +1,82 @@ +/* Shared by the dashboard and setup pages. */ +:root { + --bg:#f6f6f4; --card:#ffffff; --fg:#1b1b1b; --muted:#6b6b6b; --line:#e4e4e0; + --accent:#3d6fc4; --accent-soft:#e8eefa; --ok:#2e8b57; --bad:#c0392b; --code:#f2f2ef; +} +@media (prefers-color-scheme: dark) { + :root { + --bg:#121212; --card:#1b1b1b; --fg:#e8e8e8; --muted:#9a9a9a; --line:#2c2c2c; + --accent:#7aa2ea; --accent-soft:#1e2a40; --ok:#5cc28a; --bad:#e2685a; --code:#232323; + } +} +* { box-sizing:border-box; } +body { margin:0; background:var(--bg); color:var(--fg); font:15px/1.5 system-ui, sans-serif; } +main { max-width:800px; margin:0 auto; padding:0 16px 56px; } +a { color:var(--accent); } + +/* ---- top bar ---- */ +.topbar { display:flex; align-items:center; gap:20px; padding:16px 0; margin-bottom:8px; border-bottom:1px solid var(--line); } +.brand { font-weight:650; font-size:17px; } +.tabs { display:flex; gap:4px; } +.tabs a { color:var(--muted); text-decoration:none; padding:5px 10px; border-radius:6px; } +.tabs a:hover { color:var(--fg); } +.tabs a[aria-current="page"] { color:var(--fg); background:var(--accent-soft); } + +/* ---- controls ---- */ +input, select, button { font:inherit; color:inherit; background:var(--card); border:1px solid var(--line); border-radius:6px; padding:5px 10px; } +button { cursor:pointer; } +button:hover { border-color:var(--muted); } +button.primary { background:var(--accent); border-color:var(--accent); color:#fff; } +button.primary:hover { filter:brightness(1.08); } +button.small { padding:2px 8px; font-size:13px; } +button:disabled { opacity:.6; cursor:default; } +:focus-visible { outline:2px solid var(--accent); outline-offset:1px; } + +/* ---- layout pieces ---- */ +.row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; } +.spread { justify-content:space-between; } +.card { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:16px; margin-top:16px; } +.card > h2:first-child, .card > .row:first-child h2 { margin-top:0; } +h1 { font-size:20px; margin:16px 0 0; } +h2 { font-size:15px; margin:0 0 10px; } +h3 { font-size:14px; margin:16px 0 6px; } +.muted { color:var(--muted); } +.small-text { font-size:13px; } +.ok { color:var(--ok); } .bad, .err { color:var(--bad); } +.badge { display:inline-block; font-size:12px; padding:1px 7px; border-radius:999px; background:var(--accent-soft); color:var(--accent); white-space:nowrap; } + +.tiles { display:grid; grid-template-columns:repeat(auto-fit, minmax(160px, 1fr)); gap:12px; margin-top:16px; } +.tile { background:var(--card); border:1px solid var(--line); border-radius:10px; padding:12px 14px; } +.tile .k { font-size:13px; color:var(--muted); } +.tile .v { font-size:22px; font-weight:650; font-variant-numeric:tabular-nums; overflow-wrap:anywhere; } + +/* ---- tables ---- */ +.tablewrap { overflow-x:auto; } +table { width:100%; border-collapse:collapse; } +th, td { padding:7px 8px 7px 0; border-bottom:1px solid var(--line); text-align:left; vertical-align:top; } +tr:last-child td { border-bottom:0; } +th { font-weight:600; font-size:13px; color:var(--muted); } +td.num { text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; padding-left:12px; padding-right:0; } +td.label { overflow-wrap:anywhere; width:100%; } +td.time { white-space:nowrap; color:var(--muted); font-variant-numeric:tabular-nums; } +.bar { height:4px; background:var(--accent); border-radius:2px; margin-top:4px; opacity:.85; } + +/* ---- code ---- */ +code, pre { font:13px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; background:var(--code); border-radius:6px; } +code { padding:1px 5px; overflow-wrap:anywhere; } +pre { padding:10px 12px; overflow-x:auto; margin:0; } +.codeblock { position:relative; margin:8px 0; } +.codeblock .copy { position:absolute; top:6px; right:6px; } +ol, ul { padding-left:22px; margin:8px 0; } +li { margin:6px 0; } + +/* ---- setup ---- */ +.keybox { margin-top:12px; padding:12px; border:1px solid var(--ok); border-radius:8px; } +.keybox pre { margin:8px 0; } +details.collector { background:var(--card); border:1px solid var(--line); border-radius:10px; margin-top:12px; } +details.collector > summary { cursor:pointer; padding:14px 16px; list-style:none; display:flex; gap:10px; align-items:baseline; } +details.collector > summary::-webkit-details-marker { display:none; } +details.collector > summary::before { content:"▸"; color:var(--muted); } +details.collector[open] > summary::before { content:"▾"; } +details.collector > summary b { font-size:15px; } +details.collector > .body { padding:0 16px 16px; } diff --git a/internal/web/web.go b/internal/web/web.go index a53d39e..b49d774 100644 --- a/internal/web/web.go +++ b/internal/web/web.go @@ -18,8 +18,18 @@ var ( Setup []byte //go:embed tracker.user.js userScript []byte + //go:embed style.css + style []byte ) +// Style serves the stylesheet the pages share. It's public: the login +// redirect doesn't use it, but there's nothing private in it either. +func Style(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/css; charset=utf-8") + w.Header().Set("Cache-Control", "no-cache") + w.Write(style) +} + // Page serves a static HTML page. func Page(page []byte) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) {