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
This commit is contained in:
+11
-1
@@ -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":
|
||||
|
||||
+2
-1
@@ -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))
|
||||
|
||||
@@ -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; }
|
||||
}
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@
|
||||
<div class="pane">
|
||||
<div class="pane-head"><svg class="icon" viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M4 5h16v11H4z"/><path d="M2 19.5h20"/><path d="M8 9h8"/><path d="M8 12.5h5"/></svg><p><b>Administration</b><span>Sur votre écran</span></p></div>
|
||||
<div class="linkbox"><input id="admin-link" type="text" readonly aria-label="Lien d'administration"><button id="copy-admin" class="small" type="button">Copier</button></div>
|
||||
<a id="go-admin" class="btn primary block" href="#">Ouvrir l'administration</a>
|
||||
<a id="go-admin" class="btn primary block" href="#" target="_blank" rel="noopener">Ouvrir l'administration</a>
|
||||
</div>
|
||||
<div class="pane">
|
||||
<div class="pane-head"><svg class="icon" viewBox="0 0 24 24" width="26" height="26" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M2 4h20"/><path d="M4 4v10h16V4"/><path d="M12 14v3"/><path d="M8.5 21l3.5-4 3.5 4"/></svg><p><b>Projecteur</b><span>Affiché à la salle, à ouvrir sur l'écran projeté</span></p></div>
|
||||
|
||||
+4
-2
@@ -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"));
|
||||
|
||||
|
||||
@@ -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(); }
|
||||
});
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
+2
-1
@@ -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";
|
||||
|
||||
+26
-1
@@ -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.",
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user