419 lines
24 KiB
Vue
419 lines
24 KiB
Vue
<script setup lang="ts">
|
||
import { computed, nextTick, onMounted, reactive, ref, watch } from "vue";
|
||
import { useRoute } from "vue-router";
|
||
import { api, type AdminGoal, type Device, type NotificationSettings, type Report } from "../api";
|
||
import CodeBlock from "../components/CodeBlock.vue";
|
||
import Collector from "../components/Collector.vue";
|
||
import KeyBox from "../components/KeyBox.vue";
|
||
|
||
// The tracker's public URL, e.g. https://www.adam-french.co.uk/tracker
|
||
const base = new URL(".", location.href).href.replace(/\/$/, "");
|
||
|
||
const devices = ref<Device[]>([]);
|
||
const loaded = ref(false);
|
||
const status = ref<{ msg: string; cls?: string }>({ msg: "" });
|
||
const active = computed(() => devices.value.filter(d => !d.revoked_at));
|
||
const revoked = computed(() => devices.value.filter(d => d.revoked_at));
|
||
const goals = ref<AdminGoal[]>([]);
|
||
const goalLoaded = ref(false);
|
||
const goalForm = reactive({ kind: "tab_focus", label: "", op: ">=", target: "30m" });
|
||
const editingGoal = ref<number | null>(null);
|
||
const goalBusy = ref(false);
|
||
const pendingRevoke = ref<Device | null>(null);
|
||
const revokeCancel = ref<HTMLButtonElement>();
|
||
const reports = ref<Report[]>([]);
|
||
const notifications = reactive<NotificationSettings>({ ntfy_server: "https://ntfy.sh", ntfy_topic: "", enabled: false, retention_days: 0 });
|
||
const purgeBefore = ref(new Date(Date.now() - 90 * 86400000).toISOString().slice(0, 10));
|
||
const privacyBusy = ref(false);
|
||
|
||
// Which collector sections are open: the browser's by default, and the one a
|
||
// #section in the URL names.
|
||
const open = reactive<Record<string, boolean>>({ browser: true });
|
||
const route = useRoute();
|
||
if (route.hash) open[route.hash.slice(1)] = true;
|
||
|
||
// The last key generated, shown under the button that made it ("create" is
|
||
// the form), and the keys filled into each collector's steps.
|
||
const issued = ref<{ slot: string; device: Device; key: string } | null>(null);
|
||
const keys = reactive<Record<string, string>>({});
|
||
const keyFor = (kind: string) => keys[kind] || "trk_…";
|
||
const busy = ref("");
|
||
|
||
// The place a pair of Shortcuts automations reports. It ends up in a URL
|
||
// path, so spaces become hyphens rather than relying on Shortcuts to encode.
|
||
const place = ref("home");
|
||
const placeName = computed(() => place.value.trim().toLowerCase().replace(/[\s/?#]+/g, "-") || "home");
|
||
|
||
const kindSel = ref("browser");
|
||
const nameIn = ref("");
|
||
|
||
function ago(t?: string | null) {
|
||
if (!t) return "never";
|
||
const s = (Date.now() - +new Date(t)) / 1000;
|
||
if (s < 90) return "just now";
|
||
if (s < 3600) return Math.round(s / 60) + " min ago";
|
||
if (s < 86400) return Math.round(s / 3600) + " h ago";
|
||
return new Date(t).toLocaleDateString([], { day: "numeric", month: "short", year: "numeric" });
|
||
}
|
||
|
||
function deviceStatus(d: Device) {
|
||
if (d.revoked_at) return { label: "Revoked", cls: "bad" };
|
||
if (!d.last_seen_at) return { label: "Never seen", cls: "warn" };
|
||
const age = Date.now() - +new Date(d.last_seen_at);
|
||
return age < 2 * 86400000 ? { label: "Healthy", cls: "good" } : { label: "Stale", cls: "warn" };
|
||
}
|
||
|
||
function parseDuration(value: string) {
|
||
const m = value.trim().match(/^(?:(\d+(?:\.\d+)?)h)?\s*(?:(\d+(?:\.\d+)?)m)?\s*(?:(\d+(?:\.\d+)?)s)?$/i);
|
||
if (!m || !m[1] && !m[2] && !m[3]) return 0;
|
||
return Math.round((Number(m[1] || 0) * 3600) + (Number(m[2] || 0) * 60) + Number(m[3] || 0));
|
||
}
|
||
|
||
function formatDuration(s: number) {
|
||
const h = Math.floor(s / 3600), m = Math.floor(s % 3600 / 60), sec = s % 60;
|
||
return h ? `${h}h${m ? ` ${m}m` : ""}` : m ? `${m}m${sec ? ` ${sec}s` : ""}` : `${sec}s`;
|
||
}
|
||
|
||
async function loadDevices() {
|
||
try {
|
||
({ devices: devices.value } = await api<{ devices: Device[] }>("GET", "devices"));
|
||
loaded.value = true;
|
||
} catch (e) {
|
||
status.value = { msg: (e as Error).message, cls: "err" };
|
||
}
|
||
}
|
||
async function loadGoals() {
|
||
try {
|
||
const out = await api<{ goals: AdminGoal[] }>("GET", "goals");
|
||
goals.value = out.goals;
|
||
goalLoaded.value = true;
|
||
} catch (e) {
|
||
status.value = { msg: (e as Error).message, cls: "err" };
|
||
}
|
||
}
|
||
async function loadAdminData() {
|
||
try {
|
||
const [notification, reportList] = await Promise.all([
|
||
api<{ settings: NotificationSettings }>("GET", "notifications/status"),
|
||
api<{ reports: Report[] }>("GET", "reports"),
|
||
]);
|
||
Object.assign(notifications, notification.settings);
|
||
reports.value = reportList.reports;
|
||
} catch (e) { status.value = { msg: (e as Error).message, cls: "err" }; }
|
||
}
|
||
onMounted(() => { loadDevices(); loadGoals(); loadAdminData(); });
|
||
|
||
// A readable name that isn't taken yet (names stay taken after revoking).
|
||
function suggestName(kind: string) {
|
||
let stem = ({ location: "iphone", manual: "script" } as Record<string, string>)[kind] || kind;
|
||
if (kind === "browser") {
|
||
const ua = navigator.userAgent;
|
||
stem = /Firefox\//.test(ua) ? "firefox" : /Edg\//.test(ua) ? "edge" : /Chrome\//.test(ua) ? "chrome" : "browser";
|
||
}
|
||
const taken = new Set(devices.value.map(d => d.name));
|
||
let name = stem;
|
||
for (let i = 2; taken.has(name); i++) name = `${stem}-${i}`;
|
||
return name;
|
||
}
|
||
|
||
async function generate(kind: string, name: string, slot: string) {
|
||
busy.value = slot;
|
||
try {
|
||
if (!loaded.value) await loadDevices();
|
||
const { device, key } = await api<{ device: Device; key: string }>("POST", "devices", { kind, name: name || suggestName(kind) });
|
||
issued.value = { slot, device, key };
|
||
// Fill the key into this collector's steps so they can be copied as-is.
|
||
keys[kind] = key;
|
||
open[kind] = true;
|
||
status.value = { msg: "" };
|
||
loadDevices();
|
||
return true;
|
||
} catch (e) {
|
||
status.value = { msg: (e as Error).message, cls: "err" };
|
||
return false;
|
||
} finally {
|
||
busy.value = "";
|
||
}
|
||
}
|
||
|
||
async function create() {
|
||
if (await generate(kindSel.value, nameIn.value.trim(), "create")) nameIn.value = "";
|
||
}
|
||
|
||
async function revoke(name: string) {
|
||
pendingRevoke.value = devices.value.find(d => d.name === name) || null;
|
||
}
|
||
|
||
watch(pendingRevoke, value => { if (value) nextTick(() => revokeCancel.value?.focus()); });
|
||
|
||
async function confirmRevoke() {
|
||
const device = pendingRevoke.value;
|
||
if (!device) return;
|
||
try {
|
||
await api("DELETE", "devices/" + encodeURIComponent(device.name));
|
||
status.value = { msg: `Revoked ${device.name}.`, cls: "ok" };
|
||
pendingRevoke.value = null;
|
||
loadDevices();
|
||
} catch (e) {
|
||
status.value = { msg: (e as Error).message, cls: "err" };
|
||
}
|
||
}
|
||
|
||
async function addGoal() {
|
||
const target_s = parseDuration(goalForm.target);
|
||
if (!goalForm.kind.trim() || target_s <= 0) { status.value = { msg: "Enter a kind and a duration such as 30m or 1h.", cls: "err" }; return; }
|
||
goalBusy.value = true;
|
||
try {
|
||
const body = { kind: goalForm.kind.trim(), label: goalForm.label.trim(), op: goalForm.op, target_s };
|
||
if (editingGoal.value === null) {
|
||
const out = await api<AdminGoal>("POST", "goals", body);
|
||
goals.value.push(out);
|
||
status.value = { msg: "Goal added.", cls: "ok" };
|
||
} else {
|
||
const out = await api<AdminGoal>("PUT", "goals/" + encodeURIComponent(String(editingGoal.value)), body);
|
||
goals.value = goals.value.map(g => g.id === editingGoal.value ? out : g);
|
||
status.value = { msg: "Goal updated.", cls: "ok" };
|
||
}
|
||
resetGoalForm();
|
||
} catch (e) { status.value = { msg: (e as Error).message, cls: "err" }; }
|
||
finally { goalBusy.value = false; }
|
||
}
|
||
|
||
function editGoal(goal: AdminGoal) {
|
||
editingGoal.value = goal.id;
|
||
goalForm.kind = goal.kind;
|
||
goalForm.label = goal.label;
|
||
goalForm.op = goal.op;
|
||
goalForm.target = formatDuration(goal.target_s).replace(" ", "");
|
||
}
|
||
|
||
function resetGoalForm() {
|
||
editingGoal.value = null;
|
||
goalForm.kind = "tab_focus";
|
||
goalForm.label = "";
|
||
goalForm.op = ">=";
|
||
goalForm.target = "30m";
|
||
}
|
||
|
||
async function removeGoal(goal: AdminGoal) {
|
||
try {
|
||
await api("DELETE", "goals/" + encodeURIComponent(String(goal.id)));
|
||
goals.value = goals.value.filter(g => g.id !== goal.id);
|
||
status.value = { msg: "Goal removed.", cls: "ok" };
|
||
} catch (e) { status.value = { msg: (e as Error).message, cls: "err" }; }
|
||
}
|
||
|
||
async function saveNotifications() {
|
||
privacyBusy.value = true;
|
||
try {
|
||
Object.assign(notifications, await api<NotificationSettings>("PUT", "notifications/config", notifications));
|
||
status.value = { msg: "Notification and retention settings saved.", cls: "ok" };
|
||
} catch (e) { status.value = { msg: (e as Error).message, cls: "err" }; }
|
||
finally { privacyBusy.value = false; }
|
||
}
|
||
|
||
async function purgeData() {
|
||
if (!purgeBefore.value) return;
|
||
privacyBusy.value = true;
|
||
try {
|
||
const before = new Date(purgeBefore.value + "T00:00:00").toISOString();
|
||
const out = await api<{ deleted: number }>("POST", "privacy/purge?before=" + encodeURIComponent(before));
|
||
status.value = { msg: `Deleted ${out.deleted} records before ${purgeBefore.value}.`, cls: "ok" };
|
||
} catch (e) { status.value = { msg: (e as Error).message, cls: "err" }; }
|
||
finally { privacyBusy.value = false; }
|
||
}
|
||
|
||
const setupProgress = computed(() => {
|
||
const done = [active.value.length > 0, goals.value.length > 0, active.value.some(d => d.last_seen_at)].filter(Boolean).length;
|
||
return { done, total: 3 };
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<h1>Setup</h1>
|
||
<p class="muted">Each collector uploads to <code>{{ base }}</code> with its own API key. Open a collector below and click <b>Generate key</b>; the key is filled into its steps. A key is shown only once.</p>
|
||
|
||
<section class="card" aria-labelledby="progress-title">
|
||
<div class="row spread"><h2 id="progress-title">Getting started</h2><span class="badge">{{ setupProgress.done }}/{{ setupProgress.total }} complete</span></div>
|
||
<ol class="setup-progress">
|
||
<li :class="{ ok: active.length }"><b>{{ active.length ? "Device created" : "Create a device key" }}</b><span class="muted"> Generate a key below, then follow that collector's instructions.</span></li>
|
||
<li :class="{ ok: goals.length }"><b>{{ goals.length ? "Goals configured" : "Add a daily goal" }}</b><span class="muted"> Optional targets are managed here and appear on the dashboard.</span></li>
|
||
<li :class="{ ok: active.some(d => d.last_seen_at) }"><b>{{ active.some(d => d.last_seen_at) ? "First upload received" : "Check device health" }}</b><span class="muted"> A healthy device has uploaded in the last two days.</span></li>
|
||
</ol>
|
||
</section>
|
||
|
||
<section class="card">
|
||
<div class="row spread"><h2>Devices</h2></div>
|
||
<div class="tablewrap"><table>
|
||
<caption class="sr-only">Collector devices and upload health</caption>
|
||
<thead><tr><th scope="col">Name</th><th scope="col">Kind</th><th scope="col">Health</th><th scope="col">Last upload</th><th scope="col"><span class="sr-only">Actions</span></th></tr></thead>
|
||
<tbody v-if="!loaded"><tr><td colspan="5" class="muted">Loading…</td></tr></tbody>
|
||
<tbody v-else>
|
||
<tr v-for="d in active" :key="d.name">
|
||
<td class="label">{{ d.name }}</td>
|
||
<td><span class="badge">{{ d.kind }}</span></td>
|
||
<td><span class="status-dot" :class="deviceStatus(d).cls"></span>{{ deviceStatus(d).label }}</td>
|
||
<td class="time">{{ ago(d.last_seen_at) }}</td>
|
||
<td class="num"><button class="small" @click="revoke(d.name)">Revoke</button></td>
|
||
</tr>
|
||
<tr v-if="!active.length"><td colspan="5" class="muted">No devices yet.</td></tr>
|
||
<tr v-if="revoked.length"><td colspan="5" class="muted small-text">{{ revoked.length }} revoked: {{ revoked.map(d => d.name).join(", ") }}</td></tr>
|
||
</tbody>
|
||
</table></div>
|
||
<form class="row" style="margin-top:12px" @submit.prevent="create">
|
||
<select v-model="kindSel" aria-label="Kind">
|
||
<option value="browser">Browser</option>
|
||
<option value="hyprland">Hyprland</option>
|
||
<option value="location">iPhone location</option>
|
||
<option value="manual">Script / manual</option>
|
||
<option value="presence">Presence</option>
|
||
</select>
|
||
<input v-model="nameIn" placeholder="Name (optional)" aria-label="Name" style="flex:1; min-width:140px">
|
||
<button class="primary" :disabled="busy === 'create'">Generate key</button>
|
||
</form>
|
||
<KeyBox v-if="issued?.slot === 'create'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
|
||
<p class="small-text" :class="status.cls">{{ status.msg }}</p>
|
||
<div v-if="pendingRevoke" class="confirm" role="alertdialog" aria-modal="true" aria-labelledby="revoke-title" aria-describedby="revoke-copy" @keydown.esc="pendingRevoke = null">
|
||
<h3 id="revoke-title">Revoke {{ pendingRevoke.name }}?</h3>
|
||
<p id="revoke-copy">This stops the collector from uploading. Existing data is not deleted, but the key cannot be used again.</p>
|
||
<div class="row"><button ref="revokeCancel" class="small" @click="pendingRevoke = null">Keep device</button><button class="small danger" @click="confirmRevoke">Revoke device</button></div>
|
||
</div>
|
||
</section>
|
||
|
||
<Collector id="browser" title="Browser" hint="Violentmonkey userscript · time per site" v-model:open="open.browser">
|
||
<p>Records <code>tab_focus</code> intervals labelled by hostname. A tab counts only while it's the selected tab of the focused window, and stops after 5 minutes without input unless video or audio is playing.</p>
|
||
<button class="primary" :disabled="busy === 'browser'" @click="generate('browser', '', 'browser')">Generate key for this browser</button>
|
||
<KeyBox v-if="issued?.slot === 'browser'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
|
||
<ol>
|
||
<li>Install Violentmonkey: <a href="https://addons.mozilla.org/firefox/addon/violentmonkey/" target="_blank" rel="noopener">Firefox <span class="sr-only">(opens in a new tab)</span></a> · <a href="https://chromewebstore.google.com/detail/violentmonkey/jinjaccalgkegednnccohejagnlnfdag" target="_blank" rel="noopener">Chrome / Chromium <span class="sr-only">(opens in a new tab)</span></a></li>
|
||
<li>Open <a :href="base + '/tracker.user.js'">{{ base }}/tracker.user.js</a> and click <b>Install</b>. Violentmonkey checks this URL for updates.</li>
|
||
<li>Click the Violentmonkey toolbar icon, then <b>Activity Tracker → Set server and API key</b>. Enter the server and key:
|
||
<CodeBlock>{{ base }}</CodeBlock>
|
||
<CodeBlock>{{ keys.browser || "trk_… (generate a key above)" }}</CodeBlock></li>
|
||
<li>Check it with <b>Status / upload now</b> in the same menu. Uploads happen every minute.</li>
|
||
</ol>
|
||
<p class="muted small-text">The menu also turns full URLs and page titles on or off (both off by default), sets hosts to ignore, and changes the idle timeout. It runs on every web page and on local <code>file://</code> pages (labelled <code>file</code>; in Chrome, turn on <b>Allow access to file URLs</b> in Violentmonkey's extension details). Browsers block all extensions on <code>about:</code> pages, the new tab page, extension stores and the PDF viewer, so those aren't recorded; Hyprland still counts them as browser time.</p>
|
||
</Collector>
|
||
|
||
<Collector id="hyprland" title="Hyprland desktop" hint="focused window, idle and locked time" v-model:open="open.hyprland">
|
||
<p>Records <code>app_focus</code> intervals labelled by window class, with the title.</p>
|
||
<button class="primary" :disabled="busy === 'hyprland'" @click="generate('hyprland', '', 'hyprland')">Generate key for this machine</button>
|
||
<KeyBox v-if="issued?.slot === 'hyprland'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
|
||
<h3>1. Install the agent</h3>
|
||
<CodeBlock>git clone ssh://[email protected]:2222/adamf/ccp.git && cd ccp
|
||
make install-agent # ~/.local/bin/hypr-agent and the systemd user unit</CodeBlock>
|
||
<h3>2. Configure and start it</h3>
|
||
<CodeBlock>mkdir -p ~/.config/hypr-agent
|
||
cat > ~/.config/hypr-agent/env <<EOF
|
||
TRACKER_URL={{ base }}
|
||
TRACKER_API_KEY={{ keyFor("hyprland") }}
|
||
# HYPR_AGENT_TITLES=false # don't send window titles at all
|
||
# HYPR_AGENT_REDACT=(?i)bank|private # replace matching titles with [redacted]
|
||
EOF
|
||
chmod 600 ~/.config/hypr-agent/env
|
||
systemctl --user enable --now hypr-agent</CodeBlock>
|
||
<h3>3. Idle and lock (optional)</h3>
|
||
<p>Add to <code>~/.config/hypr/hypridle.conf</code>:</p>
|
||
<CodeBlock>general {
|
||
lock_cmd = hypr-agent lock; pidof hyprlock || hyprlock
|
||
unlock_cmd = hypr-agent unlock
|
||
}
|
||
|
||
listener {
|
||
timeout = 300
|
||
on-timeout = hypr-agent idle
|
||
on-resume = hypr-agent resume
|
||
}</CodeBlock>
|
||
<p class="muted small-text">Check it with <code>journalctl --user -u hypr-agent -f</code>. Events upload every minute and wait in <code>~/.local/state/hypr-agent/buffer.jsonl</code> while the server can't be reached.</p>
|
||
</Collector>
|
||
|
||
<Collector id="location" title="iPhone location" hint="Shortcuts automations · time at home and away" v-model:open="open.location">
|
||
<p>Records <code>place</code> intervals labelled by place (<code>home</code>, <code>gym</code>, …) and <code>away</code> in between. Each arrive or leave closes the current interval and opens the next; the current one counts up to now.</p>
|
||
<button class="primary" :disabled="busy === 'location'" @click="generate('location', '', 'location')">Generate key for this phone</button>
|
||
<KeyBox v-if="issued?.slot === 'location'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
|
||
<h3>1. Make the Tracker shortcut (once)</h3>
|
||
<ol>
|
||
<li>In the Shortcuts app, on the <b>Shortcuts</b> tab, tap <b>+</b> and name the shortcut <code>Tracker</code>.</li>
|
||
<li>Add the action <b>Get Contents of URL</b>. In the URL, type the text below, then insert the <b>Shortcut Input</b> variable right after the last slash:
|
||
<CodeBlock>{{ base }}/api/v1/location/</CodeBlock></li>
|
||
<li>Tap <b>Show More</b>. Set Method to <code>POST</code> and add a header <code>Authorization</code> = <code>Bearer {{ keyFor("location") }}</code></li>
|
||
</ol>
|
||
<p class="muted small-text">The shortcut holds your key, so don't share it.</p>
|
||
<h3>2. Add two automations per place</h3>
|
||
<p>Type the place's name to fill in the steps:</p>
|
||
<div class="row"><input v-model="place" placeholder="home" aria-label="Place name" style="flex:1; min-width:140px"></div>
|
||
<ol>
|
||
<li>On the <b>Automation</b> tab, tap <b>+</b>, choose <b>Arrive</b>, set Location to your {{ placeName }}'s address and pick <b>Run Immediately</b> (turn off <b>Notify When Run</b> if you like). Then tap <b>New Blank Automation</b>.</li>
|
||
<li>Add a <b>Text</b> action containing:
|
||
<CodeBlock>arrive/{{ placeName }}</CodeBlock>
|
||
then a <b>Run Shortcut</b> action set to <b>Tracker</b>. The Text becomes its input.</li>
|
||
<li>Repeat with <b>Leave</b> for the same address, with the Text:
|
||
<CodeBlock>leave/{{ placeName }}</CodeBlock></li>
|
||
</ol>
|
||
<p class="muted small-text">Any name works except <code>away</code>. Names are lower-cased, and spaces become hyphens. Repeated triggers are ignored, and a late "leave home" after "arrive gym" doesn't undo the arrival. Goal examples: <code>--kind place --label away --op '>=' --target 1h</code>, <code>--kind place --label gym --op '>=' --target 45m</code>.</p>
|
||
</Collector>
|
||
|
||
<Collector id="manual" title="Scripts" hint="post any interval with curl" v-model:open="open.manual">
|
||
<button class="primary" :disabled="busy === 'manual'" @click="generate('manual', '', 'manual')">Generate key for scripts</button>
|
||
<KeyBox v-if="issued?.slot === 'manual'" :key="issued.key" :device="issued.device" :api-key="issued.key" />
|
||
<CodeBlock>curl -X POST {{ base }}/api/v1/manual/events \
|
||
-H 'Authorization: Bearer {{ keyFor("manual") }}' -H 'Content-Type: application/json' \
|
||
-d '{"events":[{"id":"reading-2026-10-14","kind":"reading","label":"book",
|
||
"started_at":"2026-10-14T20:00:00Z","ended_at":"2026-10-14T20:45:00Z"}]}'</CodeBlock>
|
||
<p class="muted small-text">The <code>id</code> makes re-sending safe: a duplicate is ignored. Webcam presence (<code>/api/v1/presence/events</code>) has an endpoint but no agent yet.</p>
|
||
</Collector>
|
||
|
||
<Collector id="goals" title="Goals" hint="daily targets on the dashboard" v-model:open="open.goals">
|
||
<p>Daily targets are managed here. An empty label matches every label of that kind. Durations accept values such as <code>30m</code>, <code>1h</code>, or <code>1h 30m</code>.</p>
|
||
<form class="goal-form" @submit.prevent="addGoal">
|
||
<label>Kind<input v-model="goalForm.kind" required placeholder="tab_focus"></label>
|
||
<label>Label <span class="muted">(optional)</span><input v-model="goalForm.label" placeholder="youtube.com"></label>
|
||
<label>Rule<select v-model="goalForm.op"><option value=">=">At least</option><option value="<=">At most</option></select></label>
|
||
<label>Target per day<input v-model="goalForm.target" required placeholder="30m"></label>
|
||
<div class="row"><button class="primary" :disabled="goalBusy">{{ goalBusy ? "Saving…" : editingGoal === null ? "Add goal" : "Save goal" }}</button><button v-if="editingGoal !== null" type="button" class="small" @click="resetGoalForm">Cancel</button></div>
|
||
</form>
|
||
<div class="tablewrap" v-if="goalLoaded || goals.length">
|
||
<table>
|
||
<caption class="sr-only">Configured daily goals</caption>
|
||
<thead><tr><th scope="col">Kind</th><th scope="col">Label</th><th scope="col">Rule</th><th scope="col">Target</th><th scope="col"><span class="sr-only">Actions</span></th></tr></thead>
|
||
<tbody><tr v-for="goal in goals" :key="goal.id"><td>{{ goal.kind }}</td><td>{{ goal.label || "Any label" }}</td><td>{{ goal.op === ">=" ? "At least" : "At most" }}</td><td>{{ formatDuration(goal.target_s) }}</td><td class="num"><button class="small" @click="editGoal(goal)">Edit</button> <button class="small" @click="removeGoal(goal)">Remove</button></td></tr><tr v-if="!goals.length"><td colspan="5" class="muted">No goals configured.</td></tr></tbody>
|
||
</table>
|
||
</div>
|
||
<CodeBlock>docker exec activity-tracker tracker goal add --kind tab_focus --label youtube.com --op '<=' --target 1h
|
||
docker exec activity-tracker tracker goal add --kind walk --op '>=' --target 30m
|
||
docker exec activity-tracker tracker goal list
|
||
docker exec activity-tracker tracker goal rm --id 2</CodeBlock>
|
||
</Collector>
|
||
|
||
<section class="card" aria-labelledby="data-title">
|
||
<div class="row spread"><h2 id="data-title">Data and notifications</h2><span class="badge">Admin only</span></div>
|
||
<p class="muted small-text">Export your activity data, configure optional goal nudges, and control how long records are retained.</p>
|
||
<div class="row data-actions">
|
||
<a class="button-like" :href="base + '/api/v1/activities/export?format=csv'" download>Export activity CSV</a>
|
||
<a class="button-like" :href="base + '/api/v1/activities/export?format=json'" download>Export activity JSON</a>
|
||
</div>
|
||
<form class="settings-form" @submit.prevent="saveNotifications">
|
||
<label>ntfy server<input v-model="notifications.ntfy_server" placeholder="https://ntfy.sh"></label>
|
||
<label>Topic<input v-model="notifications.ntfy_topic" placeholder="private-topic"></label>
|
||
<label class="check"><input v-model="notifications.enabled" type="checkbox"> Enable goal nudges</label>
|
||
<label>Retention days <span class="muted">(0 = keep forever)</span><input v-model.number="notifications.retention_days" type="number" min="0"></label>
|
||
<button class="primary" :disabled="privacyBusy">Save settings</button>
|
||
</form>
|
||
<div class="privacy-tools">
|
||
<h3>Delete old records</h3>
|
||
<p class="muted small-text">This permanently deletes activities, samples, and reports before the selected date.</p>
|
||
<form class="row" @submit.prevent="purgeData">
|
||
<label>Delete before <input v-model="purgeBefore" type="date" required></label>
|
||
<button class="danger" :disabled="privacyBusy">Delete records</button>
|
||
</form>
|
||
</div>
|
||
<div v-if="reports.length" class="report-list">
|
||
<h3>Saved insights</h3>
|
||
<article v-for="report in reports.slice(0, 5)" :key="report.id" class="report">
|
||
<div class="row spread"><b>{{ report.model }}</b><span class="muted small-text">{{ new Date(report.period_start).toLocaleDateString() }}–{{ new Date(report.period_end).toLocaleDateString() }}</span></div>
|
||
<p>{{ report.body }}</p>
|
||
</article>
|
||
</div>
|
||
</section>
|
||
</template>
|