From 05ff5967e38d04162375a47494ac04e7ff3f7ae2 Mon Sep 17 00:00:00 2001 From: Patrick Niebeling Date: Mon, 9 Nov 2026 14:10:06 +0100 Subject: [PATCH] Rotate scale comments by reading time Add an automatic comment interval (now the default) that keeps each comment on stage depending on its length: 2.5 s plus 15 characters per second, between 5 and 30 seconds. Fixed intervals remain selectable. Next, previous and resume give the current comment its full time again. Co-Authored-By: Claude Opus 5.5 --- AGENTS.md | 3 +- src/Model/Entity/Slide.php | 15 ++++-- src/Service/ResultsService.php | 2 +- templates/Slides/form.php | 8 ++- .../TestCase/Controller/ScaleCommentsTest.php | 12 +++-- webroot/js/plenario.js | 53 +++++++++++++------ 6 files changed, 68 insertions(+), 25 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 4ddad91..d1e3e56 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -201,7 +201,8 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures 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 (Sekunden pro Kommentar = Setting `comment_interval`, Auswahl -`Slide::COMMENT_INTERVALS`, Standard 8, im State als `results.commentInterval`; „Kommentar X von N“, +`Slide::COMMENT_INTERVALS`, im State als `results.commentInterval`; Standard `Slide::COMMENT_INTERVAL_AUTO` (0) = Lesezeit je nach +Textlänge, `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“, vor/zurück/Pause, Zustand übersteht das Neu-Rendern beim Polling). Bei internem Feedback erscheinen sie erst, wenn der Presenter die Ergebnisse einblendet. diff --git a/src/Model/Entity/Slide.php b/src/Model/Entity/Slide.php index fae229f..fe7e7ec 100644 --- a/src/Model/Entity/Slide.php +++ b/src/Model/Entity/Slide.php @@ -56,11 +56,18 @@ class Slide extends Entity public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300]; /** - * Selectable seconds per comment when the comments of a scale rotate in the presentation. + * Comment interval "automatic": the presentation derives the time per comment + * from its length (reading speed), see `Comments.delay()` in plenario.js. + */ + public const COMMENT_INTERVAL_AUTO = 0; + + /** + * Selectable seconds per comment when the comments of a scale rotate in the presentation + * (COMMENT_INTERVAL_AUTO = depending on the length of each comment). * * @var list */ - public const COMMENT_INTERVALS = [3, 5, 8, 10, 15, 20, 30, 45, 60]; + public const COMMENT_INTERVALS = [self::COMMENT_INTERVAL_AUTO, 3, 5, 8, 10, 15, 20, 30, 45, 60]; /** * Q&A stages, see qaStage(): participants submit questions, then upvote @@ -94,10 +101,10 @@ class Slide extends Entity // private: internal feedback, ratings only visible in the admin area (never on the stage) // comments: optional comment field, comments rotate in the presentation (unless private) // comment_ratings: show the rating next to each comment in the presentation - // comment_interval: seconds per comment while they rotate (one of COMMENT_INTERVALS) + // comment_interval: seconds per comment while they rotate (one of COMMENT_INTERVALS, 0 = by length) self::TYPE_SCALE => [ 'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false, - 'comments' => false, 'comment_ratings' => false, 'comment_interval' => 8, + 'comments' => false, 'comment_ratings' => false, 'comment_interval' => self::COMMENT_INTERVAL_AUTO, ], self::TYPE_CONTENT => [], // time_limit in seconds, 0 = no limit (presenter ends the quiz) diff --git a/src/Service/ResultsService.php b/src/Service/ResultsService.php index 7c0b014..8816cc8 100644 --- a/src/Service/ResultsService.php +++ b/src/Service/ResultsService.php @@ -22,7 +22,7 @@ use Cake\ORM\Locator\LocatorAwareTrait; * 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else []; * 'value' is null unless the setting comment_ratings is on; * presentation only: participants never get results of scale slides, see PollStateService); - * 'commentInterval' => int seconds per comment while they rotate; + * 'commentInterval' => int seconds per comment while they rotate, 0 = depending on its length; * open/scale with 'private' (anonymous/internal feedback): contents are included for the * presenter/embed, which start with the results hidden and may show them on demand; * participants never get results of these slides, the public PDF strips them (withoutContents()) diff --git a/templates/Slides/form.php b/templates/Slides/form.php index b454565..3e0f1e3 100644 --- a/templates/Slides/form.php +++ b/templates/Slides/form.php @@ -176,11 +176,17 @@ $optionsError = $slide->getError('options_text'); 'type' => 'select', 'options' => array_combine( \App\Model\Entity\Slide::COMMENT_INTERVALS, - array_map(fn(int $s) => __n('{0} Sekunde', '{0} Sekunden', $s, $s), \App\Model\Entity\Slide::COMMENT_INTERVALS), + array_map( + fn(int $s) => $s === \App\Model\Entity\Slide::COMMENT_INTERVAL_AUTO + ? __('automatisch (je nach Länge des Kommentars)') + : __n('{0} Sekunde', '{0} Sekunden', $s, $s), + \App\Model\Entity\Slide::COMMENT_INTERVALS, + ), ), 'label' => __('Nächster Kommentar nach'), 'value' => $settings['comment_interval'], ]) ?> +

Form->control('settings.comment_ratings', [ 'type' => 'checkbox', 'label' => __('Bewertung beim Kommentar in der Präsentation anzeigen'), diff --git a/tests/TestCase/Controller/ScaleCommentsTest.php b/tests/TestCase/Controller/ScaleCommentsTest.php index 3ec5421..da97773 100644 --- a/tests/TestCase/Controller/ScaleCommentsTest.php +++ b/tests/TestCase/Controller/ScaleCommentsTest.php @@ -156,14 +156,19 @@ class ScaleCommentsTest extends TestCase public function testCommentIntervalIsConfigurable(): void { - $this->assertSame(8, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['comment_interval']); + $auto = Slide::COMMENT_INTERVAL_AUTO; + $this->assertSame($auto, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['comment_interval']); $this->assertSame(15, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '15'])['comment_interval']); - $this->assertSame(8, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '7'])['comment_interval']); - $this->assertSame(8, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '-1'])['comment_interval']); + $this->assertSame($auto, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '0'])['comment_interval']); + $this->assertSame($auto, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '7'])['comment_interval']); + $this->assertSame($auto, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['comment_interval' => '-1'])['comment_interval']); [, $token] = $this->scaleWithComments(['comment_interval' => 20]); $this->assertSame(20, $this->presenterResults($token)['commentInterval']); + [, $token] = $this->scaleWithComments(); + $this->assertSame($auto, $this->presenterResults($token)['commentInterval']); + $this->get("/admin/$token"); $this->assertResponseOk(); } @@ -175,6 +180,7 @@ class ScaleCommentsTest extends TestCase $this->assertResponseContains('name="settings[comment_interval]"'); $this->assertResponseContains('15 Sekunden'); + $this->assertResponseContains('automatisch (je nach Länge des Kommentars)'); } public function testParticipantsNeverSeeComments(): void diff --git a/webroot/js/plenario.js b/webroot/js/plenario.js index 8750c7b..f1f4380 100644 --- a/webroot/js/plenario.js +++ b/webroot/js/plenario.js @@ -297,7 +297,7 @@ * so position, pause and timer live here and survive the re-render. */ var Comments = { - intervalMs: 8000, + seconds: 0, key: null, index: 0, paused: false, @@ -305,9 +305,15 @@ items: [], node: null, + // Automatic interval: time to read the comment on the stage, within sensible bounds. + AUTO_BASE_MS: 2500, + AUTO_CHARS_PER_SECOND: 15, + AUTO_MIN_MS: 5000, + AUTO_MAX_MS: 30000, + /** * @param {Array} items comments, oldest first - * @param {number} [seconds] time per comment (slide setting), default 8 + * @param {number} [seconds] time per comment (slide setting), 0 = depending on its length */ render: function (items, seconds) { // A different first comment means a different slide (or a reset): start over. @@ -317,11 +323,11 @@ Comments.index = 0; Comments.paused = false; } - var intervalMs = seconds > 0 ? seconds * 1000 : 8000; - if (intervalMs !== Comments.intervalMs) { + seconds = seconds > 0 ? seconds : 0; + if (seconds !== Comments.seconds) { // Setting changed (or another slide): apply it right away. - Comments.intervalMs = intervalMs; - clearInterval(Comments.timer); + Comments.seconds = seconds; + clearTimeout(Comments.timer); Comments.timer = null; } Comments.items = items; @@ -357,8 +363,9 @@ Comments.paused = !Comments.paused; } else { Comments.step(action === 'next' ? 1 : -1); - Comments.restart(); } + // The comment shown now gets its full reading time. + Comments.restart(); Comments.update(false); }); Comments.node = node; @@ -374,21 +381,37 @@ Comments.index = (Comments.index + delta + n) % n; }, + /** + * How long a comment stays on the stage: the fixed setting, or (automatic) + * a base time plus reading time for its length, between AUTO_MIN_MS and AUTO_MAX_MS. + * + * @param {Object} item comment + * @return {number} milliseconds + */ + delay: function (item) { + if (Comments.seconds > 0) { + return Comments.seconds * 1000; + } + var length = item && item.text ? Array.from(item.text).length : 0; + var ms = Comments.AUTO_BASE_MS + length / Comments.AUTO_CHARS_PER_SECOND * 1000; + return Math.round(Math.min(Comments.AUTO_MAX_MS, Math.max(Comments.AUTO_MIN_MS, ms))); + }, + + /** (Re)start the countdown for the comment currently shown. */ restart: function () { - clearInterval(Comments.timer); - Comments.timer = setInterval(function () { + clearTimeout(Comments.timer); + Comments.timer = setTimeout(function () { if (!Comments.node || !document.body.contains(Comments.node)) { // Slide changed: stop until the next comment list is rendered. - clearInterval(Comments.timer); Comments.timer = null; return; } - if (Comments.paused || Comments.items.length < 2 || document.hidden) { - return; + if (!Comments.paused && Comments.items.length > 1 && !document.hidden) { + Comments.step(1); + Comments.update(true); } - Comments.step(1); - Comments.update(true); - }, Comments.intervalMs); + Comments.restart(); + }, Comments.delay(Comments.items[Comments.index])); }, update: function (animate) { -- 2.54.1