Add scheduled and event-driven printing with a new web UI
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]>
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
// Hash router and the printer status pill.
|
||||
|
||||
import {get} from "./api.js";
|
||||
import {$} from "./dom.js";
|
||||
import {editorView} from "./editor.js";
|
||||
import {historyView} from "./history.js";
|
||||
import {printView} from "./print.js";
|
||||
import {schedulesView} from "./schedules.js";
|
||||
import {settingsView} from "./settings.js";
|
||||
|
||||
const view = $("#view");
|
||||
let current = null; // what the active view returned: a cleanup function or {canLeave}
|
||||
let currentHash = location.hash;
|
||||
|
||||
async function route() {
|
||||
const hash = location.hash || "#print";
|
||||
if (current?.canLeave && hash !== currentHash && !current.canLeave()) {
|
||||
history.replaceState(null, "", currentHash); // stay put
|
||||
return;
|
||||
}
|
||||
if (typeof current === "function") current();
|
||||
current = null;
|
||||
currentHash = hash;
|
||||
const [tab, arg] = hash.slice(1).split("/");
|
||||
document.querySelectorAll("nav.tabs a").forEach((a) =>
|
||||
a.classList.toggle("on", a.getAttribute("href") === `#${tab}`));
|
||||
view.setAttribute("aria-busy", "true");
|
||||
if (tab === "schedules" && arg) current = await editorView(view, arg);
|
||||
else if (tab === "schedules") current = await schedulesView(view);
|
||||
else if (tab === "history") current = await historyView(view, arg);
|
||||
else if (tab === "settings") current = await settingsView(view);
|
||||
else current = printView(view);
|
||||
view.removeAttribute("aria-busy");
|
||||
window.scrollTo(0, 0);
|
||||
}
|
||||
|
||||
window.addEventListener("hashchange", route);
|
||||
window.addEventListener("beforeunload", (e) => {
|
||||
if (current?.isDirty?.()) e.preventDefault();
|
||||
});
|
||||
|
||||
async function checkStatus() {
|
||||
const pill = $("#status");
|
||||
pill.textContent = "checking…";
|
||||
pill.className = "pill";
|
||||
const r = await get("api/status");
|
||||
pill.textContent = r.body.busy ? "printer busy" : r.ok ? "printer ready" : "printer offline";
|
||||
pill.className = `pill ${r.ok ? "ok" : "err"}`;
|
||||
pill.title = r.text;
|
||||
}
|
||||
|
||||
$("#status").addEventListener("click", checkStatus);
|
||||
checkStatus();
|
||||
route();
|
||||
Reference in New Issue
Block a user