From 0028716f86139640d2b0b013b375d4a3048a1d22 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 14:54:06 +0100 Subject: [PATCH 01/11] Put own Q&A question actions below the text On narrow screens the edit/delete buttons squeezed the question text into a one-character column. Co-Authored-By: Claude Opus 5.5 --- webroot/css/plenario.css | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index a109954..51ceb22 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -540,7 +540,9 @@ textarea { resize: vertical; } .qa-item.is-current { box-shadow: inset 0 0 0 2px var(--c1); } .qa-votes { font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--qa); position: relative; } .qa-own { font-size: .85rem; color: var(--muted); white-space: nowrap; } -.qa-item:has(.qa-own-actions) { flex-wrap: wrap; } +/* Own questions: text on its own row, label and edit/delete below it (otherwise the text gets squeezed on phones). */ +.qa-item:has(.qa-own-actions) { flex-wrap: wrap; row-gap: 6px; } +.qa-item:has(.qa-own-actions) .qa-item__text { flex-basis: 100%; } .qa-own-actions { flex: none; display: inline-flex; gap: 4px; margin-left: auto; } .qa-own-actions .button { min-height: 36px; } .qa-item.is-editing { display: block; } From 891e3cb17425c2c345a062b508d039990bf8b4bb Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 15:01:36 +0100 Subject: [PATCH 02/11] Put Q&A voting controls below the question on phones Co-Authored-By: Claude Opus 5.5 --- webroot/css/plenario.css | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index 51ceb22..a472e8f 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -551,6 +551,12 @@ textarea { resize: vertical; } .qa-stepper { flex: none; display: inline-flex; align-items: center; gap: 6px; } .qa-stepper__count { min-width: 3.2em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--muted); } .qa-stepper.is-active .qa-stepper__count { color: var(--qa); } +/* Phones: voting controls below the question, so the text keeps the full width. */ +@media (max-width: 700px) { + .qa-item:has(.qa-stepper) { flex-wrap: wrap; row-gap: 8px; } + .qa-item:has(.qa-stepper) .qa-item__text { flex-basis: 100%; } + .qa-item:has(.qa-stepper) .qa-stepper { margin-left: auto; } +} .qa-upvote { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 2px solid var(--qa); background: var(--surface); color: var(--qa); font: inherit; font-size: 1.3rem; font-weight: 700; line-height: 1; cursor: pointer; } .qa-upvote--up { background: var(--qa); color: var(--surface); } .qa-upvote:disabled { opacity: .45; cursor: not-allowed; } From 759e15390e97aca842e3439517e95738fe658da3 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 15:05:09 +0100 Subject: [PATCH 03/11] Hide Q&A upvote counts until voting ends A live ranking on the stage swayed the vote. During the vote stage the presenter now gets the questions in submission order without counts, only the total of votes cast. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 3 ++- src/Service/ResultsService.php | 11 +++++++++-- templates/Admin/export.php | 2 +- tests/TestCase/Service/QaTest.php | 8 ++++++-- webroot/js/plenario.js | 8 +++----- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 88cd67d..4c6d062 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -165,7 +165,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures wird es während `vote` auf 0 gesetzt, springt `SlidesController::saveSlide()` nach `discuss`. Setting `allow_self_upvote` (Standard aus, für Themen-Priorisierung) erlaubt Stimmen auf eigene Fragen aus demselben Budget (State `qa.allowSelfUpvote`); bewusst aus, weil anonym sonst Selbstvermarktung die Rangfolge bestimmt; - Teilnehmende sehen alle Fragen in Eingangsreihenfolge **ohne** Zählung. `discuss`: Abstimmung zu, Fragen nach Upvotes + Teilnehmende sehen alle Fragen in Eingangsreihenfolge **ohne** Zählung; auch die Bühne (Presenter/Embed, PDF) bekommt in `vote` + keine Zählungen je Frage und keine Rangfolge (`ResultsService::qa()`, nur die Summe `upvotes`), damit niemand beeinflusst wird. `discuss`: Abstimmung zu, Fragen nach Upvotes sortiert (Gleichstand: älteste zuerst), `focus_response_id` = aktuelle Frage. In `discuss` blättern next/prev (→/←, Klicker) zuerst durch die Fragen, erst danach durch die Folien. Fokuswechsel per `updateAll` ohne `modified`, damit Teilnehmerseiten nicht neu laden. Teilnehmende bekommen nie `results`, sondern `qa` aus `PollStateService::qaState()`. diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 61ceee9..f383458 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -40,7 +40,8 @@ use Cake\ORM\Locator\LocatorAwareTrait; * - qa: 'stage' (collect|vote|discuss), 'stages' (available stages in order, no 'vote' without upvotes), * 'maxUpvotes' (per participant, 0 = no upvotes), 'maxPerQuestion' (per participant and question), * 'upvotes' (total), - * 'questions' => [['id', 'text', 'votes']] most upvoted first (ties: oldest first), + * 'questions' => [['id', 'text', 'votes']] most upvoted first (ties: oldest first); + * during 'vote' only [['id', 'text']] in submission order (no counts while voting is open), * 'focusId' (question being discussed|null), 'focusIndex' (0-based position in questions|null). * Presenter only – participants get their own view, see PollStateService::qaState(). */ @@ -215,6 +216,12 @@ class ResultsService protected function qa(Slide $slide): array { $questions = (new QaService())->rankedQuestions($slide); + $upvotes = array_sum(array_column($questions, 'votes')); + if ($slide->qaStage() === Slide::QA_VOTE) { + // A live ranking on the stage would sway the vote: submission order, no counts until voting ends. + usort($questions, fn($a, $b) => $a['id'] <=> $b['id']); + $questions = array_map(fn($q) => ['id' => $q['id'], 'text' => $q['text']], $questions); + } $focusIndex = null; foreach ($questions as $index => $question) { if ($question['id'] === $slide->focus_response_id) { @@ -227,7 +234,7 @@ class ResultsService 'stages' => $slide->qaStages(), 'maxUpvotes' => (int)$slide->setting('max_upvotes'), 'maxPerQuestion' => $slide->qaUpvotesPerQuestion(), - 'upvotes' => array_sum(array_column($questions, 'votes')), + 'upvotes' => $upvotes, 'questions' => $questions, 'focusId' => $focusIndex === null ? null : $slide->focus_response_id, 'focusIndex' => $focusIndex, diff --git a/templates/Admin/export.php b/templates/Admin/export.php index 020e1a1..bd8aefa 100644 --- a/templates/Admin/export.php +++ b/templates/Admin/export.php @@ -213,7 +213,7 @@ $bar = function (float $percent, bool $ok = false): string {

- 0; ?> + 0 && $r['stage'] !== 'vote'; ?> diff --git a/tests/TestCase/Service/QaTest.php b/tests/TestCase/Service/QaTest.php index 10f2f1a..e805027 100644 --- a/tests/TestCase/Service/QaTest.php +++ b/tests/TestCase/Service/QaTest.php @@ -203,12 +203,16 @@ class QaTest extends TestCase $this->assertVoteFails('Du hast diese Frage nicht unterstützt.', fn() => $this->vote($poll, $slide, 'p3', $c, 'remove')); $this->vote($poll, $slide, 'p3', $a); + // While voting is open, the stage only gets the total: no ranking, no counts per question. $results = (new ResultsService())->forSlide($slide); - $this->assertSame([[$b, 3], [$a, 1], [$c, 0]], array_map(fn($q) => [$q['id'], $q['votes']], $results['questions'])); + $this->assertSame([$a, $b, $c], array_column($results['questions'], 'id')); + $this->assertArrayNotHasKey('votes', $results['questions'][0]); $this->assertSame(4, $results['upvotes']); + $ranked = (new QaService())->rankedQuestions($slide); + $this->assertSame([[$b, 3], [$a, 1], [$c, 0]], array_map(fn($q) => [$q['id'], $q['votes']], $ranked)); $this->vote($poll, $slide, 'p3', $b, 'remove'); - $this->assertSame(2, (new ResultsService())->forSlide($slide)['questions'][0]['votes'], 'remove withdraws only one upvote'); + $this->assertSame(2, (new QaService())->rankedQuestions($slide)[0]['votes'], 'remove withdraws only one upvote'); $this->vote($poll, $slide, 'p3', $b); // Voting view of participants: all questions, submission order, no counts. diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 97ad447..5b9caa9 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -1000,7 +1000,6 @@ var onStage = options && options.onStage; var onQuestion = options && options.onQuestion; var questions = results.questions; - var maxVotes = Math.max.apply(null, questions.map(function (q) { return q.votes; }).concat([1])); var children = [Qa.steps(results.stage, onStage, results.stages)]; var withVotes = results.maxUpvotes > 0; @@ -1027,11 +1026,10 @@ + results.maxUpvotes + (results.maxUpvotes === 1 ? ' Stimme' : ' Stimmen') + (results.maxPerQuestion < results.maxUpvotes ? ' (höchstens ' + results.maxPerQuestion + ' pro Frage)' : '') + ' · bisher ' + results.upvotes + ' vergeben' })); - children.push(el('ol', { class: 'qa-list' }, questions.map(function (question) { + // No counts or ranking while voting is open (the server sends none), so the stage does not sway the vote. + children.push(el('ul', { class: 'qa-list' }, questions.map(function (question) { return el('li', { class: 'qa-item' }, [ - el('span', { class: 'qa-item__text', text: question.text }), - votes(question), - el('span', { class: 'qa-item__bar', style: 'width:' + (question.votes / maxVotes * 100) + '%' }) + el('span', { class: 'qa-item__text', text: question.text }) ]); }))); } else if (questions.length === 0) { From 9535731612a7f7ca331e61c439ccb2877ca9fd7f Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 15:07:10 +0100 Subject: [PATCH 04/11] Center Q&A voting controls on phones Co-Authored-By: Claude Opus 5.5 --- webroot/css/plenario.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index a472e8f..715f310 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -555,7 +555,7 @@ textarea { resize: vertical; } @media (max-width: 700px) { .qa-item:has(.qa-stepper) { flex-wrap: wrap; row-gap: 8px; } .qa-item:has(.qa-stepper) .qa-item__text { flex-basis: 100%; } - .qa-item:has(.qa-stepper) .qa-stepper { margin-left: auto; } + .qa-item:has(.qa-stepper) { justify-content: center; } } .qa-upvote { width: 44px; height: 44px; padding: 0; border-radius: 50%; border: 2px solid var(--qa); background: var(--surface); color: var(--qa); font: inherit; font-size: 1.3rem; font-weight: 700; line-height: 1; cursor: pointer; } .qa-upvote--up { background: var(--qa); color: var(--surface); } From e2f24877dde19bab536c73d8b876f8a2a95d4e1b Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 15:18:10 +0100 Subject: [PATCH 05/11] Add duplicating slides Copies question, description, settings and options (incl. correct quiz answers) directly behind the original, without responses. The copy starts like a new slide (Slide::startFresh()) and opens in the edit form. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 6 +- config/routes.php | 2 + src/Controller/SlidesController.php | 21 ++- src/Model/Entity/Slide.php | 15 ++ src/Model/Table/SlidesTable.php | 41 ++++++ templates/Admin/index.php | 5 + .../Controller/DuplicateSlideTest.php | 129 ++++++++++++++++++ 7 files changed, 214 insertions(+), 5 deletions(-) create mode 100644 tests/TestCase/Controller/DuplicateSlideTest.php diff --git a/AGENTS.md b/AGENTS.md index 88cd67d..09eb082 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ src/ 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 - SlidesController Folien-CRUD, Antworten offener Fragen bzw. Skala-Auswertung (`answers`), Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen, + SlidesController Folien-CRUD, 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 EmbedController /e/{key}/{id}: eine Folie zum Einbetten (z. B. Canva), activate/heartbeat/pause/control @@ -195,6 +195,10 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures (`admin:reset`, Dashboard → „Sicherheit“). Nur Quiz (`ready`) und Q&A (`collect`) springen zurück, weil ihre Phasen ohne Antworten keinen Sinn ergeben; offen/geschlossen anderer Folien, aktuelle Folie/Pause, Einstellungen bleiben. Idempotent, in einer Transaktion. Tests: `PollResetTest.php`. +- **Duplizieren** (`slides:duplicate`, POST): kopiert Fragetext (+ „(Kopie)“), Beschreibung, Einstellungen und Optionen + inkl. `is_correct`, **nie Antworten**. Die Kopie landet direkt hinter dem Original und startet wie eine neue Folie + (`Slide::startFresh()`: Quiz `ready`, Q&A `collect`, sonst offen) – auch `add()` nutzt `startFresh()`. + Tests: `DuplicateSlideTest.php`. - **Pause:** `current_slide_id = null` + `paused_slide_id` = Pause (Teilnehmende sehen „Kurze Pause“), ohne `paused_slide_id` = noch nicht gestartet. Immer über `Poll::showSlide()` / `showEmbeddedSlide()` / `pause()` / `forgetSlide()` setzen, nie `current_slide_id` direkt. Presenter: P bzw. der Pause-Button schaltet um (Aktionen `stop`/`resume`, beide idempotent, kein Server-Toggle), diff --git a/config/routes.php b/config/routes.php index 54b189e..2fd3a47 100644 --- a/config/routes.php +++ b/config/routes.php @@ -83,6 +83,8 @@ return function (RouteBuilder $routes): void { ->setPatterns($token)->setPass(['id']); $admin->connect('/slides/{id}/delete', 'Slides::delete', ['_name' => 'slides:delete']) ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); + $admin->connect('/slides/{id}/duplicate', 'Slides::duplicate', ['_name' => 'slides:duplicate']) + ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); $admin->connect('/slides/reorder', 'Slides::reorder', ['_name' => 'slides:reorder']) ->setPatterns($token)->setMethods(['POST']); $admin->connect('/slides/youtube-check', 'Slides::youtubeCheck', ['_name' => 'slides:youtube-check']) diff --git a/src/Controller/SlidesController.php b/src/Controller/SlidesController.php index 0908100..4cf998a 100644 --- a/src/Controller/SlidesController.php +++ b/src/Controller/SlidesController.php @@ -43,10 +43,8 @@ class SlidesController extends AdminAppController 'validate' => false, ]); $slide->poll_id = $this->poll->id; - // A quiz is started by the presenter (that also starts its timer). - $slide->is_voting_open = $type !== Slide::TYPE_QUIZ; - // Q&A starts by collecting questions. - $slide->stage = $type === Slide::TYPE_QA ? Slide::QA_COLLECT : null; + // A quiz is started by the presenter (that also starts its timer), Q&A starts by collecting questions. + $slide->startFresh(); $optionsText = $type === Slide::TYPE_CHOICE ? "\n" : ''; $quizOptions = []; $orderOptions = []; @@ -126,6 +124,21 @@ class SlidesController extends AdminAppController return $this->redirect($this->adminUrl()); } + /** + * Copies a slide (without responses) directly behind the original and opens the copy for editing. + * + * @param string $id Slide id + * @return \Cake\Http\Response|null + */ + public function duplicate(string $id): ?Response + { + $this->request->allowMethod(['post']); + $copy = $this->Slides->duplicate($this->loadSlide($id)); + $this->Flash->success(__('Folie dupliziert. Du bearbeitest jetzt die Kopie.')); + + return $this->redirect($this->adminUrl('slides:edit', ['id' => $copy->id])); + } + /** * Saves a complete new slide order (drag & drop), expects `ids[]` and answers with JSON. * diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index cd88f98..4391d9d 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -408,6 +408,21 @@ class Slide extends Entity return max(0, $this->voting_ends_at->getTimestamp() - ($now ?? DateTime::now())->getTimestamp()); } + /** + * Sets the state of a slide that has not been presented yet (new slide, copy): + * a quiz waits for the presenter to start it, Q&A collects questions, others are open. + * + * @return void + */ + public function startFresh(): void + { + $this->is_voting_open = !$this->isQuiz(); + $this->voting_started_at = null; + $this->voting_ends_at = null; + $this->stage = $this->isQa() ? self::QA_COLLECT : null; + $this->focus_response_id = null; + } + /** * Opens or closes voting. Opening a quiz that is not running (re)starts its * voting window and timer; opening a running quiz changes nothing. diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index afb3340..12eb2ad 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -6,6 +6,7 @@ namespace App\Model\Table; use App\Model\Entity\Slide; use App\Service\YouTubeService; use ArrayObject; +use Cake\Database\Expression\QueryExpression; use Cake\Datasource\EntityInterface; use Cake\Event\EventInterface; use Cake\ORM\RulesChecker; @@ -323,6 +324,46 @@ class SlidesTable extends Table }); } + /** + * Copies a slide incl. its settings and options (with the correct answers) and + * puts the copy directly behind the original. Responses are not copied: the copy + * starts like a new slide (quiz not started, Q&A collecting, others open). + * + * @param \App\Model\Entity\Slide $slide Original incl. slide_options + * @return \App\Model\Entity\Slide The saved copy + */ + public function duplicate(Slide $slide): Slide + { + $copy = $this->newEmptyEntity(); + $copy->poll_id = $slide->poll_id; + $copy->type = $slide->type; + $copy->question = mb_substr(__('{0} (Kopie)', $slide->question), 0, 500); + $copy->description = $slide->description; + $copy->settings = $slide->settings; + $copy->position = $slide->position + 1; + $copy->startFresh(); + + return $this->getConnection()->transactional(function () use ($slide, $copy): Slide { + $this->updateAll( + ['position' => new QueryExpression('position + 1')], + ['poll_id' => $slide->poll_id, 'position >' => $slide->position], + ); + $this->saveOrFail($copy); + foreach ($slide->slide_options ?? [] as $option) { + $newOption = $this->SlideOptions->newEntity([ + 'label' => $option->label, + 'position' => $option->position, + ]); + $newOption->set('slide_id', $copy->id); + $newOption->set('is_correct', $option->is_correct); + $this->SlideOptions->saveOrFail($newOption); + } + $this->normalizePositions($slide->poll_id); + + return $this->get($copy->id, contain: ['SlideOptions']); + }); + } + /** * Applies a complete new order (e.g. from drag & drop). * diff --git a/templates/Admin/index.php b/templates/Admin/index.php index e3bb1b9..18d38f6 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -144,6 +144,11 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s type === 'scale' ? __('Auswertung') : __('Antworten') ?> + Form->postLink(__('Duplizieren'), $url('slides:duplicate', ['id' => $slide->id]), [ + 'class' => 'button button--small', + 'title' => __('Kopie dieser Folie direkt dahinter anlegen (ohne Antworten)'), + 'aria-label' => __('Folie „{0}“ duplizieren', $slide->question), + ]) ?> 0) : ?> Form->postLink(__('Zurücksetzen'), $url('slides:reset', ['id' => $slide->id]), [ 'class' => 'button button--small', diff --git a/tests/TestCase/Controller/DuplicateSlideTest.php b/tests/TestCase/Controller/DuplicateSlideTest.php new file mode 100644 index 0000000..b7671e1 --- /dev/null +++ b/tests/TestCase/Controller/DuplicateSlideTest.php @@ -0,0 +1,129 @@ + + */ + protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; + + protected function setUp(): void + { + parent::setUp(); + $this->enableCsrfToken(); + } + + public function testCopyIsPlacedBehindOriginalWithoutResponses(): void + { + [$poll, $token] = $this->createPoll(); + $first = $this->createSlide($poll, Slide::TYPE_CHOICE, [ + 'description' => '*Wichtig*', + 'settings' => ['multiple' => true] + Slide::DEFAULT_SETTINGS[Slide::TYPE_CHOICE], + ], ['Rot', 'Grün', 'Blau']); + $last = $this->createSlide($poll, Slide::TYPE_OPEN); + $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/slides/{$first->id}/duplicate"); + + $slides = $this->slidesTable()->listForPoll($poll->id); + $this->assertSame([$first->id, $last->id], [$slides[0]->id, $slides[2]->id]); + $copy = $slides[1]; + $this->assertRedirect(['_name' => 'slides:edit', 'token' => $token, 'id' => $copy->id]); + $this->assertSame([1, 2, 3], array_map(fn($s) => $s->position, $slides)); + $this->assertSame('Frage choice (Kopie)', $copy->question); + $this->assertSame('*Wichtig*', $copy->description); + $this->assertSame($first->getSettings(), $copy->getSettings()); + $this->assertSame(['Rot', 'Grün', 'Blau'], array_map(fn($o) => $o->label, $copy->slide_options)); + $this->assertNotContains($copy->slide_options[0]->id, array_map(fn($o) => $o->id, $first->slide_options)); + + $responses = TableRegistry::getTableLocator()->get('Responses'); + $this->assertSame(0, $responses->find()->where(['slide_id' => $copy->id])->count()); + $this->assertSame(1, $responses->find()->where(['slide_id' => $first->id])->count(), 'original keeps its votes'); + $this->assertSame($first->id, $this->pollsTable()->get($poll->id)->current_slide_id, 'live slide stays'); + } + + public function testCopyStartsFresh(): void + { + [$poll, $token] = $this->createPoll(); + $quiz = $this->createSlide($poll, Slide::TYPE_QUIZ, [], ['Richtig', 'Falsch', 'Auch falsch']); + $quiz->setVotingOpen(true); + $quiz->is_voting_open = false; + $qa = $this->createSlide($poll, Slide::TYPE_QA); + $qa->stage = Slide::QA_DISCUSS; + $qa->is_voting_open = false; + $closed = $this->createSlide($poll, Slide::TYPE_SCALE, ['is_voting_open' => false]); + $this->slidesTable()->saveManyOrFail([$quiz, $qa]); + + foreach ([$quiz, $qa, $closed] as $slide) { + $this->post("/admin/$token/slides/{$slide->id}/duplicate"); + $this->assertResponseCode(302); + } + + $slides = $this->slidesTable()->listForPoll($poll->id); + $this->assertCount(6, $slides); + [, $quizCopy, , $qaCopy, , $scaleCopy] = $slides; + + $this->assertSame(Slide::QUIZ_READY, $quizCopy->quizPhase()); + $this->assertNull($quizCopy->voting_started_at); + $this->assertSame([true, false, false], array_map(fn($o) => $o->is_correct, $quizCopy->slide_options)); + $this->assertSame(Slide::QA_COLLECT, $qaCopy->qaStage()); + $this->assertTrue($qaCopy->is_voting_open); + $this->assertSame(Slide::TYPE_SCALE, $scaleCopy->type); + $this->assertTrue($scaleCopy->is_voting_open); + } + + public function testOnlySlidesOfOwnPollAndOnlyPost(): void + { + [$poll, $token] = $this->createPoll(); + [$other] = $this->createPoll('Andere'); + $own = $this->createSlide($poll); + $foreign = $this->createSlide($other); + + $this->post("/admin/$token/slides/{$foreign->id}/duplicate"); + $this->assertResponseCode(404); + $this->assertSame(1, $this->slidesTable()->find()->where(['poll_id' => $other->id])->count()); + + $this->get("/admin/$token/slides/{$own->id}/duplicate"); + $this->assertResponseCode(404); + $this->assertSame(1, $this->slidesTable()->find()->where(['poll_id' => $poll->id])->count()); + } + + public function testLongQuestionIsShortened(): void + { + [$poll, $token] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_CONTENT, ['question' => str_repeat('x', 500)], []); + + $this->post("/admin/$token/slides/{$slide->id}/duplicate"); + + $copy = $this->slidesTable()->listForPoll($poll->id)[1]; + $this->assertSame(500, mb_strlen($copy->question)); + } + + public function testDashboardOffersDuplicate(): void + { + [$poll, $token] = $this->createPoll(); + $slide = $this->createSlide($poll); + $this->get("/admin/$token"); + $this->assertResponseContains("/admin/$token/slides/{$slide->id}/duplicate"); + $this->assertResponseContains('Duplizieren'); + } +} From 3c978e6f22ffe600b8409ca4a6697a41d47ea1fd Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 15:25:41 +0100 Subject: [PATCH 06/11] Add hiding slides from the presentation Hidden slides stay prepared in the dashboard but are skipped when presenting (start, next/prev, goto), can not go live via embed and are left out of the PDF export. Hiding the live or paused slide pauses the poll like deleting it and resumes with the next visible slide. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 10 +- .../20261111150000_AddIsHiddenToSlides.php | 37 ++++ config/routes.php | 4 +- src/Controller/AdminController.php | 5 +- src/Controller/EmbedController.php | 4 +- src/Controller/SlidesController.php | 38 +++- src/Model/Entity/Poll.php | 7 +- src/Model/Entity/Slide.php | 1 + src/Model/Table/SlidesTable.php | 45 ++++- src/Service/PollStateService.php | 5 +- src/Service/ReportService.php | 4 +- templates/Admin/index.php | 23 ++- tests/TestCase/Controller/HiddenSlideTest.php | 172 ++++++++++++++++++ webroot/css/plenario.css | 4 +- webroot/js/plenario.js | 9 +- 15 files changed, 333 insertions(+), 35 deletions(-) create mode 100644 config/Migrations/20261111150000_AddIsHiddenToSlides.php create mode 100644 tests/TestCase/Controller/HiddenSlideTest.php diff --git a/AGENTS.md b/AGENTS.md index 09eb082..375ef43 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -58,7 +58,7 @@ src/ 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 - SlidesController Folien-CRUD, 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, + 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 EmbedController /e/{key}/{id}: eine Folie zum Einbetten (z. B. Canva), activate/heartbeat/pause/control @@ -95,6 +95,7 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures `embed_key` (Einbett-Schlüssel), `embed_seen_at` (letztes Lebenszeichen der eingebetteten Live-Folie), `paused_slide_id` (Folie vor der Pause), `comment_speed` (Tempo der Skala-Kommentare in Prozent, Standard 100) - `slides`: `type` (`choice|wordcloud|open|scale|content|quiz|youtube|qa|order`), `question`, `description`, `position`, + `is_hidden` (ausgeblendet: vorbereitet, aber nicht Teil der Präsentation), `settings` (JSON, je Typ siehe `Slide::DEFAULT_SETTINGS`), `is_voting_open`, `voting_started_at` / `voting_ends_at` (nur Quiz: Start und Deadline, `null` = manuell beenden), `stage` / `focus_response_id` (nur Q&A: Phase und gerade besprochene Frage) @@ -199,6 +200,13 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures inkl. `is_correct`, **nie Antworten**. Die Kopie landet direkt hinter dem Original und startet wie eine neue Folie (`Slide::startFresh()`: Quiz `ready`, Q&A `collect`, sonst offen) – auch `add()` nutzt `startFresh()`. Tests: `DuplicateSlideTest.php`. +- **Ausgeblendete Folien** (`is_hidden`, `slides:visibility` mit `hidden=1|0`, explizit statt Toggle → idempotent): + bleiben in der Verwaltung (gestrichelt, Badge „ausgeblendet“), gehören aber nicht zur Präsentation. Präsentation = + `SlidesTable::listForPoll($pollId, true)`: Start, →/←, `goto` (400 für ausgeblendete), Zähler im Presenter-State + (`count` ohne, `hiddenCount` = ausgeblendete), PDF-Export (Nummerierung wie in der Präsentation). Einbettung einer + ausgeblendeten Folie geht nicht live (`isHidden` im Embed-State). Eine ausgeblendete Folie darf nie live/pausiert sein: + Ausblenden der Live- oder pausierten Folie pausiert wie Löschen (`forgetSlide()` + `SlidesTable::replacementFor()` = + nächste sichtbare Folie, sonst die vorige). `is_hidden` ist nicht mass-assignable. Tests: `HiddenSlideTest.php`. - **Pause:** `current_slide_id = null` + `paused_slide_id` = Pause (Teilnehmende sehen „Kurze Pause“), ohne `paused_slide_id` = noch nicht gestartet. Immer über `Poll::showSlide()` / `showEmbeddedSlide()` / `pause()` / `forgetSlide()` setzen, nie `current_slide_id` direkt. Presenter: P bzw. der Pause-Button schaltet um (Aktionen `stop`/`resume`, beide idempotent, kein Server-Toggle), diff --git a/config/Migrations/20261111150000_AddIsHiddenToSlides.php b/config/Migrations/20261111150000_AddIsHiddenToSlides.php new file mode 100644 index 0000000..59ed676 --- /dev/null +++ b/config/Migrations/20261111150000_AddIsHiddenToSlides.php @@ -0,0 +1,37 @@ +table('slides'); + if (!$table->hasColumn('is_hidden')) { + $table->addColumn('is_hidden', 'boolean', [ + 'null' => false, + 'default' => false, + 'after' => 'position', + ])->update(); + } + } + + /** + * @return void + */ + public function down(): void + { + $table = $this->table('slides'); + if ($table->hasColumn('is_hidden')) { + $table->removeColumn('is_hidden')->update(); + } + } +} diff --git a/config/routes.php b/config/routes.php index 2fd3a47..f216427 100644 --- a/config/routes.php +++ b/config/routes.php @@ -85,7 +85,9 @@ return function (RouteBuilder $routes): void { ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); $admin->connect('/slides/{id}/duplicate', 'Slides::duplicate', ['_name' => 'slides:duplicate']) ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); - $admin->connect('/slides/reorder', 'Slides::reorder', ['_name' => 'slides:reorder']) + $admin->connect('/slides/{id}/visibility', 'Slides::visibility', ['_name' => 'slides:visibility']) + ->setPatterns($token)->setPass(['id'])->setMethods(['POST']); + $admin->connect('/slides/reorder','Slides::reorder', ['_name' => 'slides:reorder']) ->setPatterns($token)->setMethods(['POST']); $admin->connect('/slides/youtube-check', 'Slides::youtubeCheck', ['_name' => 'slides:youtube-check']) ->setPatterns($token)->setMethods(['POST']); diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 883c35c..117ff67 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -161,7 +161,7 @@ class AdminController extends AdminAppController { if ($this->poll->current_slide_id === null && !$this->poll->isPaused()) { $first = $this->Slides->find() - ->where(['poll_id' => $this->poll->id]) + ->where(['poll_id' => $this->poll->id, 'is_hidden' => false]) ->orderBy(['position' => 'ASC', 'id' => 'ASC']) ->first(); if ($first !== null) { @@ -203,7 +203,8 @@ class AdminController extends AdminAppController { $this->request->allowMethod(['post']); $action = (string)$this->request->getData('action'); - $slides = $this->Slides->listForPoll($this->poll->id); + // Hidden slides are skipped and can not go live. + $slides = $this->Slides->listForPoll($this->poll->id, true); $ids = array_map(fn(Slide $s) => $s->id, $slides); $index = array_search($this->poll->current_slide_id, $ids, true); $current = $index === false ? null : $slides[$index]; diff --git a/src/Controller/EmbedController.php b/src/Controller/EmbedController.php index 20262ee..46770f7 100644 --- a/src/Controller/EmbedController.php +++ b/src/Controller/EmbedController.php @@ -114,14 +114,14 @@ class EmbedController extends AppController } /** - * The embed became visible: this slide goes live. Idempotent. + * The embed became visible: this slide goes live (unless it is hidden). Idempotent. * * @return \Cake\Http\Response */ public function activate(): Response { $this->request->allowMethod(['post']); - if ($this->poll->is_active) { + if ($this->poll->is_active && !$this->slide->is_hidden) { $this->poll->showEmbeddedSlide($this->slide->id); $this->Polls->saveOrFail($this->poll); } diff --git a/src/Controller/SlidesController.php b/src/Controller/SlidesController.php index 4cf998a..a9fa3ae 100644 --- a/src/Controller/SlidesController.php +++ b/src/Controller/SlidesController.php @@ -104,15 +104,7 @@ class SlidesController extends AdminAppController $this->request->allowMethod(['post']); $slide = $this->loadSlide($id); // Deleting the live (or paused) slide pauses the poll; → resumes with the slide taking its place. - $ids = $this->Slides->find() - ->select(['id']) - ->where(['poll_id' => $this->poll->id]) - ->orderBy(['position' => 'ASC', 'id' => 'ASC']) - ->all() - ->extract('id') - ->toList(); - $index = (int)array_search($slide->id, $ids, true); - $this->poll->forgetSlide($slide->id, $ids[$index + 1] ?? $ids[$index - 1] ?? null); + $this->poll->forgetSlide($slide->id, $this->Slides->replacementFor($slide)); $this->Slides->getConnection()->transactional(function () use ($slide): void { $this->Polls->saveOrFail($this->poll); @@ -124,6 +116,34 @@ class SlidesController extends AdminAppController return $this->redirect($this->adminUrl()); } + /** + * Hides a slide from the presentation or shows it again. Field `hidden` (1|0) is explicit + * (not a toggle), so repeating the request changes nothing. Hiding the live (or paused) + * slide pauses the poll like deleting it. + * + * @param string $id Slide id + * @return \Cake\Http\Response|null + */ + public function visibility(string $id): ?Response + { + $this->request->allowMethod(['post']); + $slide = $this->loadSlide($id); + $hidden = filter_var($this->request->getData('hidden'), FILTER_VALIDATE_BOOLEAN); + + $this->Slides->getConnection()->transactional(function () use ($slide, $hidden): void { + if ($hidden) { + $this->poll->forgetSlide($slide->id, $this->Slides->replacementFor($slide)); + $this->Polls->saveOrFail($this->poll); + } + $this->Slides->updateAll(['is_hidden' => $hidden], ['id' => $slide->id]); + }); + $this->Flash->success($hidden + ? __('Folie „{0}“ ist ausgeblendet und wird beim Präsentieren übersprungen.', $slide->question) + : __('Folie „{0}“ ist wieder eingeblendet.', $slide->question)); + + return $this->redirect($this->adminUrl()); + } + /** * Copies a slide (without responses) directly behind the original and opens the copy for editing. * diff --git a/src/Model/Entity/Poll.php b/src/Model/Entity/Poll.php index 407c111..890689e 100644 --- a/src/Model/Entity/Poll.php +++ b/src/Model/Entity/Poll.php @@ -110,10 +110,11 @@ class Poll extends Entity } /** - * A slide is being deleted. If it was live or is the one a pause resumes, the poll pauses - * and resumes with $resumeSlideId instead (null: no slides left = not started). Idempotent. + * A slide leaves the presentation (deleted or hidden). If it was live or is the one a pause + * resumes, the poll pauses and resumes with $resumeSlideId instead (null: no slides left = + * not started). Idempotent. * - * @param int $slideId Deleted slide + * @param int $slideId Deleted or hidden slide * @param int|null $resumeSlideId Slide that takes its place (must belong to this poll) * @return void */ diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index 4391d9d..1d1e5fc 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -17,6 +17,7 @@ use Cake\ORM\Entity; * @property string $question * @property string|null $description * @property int $position + * @property bool $is_hidden Prepared, but skipped in the presentation (never live) * @property array|null $settings * @property bool $is_voting_open * @property \Cake\I18n\DateTime|null $voting_started_at Quiz: start of the voting window diff --git a/src/Model/Table/SlidesTable.php b/src/Model/Table/SlidesTable.php index 12eb2ad..3a7e92c 100644 --- a/src/Model/Table/SlidesTable.php +++ b/src/Model/Table/SlidesTable.php @@ -423,18 +423,51 @@ class SlidesTable extends Table * Ordered slides of a poll including options. * * @param int $pollId Poll id + * @param bool $visibleOnly Only slides that are part of the presentation (not hidden) * @return list<\App\Model\Entity\Slide> */ - public function listForPoll(int $pollId): array + public function listForPoll(int $pollId, bool $visibleOnly = false): array { - /** @var list<\App\Model\Entity\Slide> $slides */ - $slides = $this->find() + $query = $this->find() ->where(['Slides.poll_id' => $pollId]) ->contain(['SlideOptions']) - ->orderBy(['Slides.position' => 'ASC', 'Slides.id' => 'ASC']) - ->all() - ->toList(); + ->orderBy(['Slides.position' => 'ASC', 'Slides.id' => 'ASC']); + if ($visibleOnly) { + $query->where(['Slides.is_hidden' => false]); + } + /** @var list<\App\Model\Entity\Slide> $slides */ + $slides = $query->all()->toList(); return $slides; } + + /** + * The visible slide that takes the place of a slide leaving the presentation + * (deleted or hidden): the next visible one behind it, otherwise the one before. + * + * @param \App\Model\Entity\Slide $slide Slide leaving the presentation + * @return int|null Slide id, null if no other visible slide is left + */ + public function replacementFor(Slide $slide): ?int + { + $rows = $this->find() + ->select(['id', 'is_hidden']) + ->where(['poll_id' => $slide->poll_id]) + ->orderBy(['position' => 'ASC', 'id' => 'ASC']) + ->disableHydration() + ->all() + ->toList(); + $index = array_search($slide->id, array_column($rows, 'id'), true); + if ($index === false) { + return null; + } + $candidates = array_merge(array_slice($rows, $index + 1), array_reverse(array_slice($rows, 0, $index))); + foreach ($candidates as $row) { + if (!$row['is_hidden']) { + return (int)$row['id']; + } + } + + return null; + } } diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index 55a7a61..55eb5a6 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -83,7 +83,8 @@ class PollStateService public function forPresenter(Poll $poll): array { $this->Polls->pauseIfEmbedStale($poll); - $slides = $this->Slides->listForPoll($poll->id); + // The presentation consists of the visible slides only. + $slides = $this->Slides->listForPoll($poll->id, true); $current = null; $index = null; foreach ($slides as $i => $slide) { @@ -102,6 +103,7 @@ class PollStateService ], $slides), 'index' => $index, 'count' => count($slides), + 'hiddenCount' => $this->Slides->find()->where(['poll_id' => $poll->id, 'is_hidden' => true])->count(), 'slide' => $current ? $this->slidePayload($current) : null, 'results' => $current ? $this->results->forSlide($current) : null, ]; @@ -123,6 +125,7 @@ class PollStateService return [ 'poll' => $this->pollPayload($poll), 'isLive' => $poll->current_slide_id === $slide->id, + 'isHidden' => $slide->is_hidden, 'index' => null, 'count' => null, 'slide' => $this->slidePayload($slide), diff --git a/src/Service/ReportService.php b/src/Service/ReportService.php index 03c923b..5d8b806 100644 --- a/src/Service/ReportService.php +++ b/src/Service/ReportService.php @@ -16,7 +16,7 @@ use Cake\ORM\Locator\LocatorAwareTrait; * screen. With $includeInternal it also contains their answers, distribution and comments – * that version is meant for the poll owner only. * - * Per slide: ['slide' => Slide, 'number' => int (position in the poll, 1-based), + * Per slide: ['slide' => Slide, 'number' => int (position in the presentation, 1-based; hidden slides are left out), * 'internal' => bool (private slide), 'withheld' => bool (private and left out), * 'results' => ResultsService::forSlide() shape, where * open: 'answers' contains all texts (not only the newest ones), and @@ -49,7 +49,7 @@ class ReportService */ public function build(Poll $poll, bool $includeInternal): array { - $slides = $this->Slides->listForPoll($poll->id); + $slides = $this->Slides->listForPoll($poll->id, true); $includeInternal = $includeInternal && array_filter($slides, fn(Slide $slide) => $slide->isInteractive() && $slide->isPrivate()) !== []; $sections = []; diff --git a/templates/Admin/index.php b/templates/Admin/index.php index 18d38f6..8f0ab8f 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -15,7 +15,7 @@ $this->assign('title', $poll->title); $this->assign('noindex', '1'); $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $adminToken] + $params; -$hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $slide->isPrivate()) !== []; +$hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide->isInteractive() && $slide->isPrivate()) !== []; ?>
@@ -72,7 +72,7 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s $isCurrent = $poll->current_slide_id === $slide->id; $count = $responseCounts[$slide->id] ?? 0; ?> -
  • +
  • +

    $label) : ?> - + @@ -244,9 +246,9 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-

    - Form->postLink(__('Neue Einbett-Links erzeugen'), $url('admin:rotate-embed'), [ + Form->postButton(__('Neue Einbett-Links erzeugen'), $url('admin:rotate-embed'), [ 'class' => 'button button--small', - 'confirm' => __('Neue Einbett-Links erzeugen? Alle bisher eingebetteten Folien funktionieren danach nicht mehr.'), + 'data-confirm' => __('Neue Einbett-Links erzeugen? Alle bisher eingebetteten Folien funktionieren danach nicht mehr.'), ]) ?> @@ -279,18 +281,18 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-

    - Form->postLink(__('Neuen Admin-Link erzeugen'), $url('admin:rotate'), [ + Form->postButton(__('Neuen Admin-Link erzeugen'), $url('admin:rotate'), [ 'class' => 'button button--small', - 'confirm' => __('Neuen Admin-Link erzeugen? Der aktuelle Link funktioniert danach nicht mehr.'), + 'data-confirm' => __('Neuen Admin-Link erzeugen? Der aktuelle Link funktioniert danach nicht mehr.'), ]) ?>

    Html->link(__('Ergebnisse vorher als PDF sichern'), '#export') ?>

    - Form->postLink(__('Alle Antworten löschen'), $url('admin:reset'), [ + Form->postButton(__('Alle Antworten löschen'), $url('admin:reset'), [ 'class' => 'button button--small button--danger', - 'confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'), + 'data-confirm' => __('Alle Antworten aller Folien unwiderruflich löschen?'), ]) ?>

    @@ -308,3 +310,10 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide-
    + + + + +
    +
    diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 3927f82..3924b2b 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -26,9 +26,9 @@ $optionsError = $slide->getError('options_text'); ?>

    ← title)) ?>

    -
    +

    typeLabel()) ?>

    -

    +

    Form->create($slide, ['url' => $formUrl]) ?> Form->hidden('type') ?> @@ -337,7 +337,7 @@ $optionsError = $slide->getError('options_text');
    Form->button($isNew ? __('Folie anlegen') : __('Speichern'), ['class' => 'button button--primary']) ?> - +
    Form->end() ?>
    diff --git a/templates/layout/default.php b/templates/layout/default.php index 5a136cb..652a2a7 100644 --- a/templates/layout/default.php +++ b/templates/layout/default.php @@ -36,7 +36,7 @@ $title = $this->fetch('title');
    - Flash->render() ?> +
    Flash->render() ?>
    fetch('content') ?>
    diff --git a/templates/layout/fragment.php b/templates/layout/fragment.php new file mode 100644 index 0000000..70bca6d --- /dev/null +++ b/templates/layout/fragment.php @@ -0,0 +1,10 @@ + +
    Flash->render() ?>
    +fetch('content') ?> diff --git a/tests/TestCase/Controller/AdminFragmentTest.php b/tests/TestCase/Controller/AdminFragmentTest.php new file mode 100644 index 0000000..a1968f9 --- /dev/null +++ b/tests/TestCase/Controller/AdminFragmentTest.php @@ -0,0 +1,105 @@ + + */ + protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses']; + + protected function setUp(): void + { + parent::setUp(); + $this->enableCsrfToken(); + } + + public function testFragmentContainsRegionsButNoPageFrame(): void + { + [$poll, $token] = $this->createPoll(); + $this->createSlide($poll, Slide::TYPE_CHOICE); + + $this->configRequest(['headers' => ['X-Fragment' => '1']]); + $this->get("/admin/$token"); + + $this->assertResponseOk(); + $this->assertResponseContains('data-refresh="slides"'); + $this->assertResponseContains('data-refresh="head"'); + $this->assertResponseContains('data-refresh="flash"'); + $this->assertResponseNotContains('assertResponseNotContains('site-header'); + } + + public function testFullPageKeepsFrameAndRegions(): void + { + [$poll, $token] = $this->createPoll(); + $this->createSlide($poll, Slide::TYPE_CHOICE); + + $this->get("/admin/$token"); + + $this->assertResponseContains('assertResponseContains('data-refresh="flash"'); + $this->assertResponseContains('createPoll(); + $this->createSlide($poll, Slide::TYPE_CHOICE); + + $this->get("/admin/$token"); + + $this->assertResponseNotContains('onclick='); + $this->assertResponseContains('data-confirm='); + } + + public function testSlideFormFragmentIsTheDialogContent(): void + { + [$poll, $token] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_OPEN); + + $this->configRequest(['headers' => ['X-Fragment' => '1']]); + $this->get("/admin/$token/slides/{$slide->id}/edit"); + + $this->assertResponseOk(); + $this->assertResponseContains('data-modal-content'); + $this->assertResponseNotContains('site-header'); + } + + public function testValidationErrorKeepsTheFormInTheFragment(): void + { + [$poll, $token] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_OPEN); + + $this->configRequest(['headers' => ['X-Fragment' => '1']]); + $this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => '']); + + $this->assertResponseOk(); + $this->assertResponseContains('data-modal-content'); + $this->assertResponseContains('Bitte prüfe deine Eingaben.'); + } + + public function testSuccessfulSaveRedirectsToTheDashboard(): void + { + [$poll, $token] = $this->createPoll(); + $slide = $this->createSlide($poll, Slide::TYPE_OPEN); + + $this->configRequest(['headers' => ['X-Fragment' => '1']]); + $this->post("/admin/$token/slides/{$slide->id}/edit", ['question' => 'Neue Frage']); + + $this->assertRedirect(['_name' => 'admin', 'token' => $token]); + } +} diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index 9d04a1d..98a60b3 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -732,3 +732,17 @@ body.present { .theme-switch { display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-width: 40px; height: 40px; padding: 0 8px; border-radius: 8px; border: 1px solid var(--border); background: transparent; color: var(--text); font: inherit; font-size: .9rem; cursor: pointer; } .theme-switch:hover { border-color: var(--primary); } .theme-switch__icon { font-size: 1.3em; line-height: 1; } + +/* Slide form in a dialog (admin dashboard) */ +.modal { + width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: auto; + border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); + box-shadow: 0 20px 60px rgba(0, 0, 0, .35); +} +.modal::backdrop { background: rgba(10, 12, 30, .55); } +.modal .card--form { max-width: none; margin: 0; border: 0; box-shadow: none; background: transparent; } +.modal__close { position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; z-index: 1; } +.modal .message { margin: 16px 16px 0; cursor: default; } +body:has(dialog[open]) { overflow: hidden; } +.slide-item__actions form { display: contents; } +.slide-item__actions button:disabled, .admin-head__actions button:disabled { opacity: .6; cursor: progress; } diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index bffae1b..daad828 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -13,6 +13,10 @@ * - [data-sortable] admin slide list: drag & drop / arrow keys via [data-drag-handle], POSTs ids[] to the URL * - [data-order-options] slide form of ordering slides: sortable rows (correct order), "add entry" * - [data-order-form] participant answer of ordering slides: sortable items posting order[] + * - [data-live] admin dashboard: forms inside (hide, delete, duplicate, …) run via fetch and refresh + * the [data-refresh] regions instead of reloading the page (header X-Fragment) + * - [data-modal] link whose target page (slide form) opens in the + * - [data-confirm] on a submit button: window.confirm() before the form is sent (replaces inline onclick, CSP) * - [data-theme-switch] cycles the colour scheme (data-theme on , stored in localStorage), * see templates/element/theme_init.php for the pre-paint part * @@ -1127,8 +1131,8 @@ } } - function initCopy() { - document.querySelectorAll('[data-copy]').forEach(function (button) { + function initCopy(root) { + (root || document).querySelectorAll('[data-copy]').forEach(function (button) { button.addEventListener('click', function () { copyFrom(button); }); }); } @@ -2485,8 +2489,228 @@ button.hidden = false; } + // ------------------------------------------------------------------ admin dashboard without reloads + + /** + * Loads server-rendered admin pages as fragments (layout "fragment": content + flash only) + * and merges them into the open page. The HTML comes from our own templates (escaped there); + * it is adopted as DOM nodes, never written with innerHTML. + */ + var Fragments = { + request: function (url, options) { + options = options || {}; + return fetch(url, { + method: options.method || 'GET', + body: options.body, + credentials: 'same-origin', + cache: 'no-store', + headers: { Accept: 'text/html', 'X-Fragment': '1', 'X-CSRF-Token': csrfToken() } + }).then(function (response) { + if (!response.ok) { + throw new Error('HTTP ' + response.status); + } + return response.text(); + }).then(function (html) { + return new DOMParser().parseFromString(html, 'text/html'); + }); + }, + + /** Replaces the [data-refresh] regions (all, or only `names`) with those of `doc`. */ + apply: function (doc, names) { + doc.querySelectorAll('[data-refresh]').forEach(function (fresh) { + var name = fresh.getAttribute('data-refresh'); + var old = document.querySelector('[data-refresh="' + name + '"]'); + if (!old || (names && names.indexOf(name) < 0)) { + return; + } + var node = document.importNode(fresh, true); + old.replaceWith(node); + initWidgets(node); + }); + }, + + /** Shows an error where the user is looking (dialog or flash area). */ + fail: function (container, text) { + var message = el('div', { class: 'message error', role: 'alert', 'data-dismiss': '', text: text }); + container.insertBefore(message, container.firstChild); + } + }; + + function initAdminDashboard() { + var dialog = document.querySelector('[data-modal-dialog]'); + var body = dialog ? dialog.querySelector('[data-modal-body]') : null; + var dirty = false; + var focusId = null; + + function flashArea() { + return document.querySelector('[data-refresh="flash"]') || document.body; + } + + /** Keeps the keyboard position after a list refresh: same button, else the slide, else the next slide. */ + function restoreFocus(target) { + if (!target) { + return; + } + var item = target.id ? document.querySelector('[data-slide-id="' + target.id + '"]') : null; + var node = null; + if (item) { + node = (target.action && item.querySelector('form[action="' + target.action + '"] button')) + || item.querySelector('.slide-item__title'); + } else if (target.nextId) { + node = document.querySelector('[data-slide-id="' + target.nextId + '"] .slide-item__title'); + } + if (node) { + node.focus(); + } + } + + function refreshList() { + return Fragments.request(window.location.href).then(function (doc) { + Fragments.apply(doc, ['head', 'slides']); + }); + } + + function openModal(doc) { + var content = doc.querySelector('[data-modal-content]'); + var flash = doc.querySelector('[data-refresh="flash"]'); + body.replaceChildren(); + if (flash && flash.childNodes.length) { + // Shown inside the dialog (validation errors), not as flash of the page behind it. + var notes = document.importNode(flash, true); + notes.removeAttribute('data-refresh'); + body.appendChild(notes); + } + body.appendChild(document.importNode(content, true)); + initWidgets(body); + dirty = false; + if (!dialog.open) { + dialog.showModal(); + } + dialog.scrollTop = 0; + } + + function requestClose() { + if (dirty && !window.confirm('Änderungen verwerfen?')) { + return; + } + dialog.close(); + } + + /** Result of a POST: either the dashboard (done) or a form (open in the dialog). */ + function handle(doc, source) { + if (doc.querySelector('[data-modal-content]')) { + // A form: validation errors (dialog stays open) or the copy of a duplicated slide. + var wasOpen = dialog.open; + openModal(doc); + + return wasOpen ? null : refreshList(); + } + Fragments.apply(doc); + if (dialog && dialog.open) { + dirty = false; + dialog.close(); + } + restoreFocus(source); + + return null; + } + + document.addEventListener('submit', function (event) { + var form = event.target; + var submitter = event.submitter || form.querySelector('button[type=submit], button:not([type])'); + var confirmText = submitter && submitter.getAttribute('data-confirm'); + if (confirmText && !window.confirm(confirmText)) { + event.preventDefault(); + return; + } + var inDialog = dialog !== null && dialog.contains(form); + if (!inDialog && !form.closest('[data-live]')) { + return; // plain form: normal navigation + } + event.preventDefault(); + if (form.hasAttribute('aria-busy')) { + return; + } + var item = form.closest('[data-slide-id]'); + var next = item ? item.nextElementSibling : null; + var source = inDialog ? { id: focusId } : { + id: item ? item.getAttribute('data-slide-id') : null, + action: form.getAttribute('action'), + nextId: next ? next.getAttribute('data-slide-id') : null + }; + form.setAttribute('aria-busy', 'true'); + if (submitter) { + submitter.disabled = true; + } + Fragments.request(form.action, { method: 'POST', body: new FormData(form) }) + .then(function (doc) { return handle(doc, source); }) + .catch(function () { + form.removeAttribute('aria-busy'); + if (submitter) { + submitter.disabled = false; + } + Fragments.fail(inDialog ? body : flashArea(), 'Das hat nicht geklappt. Bitte lade die Seite neu und versuche es noch einmal.'); + }); + }); + + if (!dialog) { + return; + } + + document.addEventListener('click', function (event) { + var link = event.target.closest ? event.target.closest('a[data-modal]') : null; + if (!link || event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { + return; + } + event.preventDefault(); + var item = link.closest('[data-slide-id]'); + focusId = item ? item.getAttribute('data-slide-id') : null; + Fragments.request(link.href).then(openModal).catch(function () { + window.location.href = link.href; // no dialog possible: open the page as usual + }); + }); + + dialog.addEventListener('click', function (event) { + if (event.target.closest('[data-modal-close]')) { + event.preventDefault(); + requestClose(); + } + }); + + // Only a click that starts and ends on the backdrop closes (not a text selection dragged outside). + var pressedOnBackdrop = false; + dialog.addEventListener('mousedown', function (event) { pressedOnBackdrop = event.target === dialog; }); + dialog.addEventListener('click', function (event) { + if (event.target === dialog && pressedOnBackdrop) { + requestClose(); + } + }); + + dialog.addEventListener('cancel', function (event) { + if (dirty && !window.confirm('Änderungen verwerfen?')) { + event.preventDefault(); + } + }); + dialog.addEventListener('close', function () { + body.replaceChildren(); + dirty = false; + }); + body.addEventListener('input', function () { dirty = true; }); + body.addEventListener('change', function () { dirty = true; }); + } + // ------------------------------------------------------------------ boot + /** Initialises the widgets inside `root` (the whole page at boot, or a freshly inserted fragment). */ + function initWidgets(root) { + initCopy(root); + root.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm); + root.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions); + root.querySelectorAll('[data-sortable]').forEach(initSortable); + root.querySelectorAll('[data-order-options]').forEach(initOrderOptions); + root.querySelectorAll('[data-scale-style]').forEach(initScaleStyle); + } + // Flash messages: click hides them (delegated, no inline handlers because of the CSP). document.addEventListener('click', function (event) { var message = event.target.closest ? event.target.closest('[data-dismiss]') : null; @@ -2497,16 +2721,12 @@ document.addEventListener('DOMContentLoaded', function () { document.querySelectorAll('[data-theme-switch]').forEach(initThemeSwitch); - initCopy(); + initWidgets(document); initShare(); - document.querySelectorAll('[data-youtube-form]').forEach(initYouTubeForm); + initAdminDashboard(); document.querySelectorAll('[data-presenter]').forEach(initPresenter); document.querySelectorAll('[data-participant]').forEach(initParticipant); - document.querySelectorAll('[data-quiz-options]').forEach(initQuizOptions); - document.querySelectorAll('[data-sortable]').forEach(initSortable); - document.querySelectorAll('[data-order-options]').forEach(initOrderOptions); document.querySelectorAll('[data-order-form]').forEach(initOrderForm); - document.querySelectorAll('[data-scale-style]').forEach(initScaleStyle); // Prevent double submits of vote forms. document.querySelectorAll('.vote-form').forEach(function (form) { From fcf52923a7a9620bf3001f8f455b0ca9e7450fdd Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 20:35:51 +0100 Subject: [PATCH 09/11] Place the dialog close button on the outer corner The close button no longer covers form fields: the dialog does not scroll itself, an inner panel does, and the button sits on the corner. Co-Authored-By: Claude Sonnet 5.5 --- templates/Admin/index.php | 6 ++++-- webroot/css/plenario.css | 20 +++++++++++++++----- webroot/js/plenario.js | 2 +- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/templates/Admin/index.php b/templates/Admin/index.php index 329dae3..1dccab9 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -313,7 +313,9 @@ $hasInternal = array_filter($slides, fn($slide) => !$slide->is_hidden && $slide- - -
    +
    diff --git a/webroot/css/plenario.css b/webroot/css/plenario.css index 98a60b3..9a50768 100644 --- a/webroot/css/plenario.css +++ b/webroot/css/plenario.css @@ -734,14 +734,24 @@ body.present { .theme-switch__icon { font-size: 1.3em; line-height: 1; } /* Slide form in a dialog (admin dashboard) */ -.modal { - width: min(720px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); padding: 0; overflow: auto; - border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text); +/* The dialog itself does not scroll (overflow visible), so the close button can sit on its outer corner; + the inner panel carries border, background and scrolling. */ +.modal { width: min(720px, calc(100vw - 24px)); padding: 0; border: 0; background: transparent; color: var(--text); overflow: visible; } +.modal::backdrop { background: rgba(10, 12, 30, .55); } +.modal__panel { + max-height: calc(100dvh - 24px); overflow: auto; + border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); box-shadow: 0 20px 60px rgba(0, 0, 0, .35); } -.modal::backdrop { background: rgba(10, 12, 30, .55); } .modal .card--form { max-width: none; margin: 0; border: 0; box-shadow: none; background: transparent; } -.modal__close { position: sticky; top: 8px; float: right; margin: 8px 8px 0 0; z-index: 1; } +.modal__close { + position: absolute; top: -14px; right: -14px; z-index: 1; width: 36px; height: 36px; padding: 0; + display: grid; place-items: center; border: 1px solid var(--border); border-radius: 50%; + background: var(--surface); color: var(--text); font-size: 1rem; line-height: 1; cursor: pointer; + box-shadow: var(--shadow); +} +.modal__close:hover { background: var(--surface-2); } +.modal__close:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; } .modal .message { margin: 16px 16px 0; cursor: default; } body:has(dialog[open]) { overflow: hidden; } .slide-item__actions form { display: contents; } diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index daad828..94a4e58 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -2586,7 +2586,7 @@ if (!dialog.open) { dialog.showModal(); } - dialog.scrollTop = 0; + dialog.querySelector('[data-modal-panel]').scrollTop = 0; } function requestClose() { From c75f3113246ef951a61024e053adec35d55d6f5b Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 20:49:25 +0100 Subject: [PATCH 10/11] Add Docker image, entrypoint, compose example and registry build workflow Co-Authored-By: Claude Sonnet 5.5 --- .dockerignore | 16 +++++++++++++ .gitea/workflows/docker.yml | 46 +++++++++++++++++++++++++++++++++++++ AGENTS.md | 10 ++++++++ Dockerfile | 40 ++++++++++++++++++++++++++++++++ README.md | 14 +++++++++++ docker-compose.yml | 15 ++++++++++++ docker/entrypoint.sh | 16 +++++++++++++ 7 files changed, 157 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitea/workflows/docker.yml create mode 100644 Dockerfile create mode 100644 docker-compose.yml create mode 100644 docker/entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c912c95 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,16 @@ +.git +.gitea +.gitattributes +.phpunit.cache +.claude +vendor +tmp +logs +data +tests +config/app_local.php +config/.env +.env +CLAUDE.local.md +Dockerfile +docker-compose.yml diff --git a/.gitea/workflows/docker.yml b/.gitea/workflows/docker.yml new file mode 100644 index 0000000..bb33172 --- /dev/null +++ b/.gitea/workflows/docker.yml @@ -0,0 +1,46 @@ +# Container image build (Gitea Actions): builds the Dockerfile and pushes it to the Gitea registry +# on every push to main (main is protected: only merged PRs with green tests land there). +# +# Repository variables (Settings → Actions → Variables): +# DOCKER_REPO registry host, e.g. gitea.gnilebein.de +# IMAGE_NAME image name, e.g. plenario +# Repository secrets: +# PAT personal access token with package write permission +# +# Image: ${DOCKER_REPO}/${owner}/${IMAGE_NAME}:latest and : +name: Container Image + +on: + push: + branches: + - main + workflow_dispatch: + +jobs: + docker-build-image: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v6 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + + - name: Login to registry + uses: docker/login-action@v4 + with: + registry: ${{ vars.DOCKER_REPO }} + username: ${{ gitea.actor }} + password: ${{ secrets.PAT }} + + - name: Build and push + uses: docker/build-push-action@v6 + with: + file: ./Dockerfile + platforms: linux/amd64 + pull: true + push: true + provenance: false + tags: | + ${{ vars.DOCKER_REPO }}/${{ gitea.repository_owner }}/${{ vars.IMAGE_NAME }}:latest + ${{ vars.DOCKER_REPO }}/${{ gitea.repository_owner }}/${{ vars.IMAGE_NAME }}:${{ gitea.sha }} diff --git a/AGENTS.md b/AGENTS.md index 88cd67d..f6b2d0f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -314,6 +314,16 @@ Deploy erfolgt über Git (Remote: Gitea) mit `.gitea/workflows/ci.yml`: - Benötigte Variablen/Secrets sind im Kopf der Workflow-Datei dokumentiert. Zugangsdaten nur als Gitea-Secret, nie ins Repo. +**Container (Docker):** `Dockerfile` (`php:8.5-cli-alpine`, Multi-Stage mit Composer) startet über +`docker/entrypoint.sh` den eingebauten Server (`bin/cake server -H 0.0.0.0 -p 8765`, `PHP_CLI_SERVER_WORKERS=8`, +sonst bedient er nur einen Request gleichzeitig). Code in `/app`, SQLite in Volume `/data` +(`DATABASE_URL=sqlite:////data/plenario.sqlite`), Konfiguration nur per Umgebungsvariablen (`config/.env.example`). +`SECURITY_SALT` ist Pflicht (Entrypoint bricht sonst ab; `composer install --no-scripts`, damit kein Salt eingebrannt wird). +Der Start ist idempotent (Migrationen + `cache clear_all`). Der Healthcheck prüft eine statische Datei, weil die Host-Prüfung +(`APP_FULL_BASE_URL`) `127.0.0.1` auf echten Seiten mit 400 ablehnt. Betrieb hinter einem TLS-Proxy mit `X-Forwarded-Proto`. +`.gitea/workflows/docker.yml` baut bei Push auf `main` und pusht `:latest` + `:` in die Gitea-Registry +(Variablen `DOCKER_REPO`, `IMAGE_NAME`, Secret `PAT`). Beispiel: `docker-compose.yml`. + Produktiv auf dem Server in `config/.env`: `DEBUG=false`, `APP_FULL_BASE_URL`, `SECURITY_SALT`, SMTP. Ohne `DEBUG=false` steht die per Composer erzeugte `app_local.php` auf debug=true und zeigt Admin-Links direkt an. Document-Root zeigt idealerweise auf `webroot/`; liegt die App direkt im Document-Root (z. B. `public_html`), diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5f7b8fa --- /dev/null +++ b/Dockerfile @@ -0,0 +1,40 @@ +# PlenarIO container: PHP's built-in server via `bin/cake server`, app in /app, SQLite in /data. +# Configuration only through environment variables (see config/.env.example). + +FROM php:8.5-cli-alpine AS base +RUN apk add --no-cache icu-libs \ + && apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev \ + && docker-php-ext-install -j"$(nproc)" intl \ + && apk del .build-deps + +FROM base AS build +COPY --from=composer:2 /usr/bin/composer /usr/bin/composer +WORKDIR /app +COPY composer.json composer.lock ./ +# --no-scripts: the installer must not bake a random salt into app_local.php (SECURITY_SALT comes at runtime) +RUN composer install --no-dev --no-scripts --no-progress --prefer-dist --optimize-autoloader +COPY . . +RUN composer dump-autoload --no-dev --optimize \ + && cp config/app_local.example.php config/app_local.php + +FROM base +WORKDIR /app +COPY --from=build /app /app +COPY docker/entrypoint.sh /usr/local/bin/plenario-entrypoint + +ENV DEBUG=false \ + SHOW_ADMIN_LINK_AFTER_CREATE=false \ + DATABASE_URL=sqlite:////data/plenario.sqlite \ + PHP_CLI_SERVER_WORKERS=8 + +RUN chmod +x /usr/local/bin/plenario-entrypoint \ + && mkdir -p /data /app/tmp /app/logs \ + && chown -R www-data:www-data /data /app/tmp /app/logs + +USER www-data +VOLUME /data +EXPOSE 8765 +# static file: the Host-header check (APP_FULL_BASE_URL) would reject 127.0.0.1 on real pages +HEALTHCHECK --interval=30s --timeout=5s --start-period=20s \ + CMD wget -q -O /dev/null http://127.0.0.1:8765/css/plenario.css || exit 1 +ENTRYPOINT ["plenario-entrypoint"] diff --git a/README.md b/README.md index d65aab3..8aa6755 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,20 @@ stehen im Kopf der Workflow-Datei. Einmalig auf dem Server: `config/.env` anlege Liegt die App direkt im Document-Root (z. B. `public_html`), leiten `.htaccess` und `index.php` im Projektroot alles nach `webroot/` weiter. +**Container:** Das [Dockerfile](Dockerfile) baut ein schlankes Image (`php:8.5-cli-alpine`, eingebauter Server auf Port 8765). +Der Workflow [.gitea/workflows/docker.yml](.gitea/workflows/docker.yml) pusht es bei jedem Push auf `main` in die Gitea-Registry. + +```bash +docker run -d -p 8765:8765 -v plenario-data:/data \ + -e SECURITY_SALT="$(php -r 'echo bin2hex(random_bytes(32));')" \ + -e APP_FULL_BASE_URL=https://plenario.example.org \ + gitea.gnilebein.de/gnilebein/plenario:latest +``` + +Die Datenbank liegt im Volume `/data`; weitere Einstellungen (SMTP, Captcha, …) als Umgebungsvariablen +(siehe `config/.env.example`, Beispiel in `docker-compose.yml`). Beim Start laufen die Migrationen automatisch. +Vor einen TLS-Proxy schalten, der `X-Forwarded-Proto` setzt. + Live-Updates laufen über kurzes Polling (Standard alle 2 s) – kein WebSocket-Server nötig. Für sehr große Runden (mehrere hundert Teilnehmende) `POLL_INTERVAL_MS` erhöhen und MySQL/PostgreSQL statt SQLite verwenden. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..df0ffc2 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,15 @@ +# Example: docker compose up -d +# Put it behind a TLS reverse proxy that sets X-Forwarded-Proto; APP_FULL_BASE_URL = public URL. +services: + plenario: + image: gitea.gnilebein.de/gnilebein/plenario:latest + # build: . + restart: unless-stopped + ports: + - "8765:8765" + env_file: .env # SECURITY_SALT, APP_FULL_BASE_URL, MAIL_FROM, EMAIL_TRANSPORT_DEFAULT_URL, ... + volumes: + - plenario-data:/data + +volumes: + plenario-data: diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh new file mode 100644 index 0000000..473c2d0 --- /dev/null +++ b/docker/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Idempotent start: prepare writable dirs, migrate the database, then run the built-in server. +set -eu + +cd /app +mkdir -p tmp/cache tmp/sessions tmp/mails tmp/dompdf logs + +if [ -z "${SECURITY_SALT:-}" ] || [ "${SECURITY_SALT}" = "__SALT__" ]; then + echo "SECURITY_SALT is not set. Generate one with: php -r \"echo bin2hex(random_bytes(32));\"" >&2 + exit 1 +fi + +php bin/cake.php migrations migrate +php bin/cake.php cache clear_all + +exec php bin/cake.php server -H 0.0.0.0 -p "${PORT:-8765}" From 95bcd6b14dbda6ce2c271c8bd1a54f25e669cf17 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Wed, 11 Nov 2026 22:07:31 +0100 Subject: [PATCH 11/11] chore: test signed commit
    #