Vote-time presence scan, rescue codes, websocket heartbeat

Each vote can require N fresh codes read off the projector (default 3,
off for rooms without a projector); voters enrolled with a paper or
rescue code are exempt. Rescue codes enroll a phone without camera.
Projector keeps the QR up while such a vote is open. Server pings every
socket every 25s so proxies keep them open. Composer no longer closes on
enter. Schema migrates existing databases.
This commit is contained in:
2026-08-16 13:48:53 +01:00
parent fca4a1194e
commit 4650db4b40
15 changed files with 427 additions and 91 deletions
+30 -17
View File
@@ -74,11 +74,12 @@ function renderSettings(p) {
if (active !== $("#s-scans")) $("#s-scans").value = p.scans_required;
if (active !== $("#s-expected")) $("#s-expected").value = p.expected ?? "";
if (active !== $("#s-max")) $("#s-max").value = p.max_voters ?? "";
if (active !== $("#s-vote-scans")) $("#s-vote-scans").value = String(p.vote_scans);
$("#s-code").checked = p.require_code;
$("#codes-box").hidden = !p.require_code;
$("#codes-summary").textContent = state.codes.total
? `${state.codes.used} utilisé${state.codes.used > 1 ? "s" : ""} sur ${state.codes.total}`
: "Aucun code généré";
$("#access-row").hidden = !p.require_code && !state.codes.access.total;
const sum = (c, none) => (c.total ? `${c.used} utilisé${c.used > 1 ? "s" : ""} sur ${c.total}` : none);
$("#access-summary").textContent = sum(state.codes.access, "Un code par personne, avec le scan");
$("#rescue-summary").textContent = sum(state.codes.rescue, "Inscription sans caméra");
}
function renderQuestions() {
@@ -156,6 +157,9 @@ for (const t of TEMPLATES) {
onclick: () => { applyTemplate(t); $("#q-text").focus(); },
}, t.label));
}
$("#q-cancel").addEventListener("click", () => composer.close());
// enter in a field must not submit (and close) the dialog
$("#q-form").addEventListener("submit", (e) => e.preventDefault());
$("#q-kind").addEventListener("change", () => { $("#q-max-box").hidden = $("#q-kind").value !== "multi"; });
async function submitQuestion(open) {
@@ -197,6 +201,7 @@ const SETTINGS = {
"#s-expected": (el) => ({ expected: intOrNull(el.value) }),
"#s-max": (el) => ({ max_voters: intOrNull(el.value) }),
"#s-code": (el) => ({ require_code: el.checked }),
"#s-vote-scans": (el) => ({ vote_scans: +el.value }),
};
for (const [sel, build] of Object.entries(SETTINGS)) {
$(sel).addEventListener("change", async (e) => {
@@ -205,19 +210,27 @@ for (const [sel, build] of Object.entries(SETTINGS)) {
});
}
$("#codes-gen").addEventListener("click", async () => {
try {
await call("POST", "/codes", { count: +$("#codes-count").value });
toast("Codes générés");
} catch (e) { toast(errMsg(e), "bad"); }
});
$("#codes-print").addEventListener("click", async () => {
const { codes } = await call("GET", "/codes");
$("#codes-title").textContent = `Codes d'accès, ${state.poll.title}`;
$("#codes-grid").replaceChildren(...codes.map((c) => h("div", { class: "code-cell" + (c.used ? " used" : "") }, c.code)));
$("#codes-sheet").hidden = false;
$("#codes-sheet").scrollIntoView({ behavior: "smooth" });
});
const CODE_LABEL = { access: "Codes papier", rescue: "Codes de secours" };
for (const b of document.querySelectorAll("[data-gen]")) {
b.addEventListener("click", async () => {
const kind = b.dataset.gen;
try {
await call("POST", "/codes", { count: +$(`#${kind}-count`).value, rescue: kind === "rescue" });
toast(`${CODE_LABEL[kind]} générés`);
} catch (e) { toast(errMsg(e), "bad"); }
});
}
for (const b of document.querySelectorAll("[data-print]")) {
b.addEventListener("click", async () => {
const kind = b.dataset.print;
const { codes } = await call("GET", "/codes");
const list = codes.filter((c) => Boolean(c.rescue) === (kind === "rescue"));
$("#codes-title").textContent = `${CODE_LABEL[kind]}, ${state.poll.title}`;
$("#codes-grid").replaceChildren(...list.map((c) => h("div", { class: "code-cell" + (c.used ? " used" : "") }, c.code)));
$("#codes-sheet").hidden = false;
$("#codes-sheet").scrollIntoView({ behavior: "smooth" });
});
}
$("#codes-close").addEventListener("click", () => { $("#codes-sheet").hidden = true; });
$("#codes-do-print").addEventListener("click", () => window.print());