The web server now runs a scheduler over schedules kept in SQLite
(~/.local/share/receipt-maker, outside the clone). A schedule is a
trigger, a receipt made of blocks, and options:
- Triggers: once, recurring (rrule-based, DST-safe), sun times,
reminders before calendar (ICS) events, RSS/JSON watchers, webhooks
with per-schedule secrets.
- Blocks, rendered fresh as one job: templated notes ({date},
{days_until:..}, rotating {choice}, trigger vars), QR, saved images,
random image, calendar agenda, feed headlines, dividers.
- Rules: quiet hours (hold/skip/ignore), daily cap, pause, catch-up
window for missed runs (never replayed), retries on connect failure
only; a mid-job drop (new PrinterDropped) is never resent.
receipt.py renders through composable Blocks (render_note/image/qr are
wrappers, output unchanged). Print history persists, with Print again.
The page moves to web/ with Print (note/image/QR + paper preview),
Schedules (presets, editor with live preview and next runs), History
and Settings tabs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
70 lines
3.2 KiB
JavaScript
70 lines
3.2 KiB
JavaScript
// History tab: everything printed, skipped or missed, newest first.
|
|
|
|
import {get, post, printJob} from "./api.js";
|
|
import {clear, fmtTime, h, select, toast} from "./dom.js";
|
|
import {STATUS_LABELS} from "./schedules.js";
|
|
|
|
const SOURCE_LABELS = {manual: "Printed by hand", schedule: "Scheduled", calendar: "Calendar",
|
|
watch: "Watcher", webhook: "Webhook", test: "Test print"};
|
|
const STATE_CLASS = {done: "ok", failed: "err", missed: "warn", skipped: "warn"};
|
|
const PAGE = 50;
|
|
|
|
export async function historyView(view, scheduleId) {
|
|
const filters = {state: "", schedule_id: scheduleId || ""};
|
|
const list = h("div", {class: "history"});
|
|
const more = h("button", {class: "ghost", hidden: true}, "Older");
|
|
let oldest = null;
|
|
|
|
const schedules = await get("api/schedules");
|
|
const scheduleOptions = [["", "All schedules and prints"],
|
|
...(schedules.ok ? schedules.body.schedules.map((s) => [s.id, s.name]) : [])];
|
|
|
|
async function load(reset) {
|
|
if (reset) { clear(list); oldest = null; }
|
|
const params = new URLSearchParams({limit: String(PAGE)});
|
|
if (filters.state) params.set("state", filters.state);
|
|
if (filters.schedule_id) params.set("schedule_id", filters.schedule_id);
|
|
if (oldest) params.set("before", oldest);
|
|
const r = await get(`api/runs?${params}`);
|
|
if (!r.ok) return list.append(h("p", {class: "err"}, r.text));
|
|
const runs = r.body.runs;
|
|
if (!runs.length && !oldest) list.append(h("p", {class: "muted empty"}, "Nothing yet."));
|
|
runs.forEach((run) => list.append(row(run)));
|
|
oldest = runs.length ? runs[runs.length - 1].created_at : oldest;
|
|
more.hidden = runs.length < PAGE;
|
|
}
|
|
|
|
function row(run) {
|
|
const again = run.has_payload ? h("button", {class: "ghost small", onclick: async () => {
|
|
const result = await printJob(() => post(`api/runs/${run.id}/reprint`),
|
|
(text) => (again.textContent = text));
|
|
again.textContent = "Print again";
|
|
toast(result.text, result.ok ? "" : "err");
|
|
if (result.ok) load(true);
|
|
}}, "Print again") : null;
|
|
const title = run.schedule_id
|
|
? h("a", {href: `#schedules/${run.schedule_id}`}, run.name || "Schedule")
|
|
: h("span", {}, run.name || run.kind);
|
|
return h("div", {class: "run"},
|
|
h("div", {class: "when"}, fmtTime(run.created_at)),
|
|
h("div", {class: "what"},
|
|
h("div", {}, title, " ",
|
|
h("span", {class: `badge ${STATE_CLASS[run.state] || ""}`},
|
|
STATUS_LABELS[run.state] || run.state)),
|
|
h("div", {class: "muted small"}, SOURCE_LABELS[run.source] || run.source,
|
|
run.user && !run.user.startsWith("schedule:") ? ` · ${run.user}` : "",
|
|
run.message && run.state !== "done" ? ` · ${run.message}` : "")),
|
|
again);
|
|
}
|
|
|
|
more.addEventListener("click", () => load(false));
|
|
clear(view,
|
|
h("div", {class: "toolbar"}, h("h2", {}, "History"), h("span", {class: "spacer"}),
|
|
select(filters, "schedule_id", scheduleOptions, () => load(true)),
|
|
select(filters, "state", [["", "Any result"], ["done", "Printed"], ["failed", "Failed"],
|
|
["skipped", "Skipped"], ["missed", "Missed"]], () => load(true))),
|
|
h("section", {class: "card flush"}, list),
|
|
h("div", {class: "row center"}, more));
|
|
load(true);
|
|
}
|