diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index afbabda..3f61526 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -5,7 +5,7 @@ Merci de votre intérêt pour RotatyVote. ## Avant de commencer - Ouvrez une issue pour tout changement non trivial, afin d'en discuter avant d'écrire du code. -- Pour une faille de sécurité, ne l'exposez pas dans une issue publique : contactez le mainteneur en privé. +- Pour une faille de sécurité, ne l'exposez pas dans une issue publique : contactez en privé la personne qui maintient le projet. ## Mise en place @@ -18,7 +18,7 @@ RV_TEST_TLS=1 uv run pytest ## Règles -- **Anonymat d'abord.** Aucune modification ne doit permettre de relier un bulletin à un votant : pas d'identifiant votant ni d'horodatage dans `ballots`, pas de log des votes. +- **Anonymat d'abord.** Aucune modification ne doit permettre de relier un bulletin à la personne qui a voté : pas d'identifiant de personne ni d'horodatage dans `ballots`, pas de log des votes. - **Tests.** Tout changement de comportement côté serveur vient avec un test dans `tests/test_e2e.py`, y compris le cas d'échec. - **Pas de dépendance réseau côté client.** Les scripts sont servis en local, la CSP reste `'self'`. - **Interface sobre.** Texte minimal, en français, en phrases courtes. diff --git a/README.md b/README.md index dcdfbdf..ec8d6a2 100644 --- a/README.md +++ b/README.md @@ -61,8 +61,8 @@ location / { ## Déroulé 1. Créer le scrutin, garder le lien admin (clé dans l'URL, non récupérable). -2. Ouvrir les inscriptions. Le projecteur affiche le QR rotatif et le nombre d'inscrits. -3. Fermer les inscriptions quand la salle est inscrite. +2. Ouvrir les inscriptions. Le projecteur affiche le QR rotatif et le nombre d'inscriptions. +3. Fermer les inscriptions quand tout le monde est inscrit. 4. Lancer les questions préparées ou en créer en direct. Les téléphones les reçoivent instantanément. 5. Clore, publier les résultats à l'écran, exporter en JSON. @@ -70,18 +70,18 @@ location / { **Présence.** Chaque code est un HMAC du créneau horaire, valable environ 3 s. Il faut N codes distincts en une fenêtre courte. Une photo ou une capture partagée ne suffit pas. La page projecteur est protégée par sa propre clé (révocable depuis l'admin). -**Anonymat.** Deux tables séparées : `participation` (qui a voté à quelle question) et `ballots` (quel choix), écrites dans la même transaction. Aucune colonne ne relie un bulletin à un votant, aucun horodatage, identifiants aléatoires (ordre de stockage sans signification), journal SQLite non-WAL, `secure_delete`, pas de log d'accès. Les résultats restent cachés pendant le vote, admin compris. Un vote est définitif. +**Anonymat.** Deux tables séparées : `participation` (qui a voté à quelle question) et `ballots` (quel choix), écrites dans la même transaction. Aucune colonne ne relie un bulletin à la personne qui a voté, aucun horodatage, identifiants aléatoires (ordre de stockage sans signification), journal SQLite non-WAL, `secure_delete`, pas de log d'accès. Les résultats restent cachés pendant le vote, admin compris. Un vote est définitif. **Un vote par appareil et par question.** Imposé par la base (clé primaire), même en requêtes concurrentes. -**Un seul appareil par personne : non garanti techniquement.** Le même code est valable pour toute la salle. Un appareil présent peut donc inscrire plusieurs faux votants (navigation privée, script). Le cookie et la marque locale ne bloquent que la réinscription naïve. Parades : +**Un seul appareil par personne : non garanti techniquement.** Le même code est valable pour toute la salle. Un appareil dans la salle peut donc créer plusieurs fausses inscriptions (navigation privée, script). Le cookie et la marque locale ne bloquent que la réinscription naïve. Parades : -- le nombre d'inscrits affiché en permanence au projecteur, à comparer aux présents ; +- le nombre d'inscriptions affiché en permanence au projecteur, à comparer au nombre de personnes présentes ; - la fermeture des inscriptions avant les votes ; - un plafond d'inscriptions ; - **pour les enjeux élevés, les codes papier à usage unique** : distribués au hasard à l'émargement, un code inscrit un seul téléphone et n'est jamais relié au bulletin. -**Hors périmètre.** Un complice qui relaie l'écran en vidéo en direct ; un opérateur du serveur malveillant (il pourrait modifier le code). Pour ces menaces, il faut un système de vote vérifiable de bout en bout. +**Hors périmètre.** Une personne complice qui relaie l'écran en vidéo en direct ; une personne malveillante qui administre le serveur (elle pourrait modifier le code). Pour ces menaces, il faut un système de vote vérifiable de bout en bout. ## Tests diff --git a/docs/screenshots/8-admin.jpg b/docs/screenshots/8-admin.jpg index e3e3aa0..bb4d316 100644 Binary files a/docs/screenshots/8-admin.jpg and b/docs/screenshots/8-admin.jpg differ diff --git a/docs/screenshots/9-admin-nouvelle-question.jpg b/docs/screenshots/9-admin-nouvelle-question.jpg new file mode 100644 index 0000000..e22c6dc Binary files /dev/null and b/docs/screenshots/9-admin-nouvelle-question.jpg differ diff --git a/docs/screenshots/9-admin-questions.jpg b/docs/screenshots/9-admin-questions.jpg deleted file mode 100644 index 3de5ebf..0000000 Binary files a/docs/screenshots/9-admin-questions.jpg and /dev/null differ diff --git a/static/admin.html b/static/admin.html index cf73ad7..6a928b1 100644 --- a/static/admin.html +++ b/static/admin.html @@ -6,99 +6,123 @@ RotatyVote · Administration + -
-
-
rotatyvote

…

-
- connexion… - - Ouvrir le projecteur - -
-
+
+
+ rotatyvote + +
- +
+ + +
+

Nouvelle question

+
+ + + + +
+
+ + +
+ +
+ +
+ + + + +
+
+
diff --git a/static/css/admin.css b/static/css/admin.css new file mode 100644 index 0000000..4838dde --- /dev/null +++ b/static/css/admin.css @@ -0,0 +1,64 @@ +.admin-wrap { max-width: 760px; } +.a-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; } + +.summary h1 { font-size: 2rem; margin-bottom: 14px; } +.summary-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; } +.count-chip { + display: inline-flex; align-items: baseline; gap: 8px; background: var(--surface); + border-radius: 999px; padding: 8px 18px; color: var(--ink-2); font-weight: 600; +} +.count-chip b { font: 700 1.6rem/1 var(--round); color: var(--ink); letter-spacing: -.02em; } + +/* the toggle reads as a switch: knob left when closed, right + green when open */ +.enroll-toggle { gap: 10px; padding-left: 12px; } +.enroll-toggle::before { + content: ""; flex: none; width: 34px; height: 20px; border-radius: 99px; background: var(--line); + box-shadow: inset 2px 0 0 2px var(--line), inset 16px 0 0 2px #fff; transition: box-shadow .2s, background .2s; +} +.enroll-toggle.on { background: var(--ok-soft); border-color: var(--ok-soft); color: var(--ok); } +.enroll-toggle.on::before { background: var(--ok); box-shadow: inset 16px 0 0 2px var(--ok), inset 32px 0 0 2px #fff; } + +#open-screen .icon { color: var(--ink-3); } +#open-screen.connected .icon { color: var(--ok); } + +.tabs { + display: flex; gap: 4px; background: var(--surface); border-radius: 999px; padding: 4px; + margin: 26px 0 18px; width: fit-content; max-width: 100%; overflow-x: auto; +} +.tabs button { border: none; background: transparent; padding: 9px 18px; color: var(--ink-2); } +.tabs button:hover { background: var(--bg); } +.tabs button[aria-selected="true"] { background: var(--ink); color: #fff; } +.bubble { + display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; margin-left: 6px; + border-radius: 99px; background: var(--mark); color: var(--ink); font-size: .75rem; font-weight: 700; +} + +.new-q { margin-bottom: 14px; } +.empty { color: var(--ink-3); text-align: center; padding: 40px 0; } + +.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 2px; } +.chip { background: var(--bg); border-radius: 999px; padding: 5px 12px; font-size: .9rem; } +.chip.ghost { background: transparent; border: 1.5px dashed var(--line); color: var(--ink-3); } +.q .progress { margin-top: 12px; } +.q .actions { margin-top: 14px; } + +.codes-summary { margin: 10px 0; } + +.share-list { padding: 6px 20px; } +.share-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 0; } +.share-row + .share-row { border-top: 1.5px solid var(--bg); } +.share-row div { 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; } +.spacer { flex: 1; } + +@media (max-width: 560px) { + .summary-row > * { flex: 1 1 auto; } + #composer .actions button { flex: 1 1 100%; } + #composer .spacer { display: none; } +} +#q-opts { min-height: 132px; } diff --git a/static/css/app.css b/static/css/app.css index 813e117..8accae0 100644 --- a/static/css/app.css +++ b/static/css/app.css @@ -88,10 +88,7 @@ button:disabled { opacity: .35; cursor: not-allowed; transform: none; } padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--ink-2); } .badge.open { background: var(--ok-soft); color: var(--ok); } -.badge.open::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.8s infinite; } .badge.public { background: var(--mark-soft); color: #7a5c00; } -@keyframes pulse { 50% { opacity: .3; } } -@media (prefers-reduced-motion: reduce) { .badge.open::before { animation: none; } } .notice { border-radius: var(--r-field); padding: 10px 14px; font-size: .9rem; margin: 10px 0; background: var(--bg); } .notice.warn { background: var(--mark-soft); color: #5c4500; } @@ -109,7 +106,8 @@ button:disabled { opacity: .35; cursor: not-allowed; transform: none; } .q-text { font: 700 1.15rem/1.3 var(--round); margin: 10px 0; } .q-opts { margin: 0 0 8px; padding-left: 20px; color: var(--ink-2); } .q-meta { font-size: .82rem; color: var(--ink-3); margin: 4px 0; } -.focus-mark { font-size: .78rem; font-weight: 600; color: var(--ink); background: var(--mark); padding: 3px 10px; border-radius: 999px; } +.focus-mark { display: inline-flex; align-items: center; gap: 5px; font-size: .78rem; font-weight: 600; color: var(--ink); background: var(--mark); padding: 3px 10px; border-radius: 999px; } +.icon { flex: none; display: block; } .templates { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; } diff --git a/static/css/vote.css b/static/css/vote.css index 9cfa643..116ebb0 100644 --- a/static/css/vote.css +++ b/static/css/vote.css @@ -35,7 +35,7 @@ body.voter h1 { font-size: 1.6rem; margin-bottom: 18px; } .choice.blank[aria-checked="true"] { background: var(--bg); border-color: var(--ink-3); color: var(--ink); } .vq .go { margin-top: 10px; padding: 14px; font-size: 1.05rem; } .voted { display: flex; gap: 10px; align-items: center; font: 600 1rem var(--round); margin: 0; color: var(--ink-2); } -.voted::before { content: "✓"; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--mark); color: var(--ink); font-weight: 800; } +.voted-mark { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--mark); color: var(--ink); } .waiting { text-align: center; padding: 36px 0; color: var(--ink-3); } dialog { border: none; border-radius: 24px; padding: 24px; width: min(92vw, 400px); background: var(--surface); color: var(--ink); } diff --git a/static/index.html b/static/index.html index 66d40dc..5a7021d 100644 --- a/static/index.html +++ b/static/index.html @@ -37,7 +37,7 @@
- +
diff --git a/static/js/admin.js b/static/js/admin.js index 1c73263..935f7f5 100644 --- a/static/js/admin.js +++ b/static/js/admin.js @@ -1,16 +1,17 @@ -import { $, h, api, pollId, takeKey, liveSocket, resultsView, STATE_LABEL, toast, fill, pct } from "./common.js"; +import { $, h, api, pollId, takeKey, liveSocket, resultsView, STATE_LABEL, toast, fill, pct, icon } from "./common.js"; const pid = pollId(); const key = takeKey(`rv_admin_${pid}`); const base = `/api/polls/${pid}`; +const TAB_KEY = "rv_admin_tab"; let state = null; -let settingsDirty = false; const TEMPLATES = [ + { label: "Pour / Contre / Abst. / NPPPAV", opts: ["Pour", "Contre", "Abstention", "Ne prend pas part au vote"], blank: false }, { label: "Pour / Contre / Abstention", opts: ["Pour", "Contre", "Abstention"], blank: false }, { label: "Oui / Non", opts: ["Oui", "Non"], blank: true }, - { label: "Élection (candidats)", opts: ["Candidat·e A", "Candidat·e B", "Candidat·e C"], blank: true, text: "Élection : " }, - { label: "Satisfaction 1–5", opts: ["1", "2", "3", "4", "5"], blank: true }, + { label: "Élection", opts: ["Candidat·e A", "Candidat·e B", "Candidat·e C"], blank: true, text: "Élection : " }, + { label: "Note 1 à 5", opts: ["1", "2", "3", "4", "5"], blank: true }, ]; const call = (method, path, data) => api(method, base + path, data, key); @@ -24,115 +25,135 @@ function errMsg(e) { return m[e.code] || e.message; } +function showTab(name) { + for (const b of document.querySelectorAll("[data-tab]")) b.setAttribute("aria-selected", String(b.dataset.tab === name)); + for (const p of document.querySelectorAll("[data-panel]")) p.hidden = p.dataset.panel !== name; + try { localStorage.setItem(TAB_KEY, name); } catch { /* private mode */ } +} +for (const b of document.querySelectorAll("[data-tab]")) b.addEventListener("click", () => showTab(b.dataset.tab)); +let initialTab = "questions"; +try { initialTab = localStorage.getItem(TAB_KEY) || "questions"; } catch { /* private mode */ } +showTab(initialTab); function render() { const p = state.poll; $("#title").textContent = p.title; document.title = `Admin · ${p.title}`; $("#voters").textContent = state.voters; - const parts = []; - if (p.expected) parts.push(`sur ${p.expected} attendus`); - if (p.max_voters) parts.push(`${p.max_voters} max`); - $("#voters-of").textContent = `inscrits${parts.length ? ", " + parts.join(", ") : ""}`; + $("#voters-of").textContent = `inscription${state.voters > 1 ? "s" : ""}` + (p.expected ? ` sur ${p.expected}` : ""); + + const over = p.expected && state.voters > p.expected; + $("#over").hidden = !over; + if (over) $("#over").textContent = `Plus d'inscriptions que de personnes attendues (${state.voters} pour ${p.expected}).`; - const es = $("#enroll-state"); - es.hidden = !p.enrollment_open && !(p.expected && state.voters > p.expected); - if (p.enrollment_open) { - es.className = "notice ok"; - es.textContent = "Ouvertes"; - } else { - es.className = "notice info"; - es.textContent = "Fermées"; - } - if (p.expected && state.voters > p.expected) { - es.className = "notice bad"; - es.textContent = `${state.voters} inscrits pour ${p.expected} attendus`; - } const tb = $("#toggle-enroll"); - tb.textContent = p.enrollment_open ? "Fermer les inscriptions" : "Ouvrir les inscriptions"; - tb.className = "block " + (p.enrollment_open ? "danger" : "go"); + // the switch itself carries the state, no status wording + tb.textContent = "Inscriptions"; + tb.className = "enroll-toggle " + (p.enrollment_open ? "on" : "off"); + tb.setAttribute("aria-pressed", String(p.enrollment_open)); - $("#screens").textContent = state.screens ? `Projecteur connecté (${state.screens})` : "Aucun projecteur connecté"; + $("#open-screen").classList.toggle("connected", state.screens > 0); + $("#open-screen").title = state.screens ? "Projecteur connecté" : "Aucun projecteur connecté"; - if (!settingsDirty) { - $("#s-interval").value = p.interval_ms; - $("#s-scans").value = p.scans_required; - $("#s-expected").value = p.expected ?? ""; - $("#s-max").value = p.max_voters ?? ""; - $("#s-code").checked = p.require_code; - } - $("#codes-card").hidden = !p.require_code && !state.codes.total; - $("#codes-summary").textContent = `${state.codes.used} utilisé(s) sur ${state.codes.total}.`; + const open = state.questions.filter((q) => q.state === "open").length; + $("#open-count").hidden = !open; + $("#open-count").textContent = open; + renderSettings(p); renderQuestions(); } +function renderSettings(p) { + // never overwrite a field the admin is typing in + const active = document.activeElement; + const sel = $("#s-interval"); + if (![...sel.options].some((o) => +o.value === p.interval_ms)) { + sel.append(h("option", { value: p.interval_ms }, `${(p.interval_ms / 1000).toLocaleString("fr-FR")} s`)); + } + if (active !== sel) sel.value = String(p.interval_ms); + 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 ?? ""; + $("#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é"; +} + function renderQuestions() { const box = $("#questions"); box.replaceChildren(); if (!state.questions.length) { - box.append(h("p", { class: "muted" }, "Aucune question.")); + box.append(h("p", { class: "empty" }, "Aucune question pour l'instant.")); return; } - const voters = state.voters; - for (const q of state.questions) { - const focused = state.poll.focus_qid === q.id; - const badges = [h("span", { class: `badge ${q.state}` }, STATE_LABEL[q.state])]; - if (q.results_public) badges.push(h("span", { class: "badge public" }, "Résultats publiés")); - if (focused) badges.push(h("span", { class: "focus-mark" }, "● à l'écran")); - - const actions = []; - const act = (label, action, cls = "small", confirmMsg) => - h("button", { - class: cls, type: "button", - onclick: async () => { - if (confirmMsg && !confirm(confirmMsg)) return; - try { await call("POST", `/questions/${q.id}/${action}`); } catch (e) { toast(errMsg(e), "bad"); } - }, - }, label); - if (q.state === "draft") { - actions.push(act("Lancer le vote", "open", "small go")); - actions.push(act("Supprimer", "delete", "small danger", "Supprimer ce brouillon ?")); - } - if (q.state === "open") { - actions.push(act("Clore le vote", "close", "small primary", - `Clore le vote (${q.participants} votants) ? Définitif.`)); - } - if (q.state === "closed") { - actions.push(q.results_public ? act("Masquer les résultats", "unpublish") : act("Publier les résultats", "publish", "small primary")); - } - if (q.state !== "draft" && !focused) actions.push(act("Afficher à l'écran", "focus")); - - const turnout = q.state !== "draft" - ? h("div", {}, - h("div", { class: "q-meta" }, `${q.participants} / ${voters} votants`), - h("div", { class: "progress" }, fill(pct(q.participants, voters), ""))) - : null; - - box.append(h("article", { class: `q ${q.state}` }, - h("div", { class: "q-head" }, h("div", {}, badges), h("span", { class: "q-meta" }, `#${q.id}`)), - h("div", { class: "q-text" }, q.text), - q.state === "closed" ? resultsView(q) : h("ol", { class: "q-opts" }, q.options.map((o) => h("li", {}, o))), - h("div", { class: "q-meta" }, - q.kind === "multi" ? `Max ${q.max_choices} choix` : "", - q.kind === "multi" && q.allow_blank ? ", " : "", - q.allow_blank ? "blanc possible" : ""), - turnout, - h("div", { class: "actions" }, actions), - )); - } + const order = { open: 0, draft: 1, closed: 2 }; + const qs = [...state.questions].sort((a, b) => order[a.state] - order[b.state] || a.id - b.id); + for (const q of qs) box.append(questionCard(q)); } +function questionCard(q) { + const voters = state.voters; + const focused = state.poll.focus_qid === q.id; + const act = (label, action, cls = "small", confirmMsg) => + h("button", { + class: cls, type: "button", + onclick: async () => { + if (confirmMsg && !confirm(confirmMsg)) return; + try { await call("POST", `/questions/${q.id}/${action}`); } catch (e) { toast(errMsg(e), "bad"); } + }, + }, label); + const actions = []; + if (q.state === "draft") { + 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.`)); + } else { + actions.push(q.results_public + ? act("Masquer les résultats", "unpublish") + : act("Publier les résultats", "publish", "small primary")); + } + 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])]; + if (q.results_public) badges.push(h("span", { class: "badge public" }, "Publiés")); + if (focused) badges.push(h("span", { class: "focus-mark" }, icon("screen", 14), "À l'écran")); + if (q.kind === "multi") badges.push(h("span", { class: "badge" }, `${q.max_choices} choix max`)); + + 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), + 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, + h("div", { class: "actions" }, actions), + ); +} + +// composer + +const composer = $("#composer"); +function applyTemplate(t) { + $("#q-opts").value = t.opts.join("\n"); + $("#q-blank").checked = t.blank; + if (t.text && !$("#q-text").value) $("#q-text").value = t.text; +} +$("#new-q").addEventListener("click", () => { + // the first template is the default answer set + if (!$("#q-opts").value.trim()) applyTemplate(TEMPLATES[0]); + composer.showModal(); + $("#q-text").focus(); +}); for (const t of TEMPLATES) { $("#templates").append(h("button", { class: "small", type: "button", - onclick: () => { - $("#q-opts").value = t.opts.join("\n"); - $("#q-blank").checked = t.blank; - if (t.text && !$("#q-text").value) $("#q-text").value = t.text; - $("#q-text").focus(); - }, + onclick: () => { applyTemplate(t); $("#q-text").focus(); }, }, t.label)); } $("#q-kind").addEventListener("change", () => { $("#q-max-box").hidden = $("#q-kind").value !== "multi"; }); @@ -151,43 +172,43 @@ async function submitQuestion(open) { if (options.length < 2) return toast("Au moins deux réponses", "bad"); try { await call("POST", "/questions", data); - $("#q-text").value = ""; - $("#q-opts").value = ""; - toast(open ? "Vote lancé" : "Question préparée", "ok"); + $("#q-form").reset(); + $("#q-max-box").hidden = true; + composer.close(); + showTab("questions"); + toast(open ? "Vote lancé" : "Brouillon enregistré"); } catch (e) { toast(errMsg(e), "bad"); } } $("#q-draft").addEventListener("click", () => submitQuestion(false)); $("#q-push").addEventListener("click", () => submitQuestion(true)); +// enrollment + settings, saved as soon as a field changes $("#toggle-enroll").addEventListener("click", async () => { const open = !state.poll.enrollment_open; - if (!open && !confirm(`Fermer les inscriptions (${state.voters} inscrits) ?`)) return; + if (!open && !confirm(`Fermer les inscriptions (${state.voters} inscription${state.voters > 1 ? "s" : ""}) ?`)) return; try { await call("PATCH", "", { enrollment_open: open }); } catch (e) { toast(errMsg(e), "bad"); } }); -for (const id of ["#s-interval", "#s-scans", "#s-expected", "#s-max", "#s-code"]) { - $(id).addEventListener("input", () => { settingsDirty = true; }); +const intOrNull = (v) => (v ? +v : null); +const SETTINGS = { + "#s-interval": (el) => ({ interval_ms: +el.value }), + "#s-scans": (el) => ({ scans_required: +el.value }), + "#s-expected": (el) => ({ expected: intOrNull(el.value) }), + "#s-max": (el) => ({ max_voters: intOrNull(el.value) }), + "#s-code": (el) => ({ require_code: el.checked }), +}; +for (const [sel, build] of Object.entries(SETTINGS)) { + $(sel).addEventListener("change", async (e) => { + try { await call("PATCH", "", build(e.target)); toast("Enregistré"); } + catch (err) { toast(errMsg(err), "bad"); } + }); } -$("#save-settings").addEventListener("click", async () => { - try { - await call("PATCH", "", { - interval_ms: +$("#s-interval").value, - scans_required: +$("#s-scans").value, - expected: $("#s-expected").value ? +$("#s-expected").value : null, - max_voters: $("#s-max").value ? +$("#s-max").value : null, - require_code: $("#s-code").checked, - }); - settingsDirty = false; - toast("Réglages enregistrés", "ok"); - } catch (e) { toast(errMsg(e), "bad"); } -}); - $("#codes-gen").addEventListener("click", async () => { try { await call("POST", "/codes", { count: +$("#codes-count").value }); - toast("Codes générés", "ok"); + toast("Codes générés"); } catch (e) { toast(errMsg(e), "bad"); } }); $("#codes-print").addEventListener("click", async () => { @@ -200,20 +221,22 @@ $("#codes-print").addEventListener("click", async () => { $("#codes-close").addEventListener("click", () => { $("#codes-sheet").hidden = true; }); $("#codes-do-print").addEventListener("click", () => window.print()); +// sharing $("#open-screen").href = `/screen/${pid}#${encodeURIComponent(key)}`; +$("#screen-icon").replaceWith(icon("screen", 16)); +async function copy(text, label) { + try { await navigator.clipboard.writeText(text); toast(`${label} copié`); } + catch { prompt(label, text); } +} // the key is hidden from the address bar, so a bookmark would lose it -$("#copy-admin").addEventListener("click", async () => { - const link = `${location.origin}/admin/${pid}#${encodeURIComponent(key)}`; - try { await navigator.clipboard.writeText(link); toast("Lien admin copié"); } - catch { prompt("Lien admin", link); } -}); +$("#copy-admin").addEventListener("click", () => + copy(`${location.origin}/admin/${pid}#${encodeURIComponent(key)}`, "Lien admin")); $("#screen-rotate").addEventListener("click", async () => { - if (!confirm("Révoquer l'ancien lien projecteur ?")) return; + if (!confirm("Créer un nouveau lien projecteur ? L'ancien cessera de fonctionner.")) return; try { const r = await call("POST", "/screen-key"); - $("#screen-link").value = `${location.origin}/screen/${pid}#${r.screen_key}`; - $("#screen-link").select(); + await copy(`${location.origin}/screen/${pid}#${r.screen_key}`, "Lien projecteur"); } catch (e) { toast(errMsg(e), "bad"); } }); $("#export").addEventListener("click", async () => { @@ -226,7 +249,6 @@ $("#export").addEventListener("click", async () => { } catch (e) { toast(errMsg(e), "bad"); } }); - liveSocket(`/ws/${pid}/admin`, { auth: key, onMessage(msg) { @@ -244,7 +266,8 @@ liveSocket(`/ws/${pid}/admin`, { c.textContent = "refusé"; return; } - c.className = `conn ${s}`; - c.textContent = s === "online" ? "en direct" : "reconnexion…"; + c.hidden = s === "online"; + c.className = "conn offline"; + c.textContent = "Reconnexion…"; }, }); diff --git a/static/js/common.js b/static/js/common.js index a846b16..6af3215 100644 --- a/static/js/common.js +++ b/static/js/common.js @@ -146,6 +146,24 @@ export function toast(msg, kind = "info") { const SVGNS = "http://www.w3.org/2000/svg"; +const ICONS = { + screen: ["M3 5h18v11H3z", "M8 20h8", "M12 16v4"], + check: ["M5 12.5l4.5 4.5L19 7.5"], +}; + +export function icon(name, size = 16) { + const svg = document.createElementNS(SVGNS, "svg"); + for (const [k, v] of Object.entries({ viewBox: "0 0 24 24", width: size, height: size, fill: "none", + stroke: "currentColor", "stroke-width": 2, "stroke-linecap": "round", "stroke-linejoin": "round", + class: "icon", "aria-hidden": "true" })) svg.setAttribute(k, v); + for (const d of ICONS[name]) { + const p = document.createElementNS(SVGNS, "path"); + p.setAttribute("d", d); + svg.append(p); + } + return svg; +} + // segmented ring: n of total segments lit, the newest one in highlighter yellow export function ring(n, total, size = 160, label = `${n}/${total}`) { const svg = document.createElementNS(SVGNS, "svg"); diff --git a/static/js/screen.js b/static/js/screen.js index 931aea9..9eba124 100644 --- a/static/js/screen.js +++ b/static/js/screen.js @@ -22,11 +22,8 @@ function render() { document.title = st.title; $("#voters").textContent = st.voters; $("#voters-label").textContent = - `inscrit${st.voters > 1 ? "s" : ""}` + (st.expected ? ` / ${st.expected}` : ""); + `inscription${st.voters > 1 ? "s" : ""}` + (st.expected ? ` sur ${st.expected}` : ""); $("#secs").textContent = Math.ceil((st.scans_required * st.interval_ms) / 1000); - const b = $("#enroll-badge"); - b.className = `badge ${st.enrollment_open ? "open" : "closed"}`; - b.textContent = st.enrollment_open ? "Inscriptions ouvertes" : "Inscriptions closes"; const f = st.focus; const box = $("#focus"); @@ -43,7 +40,7 @@ function render() { } else if (f.results) { box.append(resultsView(f)); } else { - box.append(h("p", { class: "status" }, `Vote clos, ${f.participants} votant${f.participants > 1 ? "s" : ""}`)); + box.append(h("p", { class: "status" }, `Vote clos, ${f.participants} vote${f.participants > 1 ? "s" : ""}`)); } } layout(); @@ -99,8 +96,9 @@ liveSocket(`/ws/${pid}/screen`, { $("#denied").hidden = false; return; } - c.className = `conn ${s}`; - c.textContent = s === "online" ? "en direct" : "reconnexion…"; + c.hidden = s === "online"; + c.className = "conn offline"; + c.textContent = "Reconnexion…"; if (s !== "online") { qr = null; const cv = $("#qr"); cv.getContext("2d").clearRect(0, 0, cv.width, cv.height); } }, }); diff --git a/static/js/vote.js b/static/js/vote.js index 808f310..27d8344 100644 --- a/static/js/vote.js +++ b/static/js/vote.js @@ -1,4 +1,4 @@ -import { $, h, api, pollId, liveSocket, resultsView, toast, ring } from "./common.js"; +import { $, h, api, pollId, liveSocket, resultsView, toast, ring, icon } from "./common.js"; const pid = pollId(); const DONE_KEY = `rv_done_${pid}`; @@ -128,7 +128,7 @@ function handleScan(r) { block("Inscriptions closes."); break; case "full": - block("Nombre maximal d'inscrits atteint."); + block("Nombre maximal d'inscriptions atteint."); break; } } @@ -195,7 +195,7 @@ function questionCard(q) { return card; } if (q.voted) { - card.append(h("p", { class: "voted" }, "Vote enregistré")); + card.append(h("p", { class: "voted" }, h("span", { class: "voted-mark" }, icon("check", 16)), "Vote enregistré")); return card; } const s = sel(q.id); @@ -270,8 +270,9 @@ function connect() { }, onStatus(s) { const c = $("#conn"); - c.className = `conn ${s === "online" ? "online" : "offline"}`; - c.textContent = s === "online" ? "en direct" : "reconnexion…"; + c.hidden = s === "online"; + c.className = "conn offline"; + c.textContent = "Reconnexion…"; }, }); } @@ -296,7 +297,7 @@ async function boot() { return; } if (lsGet(DONE_KEY)) { - return block("Appareil déjà inscrit à ce scrutin (accès perdu). Voyez l'organisateur."); + return block("Appareil déjà inscrit à ce scrutin (accès perdu). Adressez-vous à l'équipe organisatrice."); } if (!me.enrollment_open) return block("Inscriptions closes."); required = me.scans_required; diff --git a/static/screen.html b/static/screen.html index d7b7854..bc2cbe8 100644 --- a/static/screen.html +++ b/static/screen.html @@ -18,7 +18,7 @@ rotatyvote
- connexion… +
@@ -48,8 +48,7 @@
diff --git a/static/vote.html b/static/vote.html index ccb8bcb..57d9bff 100644 --- a/static/vote.html +++ b/static/vote.html @@ -50,7 +50,7 @@