diff --git a/AGENTS.md b/AGENTS.md index 9e048d4..a113ae7 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -93,7 +93,7 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures `join_code` (6 Zeichen, ohne 0/O/1/I/L), `current_slide_id`, `is_active`, `last_admin_access` (höchstens alle 10 min aktualisiert, Grundlage für ein künftiges Aufräumen alter Umfragen), `embed_key` (Einbett-Schlüssel), `embed_seen_at` (letztes Lebenszeichen der eingebetteten Live-Folie), - `paused_slide_id` (Folie vor der Pause) + `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`, `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), @@ -221,8 +221,9 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures - **Skala-Kommentare** (Setting `comments`, `Slide::hasComments()`): optionales Feld `comment`, gespeichert als `text_value` in derselben Zeile wie `numeric_value` (ohne Setting wird es ignoriert). Öffentliche Skalen liefern im Presenter-/Embed-State `results.comments` (Teilnehmende bekommen sie nie: Skalen liefern ihnen grundsätzlich keine `results`, siehe `PollStateService::forParticipant()`) - (älteste zuerst, je `id`, `text`, `value` – `value` nur mit Setting `comment_ratings`, sonst `null`); `Comments` in `plenario.js` blättert sie automatisch durch (Anzeigedauer nur nach Textlänge, bewusst ohne Setting: -`Comments.delay()` = 2,5 s + 15 Zeichen/s, 5–30 s; Vor/Zurück/Fortsetzen geben dem Kommentar wieder die volle Zeit; „Kommentar X von N“, + (älteste zuerst, je `id`, `text`, `value` – `value` nur mit Setting `comment_ratings`, sonst `null`); `Comments` in `plenario.js` blättert sie automatisch durch (Anzeigedauer nach Textlänge, kein Setting pro Folie: +`Comments.delay()` = 2,5 s + 15 Zeichen/s, 5–30 s, geteilt durch das Tempo der Umfrage `polls.comment_speed` (Prozent aus +`Poll::COMMENT_SPEEDS`, im State `poll.commentSpeed` als Faktor, Dashboard → „Einstellungen“); Vor/Zurück/Fortsetzen geben dem Kommentar wieder die volle Zeit; „Kommentar X von N“, vor/zurück/Pause, Laufbalken bis zum Wechsel (`Comments.progress()`, setzt nach dem Neu-Rendern per negativem `animation-delay` fort, bei Pause unsichtbar), Zustand übersteht das Neu-Rendern beim Polling). Bei internem Feedback erscheinen sie erst, wenn der Presenter die Ergebnisse einblendet. diff --git a/config/Migrations/20261111120000_AddCommentSpeedToPolls.php b/config/Migrations/20261111120000_AddCommentSpeedToPolls.php new file mode 100644 index 0000000..92bcba1 --- /dev/null +++ b/config/Migrations/20261111120000_AddCommentSpeedToPolls.php @@ -0,0 +1,37 @@ +table('polls'); + if (!$table->hasColumn('comment_speed')) { + $table->addColumn('comment_speed', 'integer', [ + 'null' => false, + 'default' => 100, + 'after' => 'is_active', + ])->update(); + } + } + + /** + * @return void + */ + public function down(): void + { + $table = $this->table('polls'); + if ($table->hasColumn('comment_speed')) { + $table->removeColumn('comment_speed')->update(); + } + } +} diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index de406ac..883c35c 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -69,7 +69,7 @@ class AdminController extends AdminAppController { $this->request->allowMethod(['post']); $this->Polls->patchEntity($this->poll, (array)$this->request->getData(), [ - 'fields' => ['title', 'is_active'], + 'fields' => ['title', 'is_active', 'comment_speed'], ]); if ($this->Polls->save($this->poll)) { $this->Flash->success(__('Einstellungen gespeichert.')); diff --git a/src/Model/Entity/Poll.php b/src/Model/Entity/Poll.php index f413a54..407c111 100644 --- a/src/Model/Entity/Poll.php +++ b/src/Model/Entity/Poll.php @@ -18,6 +18,7 @@ use Cake\ORM\Entity; * @property \Cake\I18n\DateTime|null $embed_seen_at * @property int|null $paused_slide_id * @property bool $is_active + * @property int $comment_speed Speed of rotating scale comments in percent, see COMMENT_SPEEDS * @property \Cake\I18n\DateTime|null $last_admin_access * @property \Cake\I18n\DateTime $created * @property \Cake\I18n\DateTime $modified @@ -25,6 +26,14 @@ use Cake\ORM\Entity; */ class Poll extends Entity { + /** + * Selectable speeds of the rotating scale comments in percent: 100 = normal, + * below = each comment stays longer, above = shorter (see Comments.delay() in plenario.js). + * + * @var list + */ + public const COMMENT_SPEEDS = [50, 75, 100, 125, 150, 200]; + /** * Only harmless fields are mass assignable. Tokens, join code and the * current slide are always set explicitly in code. @@ -35,6 +44,7 @@ class Poll extends Entity 'title' => true, 'email' => true, 'is_active' => true, + 'comment_speed' => true, ]; /** diff --git a/src/Model/Table/PollsTable.php b/src/Model/Table/PollsTable.php index 1157d49..bc1f329 100644 --- a/src/Model/Table/PollsTable.php +++ b/src/Model/Table/PollsTable.php @@ -74,6 +74,10 @@ class PollsTable extends Table $validator->boolean('is_active'); + $validator + ->integer('comment_speed') + ->inList('comment_speed', Poll::COMMENT_SPEEDS, __('Bitte wähle eine der angebotenen Geschwindigkeiten.')); + return $validator; } diff --git a/src/Service/PollStateService.php b/src/Service/PollStateService.php index f4b87a9..55a7a61 100644 --- a/src/Service/PollStateService.php +++ b/src/Service/PollStateService.php @@ -361,6 +361,8 @@ class PollStateService 'joinCodeFormatted' => $poll->formattedJoinCode(), 'isActive' => $poll->is_active, 'isPaused' => $poll->isPaused(), + // Factor for the rotating scale comments on stage (1 = normal, 2 = twice as fast) + 'commentSpeed' => ($poll->comment_speed ?? 100) / 100, ]; } diff --git a/templates/Admin/index.php b/templates/Admin/index.php index b5781ac..e3bb1b9 100644 --- a/templates/Admin/index.php +++ b/templates/Admin/index.php @@ -228,6 +228,20 @@ $hasInternal = array_filter($slides, fn($slide) => $slide->isInteractive() && $s 'type' => 'checkbox', 'label' => __('Umfrage ist aktiv (Teilnehmende können abstimmen)'), ]) ?> + Form->control('comment_speed', [ + 'type' => 'select', + 'label' => __('Tempo der Kommentare in der Präsentation'), + 'options' => [ + 50 => __('Viel langsamer (doppelt so lange)'), + 75 => __('Langsamer'), + 100 => __('Normal'), + 125 => __('Schneller'), + 150 => __('Deutlich schneller'), + 200 => __('Sehr schnell (halb so lange)'), + ], + 'aria-describedby' => 'comment-speed-hint', + ]) ?> +

Form->button(__('Speichern'), ['class' => 'button']) ?> Form->end() ?> diff --git a/templates/Slides/form.php b/templates/Slides/form.php index 536968f..28cd2c9 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -182,7 +182,7 @@ $optionsError = $slide->getError('options_text'); 'label' => __('Kommentarfeld anzeigen (Teilnehmende können ihre Bewertung optional begründen)'), 'checked' => (bool)$settings['comments'], ]) ?> -

+

Form->control('settings.comment_ratings', [ 'type' => 'checkbox', 'label' => __('Bewertung beim Kommentar in der Präsentation anzeigen'), diff --git a/tests/TestCase/Controller/AdminControllerTest.php b/tests/TestCase/Controller/AdminControllerTest.php index 4fed605..1668ef4 100644 --- a/tests/TestCase/Controller/AdminControllerTest.php +++ b/tests/TestCase/Controller/AdminControllerTest.php @@ -62,6 +62,27 @@ class AdminControllerTest extends TestCase $this->assertSame('Neu', $this->pollsTable()->get($poll->id)->title); } + public function testCommentSpeedIsSavedAndSentToThePresenter(): void + { + [$poll, $token] = $this->createPoll(); + $this->get("/admin/$token/state"); + $this->assertEquals(1, json_decode((string)$this->_response->getBody(), true)['poll']['commentSpeed']); + + $this->post("/admin/$token/settings", ['title' => 'Testumfrage', 'is_active' => '1', 'comment_speed' => '150']); + $this->assertSame(150, $this->pollsTable()->get($poll->id)->comment_speed); + + $this->get("/admin/$token/state"); + $this->assertEquals(1.5, json_decode((string)$this->_response->getBody(), true)['poll']['commentSpeed']); + } + + public function testInvalidCommentSpeedIsRejected(): void + { + [$poll, $token] = $this->createPoll(); + + $this->post("/admin/$token/settings", ['title' => 'Testumfrage', 'is_active' => '1', 'comment_speed' => '1000']); + $this->assertSame(100, $this->pollsTable()->get($poll->id)->comment_speed); + } + public function testTokenOfOtherPollCannotAccessSlides(): void { [$pollA] = $this->createPoll('A'); diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 95fc7c3..4fbcdfa 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -303,6 +303,8 @@ timer: null, items: [], format: String, + // Speed factor of the poll (state.poll.commentSpeed): 2 = half the time per comment. + speed: 1, node: null, // Countdown of the comment shown (drives the progress bar across re-renders). startedAt: 0, @@ -392,7 +394,9 @@ delay: function (item) { var length = item && item.text ? Array.from(item.text).length : 0; var ms = Comments.BASE_MS + length / Comments.CHARS_PER_SECOND * 1000; - return Math.round(Math.min(Comments.MAX_MS, Math.max(Comments.MIN_MS, ms))); + // The poll's speed factor scales the bounds too, so short comments change as well. + var speed = Comments.speed > 0 ? Comments.speed : 1; + return Math.round(Math.min(Comments.MAX_MS, Math.max(Comments.MIN_MS, ms)) / speed); }, /** (Re)start the countdown for the comment currently shown. */ @@ -1238,6 +1242,7 @@ container.appendChild(Results.privateSummary(state.results)); return; } + Comments.speed = state.poll && state.poll.commentSpeed; Results.render(container, slide && slide.isInteractive ? state.results : null, { onStage: function (stage) { control('stage', { stage: stage }); }, onQuestion: function (step) { control('question', { step: step }); }