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:
@@ -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");
|
||||
|
||||
@@ -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(); });
|
||||
Reference in New Issue
Block a user