/* The message log at the end of Sources' Runs section. * * `/api/notices` is the queue's own route (`pipeline/web/jobs.py`) -- the log * belongs to the queue, the wording belongs to the app, and this is only the * reading of it. It redraws on `app:notice` so a failure that happens while * you are looking at the page appears without a reload. */ (function () { "use strict"; const host = document.getElementById("notices"); const clearAll = document.getElementById("clear-all"); if (!host) return; const esc = window.esc; function when(iso) { if (!iso) return ""; const d = new Date(iso); return isNaN(d) ? iso : d.toLocaleString(); } function row(n) { const count = n.count > 1 ? `x${n.count}` : ""; return `
${esc(n.text)} ${count}
${esc(n.code)}${n.key ? " / " + esc(n.key) : ""} -- last said ${esc(when(n.last_at))} ${n.kind === "bug" ? "-- looks like a bug rather than a bad day" : ""}
${n.fix ? `
${esc(n.fix)}
` : ""} ${n.detail ? `
details
${esc(n.detail)}
` : ""}
`; } async function draw() { let list; try { list = await window.api("/api/notices"); } catch (e) { host.innerHTML = 'could not read the log'; return; } if (!list.length) { host.innerHTML = 'Nothing to report.'; return; } host.innerHTML = list.map(row).join(""); } host.addEventListener("click", async (e) => { const id = e.target.dataset && e.target.dataset.clear; if (!id) return; e.target.disabled = true; try { await window.api(`/api/notices/${id}`, { method: "DELETE" }); await draw(); } catch (err) { e.target.disabled = false; } }); if (clearAll) { clearAll.addEventListener("click", async () => { clearAll.disabled = true; try { const out = await window.api("/api/notices", { method: "DELETE" }); window.toast.good(`Cleared ${out.cleared}.`); await draw(); } catch (e) { /* already toasted */ } finally { clearAll.disabled = false; } }); } document.addEventListener("app:notice", draw); document.addEventListener("DOMContentLoaded", draw); })();