From bd57f23be6f122a32f71554a3cd7c30f04bdc903 Mon Sep 17 00:00:00 2001
From: Patrick Niebeling
Date: Fri, 20 Nov 2026 10:57:33 +0100
Subject: [PATCH] Add admin menu drawer and poll cloning, drop participant
screen tools
- Remove fullscreen and wake lock buttons from the participant view.
- Turn the admin sidebar into a drawer below 900px, opened from a header
menu button next to the theme switch (progressive enhancement).
- Add "Umfrage kopieren": clone a poll with all slides, options and images
but without responses, with its own join code and admin link.
Co-Authored-By: Claude Sonnet 5.5
---
AGENTS.md | 2 +-
config/routes.php | 2 +
docs/architecture.md | 2 +-
docs/frontend.md | 12 +-
docs/presenter.md | 8 ++
src/Controller/AdminController.php | 38 ++++++
src/Model/Table/PollsTable.php | 31 +++++
src/Model/Table/SlidesTable.php | 104 ++++++++++++----
src/Service/ImageService.php | 15 ++-
templates/Admin/index.php | 28 ++++-
templates/Participate/view.php | 21 ----
templates/layout/default.php | 2 +-
tests/TestCase/Controller/ClonePollTest.php | 94 +++++++++++++++
webroot/css/plenario.css | 26 ++++
webroot/js/plenario.js | 127 +++++++-------------
15 files changed, 374 insertions(+), 138 deletions(-)
create mode 100644 tests/TestCase/Controller/ClonePollTest.php
diff --git a/AGENTS.md b/AGENTS.md
index cf44474..995e172 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -53,7 +53,7 @@ passende Dokument und pflegt es danach** (Details zu Verhalten, Settings, Tests
| Verzeichnisstruktur, Klassen, Tabellen | [docs/architecture.md](docs/architecture.md) |
| Folientypen (Wortwolke, Quiz, Q&A, Reihenfolge, YouTube, Skala/Sterne, Kommentare), Checkliste „Neuen Folientyp hinzufügen“ | [docs/slide-types.md](docs/slide-types.md) |
| Folienbilder (Upload, Ablage, Löschen) | [docs/images.md](docs/images.md) |
-| Live-Schaltung, Referentenansicht, Pause, Ausblenden, Zurücksetzen, Duplizieren, Einbettung, internes Feedback | [docs/presenter.md](docs/presenter.md) |
+| Live-Schaltung, Referentenansicht, Pause, Ausblenden, Zurücksetzen, Duplizieren, Umfrage kopieren, Einbettung, internes Feedback | [docs/presenter.md](docs/presenter.md) |
| Dashboard-Fragmente, Farbschema, Textformatierung, Vollbild | [docs/frontend.md](docs/frontend.md) |
| PDF-Export | [docs/pdf-export.md](docs/pdf-export.md) |
| Ablauf/Cleanup von Umfragen, CI/Deploy, Releases, Docker, Renovate | [docs/operations.md](docs/operations.md) |
diff --git a/config/routes.php b/config/routes.php
index 1ca5dba..92d106e 100644
--- a/config/routes.php
+++ b/config/routes.php
@@ -73,6 +73,8 @@ return function (RouteBuilder $routes): void {
->setPatterns($token)->setMethods(['POST']);
$admin->connect('/reset', 'Admin::reset', ['_name' => 'admin:reset'])
->setPatterns($token)->setMethods(['POST']);
+ $admin->connect('/clone', 'Admin::cloneAll', ['_name' => 'admin:clone'])
+ ->setPatterns($token)->setMethods(['POST']);
$admin->connect('/delete', 'Admin::delete', ['_name' => 'admin:delete'])
->setPatterns($token)->setMethods(['POST']);
$admin->connect('/present', 'Admin::present', ['_name' => 'admin:present'])->setPatterns($token);
diff --git a/docs/architecture.md b/docs/architecture.md
index b4a090f..0e26080 100644
--- a/docs/architecture.md
+++ b/docs/architecture.md
@@ -17,7 +17,7 @@ src/
`protect()` (no-referrer/noindex/no-store für Seiten mit Geheimnis in der URL: Admin, Embed)
HomeController Startseite, Anlegen (/create), Bestätigung, Join, Recover
AdminAppController Basis für /admin/{token}: löst Poll über Token-Hash auf (404 sonst), setzt Privacy-Header (no-referrer, no-store)
- AdminController Dashboard, Settings, Present, State-JSON, Control, QR, PDF-Export, Token rotieren, Zurücksetzen, Löschen
+ AdminController Dashboard, Settings, Present, State-JSON, Control, QR, PDF-Export, Token rotieren, Zurücksetzen, Kopieren (`cloneAll`), Löschen
SlidesController Folien-CRUD, Ein-/Ausblenden (`visibility`), Duplizieren (`duplicate` → `SlidesTable::duplicate()`, Kopie direkt dahinter, öffnet das Formular der Kopie), Antworten offener Fragen bzw. Skala-Auswertung (`answers`), Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen,
YouTube-Link prüfen (`youtubeCheck`, JSON)
ParticipateController /p/{code}: Ansicht, State-JSON, Abstimmen, eigene Antwort/Kommentar bearbeiten; anonymes Cookie plenario_pid
diff --git a/docs/frontend.md b/docs/frontend.md
index e84a038..b61595b 100644
--- a/docs/frontend.md
+++ b/docs/frontend.md
@@ -37,13 +37,13 @@ Neue Farben als Token in beiden Dark-Blöcken von `plenario.css` pflegen; auf de
(Presenter/Embed; baut DOM-Knoten, kein `innerHTML`). Regeln in beiden gleich halten (Regex `INLINE`/`LIST_ITEM`),
Tests: `FormatHelperTest.php`.
-## Vollbild & Display anlassen
+## Verwaltung: Menü-Drawer
-- **Vollbild & Display anlassen** (Teilnehmeransicht, `initScreenTools` in `plenario.js`): zwei optionale Icon-Buttons im Header neben dem Farbschema-Schalter (Layout-Block `headerTools`)
- (`data-fullscreen-toggle`, `data-wakelock-toggle`), bleiben ohne Browser-Unterstützung versteckt (iPhone-Safari kennt kein Vollbild).
- Der Wake Lock ist standardmäßig an (braucht keine Nutzergeste); nur ein bewusstes Ausschalten wird gemerkt.
- Die Seite lädt bei Folienwechsel neu: der Wake Lock wird per `sessionStorage` (`plenario-wakelock`) wieder angefordert,
- Vollbild braucht eine Nutzergeste und muss nach dem Wechsel ggf. neu gewählt werden.
+- Die Seitenleiste der Verwaltung (Teilnahme, Einstellungen, PDF, Einbetten, Kopieren, Sicherheit) wird unter 900 px zu einem Drawer von rechts.
+ Der Menü-Button (`data-drawer-toggle`, Layout-Block `headerMenu`) sitzt im Header rechts neben dem Farbschema-Schalter.
+ `initDrawer` in `plenario.js` fügt dem `
-
- start('headerTools'); ?>
-
-
- end(); ?>
-
is_active) : ?>
= __('Diese Umfrage ist geschlossen.') ?>
diff --git a/templates/layout/default.php b/templates/layout/default.php
index 26cf63f..14333cf 100644
--- a/templates/layout/default.php
+++ b/templates/layout/default.php
@@ -33,8 +33,8 @@ $title = $this->fetch('title');
= __('Admin-Link verloren?') ?>
diff --git a/tests/TestCase/Controller/ClonePollTest.php b/tests/TestCase/Controller/ClonePollTest.php
new file mode 100644
index 0000000..3c3269f
--- /dev/null
+++ b/tests/TestCase/Controller/ClonePollTest.php
@@ -0,0 +1,94 @@
+
+ */
+ protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
+
+ protected function setUp(): void
+ {
+ parent::setUp();
+ $this->enableCsrfToken();
+ }
+
+ public function testCopiesSlidesButNoResponses(): void
+ {
+ [$poll, $token] = $this->createPoll();
+ $first = $this->createSlide($poll, Slide::TYPE_CHOICE, ['description' => '*Wichtig*'], ['Rot', 'Grün']);
+ $quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch']);
+ $hidden = $this->createSlide($poll, Slide::TYPE_OPEN);
+ $hidden->is_hidden = true;
+ $this->slidesTable()->saveOrFail($hidden);
+ $poll = $this->goLive($poll, $first);
+ (new VoteService())->submit($poll, $first, VoteService::participantHash(str_repeat('a', 32), $poll->id), [
+ 'option_id' => $first->slide_options[0]->id,
+ ]);
+
+ $this->post("/admin/$token/clone");
+
+ $polls = $this->pollsTable()->find()->orderBy(['id' => 'ASC'])->all()->toList();
+ $this->assertCount(2, $polls);
+ $copy = $polls[1];
+ $this->assertNotSame($poll->join_code, $copy->join_code);
+ $this->assertSame($poll->email, $copy->email);
+ $this->assertStringEndsWith('(Kopie)', $copy->title);
+ $this->assertNull($copy->current_slide_id, 'copy is not started');
+ $this->assertSame($first->id, $this->pollsTable()->get($poll->id)->current_slide_id, 'original stays live');
+
+ $slides = $this->slidesTable()->listForPoll($copy->id);
+ $this->assertSame([1, 2, 3], array_map(fn($s) => $s->position, $slides));
+ $this->assertSame(
+ [$first->question, $quiz->question, $hidden->question],
+ array_map(fn($s) => $s->question, $slides),
+ );
+ $this->assertSame('*Wichtig*', $slides[0]->description);
+ $this->assertSame(['Rot', 'Grün'], array_map(fn($o) => $o->label, $slides[0]->slide_options));
+ $this->assertSame([true, false], array_map(fn($o) => $o->is_correct, $slides[1]->slide_options));
+ $this->assertTrue($slides[2]->is_hidden);
+ $this->assertSame(Slide::QUIZ_READY, $slides[1]->quizPhase());
+
+ $responses = TableRegistry::getTableLocator()->get('Responses');
+ $this->assertSame(0, $responses->find()->matching('Slides', fn($q) => $q->where(['Slides.poll_id' => $copy->id]))->count());
+ $this->assertSame(1, $responses->find()->where(['slide_id' => $first->id])->count(), 'original keeps its votes');
+ $this->assertCount(3, $this->slidesTable()->listForPoll($poll->id));
+ }
+
+ public function testRedirectsToAdminOfTheCopyOnlyViaPost(): void
+ {
+ [, $token] = $this->createPoll();
+
+ $this->get("/admin/$token/clone");
+ $this->assertResponseCode(404);
+
+ $this->post("/admin/$token/clone");
+ $this->assertResponseCode(302);
+ $this->assertRedirectContains('/admin/');
+ $this->assertHeaderNotContains('Location', $token);
+ }
+
+ public function testDashboardOffersCloneAndMenu(): void
+ {
+ [, $token] = $this->createPoll();
+ $this->get("/admin/$token");
+ $this->assertResponseContains("/admin/$token/clone");
+ $this->assertResponseContains('data-drawer-toggle');
+ }
+}
diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css
index 240ab5d..2c1f4e5 100644
--- a/webroot/css/plenario.css
+++ b/webroot/css/plenario.css
@@ -140,6 +140,32 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
.grid--sidebar { grid-template-columns: 1fr; }
}
+/* Sidebar as menu drawer (JS adds .sidebar--drawer; without JS the sidebar stays below the slides). */
+.menu-toggle { display: none; }
+.sidebar__bar { display: none; }
+.drawer-backdrop { display: none; }
+@media (max-width: 900px) {
+ .menu-toggle:not([hidden]) { display: inline-flex; }
+ .sidebar--drawer {
+ position: fixed; top: 0; right: 0; bottom: 0; z-index: 40;
+ width: min(92vw, 400px); padding: 0 16px 24px; overflow-y: auto; overscroll-behavior: contain;
+ background: var(--bg); box-shadow: -8px 0 32px rgba(20, 22, 50, .25);
+ visibility: hidden; transform: translateX(100%);
+ transition: transform .2s ease, visibility 0s linear .2s;
+ }
+ .drawer-open .sidebar--drawer { visibility: visible; transform: none; transition: transform .2s ease; }
+ .sidebar--drawer .sidebar__bar {
+ position: sticky; top: 0; z-index: 1; display: flex; align-items: center; justify-content: space-between;
+ margin: 0 -16px 16px; padding: 12px 16px; background: var(--bg); border-bottom: 1px solid var(--border);
+ }
+ .sidebar--drawer .sidebar__close { position: static; }
+ .drawer-open .drawer-backdrop { display: block; position: fixed; inset: 0; z-index: 39; background: rgba(20, 22, 50, .45); }
+ .drawer-open { overflow: hidden; }
+}
+@media (prefers-reduced-motion: reduce) {
+ .sidebar--drawer { transition: none; }
+}
+
/* ---------------------------------------------------------------- components */
.card {
background: var(--surface);
diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js
index a38b0ce..025f80c 100644
--- a/webroot/js/plenario.js
+++ b/webroot/js/plenario.js
@@ -1704,88 +1704,7 @@
// ------------------------------------------------------------------ participant
- // Fullscreen and screen wake lock for the participant view (both optional, buttons stay hidden if unsupported).
- function initScreenTools(root) {
- function setPressed(button, on) {
- var text = button.getAttribute(on ? 'data-label-on' : 'data-label-off');
- button.setAttribute('aria-pressed', on ? 'true' : 'false');
- button.setAttribute('aria-label', text);
- button.title = text;
- }
-
- // The buttons live in the layout header, outside the participant root.
- var fsButton = document.querySelector('[data-fullscreen-toggle]');
- if (fsButton && document.fullscreenEnabled) {
- fsButton.hidden = false;
- fsButton.addEventListener('click', function () {
- if (document.fullscreenElement) {
- document.exitFullscreen();
- } else {
- document.documentElement.requestFullscreen().catch(function () {});
- }
- });
- // Also fires when leaving with Esc/back gesture.
- document.addEventListener('fullscreenchange', function () {
- setPressed(fsButton, !!document.fullscreenElement);
- });
- }
-
- var wlButton = document.querySelector('[data-wakelock-toggle]');
- if (wlButton && 'wakeLock' in navigator) {
- // The page reloads on every slide change, so the choice is kept per tab and re-applied on load.
- var STORE = 'plenario-wakelock';
- // On by default; only an explicit "off" is remembered.
- var wanted = true;
- var sentinel = null;
- try {
- wanted = sessionStorage.getItem(STORE) !== '0';
- } catch (e) {
- // storage blocked: choice only lasts until the next slide
- }
- var remember = function () {
- try {
- sessionStorage.setItem(STORE, wanted ? '1' : '0');
- } catch (e) {
- // ignore
- }
- };
-
- var acquire = function () {
- if (!wanted || sentinel || document.visibilityState !== 'visible') {
- return Promise.resolve();
- }
- return navigator.wakeLock.request('screen').then(function (lock) {
- sentinel = lock;
- // The browser releases the lock when the tab is hidden; re-acquired on return.
- lock.addEventListener('release', function () {
- sentinel = null;
- });
- }).catch(function () {
- wanted = false; // denied (e.g. battery saver)
- remember();
- setPressed(wlButton, false);
- });
- };
-
- wlButton.hidden = false;
- setPressed(wlButton, wanted);
- acquire();
- wlButton.addEventListener('click', function () {
- wanted = !wanted;
- remember();
- setPressed(wlButton, wanted);
- if (wanted) {
- acquire();
- } else if (sentinel) {
- sentinel.release();
- }
- });
- document.addEventListener('visibilitychange', acquire);
- }
- }
-
function initParticipant(root) {
- initScreenTools(root);
var stateUrl = root.getAttribute('data-state-url');
var voteUrl = root.getAttribute('data-vote-url');
var version = root.getAttribute('data-version');
@@ -3161,10 +3080,56 @@
}
});
+ // Admin menu drawer: below 900px the sidebar slides in from the right (CSS), opened by the header button.
+ // Without JS the button stays hidden and the sidebar remains a normal block below the slides.
+ function initDrawer() {
+ var toggle = document.querySelector('[data-drawer-toggle]');
+ var drawer = toggle ? document.getElementById(toggle.getAttribute('aria-controls')) : null;
+ if (!toggle || !drawer) {
+ return;
+ }
+ var root = document.body;
+ drawer.classList.add('sidebar--drawer');
+ toggle.hidden = false;
+
+ function setOpen(open) {
+ root.classList.toggle('drawer-open', open);
+ toggle.setAttribute('aria-expanded', open ? 'true' : 'false');
+ if (open) {
+ var close = drawer.querySelector('[data-drawer-close]');
+ if (close) {
+ close.focus();
+ }
+ }
+ }
+ toggle.addEventListener('click', function () {
+ setOpen(!root.classList.contains('drawer-open'));
+ });
+ document.addEventListener('click', function (event) {
+ var target = event.target.closest ? event.target.closest('[data-drawer-close], a[href^="#"]') : null;
+ if (target && root.classList.contains('drawer-open') && (target.hasAttribute('data-drawer-close') || drawer.contains(target))) {
+ setOpen(false);
+ }
+ });
+ document.addEventListener('keydown', function (event) {
+ if (event.key === 'Escape' && root.classList.contains('drawer-open') && !document.querySelector('dialog[open]')) {
+ setOpen(false);
+ toggle.focus();
+ }
+ });
+ // Back to a wide screen: the sidebar is a normal column again.
+ window.addEventListener('resize', function () {
+ if (window.innerWidth > 900 && root.classList.contains('drawer-open')) {
+ setOpen(false);
+ }
+ });
+ }
+
document.addEventListener('DOMContentLoaded', function () {
document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch);
initWidgets(document);
initShare();
+ initDrawer();
initQrDownload();
initAdminDashboard();
document.querySelectorAll('[data-presenter]').forEach(initPresenter);