From f8d8980335bf9d148121a45a9740793eef9e0afe Mon Sep 17 00:00:00 2001 From: Showdown76py Date: Tue, 17 Nov 2026 01:52:30 +0100 Subject: [PATCH] Reopen a closed vote until its results are shown; check mark in the center mark and on the phone; vote title during enrollment; projector opens in a window --- rotatyvote/app.py | 12 +++++++++++- rotatyvote/db.py | 3 ++- static/css/vote.css | 19 +++++++++++++++++++ static/index.html | 2 +- static/js/admin.js | 6 ++++-- static/js/index.js | 7 +++++++ static/js/ringcode.js | 5 +++++ static/js/screen.js | 3 ++- static/js/vote.js | 27 ++++++++++++++++++++++++++- tests/test_e2e.py | 10 ++++++++++ 10 files changed, 87 insertions(+), 7 deletions(-) diff --git a/rotatyvote/app.py b/rotatyvote/app.py index 77463ca..7d28cc2 100644 --- a/rotatyvote/app.py +++ b/rotatyvote/app.py @@ -54,7 +54,7 @@ def q_public(q, with_results: bool): d = { "id": q["id"], "text": q["text"], "kind": q["kind"], "options": json.loads(q["options"]), "max_choices": q["max_choices"], "allow_blank": bool(q["allow_blank"]), "state": q["state"], - "results_public": bool(q["results_public"]), "participants": db.participants(q["id"]), + "results_public": bool(q["results_public"]), "shown": bool(q["shown"]), "participants": db.participants(q["id"]), } # nobody, admin included, sees tallies while a question is open if with_results and q["state"] == "closed": @@ -514,10 +514,20 @@ async def admin_question_action(request: Request): if st != "open": return err("not_open") db.set_question(qid, state="closed") + elif action == "reopen": + # a late vote can still come in, but never once the room has seen the tally + if st != "closed": + return err("not_closed") + if q["shown"]: + return err("already_shown") + db.set_question(qid, state="open") + db.update_poll(pid, focus_qid=qid) elif action in ("publish", "unpublish"): if st != "closed": return err("not_closed") db.set_question(qid, results_public=int(action == "publish")) + if action == "publish": + db.set_question(qid, shown=1) if action == "publish": db.update_poll(pid, focus_qid=qid) elif action == "focus": diff --git a/rotatyvote/db.py b/rotatyvote/db.py index 698c32c..633a5da 100644 --- a/rotatyvote/db.py +++ b/rotatyvote/db.py @@ -88,6 +88,7 @@ class DB: ("access_codes", "rescue", "INTEGER NOT NULL DEFAULT 0"), ("polls", "code_style", "TEXT NOT NULL DEFAULT 'qr'"), ("polls", "trial", "INTEGER NOT NULL DEFAULT 0"), + ("questions", "shown", "INTEGER NOT NULL DEFAULT 0"), ): cols = {r[1] for r in self.c.execute(f"PRAGMA table_info({table})")} if col not in cols: @@ -222,7 +223,7 @@ class DB: return self.all("SELECT * FROM questions WHERE poll_id=? ORDER BY position", pid) def set_question(self, qid, **fields): - allowed = {"state", "results_public"} + allowed = {"state", "results_public", "shown"} fields = {k: v for k, v in fields.items() if k in allowed} sets = ",".join(f"{k}=?" for k in fields) self.c.execute(f"UPDATE questions SET {sets} WHERE id=?", (*fields.values(), qid)) diff --git a/static/css/vote.css b/static/css/vote.css index bac85a3..029e2d6 100644 --- a/static/css/vote.css +++ b/static/css/vote.css @@ -50,3 +50,22 @@ dialog[open] { animation: rise .2s ease-out; } #confirm-choices { list-style: none; padding: 0; margin: 0 0 8px; } #confirm-choices li { font: 700 1.2rem var(--round); background: var(--mark); border-radius: 12px; padding: 10px 14px; margin: 6px 0; } dialog .actions button { flex: 1; } + +/* confirmation after enrolling or voting: the projector's mark, its check drawing in */ +.celebrate { + position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 18px; + background: color-mix(in srgb, var(--bg) 92%, transparent); color: var(--ink); + animation: cel-in .3s ease both; +} +.celebrate svg { width: 132px; height: 132px; animation: cel-pop .5s cubic-bezier(.2, .9, .3, 1.25) both; } +.celebrate .tick { stroke-dasharray: 1; stroke-dashoffset: 1; animation: cel-tick .45s .25s cubic-bezier(.3, .7, .2, 1) forwards; } +.celebrate p { margin: 0; font: 700 1.3rem var(--round); animation: cel-in .4s .35s ease both; } +.celebrate.out { animation: cel-out .4s ease forwards; } +@keyframes cel-in { from { opacity: 0; } } +@keyframes cel-out { to { opacity: 0; } } +@keyframes cel-pop { from { transform: scale(.6) rotate(-40deg); opacity: 0; } } +@keyframes cel-tick { to { stroke-dashoffset: 0; } } +@media (prefers-reduced-motion: reduce) { + .celebrate, .celebrate svg, .celebrate p { animation: none; } + .celebrate .tick { animation: none; stroke-dashoffset: 0; } +} diff --git a/static/index.html b/static/index.html index d5371a0..5b95b0f 100644 --- a/static/index.html +++ b/static/index.html @@ -74,7 +74,7 @@

AdministrationSur votre écran

- Ouvrir l'administration + Ouvrir l'administration

ProjecteurAffiché à la salle, à ouvrir sur l'écran projeté

diff --git a/static/js/admin.js b/static/js/admin.js index 70c51db..63724a6 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -21,6 +21,7 @@ function errMsg(e) { not_draft: "La question n'est plus en brouillon", not_open: "La question n'est pas ouverte", not_closed: "La question n'est pas close", + already_shown: "Résultats déjà publiés, le vote ne peut plus être rouvert", }; return m[e.code] || e.message; } @@ -113,11 +114,12 @@ function questionCard(q) { actions.push(act("Lancer le vote", "open", "small go")); actions.push(act("Supprimer", "delete", "small danger", "Supprimer ce brouillon ?")); } else if (q.state === "open") { - actions.push(act("Clore le vote", "close", "small primary", `Clore le vote (${q.participants} vote${q.participants > 1 ? "s" : ""}) ? Définitif.`)); + actions.push(act("Clore le vote", "close", "small primary", `Clore le vote (${q.participants} vote${q.participants > 1 ? "s" : ""}) ?`)); } else { actions.push(q.results_public ? act("Masquer les résultats", "unpublish") - : act("Publier les résultats", "publish", "small primary")); + : act("Publier les résultats", "publish", "small primary", "Publier les résultats ? Le vote ne pourra plus être rouvert.")); + if (!q.shown) actions.push(act("Rouvrir le vote", "reopen")); } if (q.state !== "draft" && !focused) actions.push(act([icon("screen", 15), "Afficher à l'écran"], "focus")); diff --git a/static/js/index.js b/static/js/index.js index 35a5915..0d8a0a6 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -43,3 +43,10 @@ for (const [btn, input] of [["#copy-admin", "#admin-link"], ["#copy-screen", "#s catch { $(input).select(); } }); } + +// a real window, not a tab: it can be dragged onto the projected display and put full screen there +$("#go-screen").addEventListener("click", (e) => { + const w = window.open($("#go-screen").href, "_blank", "popup,width=1280,height=720"); + // blocked popup: the plain link still opens a tab + if (w) { w.opener = null; e.preventDefault(); } +}); diff --git a/static/js/ringcode.js b/static/js/ringcode.js index 05250a0..22da126 100644 --- a/static/js/ringcode.js +++ b/static/js/ringcode.js @@ -163,6 +163,11 @@ function logo(ctx, cx, cy, r) { ctx.strokeStyle = j === 0 ? "#ffcc00" : "#ffffff"; ctx.beginPath(); ctx.arc(cx, cy, rr, a, a + dash); ctx.stroke(); } + // check mark inside, same one the phone shows once its scans count + ctx.strokeStyle = "#ffffff"; + ctx.lineWidth = 2.4 * u; + ctx.lineJoin = "round"; + ctx.beginPath(); ctx.moveTo(cx - 3.2 * u, cy + 0.15 * u); ctx.lineTo(cx - 0.9 * u, cy + 2.45 * u); ctx.lineTo(cx + 3.35 * u, cy - 2.3 * u); ctx.stroke(); } const EASE = { diff --git a/static/js/screen.js b/static/js/screen.js index 4429b44..5795630 100644 --- a/static/js/screen.js +++ b/static/js/screen.js @@ -40,7 +40,8 @@ function layout() { reveal($("#idle"), !qrOn && !focus); $(".s-main").classList.toggle("split", qrOn && !!focus); const ring = st.code_style === "ring"; - $("#qr-title").textContent = st.enrollment_open ? "Inscription" : ring ? "Visez le cercle pour voter" : "Scannez pour voter"; + // a vote waiting for presence scans takes the title, even while late arrivals can still enroll + $("#qr-title").textContent = st.presence || !st.enrollment_open ? (ring ? "Visez le cercle pour voter" : "Scannez pour voter") : "Inscription"; $("#qr-steps").hidden = !st.enrollment_open; // rings can't be opened by the camera app, so a small fixed qr leads to the page $("#step1").textContent = ring ? "Ouvrez la page de vote" : "Scannez ce code"; diff --git a/static/js/vote.js b/static/js/vote.js index b255c0c..b384060 100644 --- a/static/js/vote.js +++ b/static/js/vote.js @@ -192,9 +192,34 @@ function enrolled() { stopScanner(); lsSet(DONE_KEY, "1"); navigator.vibrate?.([40, 60, 40]); + celebrate("Inscription validée"); boot(); } +// the projector's center mark with its check, drawn in, held a moment, then gone +const MARK_NS = "http://www.w3.org/2000/svg"; +function celebrate(text) { + const svg = document.createElementNS(MARK_NS, "svg"); + svg.setAttribute("viewBox", "0 0 32 32"); + svg.setAttribute("aria-hidden", "true"); + const g = document.createElementNS(MARK_NS, "g"); + g.setAttribute("transform", "rotate(-90 16 16)"); + for (const [stroke, dash] of [["currentColor", "4.52 7"], ["#ffcc00", "4.52 64.6"]]) { + const c = document.createElementNS(MARK_NS, "circle"); + for (const [k, v] of Object.entries({ cx: 16, cy: 16, r: 11, fill: "none", stroke, "stroke-width": 5, + "stroke-linecap": "round", "stroke-dasharray": dash, "stroke-dashoffset": -3.5 })) c.setAttribute(k, v); + g.append(c); + } + const tick = document.createElementNS(MARK_NS, "path"); + for (const [k, v] of Object.entries({ d: "M12.8 16.15l2.3 2.3 4.25-4.75", fill: "none", stroke: "currentColor", "stroke-width": 2.4, + "stroke-linecap": "round", "stroke-linejoin": "round", pathLength: 1, class: "tick" })) tick.setAttribute(k, v); + svg.append(g, tick); + const el = h("div", { class: "celebrate", role: "status" }, svg, h("p", {}, text)); + document.body.append(el); + setTimeout(() => el.classList.add("out"), 1300); + setTimeout(() => el.remove(), 1700); +} + $("#start-cam").addEventListener("click", startScanner); $("#no-cam").addEventListener("click", () => { stopScanner(); show("#v-rescue"); $("#rescue-code").focus(); }); @@ -321,7 +346,7 @@ async function confirmVote(q) { try { await api("POST", `${apiBase}/vote`, { question_id: q.id, choices: s.blank ? [] : choices, presence }); selections.delete(q.id); - toast("Vote enregistré", "ok"); + celebrate("Vote enregistré"); navigator.vibrate?.(60); } catch (e) { const m = { already_voted: "Déjà voté.", not_open: "Vote clos.", not_enrolled: "Appareil non inscrit.", diff --git a/tests/test_e2e.py b/tests/test_e2e.py index 0d65855..04cfaa5 100644 --- a/tests/test_e2e.py +++ b/tests/test_e2e.py @@ -173,12 +173,22 @@ def test_full_flow_and_anonymity(server): r = await a.post(f"/api/v/{p['id']}/vote", json={"question_id": qid, "choices": [0]}) assert r.status_code == 409 and r.json()["error"] == "not_open" + # closed too early: reopening keeps the ballots and the voted flags + assert admin(server, p, "POST", f"/questions/{qid}/reopen").status_code == 200 + r = await a.post(f"/api/v/{p['id']}/vote", json={"question_id": qid, "choices": [1]}) + assert r.status_code == 409 and r.json()["error"] == "already_voted" + assert admin(server, p, "POST", f"/questions/{qid}/close").status_code == 200 + # voters only see results once published me = (await a.get(f"/api/v/{p['id']}/me")).json() assert me["questions"] == [] admin(server, p, "POST", f"/questions/{qid}/publish") me = (await a.get(f"/api/v/{p['id']}/me")).json() assert me["questions"][0]["results"]["counts"] == [1, 0] + # once the room has seen the tally there is no going back, even after hiding it + admin(server, p, "POST", f"/questions/{qid}/unpublish") + r = admin(server, p, "POST", f"/questions/{qid}/reopen") + assert r.status_code == 400 and r.json()["error"] == "already_shown" await a.aclose() await b.aclose()