Results share link: read-only /r page with a revocable key, the admin ticks which closed questions it shows (sharing locks reopen like publish), refreshes every 15 s

This commit is contained in:
2026-11-19 01:11:05 +01:00
parent 41b4ac1a78
commit 98d8199ffd
7 changed files with 146 additions and 4 deletions
+8
View File
@@ -133,8 +133,16 @@
</div>
</div>
</div>
<div class="card share-list" id="share-card">
<div class="share-row">
<div><b>Lien des résultats</b><span class="muted" id="share-summary"></span></div>
<div class="code-actions" id="share-actions"></div>
</div>
<div id="share-qs"></div>
</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>
+6
View File
@@ -79,3 +79,9 @@
font: .82rem/1.5 ui-monospace, "SF Mono", Menlo, Consolas, monospace; white-space: pre; tab-size: 4;
}
#ex-preview.empty { white-space: normal; color: var(--ink-3); font-family: var(--sans); text-align: center; padding: 32px 16px; }
#share-qs { border-top: 1.5px solid var(--bg); padding: 6px 0 10px; }
#share-qs:empty { display: none; }
.share-q { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-weight: 500; cursor: pointer; }
.share-q input { margin-top: 3px; flex: none; }
.share-none { margin: 8px 0; font-size: .85rem; }
+43
View File
@@ -65,6 +65,7 @@ function render() {
renderSettings(p);
renderQuestions();
renderShare(p);
}
function renderSettings(p) {
@@ -134,6 +135,7 @@ function 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" }, "Publiés"));
if (q.shared && state.poll.share_key) badges.push(h("span", { class: "badge public" }, "Partagé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`));
@@ -306,6 +308,47 @@ $("#export").addEventListener("click", async () => {
} catch (e) { toast(errMsg(e), "bad"); }
});
// read-only results link, the admin ticks which closed questions it shows
const shareUrl = (k) => `${location.origin}/r/${pid}#${k}`;
function renderShare(p) {
const btn = (label, onclick, cls = "small") => h("button", { class: cls, type: "button", onclick }, label);
const rotate = async (msg) => {
if (msg && !confirm(msg)) return;
try { const r = await call("POST", "/share-key"); await copy(shareUrl(r.share_key), "Lien des résultats"); }
catch (e) { toast(errMsg(e), "bad"); }
};
const off = async () => {
if (!confirm("Désactiver le lien des résultats ?")) return;
try { await call("DELETE", "/share-key"); } catch (e) { toast(errMsg(e), "bad"); }
};
const closed = state.questions.filter((q) => q.state === "closed").sort((a, b) => a.id - b.id);
const n = closed.filter((q) => q.shared).length;
$("#share-summary").textContent = p.share_key ? `${n} question${n > 1 ? "s" : ""} visible${n > 1 ? "s" : ""}` : "Lecture seule";
$("#share-actions").replaceChildren(...(p.share_key
? [btn("Copier", () => copy(shareUrl(p.share_key), "Lien des résultats")),
btn("Nouveau lien", () => rotate("Créer un nouveau lien ? L'ancien cessera de fonctionner.")),
btn("Désactiver", off, "small danger")]
: [btn("Créer", () => rotate())]));
if (!p.share_key) return $("#share-qs").replaceChildren();
$("#share-qs").replaceChildren(...(closed.length
? closed.map((q) => h("label", { class: "share-q" },
h("input", {
type: "checkbox", checked: q.shared,
onchange: async (e) => {
const on = e.target.checked;
if (on && !q.shown && !confirm("Partager ces résultats ? Le vote ne pourra plus être rouvert.")) {
e.target.checked = false;
return;
}
try { await call("POST", `/questions/${q.id}/${on ? "share" : "unshare"}`); }
catch (err) { e.target.checked = !on; toast(errMsg(err), "bad"); }
},
}), h("span", {}, q.text)))
: [h("p", { class: "muted share-none" }, "Aucune question close.")]));
}
// text export, built in the browser from the closed tallies the socket already sends
const exDlg = $("#export-dlg");
+27
View File
@@ -0,0 +1,27 @@
import { $, h, api, pollId, hashKey, resultsView } from "./common.js";
const pid = pollId();
// the key stays in the address bar so the link can be passed on as is
const key = hashKey();
async function load() {
let data;
try { data = await api("GET", `/api/r/${pid}`, undefined, key); }
catch {
$("#denied").hidden = false;
$("#list").replaceChildren();
return;
}
$("#denied").hidden = true;
$("#title").textContent = data.title;
document.title = `Résultats · ${data.title}`;
const qs = data.questions.sort((a, b) => a.id - b.id);
$("#list").replaceChildren(...(qs.length
? qs.map((q) => h("article", { class: "q" }, h("div", { class: "q-text" }, q.text), resultsView(q)))
: [h("p", { class: "muted" }, "Aucun résultat pour l'instant.")]));
}
load();
// questions get added as the meeting goes on
setInterval(() => { if (!document.hidden) load(); }, 15000);
document.addEventListener("visibilitychange", () => { if (!document.hidden) load(); });
+21
View File
@@ -0,0 +1,21 @@
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>RotatyVote · Résultats</title>
<link rel="icon" href="/static/img/mark.svg" type="image/svg+xml">
<link rel="stylesheet" href="/static/css/app.css">
<script type="module" src="/static/js/results.js"></script>
</head>
<body>
<main class="wrap narrow results-page">
<div class="topbar">
<span class="brand"><img src="/static/img/mark.svg" alt=""><span>rotaty<b>vote</b></span></span>
</div>
<h1 id="title">Résultats</h1>
<p id="denied" class="notice bad" hidden>Lien invalide ou désactivé.</p>
<div id="list"></div>
</main>
</body>
</html>