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 <[email protected]>
This commit is contained in:
+53
-41
@@ -4,49 +4,40 @@
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title>Activity Tracker</title>
|
||||
<style>
|
||||
:root { --bg:#fafafa; --fg:#1a1a1a; --muted:#6b6b6b; --line:#e2e2e2; --bar:#4a7bd0; --ok:#2e8b57; --bad:#c0392b; }
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root { --bg:#151515; --fg:#e6e6e6; --muted:#999; --line:#2c2c2c; --bar:#6f9be6; --ok:#5cc28a; --bad:#e2685a; }
|
||||
}
|
||||
* { box-sizing: border-box; }
|
||||
body { margin:0; background:var(--bg); color:var(--fg); font:15px/1.45 system-ui, sans-serif; }
|
||||
main { max-width:760px; margin:0 auto; padding:24px 16px 48px; }
|
||||
header { display:flex; flex-wrap:wrap; gap:8px; align-items:center; justify-content:space-between; }
|
||||
h1 { font-size:20px; margin:0; }
|
||||
h2 { font-size:13px; text-transform:uppercase; letter-spacing:.05em; color:var(--muted); margin:28px 0 8px; }
|
||||
input, button { font:inherit; color:inherit; background:transparent; border:1px solid var(--line); border-radius:6px; padding:4px 8px; }
|
||||
button { cursor:pointer; }
|
||||
.nav { display:flex; gap:6px; align-items:center; }
|
||||
.muted { color:var(--muted); }
|
||||
.err { color:var(--bad); }
|
||||
table { width:100%; border-collapse:collapse; }
|
||||
td { padding:5px 0; border-bottom:1px solid var(--line); vertical-align:top; }
|
||||
td.num { text-align:right; white-space:nowrap; font-variant-numeric:tabular-nums; padding-left:12px; }
|
||||
td.label { overflow-wrap:anywhere; }
|
||||
.bar { height:4px; background:var(--bar); border-radius:2px; margin-top:3px; }
|
||||
.ok { color:var(--ok); } .bad { color:var(--bad); }
|
||||
a { color:var(--bar); }
|
||||
</style>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<main>
|
||||
<header>
|
||||
<h1>Activity Tracker</h1>
|
||||
<div class="nav">
|
||||
<button id="prev" aria-label="Previous day">‹</button>
|
||||
<input type="date" id="date">
|
||||
<button id="next" aria-label="Next day">›</button>
|
||||
<nav class="topbar">
|
||||
<span class="brand">Activity Tracker</span>
|
||||
<div class="tabs">
|
||||
<a href="./" aria-current="page">Dashboard</a>
|
||||
<a href="setup">Setup</a>
|
||||
</div>
|
||||
</header>
|
||||
</nav>
|
||||
|
||||
<div class="row spread">
|
||||
<h1 id="title">Today</h1>
|
||||
<div class="row">
|
||||
<button id="prev" aria-label="Previous day">‹</button>
|
||||
<input type="date" id="date" aria-label="Day">
|
||||
<button id="next" aria-label="Next day">›</button>
|
||||
<button id="today">Today</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p id="status" class="muted"></p>
|
||||
<div id="content" hidden>
|
||||
<h2>Goals</h2><table id="goals"></table>
|
||||
<h2>By kind</h2><table id="kinds"></table>
|
||||
<h2>Top labels</h2><table id="labels"></table>
|
||||
<h2>Timeline</h2><table id="timeline"></table>
|
||||
<div class="tiles">
|
||||
<div class="tile"><div class="k">Desktop time</div><div class="v" id="t-desktop">–</div></div>
|
||||
<div class="tile"><div class="k">Browser time</div><div class="v" id="t-browser">–</div></div>
|
||||
<div class="tile"><div class="k">Top site or app</div><div class="v" id="t-top">–</div></div>
|
||||
<div class="tile"><div class="k">Goals met</div><div class="v" id="t-goals">–</div></div>
|
||||
</div>
|
||||
<section class="card"><h2>Goals</h2><div class="tablewrap"><table id="goals"></table></div></section>
|
||||
<section class="card"><h2>By kind</h2><div class="tablewrap"><table id="kinds"></table></div></section>
|
||||
<section class="card"><h2>Top labels</h2><div class="tablewrap"><table id="labels"></table></div></section>
|
||||
<section class="card"><h2>Timeline</h2><div class="tablewrap"><table id="timeline"></table></div></section>
|
||||
</div>
|
||||
</main>
|
||||
<script>
|
||||
@@ -60,6 +51,9 @@ function dur(s) {
|
||||
}
|
||||
const time = t => new Date(t).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
||||
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&":"&", "<":"<", ">":">", '"':""" }[c]));
|
||||
// Friendlier names for the kinds collectors send; anything else shows as is.
|
||||
const KINDS = { app_focus: "desktop", tab_focus: "browser", at_desk: "at desk", in_bed: "in bed" };
|
||||
const kind = k => esc(KINDS[k] || k);
|
||||
const today = () => new Date().toLocaleDateString("en-CA"); // YYYY-MM-DD in local time
|
||||
|
||||
async function api(path) {
|
||||
@@ -75,39 +69,56 @@ function rows(el, items, render, empty) {
|
||||
el.innerHTML = items.length ? items.map(render).join("") : `<tr><td class="muted">${empty}</td></tr>`;
|
||||
}
|
||||
|
||||
function setTitle(date) {
|
||||
const d = new Date(date + "T12:00:00");
|
||||
const diff = Math.round((new Date(today() + "T12:00:00") - d) / 864e5);
|
||||
$("title").textContent = diff === 0 ? "Today" : diff === 1 ? "Yesterday"
|
||||
: d.toLocaleDateString([], { weekday: "long", day: "numeric", month: "long" });
|
||||
$("today").disabled = diff === 0;
|
||||
}
|
||||
|
||||
async function load() {
|
||||
const date = $("date").value;
|
||||
setTitle(date);
|
||||
$("status").textContent = "Loading…";
|
||||
try {
|
||||
const sum = await api("summary/daily?date=" + date);
|
||||
const q = new URLSearchParams({ from: sum.from, to: sum.to, limit: "500" });
|
||||
const { activities } = await api("activities?" + q);
|
||||
|
||||
$("t-desktop").textContent = dur(sum.by_kind.app_focus || 0);
|
||||
$("t-browser").textContent = dur(sum.by_kind.tab_focus || 0);
|
||||
const focus = sum.totals.filter(t => t.kind === "app_focus" || t.kind === "tab_focus")
|
||||
.sort((a, b) => b.seconds - a.seconds)[0];
|
||||
$("t-top").textContent = focus ? focus.label || "—" : "–";
|
||||
$("t-goals").textContent = sum.goals.length ? `${sum.goals.filter(g => g.met).length} / ${sum.goals.length}` : "–";
|
||||
|
||||
rows($("goals"), sum.goals, g => `<tr>
|
||||
<td class="label">${esc(g.kind)}${g.label ? " · " + esc(g.label) : ""}
|
||||
<td class="label">${kind(g.kind)}${g.label ? " · " + esc(g.label) : ""}
|
||||
<span class="muted">${esc(g.op)} ${dur(g.target_s)}</span></td>
|
||||
<td class="num">${dur(g.actual_s)}</td>
|
||||
<td class="num ${g.met ? "ok" : "bad"}">${g.met ? "✓ met" : "✗ missed"}</td></tr>`,
|
||||
"No goals. Add one with <code>tracker goal add</code>.");
|
||||
`No goals yet. See <a href="setup#goals">Setup</a>.`);
|
||||
|
||||
const kinds = Object.entries(sum.by_kind).sort((a, b) => b[1] - a[1]);
|
||||
const maxK = kinds[0]?.[1] || 1;
|
||||
rows($("kinds"), kinds, ([k, s]) => `<tr>
|
||||
<td class="label">${esc(k)}<div class="bar" style="width:${s / maxK * 100}%"></div></td>
|
||||
<td class="label">${kind(k)}<div class="bar" style="width:${s / maxK * 100}%"></div></td>
|
||||
<td class="num">${dur(s)}</td></tr>`, "Nothing recorded.");
|
||||
|
||||
const labels = [...sum.totals].sort((a, b) => b.seconds - a.seconds).slice(0, 15);
|
||||
const maxL = labels[0]?.seconds || 1;
|
||||
rows($("labels"), labels, t => `<tr>
|
||||
<td class="label">${esc(t.label || "—")} <span class="muted">${esc(t.kind)}</span>
|
||||
<td class="label">${esc(t.label || "—")} <span class="badge">${kind(t.kind)}</span>
|
||||
<div class="bar" style="width:${t.seconds / maxL * 100}%"></div></td>
|
||||
<td class="num">${dur(t.seconds)}</td></tr>`, "Nothing recorded.");
|
||||
|
||||
const acts = activities.filter(a => a.duration_s >= 60)
|
||||
.sort((a, b) => new Date(b.started_at) - new Date(a.started_at));
|
||||
rows($("timeline"), acts, a => `<tr>
|
||||
<td class="num muted" style="padding:5px 12px 5px 0">${time(a.started_at)}–${time(a.ended_at)}</td>
|
||||
<td class="label">${esc(a.label || a.kind)} <span class="muted">${esc(a.kind)}${a.attrs?.title ? " · " + esc(a.attrs.title) : ""}</span></td>
|
||||
<td class="time">${time(a.started_at)}–${time(a.ended_at)}</td>
|
||||
<td class="label">${esc(a.label || a.kind)} <span class="badge">${kind(a.kind)}</span>
|
||||
${a.attrs?.title ? `<div class="muted small-text">${esc(a.attrs.title)}</div>` : ""}</td>
|
||||
<td class="num">${dur(a.duration_s)}</td></tr>`, "No activities of a minute or longer.");
|
||||
|
||||
$("content").hidden = false;
|
||||
@@ -126,6 +137,7 @@ function shift(days) {
|
||||
|
||||
$("prev").onclick = () => shift(-1);
|
||||
$("next").onclick = () => shift(1);
|
||||
$("today").onclick = () => { $("date").value = today(); load(); };
|
||||
$("date").onchange = load;
|
||||
$("date").value = today();
|
||||
load();
|
||||
|
||||
Reference in New Issue
Block a user