Camera app scan: the first scan only opens the page, joining takes the ring or a second scan read within 4 s of the qr leaving the screen (votes keep 12 s); organizers can turn it off; open vote options and turnout bar stay above the big qr; native scan noted under the check
This commit is contained in:
@@ -80,6 +80,9 @@ function renderSettings(p) {
|
||||
if (active !== $("#s-code-style")) $("#s-code-style").value = p.code_style;
|
||||
if (active !== $("#s-entry-big")) $("#s-entry-big").value = p.entry_big ? "1" : "0";
|
||||
$("#s-entry-big").disabled = p.code_style !== "ring";
|
||||
if (active !== $("#s-camera")) $("#s-camera").value = p.camera_pass ? "1" : "0";
|
||||
// the classic qr is the camera app code itself
|
||||
$("#s-camera").disabled = p.code_style !== "ring";
|
||||
$("#s-code").checked = p.require_code;
|
||||
$("#access-row").hidden = !p.require_code && !state.codes.access.total;
|
||||
const sum = (c, none) => (c.total ? `${c.used} utilisé${c.used > 1 ? "s" : ""} sur ${c.total}` : none);
|
||||
@@ -239,6 +242,7 @@ const SETTINGS = {
|
||||
"#s-vote-scans": (el) => ({ vote_scans: +el.value }),
|
||||
"#s-code-style": (el) => ({ code_style: el.value }),
|
||||
"#s-entry-big": (el) => ({ entry_big: el.value === "1" }),
|
||||
"#s-camera": (el) => ({ camera_pass: el.value === "1" }),
|
||||
};
|
||||
for (const [sel, build] of Object.entries(SETTINGS)) {
|
||||
$(sel).addEventListener("change", async (e) => {
|
||||
|
||||
@@ -4,6 +4,8 @@ const cfg = await api("GET", "/api/config").catch(() => ({}));
|
||||
$("#pw-box").hidden = !cfg.create_password;
|
||||
|
||||
$("#codes-on").addEventListener("change", (e) => { $("#codes-box").hidden = !e.target.checked; });
|
||||
// the classic qr is the camera app code itself
|
||||
$("#code-style").addEventListener("change", (e) => { $("#camera").disabled = e.target.value !== "ring"; });
|
||||
|
||||
$("#form").addEventListener("submit", async (e) => {
|
||||
e.preventDefault();
|
||||
@@ -15,6 +17,7 @@ $("#form").addEventListener("submit", async (e) => {
|
||||
interval_ms: +$("#interval").value,
|
||||
scans_required: +$("#scans").value,
|
||||
code_style: $("#code-style").value,
|
||||
camera_pass: $("#camera").value === "1",
|
||||
expected: $("#expected").value ? +$("#expected").value : null,
|
||||
max_voters: $("#maxv").value ? +$("#maxv").value : null,
|
||||
require_code: $("#codes-on").checked,
|
||||
|
||||
+15
-7
@@ -53,11 +53,12 @@ function layout() {
|
||||
const qrOn = st.enrollment_open || st.presence;
|
||||
const ring = st.code_style === "ring";
|
||||
// the camera app code: enrolls, and proves presence for a vote, so it stays up whenever the ring does
|
||||
const entryOn = !!(ring && qrOn && entry);
|
||||
const cam = st.camera_pass !== false;
|
||||
const entryOn = !!(ring && entry && (st.enrollment_open || (cam && st.presence)));
|
||||
// with the big qr on, a vote waiting for scans (or closed with nothing to show) moves above it
|
||||
const f = st.focus, idleVote = f && f.state === "closed" && !f.results;
|
||||
// an upright screen has no room for the question above the qr (.entry-q hidden): it keeps its own block
|
||||
const openVote = f && f.state === "open" && st.presence && !matchMedia("(max-aspect-ratio: 1/1)").matches;
|
||||
const openVote = cam && f && f.state === "open" && st.presence && !matchMedia("(max-aspect-ratio: 1/1)").matches;
|
||||
const big = entryOn && st.entry_big && (!f || idleVote || openVote);
|
||||
const focus = big ? null : f;
|
||||
reveal($("#enroll"), qrOn);
|
||||
@@ -68,7 +69,7 @@ function layout() {
|
||||
// a vote waiting for presence scans takes the title, even while late arrivals can still enroll
|
||||
$("#qr-title").textContent = st.presence || !st.enrollment_open ? (ring ? "Visez le cercle pour voter" : "Scannez pour voter") : "Inscription";
|
||||
$("#qr-steps").hidden = !st.enrollment_open;
|
||||
$("#step1").textContent = ring ? "Scannez le QR avec l'appareil photo" : "Scannez avec l'appareil photo";
|
||||
$("#step1").textContent = ring ? (cam ? "Scannez le QR avec l'appareil photo" : "Ouvrez la page de vote") : "Scannez avec l'appareil photo";
|
||||
$("#step2").hidden = !ring;
|
||||
reveal($("#entry"), entryOn);
|
||||
document.body.classList.toggle("has-entry", entryOn);
|
||||
@@ -76,16 +77,23 @@ function layout() {
|
||||
const showQ = big && !!f;
|
||||
document.body.classList.toggle("entry-q-on", showQ);
|
||||
$("#entry-q").hidden = !showQ;
|
||||
// an open vote keeps its options and turnout bar on screen, just above the qr
|
||||
const opts = showQ && !!openVote;
|
||||
document.body.classList.toggle("entry-opts-on", opts);
|
||||
$("#entry-q-opts").hidden = !opts;
|
||||
$("#entry-q-turnout").hidden = !opts;
|
||||
$("#entry-q-count").hidden = opts;
|
||||
if (showQ) {
|
||||
$("#entry-q-text").textContent = f.text;
|
||||
if (openVote) {
|
||||
const all = f.participants + (f.extra_ballots || 0);
|
||||
$("#entry-q-count").textContent = `${all} vote${all > 1 ? "s" : ""} sur ${st.voters + (f.extra_ballots || 0)}`;
|
||||
if (opts) {
|
||||
const ul = $("#entry-q-opts"), key = JSON.stringify(f.options);
|
||||
if (ul.dataset.key !== key) { ul.dataset.key = key; ul.replaceChildren(...f.options.map((o) => h("li", {}, o))); }
|
||||
paintTurnout($("#entry-q-turnout"), f);
|
||||
} else {
|
||||
$("#entry-q-count").textContent = `Vote clos, ${f.participants} bulletin${f.participants > 1 ? "s" : ""}`;
|
||||
}
|
||||
}
|
||||
$("#entry-hint").textContent = "Scannez avec l'appareil photo";
|
||||
$("#entry-hint").textContent = cam ? "Scannez avec l'appareil photo" : big ? "Scannez ici, puis visez le cercle" : "Pas encore sur la page ?";
|
||||
$(".qr-wrap").classList.toggle("ring", ring);
|
||||
flip(entryEl, before);
|
||||
}
|
||||
|
||||
+39
-19
@@ -6,6 +6,8 @@ const DONE_KEY = `rv_done_${pid}`;
|
||||
const apiBase = `/api/v/${pid}`;
|
||||
|
||||
const PENDING_KEY = `rv_pending_${pid}`;
|
||||
const ARRIVED_KEY = `rv_arrived_${pid}`;
|
||||
const VIA_QR = "Avec la caméra native, via le QR";
|
||||
|
||||
// the camera app redirect leaves a one-time claim (or why there is none) in the hash. off the url bar at once
|
||||
const hash = new URLSearchParams(location.hash.slice(1));
|
||||
@@ -14,6 +16,7 @@ if (location.hash) history.replaceState(null, "", location.pathname);
|
||||
// a camera app scan covers votes for a few seconds (server PASS_HOLD_MS, minus the round trip)
|
||||
let passUntil = 0;
|
||||
let presenceFor = null;
|
||||
let camPass = true; // organizers can turn the camera app way off
|
||||
|
||||
let scanner = null;
|
||||
let required = 5;
|
||||
@@ -59,17 +62,20 @@ function scanMsg(text, kind = "") {
|
||||
// the camera app way: a quiet line under a working scanner, step by step without one.
|
||||
// people are already on the page, so it has to say why they leave it and what happens after
|
||||
function camAlt(el, solo, vote = false) {
|
||||
el.hidden = !camPass;
|
||||
el.classList.toggle("solo", solo);
|
||||
if (!solo) {
|
||||
el.replaceChildren(icon("camera", 18), h("span", {}, "Ça ne marche pas ? Scannez le grand QR de l'écran avec l'appareil photo."));
|
||||
el.replaceChildren(icon("camera", 18), h("span", {}, "Ça ne marche pas ? Rouvrez votre scanneur de code QR et scannez le grand QR."));
|
||||
return;
|
||||
}
|
||||
// "re-open": the same scanner that brought them here, not something new to find
|
||||
// the vote dialog has the heading in its own title
|
||||
el.replaceChildren(icon("camera", 36), vote ? "" : h("b", {}, "Inscrivez-vous avec l'appareil photo"),
|
||||
el.replaceChildren(icon("camera", 36), vote ? "" : h("b", {}, "Confirmez avec votre scanneur de code QR"),
|
||||
h("ol", {},
|
||||
h("li", {}, "Quittez cette page et ouvrez l'appareil photo du téléphone."),
|
||||
h("li", {}, "Rouvrez votre scanneur de code QR, celui qui vous a amené·e ici."),
|
||||
h("li", {}, "Scannez le grand QR de l'écran."),
|
||||
h("li", {}, vote ? "Touchez le lien qui s'affiche. Votre vote part tout seul." : "Touchez le lien qui s'affiche. Vous êtes inscrit·e.")));
|
||||
// joining only takes a code that left the screen less than 4 s ago
|
||||
h("li", {}, vote ? "Touchez le lien qui s'affiche. Votre vote part tout seul." : "Touchez tout de suite le lien qui s'affiche. Vous êtes inscrit·e.")));
|
||||
}
|
||||
|
||||
async function startScanner() {
|
||||
@@ -302,7 +308,7 @@ async function afterPass(r) {
|
||||
switch (r.status) {
|
||||
case "enrolled":
|
||||
passUntil = Date.now() + 8000;
|
||||
enrolled();
|
||||
enrolled(true);
|
||||
break;
|
||||
case "pass": {
|
||||
passUntil = Date.now() + (r.hold_ms || 10000) - 1500;
|
||||
@@ -325,6 +331,9 @@ async function afterPass(r) {
|
||||
case "expired":
|
||||
toast("QR expiré, scannez-le à nouveau.", "bad");
|
||||
break;
|
||||
case "late":
|
||||
toast("Lien ouvert trop tard. Rescannez et touchez le lien tout de suite.", "bad");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,17 +376,17 @@ function handleScan(r) {
|
||||
}
|
||||
}
|
||||
|
||||
function enrolled() {
|
||||
function enrolled(viaCam = false) {
|
||||
stopScanner();
|
||||
lsSet(DONE_KEY, "1");
|
||||
navigator.vibrate?.([40, 60, 40]);
|
||||
celebrate("Inscription validée");
|
||||
celebrate("Inscription validée", viaCam ? VIA_QR : "");
|
||||
boot();
|
||||
}
|
||||
|
||||
// the projector's center mark with its check, drawn in, held a moment, then gone
|
||||
const MARK_NS = "http://www.w3.org/2000/svg";
|
||||
function celebrate(text) {
|
||||
function celebrate(text, sub = "") {
|
||||
const svg = document.createElementNS(MARK_NS, "svg");
|
||||
svg.setAttribute("viewBox", "0 0 32 32");
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
@@ -393,10 +402,12 @@ function celebrate(text) {
|
||||
for (const [k, v] of Object.entries({ d: "M12.8 16.15l2.3 2.3 4.25-4.75", fill: "none", stroke: "currentColor", "stroke-width": 2.4,
|
||||
"stroke-linecap": "round", "stroke-linejoin": "round", pathLength: 1, class: "tick" })) tick.setAttribute(k, v);
|
||||
svg.append(g, tick);
|
||||
const el = h("div", { class: "celebrate", role: "status" }, svg, h("p", {}, text));
|
||||
const el = h("div", { class: "celebrate", role: "status" }, svg, h("p", {}, text), sub ? h("small", {}, sub) : "");
|
||||
document.body.append(el);
|
||||
setTimeout(() => el.classList.add("out"), 1300);
|
||||
setTimeout(() => el.remove(), 1700);
|
||||
// a second line takes longer to read
|
||||
const hold = sub ? 2000 : 1300;
|
||||
setTimeout(() => el.classList.add("out"), hold);
|
||||
setTimeout(() => el.remove(), hold + 400);
|
||||
}
|
||||
|
||||
$("#start-cam").addEventListener("click", startScanner);
|
||||
@@ -526,7 +537,7 @@ async function castVote(q, choices, retried = false) {
|
||||
let presence;
|
||||
if (lastState.vote_scans > 0 && Date.now() > passUntil) {
|
||||
// kept for the tab the camera app opens, which sends it on its own
|
||||
lsSet(PENDING_KEY, JSON.stringify({ qid: q.id, choices, at: Date.now() }));
|
||||
if (camPass) lsSet(PENDING_KEY, JSON.stringify({ qid: q.id, choices, at: Date.now() }));
|
||||
presence = await collectPresence(lastState.vote_scans, q.id);
|
||||
// cancelled (or voted from the other tab): a later scan must not cast a choice left behind
|
||||
if (!presence) {
|
||||
@@ -538,7 +549,8 @@ async function castVote(q, choices, retried = false) {
|
||||
await api("POST", `${apiBase}/vote`, { question_id: q.id, choices, presence });
|
||||
try { localStorage.removeItem(PENDING_KEY); } catch { /* private mode */ }
|
||||
selections.delete(q.id);
|
||||
celebrate("Vote enregistré");
|
||||
// no codes sent while some were due: the camera app scan covered it
|
||||
celebrate("Vote enregistré", !presence && lastState.vote_scans > 0 ? VIA_QR : "");
|
||||
navigator.vibrate?.(60);
|
||||
} catch (e) {
|
||||
// the camera app scan ran out on the server side: scan again
|
||||
@@ -600,9 +612,14 @@ function collectPresence(n, qid) {
|
||||
dlg.addEventListener("close", () => finish(null), { once: true });
|
||||
// no camera here: the camera app opens a new tab that sends the kept choice
|
||||
sc.start().catch((e) => {
|
||||
$("#p-title").textContent = "Validez avec l'appareil photo";
|
||||
$("#p-msg").textContent = camError(e);
|
||||
$("#p-scan").hidden = true;
|
||||
if (!camPass) {
|
||||
// no camera and no camera app way: the desk can still count this vote by hand (votes en plus)
|
||||
$("#p-msg").textContent = `${camError(e)} Sinon, signalez-vous à la tribune.`;
|
||||
return;
|
||||
}
|
||||
$("#p-title").textContent = "Validez avec votre scanneur de code QR";
|
||||
$("#p-msg").textContent = camError(e);
|
||||
camAlt($("#p-alt"), true, true);
|
||||
});
|
||||
return result;
|
||||
@@ -621,6 +638,7 @@ function connect() {
|
||||
lastJson = j;
|
||||
show("#v-vote");
|
||||
$("#title").textContent = msg.title;
|
||||
camPass = msg.camera_pass !== false;
|
||||
renderVote(msg);
|
||||
}
|
||||
else if (msg.type === "not_enrolled") { socket?.close(); socket = null; boot(); }
|
||||
@@ -645,6 +663,8 @@ async function boot() {
|
||||
}
|
||||
$("#title").textContent = me.title;
|
||||
document.title = me.title;
|
||||
camPass = me.camera_pass !== false;
|
||||
camAlt($("#enroll-alt"), $("#enroll-alt").classList.contains("solo"));
|
||||
if (me.enrolled) {
|
||||
lsSet(DONE_KEY, "1");
|
||||
show("#v-vote");
|
||||
@@ -665,12 +685,12 @@ async function boot() {
|
||||
}
|
||||
|
||||
async function start() {
|
||||
// the claim goes first: it may enroll this phone before the page asks who it is
|
||||
const r = claim ? await redeem({ claim }) : null;
|
||||
if (r?.status === "enrolled") { lsSet(DONE_KEY, "1"); celebrate("Inscription validée"); passUntil = Date.now() + 8000; }
|
||||
await boot();
|
||||
if (r && r.status !== "enrolled") afterPass(r);
|
||||
// the scan that brings someone here only opens the page: joining takes the ring, or a second scan
|
||||
const arrived = +lsGet(ARRIVED_KEY) > Date.now() - 3 * 3600e3;
|
||||
if (claim && (lastState || arrived)) afterPass(await redeem({ claim }));
|
||||
else if (camExpired) afterPass({ status: "expired" });
|
||||
if (!lastState) lsSet(ARRIVED_KEY, String(Date.now()));
|
||||
}
|
||||
|
||||
camAlt($("#enroll-alt"), false);
|
||||
|
||||
Reference in New Issue
Block a user