Files
ccp/internal/web/index.html
T
adamfandClaude Opus 5.5 13602272fc
Test and publish / test (push) Successful in 20s
Test and publish / publish (push) Has been cancelled
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]>
2026-10-14 21:32:57 +01:00

147 lines
6.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Activity Tracker</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<main>
<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>
</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>
<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>
const $ = id => document.getElementById(id);
function dur(s) {
s = Math.round(s);
const h = Math.floor(s / 3600), m = Math.floor(s % 3600 / 60);
if (h) return `${h}h ${String(m).padStart(2, "0")}m`;
return m ? `${m}m` : `${s}s`;
}
const time = t => new Date(t).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&":"&amp;", "<":"&lt;", ">":"&gt;", '"':"&quot;" }[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) {
// Authenticated by the main site's session cookies, which the browser sends.
const r = await fetch("api/v1/" + path);
const body = await r.json().catch(() => ({}));
if (r.status === 401) { location.reload(); throw new Error("session expired"); } // reload goes to the login page
if (!r.ok) throw new Error(body.error || r.statusText);
return body;
}
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">${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 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">${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="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="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;
$("status").textContent = activities.length >= 500 ? "Timeline shows the first 500 activities." : "";
} catch (e) {
$("status").innerHTML = `<span class="err">${esc(e.message)}</span>`;
}
}
function shift(days) {
const d = new Date($("date").value + "T12:00:00");
d.setDate(d.getDate() + days);
$("date").value = d.toLocaleDateString("en-CA");
load();
}
$("prev").onclick = () => shift(-1);
$("next").onclick = () => shift(1);
$("today").onclick = () => { $("date").value = today(); load(); };
$("date").onchange = load;
$("date").value = today();
load();
</script>
</body>
</html>