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
+100 -76
View File
@@ -6,99 +6,123 @@
<title>RotatyVote · Administration</title>
<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/admin.css">
<script type="module" src="/static/js/admin.js"></script>
</head>
<body>
<main class="wrap">
<div class="topbar 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>
<div class="actions">
<span id="conn" class="conn">connexion…</span>
<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>
<main class="wrap admin-wrap">
<header class="a-head no-print">
<a class="brand" href="/"><img src="/static/img/mark.svg" alt=""><span>rotaty<b>vote</b></span></a>
<span id="conn" class="conn" hidden></span>
</header>
<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>
<aside class="no-print">
<section class="card">
<h2>Inscriptions</h2>
<div class="stat"><b id="voters">0</b><span id="voters-of" class="muted">inscrits</span></div>
<div id="enroll-state" class="notice"></div>
<button id="toggle-enroll" class="block" type="button"></button>
<p id="screens" class="hint"></p>
</section>
<div id="app" hidden>
<section class="summary no-print">
<h1 id="title">…</h1>
<div class="summary-row">
<div class="count-chip"><b id="voters">0</b><span id="voters-of">inscriptions</span></div>
<button id="toggle-enroll" type="button"></button>
<a id="open-screen" class="btn" target="_blank" rel="noopener"><span id="screen-icon"></span>Projecteur</a>
</div>
<p id="over" class="notice bad" hidden></p>
</section>
<section class="card">
<h2>Réglages</h2>
<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><label for="s-scans">Codes requis</label><input id="s-scans" type="number" min="2" max="20"></div>
</div>
<div class="row">
<div><label for="s-expected">Attendus</label><input id="s-expected" type="number" min="0" placeholder="—"></div>
<div><label for="s-max">Plafond</label><input id="s-max" type="number" min="0" placeholder="aucun"></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>
<nav class="tabs no-print" role="tablist">
<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 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 class="actions"><button id="codes-print" class="small" type="button">Afficher / imprimer</button></div>
</section>
<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 class="card">
<h2>Lien projecteur</h2>
<div class="linkbox"><input id="screen-link" type="text" readonly placeholder="—"><button id="screen-rotate" class="small" type="button">Nouveau</button></div>
</section>
</aside>
<div>
<section class="card no-print">
<h2>Nouvelle question</h2>
<div class="templates" id="templates"></div>
<label for="q-text">Question</label>
<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>
<textarea id="q-opts" placeholder="Pour&#10;Contre"></textarea>
<section data-panel="enroll" class="no-print" hidden>
<div class="card">
<div class="row">
<div>
<label for="q-kind">Type</label>
<select id="q-kind"><option value="single">Choix unique</option><option value="multi">Choix multiple</option></select>
<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 id="q-max-box" hidden>
<label for="q-max">Choix maximum</label>
<input id="q-max" type="number" min="1" value="2">
<div><label for="s-scans">Codes à scanner</label><input id="s-scans" type="number" min="2" max="20"></div>
</div>
<div class="row">
<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>
</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>
<label class="inline"><input id="q-blank" type="checkbox" checked> Autoriser le vote blanc</label>
<div class="actions">
<button id="q-draft" type="button">Préparer (brouillon)</button>
<button id="q-push" class="go" type="button">Lancer le vote maintenant</button>
</div>
</section>
<section data-panel="share" class="no-print" hidden>
<div class="card share-list">
<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>
</section>
<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 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>
<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>
</main>
<dialog id="composer">
<form method="dialog" id="q-form">
<h2>Nouvelle question</h2>
<div class="templates" id="templates"></div>
<label for="q-text">Question</label>
<input id="q-text" type="text" maxlength="500" placeholder="Approuvez-vous le rapport moral ?">
<label for="q-opts">Réponses, une par ligne</label>
<textarea id="q-opts" placeholder="Pour&#10;Contre"></textarea>
<div class="row">
<div>
<label for="q-kind">Type</label>
<select id="q-kind"><option value="single">Choix unique</option><option value="multi">Choix multiple</option></select>
</div>
<div id="q-max-box" hidden>
<label for="q-max">Choix maximum</label>
<input id="q-max" type="number" min="1" value="2">
</div>
</div>
<label class="inline"><input id="q-blank" type="checkbox"> Autoriser le vote blanc</label>
<div class="actions">
<button value="cancel" type="submit" formnovalidate>Annuler</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>
</form>
</dialog>
</body>
</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);
}
.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; }
+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); }
.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); }
+1 -1
View File
@@ -37,7 +37,7 @@
<div class="row">
<div>
<label for="expected">Participants attendus</label>
<label for="expected">Personnes attendues</label>
<input id="expected" type="number" min="1" placeholder="facultatif">
</div>
<div>
+142 -119
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 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…";
},
});
+18
View File
@@ -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");
+5 -7
View File
@@ -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); }
},
});
+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 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;
+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>
<div id="s-title" class="s-title"></div>
<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>
</div>
</header>
@@ -48,8 +48,7 @@
</main>
<footer class="s-foot">
<div class="s-count"><b id="voters">0</b> <span id="voters-label">appareils inscrits</span></div>
<div id="enroll-badge" class="badge"></div>
<div class="s-count"><b id="voters">0</b> <span id="voters-label">inscriptions</span></div>
</footer>
</body>
</html>
+1 -1
View File
@@ -50,7 +50,7 @@
</section>
<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>
<p id="waiting" class="waiting muted">En attente d'une question…</p>
</section>