Merge pull request 'Rotate scale comments by reading time' (#39) from feature/comment-auto-interval into main
Reviewed-on: #39
This commit was merged in pull request #39.
This commit is contained in:
commit
db22863608
6 files changed
+68
-25
No files matched your search
@@ -215,7 +215,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.
|
||||
|
||||
|
||||
@@ -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<int>
|
||||
*/
|
||||
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)
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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'],
|
||||
]) ?>
|
||||
<p class="hint"><?= __('„Automatisch“ lässt jedem Kommentar so viel Zeit, wie man zum Lesen braucht: kurze stehen etwa 5 Sekunden, lange bis zu 30 Sekunden.') ?></p>
|
||||
<?= $this->Form->control('settings.comment_ratings', [
|
||||
'type' => 'checkbox',
|
||||
'label' => __('Bewertung beim Kommentar in der Präsentation anzeigen'),
|
||||
|
||||
@@ -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
|
||||
|
||||
+38
-15
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user