Admin: tabs, question composer dialog, settings autosave

Default answers Pour/Contre/Abstention/NPPPAV, svg icons instead of status
dots, no live/open status labels, inclusive wording across the UI and docs.
This commit is contained in:
2026-11-16 13:26:46 +01:00
parent 74c9b34ec1
commit e328a0983f
16 changed files with 351 additions and 226 deletions
+2 -2
View File
@@ -5,7 +5,7 @@ Merci de votre intérêt pour RotatyVote.
## Avant de commencer ## Avant de commencer
- Ouvrez une issue pour tout changement non trivial, afin d'en discuter avant d'écrire du code. - 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 ## Mise en place
@@ -18,7 +18,7 @@ RV_TEST_TLS=1 uv run pytest
## Règles ## 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. - **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'`. - **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. - **Interface sobre.** Texte minimal, en français, en phrases courtes.
+6 -6
View File
@@ -61,8 +61,8 @@ location / {
## Déroulé ## Déroulé
1. Créer le scrutin, garder le lien admin (clé dans l'URL, non récupérable). 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. 2. Ouvrir les inscriptions. Le projecteur affiche le QR rotatif et le nombre d'inscriptions.
3. Fermer les inscriptions quand la salle est inscrite. 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. 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. 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). **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 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 ; - la fermeture des inscriptions avant les votes ;
- un plafond d'inscriptions ; - 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. - **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 ## Tests
Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

+83 -59
View File
@@ -6,69 +6,104 @@
<title>RotatyVote · Administration</title> <title>RotatyVote · Administration</title>
<link rel="icon" href="/static/img/mark.svg" type="image/svg+xml"> <link rel="icon" href="/static/img/mark.svg" type="image/svg+xml">
<link rel="stylesheet" href="/static/css/app.css"> <link rel="stylesheet" href="/static/css/app.css">
<link rel="stylesheet" href="/static/css/admin.css">
<script type="module" src="/static/js/admin.js"></script> <script type="module" src="/static/js/admin.js"></script>
</head> </head>
<body> <body>
<main class="wrap"> <main class="wrap admin-wrap">
<div class="topbar no-print"> <header class="a-head no-print">
<div><a class="brand" href="/"><img src="/static/img/mark.svg" alt=""><span>rotaty<b>vote</b></span></a><h1 id="title">…</h1></div> <a class="brand" href="/"><img src="/static/img/mark.svg" alt=""><span>rotaty<b>vote</b></span></a>
<div class="actions"> <span id="conn" class="conn" hidden></span>
<span id="conn" class="conn">connexion…</span> </header>
<button id="copy-admin" class="small" type="button">Copier le lien admin</button>
<a id="open-screen" class="btn small" target="_blank" rel="noopener">Ouvrir le projecteur</a>
<button id="export" class="small" type="button">Exporter (JSON)</button>
</div>
</div>
<div id="denied" class="notice bad" hidden>Clé d'administration absente ou invalide. Utilisez le lien complet reçu à la création.</div> <div id="denied" class="notice bad" hidden>Clé d'administration absente ou invalide. Utilisez le lien complet reçu à la création.</div>
<div id="app" class="grid admin" hidden> <div id="app" hidden>
<aside class="no-print"> <section class="summary no-print">
<section class="card"> <h1 id="title">…</h1>
<h2>Inscriptions</h2> <div class="summary-row">
<div class="stat"><b id="voters">0</b><span id="voters-of" class="muted">inscrits</span></div> <div class="count-chip"><b id="voters">0</b><span id="voters-of">inscriptions</span></div>
<div id="enroll-state" class="notice"></div> <button id="toggle-enroll" type="button"></button>
<button id="toggle-enroll" class="block" type="button"></button> <a id="open-screen" class="btn" target="_blank" rel="noopener"><span id="screen-icon"></span>Projecteur</a>
<p id="screens" class="hint"></p> </div>
<p id="over" class="notice bad" hidden></p>
</section> </section>
<section class="card"> <nav class="tabs no-print" role="tablist">
<h2>Réglages</h2> <button role="tab" data-tab="questions" type="button">Questions<span id="open-count" class="bubble" hidden></span></button>
<button role="tab" data-tab="enroll" type="button">Inscriptions</button>
<button role="tab" data-tab="share" type="button">Partage</button>
</nav>
<section data-panel="questions" class="no-print">
<button id="new-q" class="primary new-q" type="button">Nouvelle question</button>
<div id="questions"></div>
</section>
<section data-panel="enroll" class="no-print" hidden>
<div class="card">
<div class="row"> <div class="row">
<div><label for="s-interval">Rotation (ms)</label><input id="s-interval" type="number" min="300" max="5000" step="100"></div> <div>
<div><label for="s-scans">Codes requis</label><input id="s-scans" type="number" min="2" max="20"></div> <label for="s-interval">Rotation du QR</label>
<select id="s-interval">
<option value="500">0,5 s</option>
<option value="1000">1 s</option>
<option value="1500">1,5 s</option>
<option value="2000">2 s</option>
</select>
</div>
<div><label for="s-scans">Codes à scanner</label><input id="s-scans" type="number" min="2" max="20"></div>
</div> </div>
<div class="row"> <div class="row">
<div><label for="s-expected">Attendus</label><input id="s-expected" type="number" min="0" placeholder="—"></div> <div><label for="s-expected">Personnes attendues</label><input id="s-expected" type="number" min="0" placeholder="non précisé"></div>
<div><label for="s-max">Plafond</label><input id="s-max" type="number" min="0" placeholder="aucun"></div> <div><label for="s-max">Plafond</label><input id="s-max" type="number" min="0" placeholder="aucun"></div>
</div> </div>
<label class="inline"><input id="s-code" type="checkbox"> Exiger un code papier</label>
<div class="actions"><button id="save-settings" class="small" type="button">Enregistrer</button></div>
</section>
<section class="card" id="codes-card">
<h2>Codes papier</h2>
<p id="codes-summary" class="muted"></p>
<div class="row">
<input id="codes-count" type="number" min="1" max="5000" value="20" aria-label="Nombre de codes">
<button id="codes-gen" class="small" type="button">Générer</button>
</div> </div>
<div class="actions"><button id="codes-print" class="small" type="button">Afficher / imprimer</button></div> <div class="card">
<label class="inline"><input id="s-code" type="checkbox"> Exiger un code papier</label>
<div id="codes-box" hidden>
<p id="codes-summary" class="muted codes-summary"></p>
<div class="linkbox">
<input id="codes-count" type="number" min="1" max="5000" value="20" aria-label="Nombre de codes à générer">
<button id="codes-gen" class="small" type="button">Générer</button>
<button id="codes-print" class="small" type="button">Imprimer</button>
</div>
</div>
</div>
</section> </section>
<section class="card"> <section data-panel="share" class="no-print" hidden>
<h2>Lien projecteur</h2> <div class="card share-list">
<div class="linkbox"><input id="screen-link" type="text" readonly placeholder="—"><button id="screen-rotate" class="small" type="button">Nouveau</button></div> <div class="share-row">
<div><b>Lien admin</b><span class="muted">Seule clé d'accès à cette page</span></div>
<button id="copy-admin" class="small" type="button">Copier</button>
</div>
<div class="share-row">
<div><b>Lien projecteur</b><span class="muted">Révoque le précédent</span></div>
<button id="screen-rotate" class="small" type="button">Nouveau lien</button>
</div>
<div class="share-row">
<div><b>Résultats</b><span class="muted">Bulletins anonymes et décomptes</span></div>
<button id="export" class="small" type="button">Exporter</button>
</div>
</div>
</section> </section>
</aside>
<div> <section id="codes-sheet" class="card" hidden>
<section class="card no-print"> <div class="no-print actions"><button id="codes-close" class="small" type="button">Fermer</button><button id="codes-do-print" class="small primary" type="button">Imprimer</button></div>
<h2 id="codes-title"></h2>
<div id="codes-grid" class="codes-print"></div>
</section>
</div>
</main>
<dialog id="composer">
<form method="dialog" id="q-form">
<h2>Nouvelle question</h2> <h2>Nouvelle question</h2>
<div class="templates" id="templates"></div> <div class="templates" id="templates"></div>
<label for="q-text">Question</label> <label for="q-text">Question</label>
<input id="q-text" type="text" maxlength="500" placeholder="Approuvez-vous le rapport moral ?"> <input id="q-text" type="text" maxlength="500" placeholder="Approuvez-vous le rapport moral ?">
<label for="q-opts">Réponses <span class="hint">(une par ligne)</span></label> <label for="q-opts">Réponses, une par ligne</label>
<textarea id="q-opts" placeholder="Pour&#10;Contre"></textarea> <textarea id="q-opts" placeholder="Pour&#10;Contre"></textarea>
<div class="row"> <div class="row">
<div> <div>
@@ -80,25 +115,14 @@
<input id="q-max" type="number" min="1" value="2"> <input id="q-max" type="number" min="1" value="2">
</div> </div>
</div> </div>
<label class="inline"><input id="q-blank" type="checkbox" checked> Autoriser le vote blanc</label> <label class="inline"><input id="q-blank" type="checkbox"> Autoriser le vote blanc</label>
<div class="actions"> <div class="actions">
<button id="q-draft" type="button">Préparer (brouillon)</button> <button value="cancel" type="submit" formnovalidate>Annuler</button>
<button id="q-push" class="go" type="button">Lancer le vote maintenant</button> <span class="spacer"></span>
<button id="q-draft" type="button">Garder en brouillon</button>
<button id="q-push" class="go" type="button">Lancer le vote</button>
</div> </div>
</section> </form>
</dialog>
<section class="no-print">
<h2>Questions</h2>
<div id="questions"></div>
</section>
<section id="codes-sheet" class="card" hidden>
<div class="no-print actions"><button id="codes-close" class="small" type="button">Fermer</button><button id="codes-do-print" class="small primary" type="button">Imprimer</button></div>
<h2 id="codes-title"></h2>
<div id="codes-grid" class="codes-print"></div>
</section>
</div>
</div>
</main>
</body> </body>
</html> </html>
+64
View File
@@ -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; }
+2 -4
View File
@@ -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); padding: 3px 10px; border-radius: 999px; background: var(--bg); color: var(--ink-2);
} }
.badge.open { background: var(--ok-soft); color: var(--ok); } .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; } .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 { 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; } .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-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-opts { margin: 0 0 8px; padding-left: 20px; color: var(--ink-2); }
.q-meta { font-size: .82rem; color: var(--ink-3); margin: 4px 0; } .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; } .templates { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 4px; }
+1 -1
View File
@@ -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); } .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; } .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 { 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); } .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); } dialog { border: none; border-radius: 24px; padding: 24px; width: min(92vw, 400px); background: var(--surface); color: var(--ink); }
+1 -1
View File
@@ -37,7 +37,7 @@
<div class="row"> <div class="row">
<div> <div>
<label for="expected">Participants attendus</label> <label for="expected">Personnes attendues</label>
<input id="expected" type="number" min="1" placeholder="facultatif"> <input id="expected" type="number" min="1" placeholder="facultatif">
</div> </div>
<div> <div>
+124 -101
View File
@@ -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 pid = pollId();
const key = takeKey(`rv_admin_${pid}`); const key = takeKey(`rv_admin_${pid}`);
const base = `/api/polls/${pid}`; const base = `/api/polls/${pid}`;
const TAB_KEY = "rv_admin_tab";
let state = null; let state = null;
let settingsDirty = false;
const TEMPLATES = [ 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: "Pour / Contre / Abstention", opts: ["Pour", "Contre", "Abstention"], blank: false },
{ label: "Oui / Non", opts: ["Oui", "Non"], blank: true }, { 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: "Élection", 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: "Note 1 à 5", opts: ["1", "2", "3", "4", "5"], blank: true },
]; ];
const call = (method, path, data) => api(method, base + path, data, key); const call = (method, path, data) => api(method, base + path, data, key);
@@ -24,64 +25,77 @@ function errMsg(e) {
return m[e.code] || e.message; 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() { function render() {
const p = state.poll; const p = state.poll;
$("#title").textContent = p.title; $("#title").textContent = p.title;
document.title = `Admin · ${p.title}`; document.title = `Admin · ${p.title}`;
$("#voters").textContent = state.voters; $("#voters").textContent = state.voters;
const parts = []; $("#voters-of").textContent = `inscription${state.voters > 1 ? "s" : ""}` + (p.expected ? ` sur ${p.expected}` : "");
if (p.expected) parts.push(`sur ${p.expected} attendus`);
if (p.max_voters) parts.push(`${p.max_voters} max`); const over = p.expected && state.voters > p.expected;
$("#voters-of").textContent = `inscrits${parts.length ? ", " + parts.join(", ") : ""}`; $("#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"); const tb = $("#toggle-enroll");
tb.textContent = p.enrollment_open ? "Fermer les inscriptions" : "Ouvrir les inscriptions"; // the switch itself carries the state, no status wording
tb.className = "block " + (p.enrollment_open ? "danger" : "go"); 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) { const open = state.questions.filter((q) => q.state === "open").length;
$("#s-interval").value = p.interval_ms; $("#open-count").hidden = !open;
$("#s-scans").value = p.scans_required; $("#open-count").textContent = open;
$("#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}.`;
renderSettings(p);
renderQuestions(); 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() { function renderQuestions() {
const box = $("#questions"); const box = $("#questions");
box.replaceChildren(); box.replaceChildren();
if (!state.questions.length) { if (!state.questions.length) {
box.append(h("p", { class: "muted" }, "Aucune question.")); box.append(h("p", { class: "empty" }, "Aucune question pour l'instant."));
return; return;
} }
const voters = state.voters; const order = { open: 0, draft: 1, closed: 2 };
for (const q of state.questions) { const qs = [...state.questions].sort((a, b) => order[a.state] - order[b.state] || a.id - b.id);
const focused = state.poll.focus_qid === q.id; for (const q of qs) box.append(questionCard(q));
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 = []; function questionCard(q) {
const voters = state.voters;
const focused = state.poll.focus_qid === q.id;
const act = (label, action, cls = "small", confirmMsg) => const act = (label, action, cls = "small", confirmMsg) =>
h("button", { h("button", {
class: cls, type: "button", class: cls, type: "button",
@@ -90,49 +104,56 @@ function renderQuestions() {
try { await call("POST", `/questions/${q.id}/${action}`); } catch (e) { toast(errMsg(e), "bad"); } try { await call("POST", `/questions/${q.id}/${action}`); } catch (e) { toast(errMsg(e), "bad"); }
}, },
}, label); }, label);
const actions = [];
if (q.state === "draft") { if (q.state === "draft") {
actions.push(act("Lancer le vote", "open", "small go")); actions.push(act("Lancer le vote", "open", "small go"));
actions.push(act("Supprimer", "delete", "small danger", "Supprimer ce brouillon ?")); 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 === "open") { if (q.state !== "draft" && !focused) actions.push(act([icon("screen", 15), "Afficher à l'écran"], "focus"));
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" const badges = [h("span", { class: `badge ${q.state}` }, STATE_LABEL[q.state])];
? h("div", {}, if (q.results_public) badges.push(h("span", { class: "badge public" }, "Publiés"));
h("div", { class: "q-meta" }, `${q.participants} / ${voters} votants`), if (focused) badges.push(h("span", { class: "focus-mark" }, icon("screen", 14), "À l'écran"));
h("div", { class: "progress" }, fill(pct(q.participants, voters), ""))) if (q.kind === "multi") badges.push(h("span", { class: "badge" }, `${q.max_choices} choix max`));
: null;
box.append(h("article", { class: `q ${q.state}` }, return 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-head" }, h("div", {}, badges),
q.state !== "draft" ? h("span", { class: "q-meta" }, `${q.participants} / ${voters}`) : null),
h("div", { class: "q-text" }, q.text), h("div", { class: "q-text" }, q.text),
q.state === "closed" ? resultsView(q) : h("ol", { class: "q-opts" }, q.options.map((o) => h("li", {}, o))), q.state === "closed"
h("div", { class: "q-meta" }, ? resultsView(q)
q.kind === "multi" ? `Max ${q.max_choices} choix` : "", : h("div", { class: "chips" }, q.options.map((o) => h("span", { class: "chip" }, o)),
q.kind === "multi" && q.allow_blank ? ", " : "", q.allow_blank ? h("span", { class: "chip ghost" }, "Blanc") : null),
q.allow_blank ? "blanc possible" : ""), q.state === "open" ? h("div", { class: "progress" }, fill(pct(q.participants, voters), "")) : null,
turnout,
h("div", { class: "actions" }, actions), h("div", { class: "actions" }, actions),
)); );
}
} }
// composer
for (const t of TEMPLATES) { const composer = $("#composer");
$("#templates").append(h("button", { function applyTemplate(t) {
class: "small", type: "button",
onclick: () => {
$("#q-opts").value = t.opts.join("\n"); $("#q-opts").value = t.opts.join("\n");
$("#q-blank").checked = t.blank; $("#q-blank").checked = t.blank;
if (t.text && !$("#q-text").value) $("#q-text").value = t.text; 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(); $("#q-text").focus();
}, });
for (const t of TEMPLATES) {
$("#templates").append(h("button", {
class: "small", type: "button",
onclick: () => { applyTemplate(t); $("#q-text").focus(); },
}, t.label)); }, t.label));
} }
$("#q-kind").addEventListener("change", () => { $("#q-max-box").hidden = $("#q-kind").value !== "multi"; }); $("#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"); if (options.length < 2) return toast("Au moins deux réponses", "bad");
try { try {
await call("POST", "/questions", data); await call("POST", "/questions", data);
$("#q-text").value = ""; $("#q-form").reset();
$("#q-opts").value = ""; $("#q-max-box").hidden = true;
toast(open ? "Vote lancé" : "Question préparée", "ok"); composer.close();
showTab("questions");
toast(open ? "Vote lancé" : "Brouillon enregistré");
} catch (e) { toast(errMsg(e), "bad"); } } catch (e) { toast(errMsg(e), "bad"); }
} }
$("#q-draft").addEventListener("click", () => submitQuestion(false)); $("#q-draft").addEventListener("click", () => submitQuestion(false));
$("#q-push").addEventListener("click", () => submitQuestion(true)); $("#q-push").addEventListener("click", () => submitQuestion(true));
// enrollment + settings, saved as soon as a field changes
$("#toggle-enroll").addEventListener("click", async () => { $("#toggle-enroll").addEventListener("click", async () => {
const open = !state.poll.enrollment_open; 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"); } 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"]) { const intOrNull = (v) => (v ? +v : null);
$(id).addEventListener("input", () => { settingsDirty = true; }); 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 () => { $("#codes-gen").addEventListener("click", async () => {
try { try {
await call("POST", "/codes", { count: +$("#codes-count").value }); 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"); } } catch (e) { toast(errMsg(e), "bad"); }
}); });
$("#codes-print").addEventListener("click", async () => { $("#codes-print").addEventListener("click", async () => {
@@ -200,20 +221,22 @@ $("#codes-print").addEventListener("click", async () => {
$("#codes-close").addEventListener("click", () => { $("#codes-sheet").hidden = true; }); $("#codes-close").addEventListener("click", () => { $("#codes-sheet").hidden = true; });
$("#codes-do-print").addEventListener("click", () => window.print()); $("#codes-do-print").addEventListener("click", () => window.print());
// sharing
$("#open-screen").href = `/screen/${pid}#${encodeURIComponent(key)}`; $("#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 // the key is hidden from the address bar, so a bookmark would lose it
$("#copy-admin").addEventListener("click", async () => { $("#copy-admin").addEventListener("click", () =>
const link = `${location.origin}/admin/${pid}#${encodeURIComponent(key)}`; copy(`${location.origin}/admin/${pid}#${encodeURIComponent(key)}`, "Lien admin"));
try { await navigator.clipboard.writeText(link); toast("Lien admin copié"); }
catch { prompt("Lien admin", link); }
});
$("#screen-rotate").addEventListener("click", async () => { $("#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 { try {
const r = await call("POST", "/screen-key"); const r = await call("POST", "/screen-key");
$("#screen-link").value = `${location.origin}/screen/${pid}#${r.screen_key}`; await copy(`${location.origin}/screen/${pid}#${r.screen_key}`, "Lien projecteur");
$("#screen-link").select();
} catch (e) { toast(errMsg(e), "bad"); } } catch (e) { toast(errMsg(e), "bad"); }
}); });
$("#export").addEventListener("click", async () => { $("#export").addEventListener("click", async () => {
@@ -226,7 +249,6 @@ $("#export").addEventListener("click", async () => {
} catch (e) { toast(errMsg(e), "bad"); } } catch (e) { toast(errMsg(e), "bad"); }
}); });
liveSocket(`/ws/${pid}/admin`, { liveSocket(`/ws/${pid}/admin`, {
auth: key, auth: key,
onMessage(msg) { onMessage(msg) {
@@ -244,7 +266,8 @@ liveSocket(`/ws/${pid}/admin`, {
c.textContent = "refusé"; c.textContent = "refusé";
return; return;
} }
c.className = `conn ${s}`; c.hidden = s === "online";
c.textContent = s === "online" ? "en direct" : "reconnexion…"; c.className = "conn offline";
c.textContent = "Reconnexion…";
}, },
}); });
+18
View File
@@ -146,6 +146,24 @@ export function toast(msg, kind = "info") {
const SVGNS = "http://www.w3.org/2000/svg"; 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 // segmented ring: n of total segments lit, the newest one in highlighter yellow
export function ring(n, total, size = 160, label = `${n}/${total}`) { export function ring(n, total, size = 160, label = `${n}/${total}`) {
const svg = document.createElementNS(SVGNS, "svg"); const svg = document.createElementNS(SVGNS, "svg");
+5 -7
View File
@@ -22,11 +22,8 @@ function render() {
document.title = st.title; document.title = st.title;
$("#voters").textContent = st.voters; $("#voters").textContent = st.voters;
$("#voters-label").textContent = $("#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); $("#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 f = st.focus;
const box = $("#focus"); const box = $("#focus");
@@ -43,7 +40,7 @@ function render() {
} else if (f.results) { } else if (f.results) {
box.append(resultsView(f)); box.append(resultsView(f));
} else { } 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(); layout();
@@ -99,8 +96,9 @@ liveSocket(`/ws/${pid}/screen`, {
$("#denied").hidden = false; $("#denied").hidden = false;
return; return;
} }
c.className = `conn ${s}`; c.hidden = s === "online";
c.textContent = s === "online" ? "en direct" : "reconnexion…"; 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); } if (s !== "online") { qr = null; const cv = $("#qr"); cv.getContext("2d").clearRect(0, 0, cv.width, cv.height); }
}, },
}); });
+7 -6
View File
@@ -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 pid = pollId();
const DONE_KEY = `rv_done_${pid}`; const DONE_KEY = `rv_done_${pid}`;
@@ -128,7 +128,7 @@ function handleScan(r) {
block("Inscriptions closes."); block("Inscriptions closes.");
break; break;
case "full": case "full":
block("Nombre maximal d'inscrits atteint."); block("Nombre maximal d'inscriptions atteint.");
break; break;
} }
} }
@@ -195,7 +195,7 @@ function questionCard(q) {
return card; return card;
} }
if (q.voted) { 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; return card;
} }
const s = sel(q.id); const s = sel(q.id);
@@ -270,8 +270,9 @@ function connect() {
}, },
onStatus(s) { onStatus(s) {
const c = $("#conn"); const c = $("#conn");
c.className = `conn ${s === "online" ? "online" : "offline"}`; c.hidden = s === "online";
c.textContent = s === "online" ? "en direct" : "reconnexion…"; c.className = "conn offline";
c.textContent = "Reconnexion…";
}, },
}); });
} }
@@ -296,7 +297,7 @@ async function boot() {
return; return;
} }
if (lsGet(DONE_KEY)) { 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."); if (!me.enrollment_open) return block("Inscriptions closes.");
required = me.scans_required; required = me.scans_required;
+2 -3
View File
@@ -18,7 +18,7 @@
<span class="brand"><img src="/static/img/mark.svg" alt=""><span>rotaty<b>vote</b></span></span> <span class="brand"><img src="/static/img/mark.svg" alt=""><span>rotaty<b>vote</b></span></span>
<div id="s-title" class="s-title"></div> <div id="s-title" class="s-title"></div>
<div class="s-tools"> <div class="s-tools">
<span id="conn" class="conn">connexion…</span> <span id="conn" class="conn" hidden></span>
<button id="fs" class="small" type="button">Plein écran</button> <button id="fs" class="small" type="button">Plein écran</button>
</div> </div>
</header> </header>
@@ -48,8 +48,7 @@
</main> </main>
<footer class="s-foot"> <footer class="s-foot">
<div class="s-count"><b id="voters">0</b> <span id="voters-label">appareils inscrits</span></div> <div class="s-count"><b id="voters">0</b> <span id="voters-label">inscriptions</span></div>
<div id="enroll-badge" class="badge"></div>
</footer> </footer>
</body> </body>
</html> </html>
+1 -1
View File
@@ -50,7 +50,7 @@
</section> </section>
<section id="v-vote" hidden> <section id="v-vote" hidden>
<p class="enrolled-chip"><span class="badge open">Inscrit</span></p> <p class="enrolled-chip"><span class="badge open">Inscription validée</span></p>
<div id="questions"></div> <div id="questions"></div>
<p id="waiting" class="waiting muted">En attente d'une question…</p> <p id="waiting" class="waiting muted">En attente d'une question…</p>
</section> </section>