Merge pull request 'Add quiz slide type' (#6) from feature/quiz-slide into main
CI / Deploy / test (push) Successful in 46s
CI / Deploy / deploy (push) Successful in 5s

Reviewed-on: #6
This commit was merged in pull request #6.
This commit is contained in:
gnilebein committed 2026-11-07 14:40:24 +01:00
commit 50010484be
18 files changed
+999 -43

No files matched your search

+52
View File
@@ -145,6 +145,7 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
.badge--type-open { background: #dcf5f0; color: #0b7766; }
.badge--type-scale { background: #fdeed8; color: #9a5a00; }
.badge--type-content { background: #e3eefb; color: #1f6bb0; }
.badge--type-quiz { background: #f1e3fb; color: #7a2fb0; }
.message { padding: 12px 16px; border-radius: 8px; margin-bottom: 20px; cursor: pointer; background: var(--surface-2); border-left: 4px solid var(--muted); }
.message.success { border-color: var(--ok); }
@@ -209,6 +210,18 @@ textarea { resize: vertical; }
.type-card--open { border-top-color: var(--c2); }
.type-card--scale { border-top-color: var(--c3); }
.type-card--content { border-top-color: var(--c4); }
.type-card--quiz { border-top-color: var(--c5); }
/* ---------------------------------------------------------------- slide form: quiz answers */
.quiz-options { border: 0; padding: 0; margin: 0 0 16px; }
.quiz-options legend { font-weight: 600; margin-bottom: 4px; }
.quiz-options__list { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 8px; }
.quiz-option { display: flex; gap: 10px; align-items: center; }
.quiz-option input[type=text] { flex: 1; margin: 0; }
.quiz-option__correct { display: inline-flex; gap: 6px; align-items: center; white-space: nowrap; padding: 8px 10px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; font-weight: 600; }
.quiz-option__correct:has(input:checked) { border-color: var(--ok); color: var(--ok); }
.quiz-option__correct input { width: 18px; height: 18px; margin: 0; accent-color: var(--ok); }
.quiz-options.error .quiz-options__list input[type=text] { border-color: var(--danger); }
.join-code { font-size: 2rem; font-weight: 800; letter-spacing: .12em; text-align: center; margin: 0 0 12px; }
.qr { display: block; margin: 0 auto 16px; background: #fff; border-radius: 8px; padding: 6px; }
@@ -249,6 +262,21 @@ textarea { resize: vertical; }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 rgba(75, 63, 224, .5); } 100% { box-shadow: 0 0 0 24px rgba(75, 63, 224, 0); } }
.prose { font-size: 1.1rem; }
/* quiz (participant) */
.choice--quiz { border-left-width: 8px; border-left-color: var(--c0); font-size: 1.1rem; }
.choice--c1 { border-left-color: var(--c1); }
.choice--c2 { border-left-color: var(--c2); }
.choice--c3 { border-left-color: var(--c3); }
.choice--c4 { border-left-color: var(--c4); }
.choice--c5 { border-left-color: var(--c5); }
.choices--quiz { border: 0; padding: 0; }
.countdown { display: flex; align-items: baseline; justify-content: center; gap: 8px; margin: 8px 0 0; color: var(--muted); }
.countdown__value { font-size: 2rem; font-variant-numeric: tabular-nums; color: var(--text); }
.countdown.is-urgent .countdown__value { color: var(--danger); }
.verdict { font-size: 1.6rem; font-weight: 800; margin: 12px 0 0; }
.verdict--correct { color: var(--ok); }
.verdict--wrong { color: var(--danger); }
/* ---------------------------------------------------------------- results (shared) */
.results-empty { color: var(--muted); font-style: italic; }
.is-hidden { visibility: hidden; }
@@ -306,6 +334,25 @@ textarea { resize: vertical; }
.cloud__word.is-mine .cloud__vote--up, .cloud__word.is-down .cloud__vote--down { background: var(--surface-2); }
.cloud__word.is-down .cloud__vote--up { opacity: .55; }
/* quiz results */
.quiz-status { color: var(--muted); font-style: italic; margin: 0 0 1em; }
.quiz-timer { margin: 0 0 .6em; font-size: 2.6em; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--c5); }
.quiz-timer.is-urgent { color: var(--danger); }
.quiz-timer.is-over { opacity: .5; }
.quiz-grid { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: 12px; }
.quiz-tile { padding: .8em 1em; border-radius: 10px; background: var(--surface-2); border-left: .4em solid var(--c0); font-weight: 700; word-break: break-word; }
.quiz-tile--c1 { border-left-color: var(--c1); }
.quiz-tile--c2 { border-left-color: var(--c2); }
.quiz-tile--c3 { border-left-color: var(--c3); }
.quiz-tile--c4 { border-left-color: var(--c4); }
.quiz-tile--c5 { border-left-color: var(--c5); }
.quiz-summary { margin: 0 0 1em; font-size: 1.2em; }
.quiz-summary strong { color: var(--ok); }
.bar--correct .bar__fill { background: var(--ok); }
.bar--correct .bar__label { color: var(--ok); }
.bar--wrong .bar__fill { background: var(--muted); opacity: .6; }
.bar.is-mine .bar__label { text-decoration: underline; text-underline-offset: 3px; }
.answers { list-style: none; padding: 0; margin: 0; columns: 280px; column-gap: 12px; }
.answer { break-inside: avoid; background: var(--surface-2); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; word-break: break-word; }
@@ -341,6 +388,11 @@ body.present {
.stage .average__track { height: 1em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
.stage .answers { columns: 340px; }
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
.stage .quiz-tile { font-size: clamp(1.2rem, 2.2vw, 2rem); }
/* brighter green for contrast on the dark stage */
.stage .quiz-summary strong, .stage .bar--correct .bar__label { color: #3ddc97; }
.stage .bar--correct .bar__fill { background: #3ddc97; }
.stage__controls { display: flex; gap: 8px; align-items: center; justify-content: center; flex-wrap: wrap; opacity: .35; transition: opacity .2s; padding-top: 12px; }
.stage__controls:hover, .stage__controls:focus-within { opacity: 1; }
+160 -7
View File
@@ -5,6 +5,8 @@
* - [data-copy] copy the value of the sibling [data-copy-source]
* - [data-presenter] presenter screen, polls /admin/{token}/state
* - [data-participant] participant page, polls /p/{code}/state
* - [data-countdown] quiz timer (data-remaining = seconds), fires `plenario:timeup` on document
* - [data-quiz-options] slide form: "add answer" button for quiz slides
*
* Results JSON shape: see src/Service/ResultsService.php
*/
@@ -95,6 +97,49 @@
return Number(value).toLocaleString('de-DE');
}
function formatSeconds(seconds) {
var s = Math.max(0, Math.ceil(seconds));
return Math.floor(s / 60) + ':' + String(s % 60).padStart(2, '0');
}
// ------------------------------------------------------------------ countdown
/**
* Ticks every [data-countdown] element (data-remaining = seconds left when it
* was rendered). The server stays authoritative: when a timer reaches zero,
* `plenario:timeup` is dispatched so the page fetches the new state.
*/
var Countdown = {
timer: null,
start: function () {
if (Countdown.timer === null) {
Countdown.timer = setInterval(Countdown.tick, 250);
}
Countdown.tick();
},
tick: function () {
document.querySelectorAll('[data-countdown]').forEach(function (node) {
if (!node.plenarioDeadline) {
node.plenarioDeadline = Date.now() + parseFloat(node.getAttribute('data-remaining')) * 1000;
}
var left = (node.plenarioDeadline - Date.now()) / 1000;
var value = node.querySelector('[data-countdown-value]') || node;
var text = formatSeconds(left);
if (value.textContent !== text) {
value.textContent = text;
}
node.classList.toggle('is-urgent', left <= 5);
if (left <= 0 && !node.plenarioDone) {
node.plenarioDone = true;
node.classList.add('is-over');
document.dispatchEvent(new CustomEvent('plenario:timeup'));
}
});
}
};
// ------------------------------------------------------------------ word matching
/**
@@ -247,7 +292,8 @@
if (typeof renderer !== 'function') {
return;
}
if (results.participants === 0) {
// A quiz shows its answer options even before anyone has answered.
if (results.participants === 0 && !(results.type === 'quiz' && !results.revealed)) {
container.appendChild(el('p', { class: 'results-empty', text: 'Noch keine Antworten' }));
return;
}
@@ -394,6 +440,53 @@
}));
},
/**
* Before the end only the answer options (and the timer) are shown;
* counts and correct answers arrive with `revealed` (see ResultsService).
* options: {answerId: id of the participant's own answer|null}
*/
quiz: function (results, options) {
var answerId = options && options.answerId;
if (!results.revealed) {
var children = [];
if (results.phase === 'running' && results.remaining !== null) {
children.push(el('p', {
class: 'quiz-timer',
role: 'timer',
'data-countdown': '',
'data-remaining': String(results.remaining)
}, [el('strong', { 'data-countdown-value': '', text: formatSeconds(results.remaining) })]));
} else if (results.phase === 'running') {
children.push(el('p', { class: 'quiz-status', text: 'Quiz läuft – ohne Zeitlimit' }));
} else {
children.push(el('p', { class: 'quiz-status', text: 'Bereit – starte das Quiz, um die Antworten freizugeben' }));
}
children.push(el('ol', { class: 'quiz-grid' }, results.options.map(function (option, index) {
return el('li', { class: 'quiz-tile quiz-tile--c' + (index % 6), text: option.label });
})));
return el('div', { class: 'quiz-results quiz-results--' + results.phase }, children);
}
var max = Math.max.apply(null, results.options.map(function (o) { return o.count; }).concat([1]));
var percent = results.participants > 0 ? Math.round(results.correctCount / results.participants * 100) : 0;
var summary = el('p', { class: 'quiz-summary' }, [
el('strong', { text: results.correctCount + ' von ' + results.participants }),
el('span', { text: ' richtig (' + percent + ' %)' })
]);
var bars = el('div', { class: 'bars' }, results.options.map(function (option) {
var mine = answerId !== null && answerId !== undefined && option.id === answerId;
var label = (option.correct ? '✓ ' : '') + option.label + (mine ? ' (deine Antwort)' : '');
return el('div', { class: 'bar ' + (option.correct ? 'bar--correct' : 'bar--wrong') + (mine ? ' is-mine' : '') }, [
el('div', { class: 'bar__label', text: label }),
el('div', { class: 'bar__track' }, [
el('div', { class: 'bar__fill', style: 'width:' + (option.count / max * 100) + '%' })
]),
el('div', { class: 'bar__value', text: formatNumber(option.percent) + ' % (' + option.count + ')' })
]);
}));
return el('div', { class: 'quiz-results quiz-results--finished' }, [summary, bars]);
},
open: function (results) {
return el('ul', { class: 'answers' }, results.answers.map(function (answer) {
return el('li', { class: 'answer', text: answer.text });
@@ -467,15 +560,20 @@
return;
}
q('[data-type]').textContent = slide.typeLabel;
var quizPhase = slide.type === 'quiz' && state.results ? state.results.phase : null;
q('[data-type]').textContent = quizPhase
? slide.typeLabel + ' · ' + { ready: 'bereit', running: 'läuft', finished: 'Auflösung' }[quizPhase]
: slide.typeLabel;
q('[data-question]').textContent = slide.question;
q('[data-description]').textContent = slide.description;
root.classList.toggle('stage--content', !slide.isInteractive);
root.classList.toggle('stage--closed', slide.isInteractive && !slide.isVotingOpen);
root.classList.toggle('stage--closed', slide.isInteractive && !slide.isVotingOpen && !quizPhase);
var voting = q('[data-voting]');
voting.hidden = !slide.isInteractive;
voting.textContent = slide.isVotingOpen ? 'Abstimmung schließen' : 'Abstimmung öffnen';
voting.textContent = quizPhase
? { ready: 'Quiz starten', running: 'Quiz beenden', finished: 'Quiz erneut öffnen' }[quizPhase]
: (slide.isVotingOpen ? 'Abstimmung schließen' : 'Abstimmung öffnen');
q('[data-participants]').textContent = slide.isInteractive
? state.results.participants + ' ' + (state.results.participants === 1 ? 'Antwort' : 'Antworten')
@@ -484,6 +582,7 @@
var container = q('[data-results]');
container.classList.toggle('is-hidden', hideResults);
Results.render(container, slide.isInteractive ? state.results : null);
Countdown.start();
}
function refresh() {
@@ -564,7 +663,11 @@
}
});
poll(refresh, interval);
var poller = poll(refresh, interval);
document.addEventListener('plenario:timeup', function () {
// The server closes the quiz once the deadline has passed.
setTimeout(poller.now, 300);
});
}
// ------------------------------------------------------------------ participant
@@ -604,6 +707,7 @@
Results.render(container, state.results, {
mine: state.words ? state.words.mine : [],
down: state.words ? state.words.down : [],
answerId: state.quiz ? state.quiz.answerId : null,
onUpvote: upvote ? function (word) { sendWord(word.text); } : null,
onDownvote: upvote && state.words.allowDownvotes ? function (word) { sendWord(word.text, 'down'); } : null
});
@@ -759,7 +863,16 @@
} catch (e) { /* ignore */ }
}
poll(function () {
var quizForm = root.querySelector('[data-quiz-form]');
document.addEventListener('plenario:timeup', function () {
if (quizForm) {
quizForm.querySelectorAll('input, button').forEach(function (input) { input.disabled = true; });
}
setTimeout(participantPoller.now, 300);
});
Countdown.start();
var participantPoller = poll(function () {
return getJson(stateUrl).then(function (state) {
if (state.version !== version) {
// Do not destroy what the participant is typing right now.
@@ -775,12 +888,52 @@
}, interval);
}
// ------------------------------------------------------------------ slide form
/** Quiz slide form: add further answer rows (the server renders a few already). */
function initQuizOptions(fieldset) {
var list = fieldset.querySelector('[data-quiz-list]');
var button = fieldset.querySelector('[data-quiz-add]');
var max = parseInt(fieldset.getAttribute('data-max'), 10) || 10;
function rows() {
return list.querySelectorAll('[data-quiz-row]');
}
function update() {
button.hidden = rows().length >= max;
}
button.addEventListener('click', function () {
var index = rows().length;
if (index >= max) {
return;
}
var row = rows()[0].cloneNode(true);
var label = row.querySelector('label[for]');
var text = row.querySelector('input[type=text]');
var check = row.querySelector('input[type=checkbox]');
var id = 'quiz-option-' + index;
label.setAttribute('for', id);
label.textContent = 'Antwort ' + (index + 1);
text.id = id;
text.name = 'quiz_options[' + index + '][label]';
text.value = '';
text.placeholder = 'Antwort ' + (index + 1);
text.required = false;
check.name = 'quiz_options[' + index + '][correct]';
check.checked = false;
list.appendChild(row);
text.focus();
update();
});
update();
}
// ------------------------------------------------------------------ boot
document.addEventListener('DOMContentLoaded', function () {
initCopy();
document.querySelectorAll('[data-presenter]').forEach(initPresenter);
document.querySelectorAll('[data-participant]').forEach(initParticipant);
document.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions);
// Prevent double submits of vote forms.
document.querySelectorAll('.vote-form').forEach(function (form) {
@@ -796,5 +949,5 @@
});
});
window.Plenario = { Results: Results, Words: Words };
window.Plenario = { Results: Results, Words: Words, Countdown: Countdown };
})();