Hand-added votes per question (paper, show of hands): counted in the turnout and shown hatched orange at the end of each result bar, kept apart from phone ballots

This commit is contained in:
2026-11-17 14:42:54 +01:00
parent ad6c3c6f57
commit c924107f1d
11 changed files with 164 additions and 32 deletions
+14
View File
@@ -131,6 +131,20 @@
</div>
</main>
<dialog id="extra-dlg">
<form method="dialog" id="extra-form">
<h2>Votes en plus</h2>
<p class="muted" id="extra-q"></p>
<div id="extra-fields"></div>
<p class="hint">Bulletins papier, vote à main levée… Ils s'ajoutent aux votes par téléphone et s'affichent en orange hachuré.</p>
<div class="actions">
<button value="cancel" type="submit">Annuler</button>
<span class="spacer"></span>
<button value="ok" class="primary" type="submit">Enregistrer</button>
</div>
</form>
</dialog>
<dialog id="composer">
<form method="dialog" id="q-form">
<h2>Nouvelle question</h2>
+9 -6
View File
@@ -54,15 +54,18 @@
.share-row > div:first-child { display: grid; }
.share-row .muted { font-size: .85rem; }
#composer { border: none; border-radius: 24px; padding: 24px; width: min(94vw, 560px); background: var(--surface); color: var(--ink); }
#composer::backdrop { background: rgba(28, 32, 54, .45); backdrop-filter: blur(2px); }
#composer[open] { animation: rise .2s ease-out; }
#composer h2 { font-size: 1.3rem; }
#composer, #extra-dlg { border: none; border-radius: 24px; padding: 24px; width: min(94vw, 560px); background: var(--surface); color: var(--ink); }
#composer::backdrop, #extra-dlg::backdrop { background: rgba(28, 32, 54, .45); backdrop-filter: blur(2px); }
#composer[open], #extra-dlg[open] { animation: rise .2s ease-out; }
#composer h2, #extra-dlg h2 { font-size: 1.3rem; }
.spacer { flex: 1; }
@media (max-width: 560px) {
.summary-row > * { flex: 1 1 auto; }
#composer .actions button { flex: 1 1 100%; }
#composer .spacer { display: none; }
#composer .actions button, #extra-dlg .actions button { flex: 1 1 100%; }
#composer .spacer, #extra-dlg .spacer { display: none; }
}
#q-opts { min-height: 132px; }
.extra-row { margin: 8px 0; display: grid; grid-template-columns: 1fr 110px; gap: 12px; align-items: center; font-weight: 600; }
.extra-row input { text-align: right; }
+8
View File
@@ -116,6 +116,11 @@ button:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.bar-label { overflow-wrap: anywhere; }
.bar-track { height: 12px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--ink-3); border-radius: 99px; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
/* one bar = phone ballots then hand-added votes, hatched orange */
.bar-stack { height: 100%; display: flex; border-radius: 99px; overflow: hidden; transition: width .6s cubic-bezier(.2, .8, .2, 1); }
.bar-stack > div { flex: 1 1 0; border-radius: 0; height: 100%; }
.bar-extra, .progress > .p-extra { background: repeating-linear-gradient(-45deg, #f08a24 0 5px, #f9c58f 5px 10px); }
.extra-note { color: #b85e0b; font-weight: 600; }
.bar-row.lead .bar-fill { background: var(--mark); }
.bar-row.lead .bar-label { font-weight: 700; }
.bar-num { font: 700 1rem var(--round); min-width: 80px; text-align: right; }
@@ -124,6 +129,9 @@ button:disabled { opacity: .35; cursor: not-allowed; transform: none; }
.progress { height: 8px; background: var(--bg); border-radius: 99px; overflow: hidden; margin-top: 6px; }
.progress > div { height: 100%; background: var(--ink); border-radius: 99px; transition: width .3s; }
.progress { display: flex; }
.progress > .p-extra { border-radius: 0 99px 99px 0; }
.progress > div:not(:last-child) { border-radius: 99px 0 0 99px; }
.ring { display: block; overflow: visible; }
.ring .seg, .ring .fill { fill: none; stroke-linecap: round; }
+1 -1
View File
@@ -134,7 +134,7 @@ body.entry-q-on { --dock-qr: clamp(160px, min(46vh, 30vw), 520px); }
#focus.enter :is(.opts li, .bar-row):nth-child(4) { animation-delay: .26s; }
#focus.enter :is(.opts li, .bar-row):nth-child(n+5) { animation-delay: .32s; }
#focus.enter .turnout, #focus.enter .results-foot, #focus.enter .status { animation: s-in .45s .3s cubic-bezier(.2, .7, .2, 1) both; }
#focus.enter .bar-fill { transform-origin: left; animation: s-grow .9s .25s cubic-bezier(.2, .7, .2, 1) both; }
#focus.enter .bar-stack { transform-origin: left; animation: s-grow .9s .25s cubic-bezier(.2, .7, .2, 1) both; }
.turnout .progress > div { transition: width .5s cubic-bezier(.2, .7, .2, 1); }
#voters { display: inline-block; }
#voters.bump { animation: s-bump .35s ease; }
+32 -3
View File
@@ -116,13 +116,14 @@ 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" : ""}) ?`));
actions.push(act("Clore le vote", "close", "small primary", `Clore le vote (${q.participants + q.extra_ballots} vote${q.participants + q.extra_ballots > 1 ? "s" : ""}) ?`));
} else {
actions.push(q.results_public
? act("Masquer les résultats", "unpublish")
: 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") actions.push(h("button", { class: "small", type: "button", onclick: () => editExtra(q) }, "Votes en plus"));
if (q.state !== "draft" && !focused) actions.push(act([icon("screen", 15), "Afficher à l'écran"], "focus"));
const badges = [h("span", { class: `badge ${q.state}` }, STATE_LABEL[q.state])];
@@ -132,17 +133,45 @@ function questionCard(q) {
return h("article", { class: `q ${q.state}` },
h("div", { class: "q-head" }, h("div", {}, badges),
q.state !== "draft" ? h("span", { class: "q-meta" }, `${q.participants} / ${voters}`) : null),
q.state !== "draft" ? h("span", { class: "q-meta" }, `${q.participants} / ${voters}`,
q.extra_ballots ? h("span", { class: "extra-note" }, ` + ${q.extra_ballots}`) : null) : null),
h("div", { class: "q-text" }, q.text),
q.state === "closed"
? resultsView(q)
: h("div", { class: "chips" }, q.options.map((o) => h("span", { class: "chip" }, o)),
q.allow_blank ? h("span", { class: "chip ghost" }, "Blanc") : null),
q.state === "open" ? h("div", { class: "progress" }, fill(pct(q.participants, voters), "")) : null,
q.state === "open" ? h("div", { class: "progress" }, fill(pct(q.participants, voters + q.extra_ballots), ""),
q.extra_ballots ? fill(pct(q.extra_ballots, voters + q.extra_ballots), "p-extra") : null) : null,
h("div", { class: "actions" }, actions),
);
}
// votes added by hand, in a dialog: the question list re-renders on every incoming vote
async function editExtra(q) {
const dlg = $("#extra-dlg"), e = q.extra, inputs = [];
const field = (label, value) => {
const inp = h("input", { type: "number", min: 0, max: 100000, value: String(value), inputmode: "numeric" });
inputs.push(inp);
return h("label", { class: "extra-row" }, h("span", {}, label), inp);
};
$("#extra-q").textContent = q.text;
$("#extra-fields").replaceChildren(...[
...q.options.map((o, i) => field(o, e.counts[i] || 0)),
q.allow_blank ? field("Blanc", e.blank) : null,
q.kind === "multi" ? field("Bulletins (choix multiple)", e.ballots) : null,
].filter(Boolean));
dlg.returnValue = "";
dlg.showModal();
await new Promise((res) => dlg.addEventListener("close", res, { once: true }));
if (dlg.returnValue !== "ok") return;
const vals = inputs.map((i) => Math.max(0, Math.floor(+i.value || 0)));
const n = q.options.length;
const payload = { counts: vals.slice(0, n), blank: q.allow_blank ? vals[n] : 0 };
if (q.kind === "multi") payload.ballots = vals[vals.length - 1];
try { await call("POST", `/questions/${q.id}/extra`, payload); toast("Votes ajoutés", "ok"); }
catch (err) { toast(err.code === "bad_extra" ? "Nombre de bulletins incohérent" : errMsg(err), "bad"); }
}
// composer
const composer = $("#composer");
+24 -9
View File
@@ -117,23 +117,38 @@ export function fill(percent, cls = "bar-fill") {
export function resultsView(q) {
const r = q.results;
if (!r) return null;
const base = r.ballots - r.blank;
const max = Math.max(1, ...r.counts);
const rows = q.options.map((label, i) =>
h("div", { class: "bar-row" + (r.counts[i] === max && r.counts[i] > 0 ? " lead" : "") },
// votes added by hand ride at the end of each bar, hatched orange, so nobody mistakes them for phone ballots
const ex = r.extra || { counts: r.counts.map(() => 0), blank: 0, ballots: 0 };
const tot = r.counts.map((c, i) => c + (ex.counts[i] || 0));
const ballots = r.ballots + ex.ballots, blank = r.blank + ex.blank, base = ballots - blank;
const max = Math.max(1, ...tot);
const rows = q.options.map((label, i) => {
const stack = h("div", { class: "bar-stack" },
seg("bar-fill", r.counts[i]), ex.counts[i] ? seg("bar-extra", ex.counts[i]) : null);
stack.style.width = `${pct(tot[i], max)}%`;
return h("div", { class: "bar-row" + (tot[i] === max && tot[i] > 0 ? " lead" : "") },
h("div", { class: "bar-label" }, label),
h("div", { class: "bar-track" }, fill(pct(r.counts[i], max))),
h("div", { class: "bar-num" }, r.counts[i], h("small", {}, ` ${pct(r.counts[i], base).toLocaleString("fr-FR")} %`)),
));
h("div", { class: "bar-track" }, stack),
h("div", { class: "bar-num" }, tot[i], h("small", {}, ` ${pct(tot[i], base).toLocaleString("fr-FR")} %`)),
);
});
return h("div", { class: "results" },
rows,
h("p", { class: "results-foot" },
`${r.ballots} bulletin${r.ballots > 1 ? "s" : ""}`,
q.allow_blank ? `, dont ${r.blank} blanc${r.blank > 1 ? "s" : ""}` : "",
`${ballots} bulletin${ballots > 1 ? "s" : ""}`,
q.allow_blank ? `, dont ${blank} blanc${blank > 1 ? "s" : ""}` : "",
ex.ballots ? h("span", { class: "extra-note" }, `, dont ${ex.ballots} ajouté${ex.ballots > 1 ? "s" : ""} à la main`) : "",
),
);
}
// a flex share of a bar (CSSOM write, the CSP blocks style="")
function seg(cls, n) {
const el = h("div", { class: cls });
el.style.flexGrow = String(n);
return el;
}
export const STATE_LABEL = { draft: "Brouillon", open: "Vote ouvert", closed: "Clos" };
export function toast(msg, kind = "info") {
+18 -9
View File
@@ -1,4 +1,4 @@
import { $, h, pollId, takeKey, liveSocket, drawQR, resultsView, fill, pct } from "./common.js";
import { $, h, pollId, takeKey, liveSocket, drawQR, resultsView, pct } from "./common.js";
import { render as drawRing, DISC } from "./ringcode.js";
const pid = pollId();
@@ -80,13 +80,10 @@ function render() {
const f = st.focus;
const box = $("#focus");
const view = f ? `${f.id}|${f.state}|${f.results ? 1 : 0}|${f.text}` : "";
const view = f ? `${f.id}|${f.state}|${f.results ? JSON.stringify(f.results) : 0}|${f.text}` : "";
if (f && view === focusView && f.state === "open") {
// same question still open: only the turnout moves, in place so the bar slides
const t = box.querySelector(".turnout");
t.querySelector("b").textContent = f.participants;
t.querySelector(".t-of").textContent = ` vote${f.participants > 1 ? "s" : ""} sur ${st.voters}`;
t.querySelector(".progress > div").style.width = `${pct(f.participants, st.voters)}%`;
paintTurnout(box.querySelector(".turnout"), f);
} else if (view !== focusView) {
focusView = view;
if (f) {
@@ -95,9 +92,9 @@ function render() {
if (f.state === "open") {
box.append(
h("ul", { class: "opts" }, f.options.map((o) => h("li", {}, o))),
h("div", { class: "turnout" },
h("b", {}, f.participants), h("span", { class: "t-of" }, ` vote${f.participants > 1 ? "s" : ""} sur ${st.voters}`),
h("div", { class: "progress" }, fill(pct(f.participants, st.voters), ""))),
paintTurnout(h("div", { class: "turnout" },
h("b", {}), h("span", { class: "t-of" }),
h("div", { class: "progress" }, h("div", {}), h("div", { class: "p-extra" }))), f),
);
} else if (f.results) {
box.append(resultsView(f));
@@ -110,6 +107,18 @@ function render() {
layout();
}
// "9 votes sur 10, dont 3 ajoutés": hand-added votes count in, and show hatched at the end of the bar
function paintTurnout(t, f) {
const extra = f.extra_ballots || 0, all = f.participants + extra, of = st.voters + extra;
t.querySelector("b").textContent = all;
t.querySelector(".t-of").textContent = ` vote${all > 1 ? "s" : ""} sur ${of}` +
(extra ? `, dont ${extra} ajouté${extra > 1 ? "s" : ""}` : "");
const [phone, added] = t.querySelectorAll(".progress > div");
phone.style.width = `${pct(f.participants, of)}%`;
added.style.width = `${pct(extra, of)}%`;
return t;
}
function paintQR() {
if (!qr || qr.type !== "qr") return;
const c = $("#qr");