Add a star rating style to scale slides
Scales can now be shown as stars (1 to n) instead of numbered steps: participants tap stars, the stage shows the average as partly filled stars and the distribution as bars from most to fewest stars, and the evaluation page and PDF export print ratings as stars. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1ee870d67c
commit
c1f9be2eef
14 files changed
+400
-31
No files matched your search
@@ -226,6 +226,11 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
|||||||
vor/zurück/Pause, Laufbalken bis zum Wechsel (`Comments.progress()`, setzt nach dem Neu-Rendern per negativem
|
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,
|
`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.
|
wenn der Presenter die Ergebnisse einblendet.
|
||||||
|
- **Sterne-Bewertung** (Skala mit Setting `style = stars`, `Slide::isStarRating()`, Standard `numbers`): immer 1 bis `scale_max`
|
||||||
|
Sterne (`SlidesTable::sanitizeSettings()` erzwingt `scale_min = 1`), gespeichert wie jede Skala als `numeric_value`.
|
||||||
|
Teilnehmende wählen Sterne (Radios in DOM-Reihenfolge 1..n, Füllung per CSS `:has()`), der State enthält `results.stars`;
|
||||||
|
`Results.stars` in `plenario.js` zeigt den Durchschnitt als teilweise gefüllte Sterne und die Verteilung als Balken 5 → 1.
|
||||||
|
Text-Ausgabe (Auswertung, PDF) über `Slide::ratingText()` (`★★★★☆`), barrierearm über `element/rating`.
|
||||||
- **Antwort nachträglich bearbeiten** (gegen Tippfehler, `VoteService::hasEditableText()`): Antwort einer offenen Frage
|
- **Antwort nachträglich bearbeiten** (gegen Tippfehler, `VoteService::hasEditableText()`): Antwort einer offenen Frage
|
||||||
(darf nicht leer werden) bzw. Kommentar einer Skala (ändern, ergänzen, leeren; die Bewertung bleibt unveränderlich),
|
(darf nicht leer werden) bzw. Kommentar einer Skala (ändern, ergänzen, leeren; die Bewertung bleibt unveränderlich),
|
||||||
nur solange die Abstimmung offen ist. `participate:edit` → `VoteService::editText()`, gleiche Vorbedingungen wie
|
nur solange die Abstimmung offen ist. `participate:edit` → `VoteService::editText()`, gleiche Vorbedingungen wie
|
||||||
|
|||||||
@@ -55,6 +55,12 @@ class Slide extends Entity
|
|||||||
*/
|
*/
|
||||||
public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300];
|
public const QUIZ_TIME_LIMITS = [0, 10, 15, 20, 30, 45, 60, 90, 120, 180, 300];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display styles of a scale: numbered steps or a star rating (always starts at 1 star).
|
||||||
|
*/
|
||||||
|
public const SCALE_NUMBERS = 'numbers';
|
||||||
|
public const SCALE_STARS = 'stars';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Q&A stages, see qaStage(): participants submit questions, then upvote
|
* Q&A stages, see qaStage(): participants submit questions, then upvote
|
||||||
* them, then the presenter discusses them one by one (most upvoted first).
|
* them, then the presenter discusses them one by one (most upvoted first).
|
||||||
@@ -88,7 +94,9 @@ class Slide extends Entity
|
|||||||
// comments: optional comment field, comments rotate in the presentation (unless private)
|
// comments: optional comment field, comments rotate in the presentation (unless private)
|
||||||
// comment_ratings: show the rating next to each comment in the presentation
|
// comment_ratings: show the rating next to each comment in the presentation
|
||||||
// (time per comment depends on its length, see Comments.delay() in plenario.js)
|
// (time per comment depends on its length, see Comments.delay() in plenario.js)
|
||||||
|
// style: numbers or stars (SCALE_*), stars always start at scale_min = 1
|
||||||
self::TYPE_SCALE => [
|
self::TYPE_SCALE => [
|
||||||
|
'style' => self::SCALE_NUMBERS,
|
||||||
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
|
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
|
||||||
'comments' => false, 'comment_ratings' => false,
|
'comments' => false, 'comment_ratings' => false,
|
||||||
],
|
],
|
||||||
@@ -449,4 +457,31 @@ class Slide extends Entity
|
|||||||
{
|
{
|
||||||
return $this->type === self::TYPE_SCALE && (bool)$this->setting('comments');
|
return $this->type === self::TYPE_SCALE && (bool)$this->setting('comments');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale shown as a star rating (1 to scale_max stars) instead of numbered steps.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function isStarRating(): bool
|
||||||
|
{
|
||||||
|
return $this->type === self::TYPE_SCALE && $this->setting('style') === self::SCALE_STARS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rating of a scale as plain text: the number, or filled and empty stars (e.g. ★★★★☆).
|
||||||
|
*
|
||||||
|
* @param int $value Rating
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function ratingText(int $value): string
|
||||||
|
{
|
||||||
|
if (!$this->isStarRating()) {
|
||||||
|
return (string)$value;
|
||||||
|
}
|
||||||
|
$max = (int)$this->setting('scale_max');
|
||||||
|
$value = max(0, min($max, $value));
|
||||||
|
|
||||||
|
return str_repeat('★', $value) . str_repeat('☆', $max - $value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -150,7 +150,10 @@ class SlidesTable extends Table
|
|||||||
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
$settings['private'] = filter_var($input['private'] ?? false, FILTER_VALIDATE_BOOLEAN);
|
||||||
break;
|
break;
|
||||||
case Slide::TYPE_SCALE:
|
case Slide::TYPE_SCALE:
|
||||||
$min = max(0, min(1, (int)($input['scale_min'] ?? 1)));
|
$stars = ($input['style'] ?? null) === Slide::SCALE_STARS;
|
||||||
|
$settings['style'] = $stars ? Slide::SCALE_STARS : Slide::SCALE_NUMBERS;
|
||||||
|
// Stars always start at one star (zero stars is no rating).
|
||||||
|
$min = $stars ? 1 : max(0, min(1, (int)($input['scale_min'] ?? 1)));
|
||||||
$max = max(2, min(10, (int)($input['scale_max'] ?? 5)));
|
$max = max(2, min(10, (int)($input['scale_max'] ?? 5)));
|
||||||
$settings['scale_min'] = $min;
|
$settings['scale_min'] = $min;
|
||||||
$settings['scale_max'] = $max;
|
$settings['scale_max'] = $max;
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
|||||||
* weight follows count)
|
* weight follows count)
|
||||||
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
|
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
|
||||||
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
|
* - scale: 'buckets' => [['value', 'count', 'percent']], 'average' => float|null,
|
||||||
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool);
|
* 'min', 'max', 'minLabel', 'maxLabel', 'private' (bool), 'stars' (bool: star rating, min = 1);
|
||||||
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
|
* 'comments' => [['id', 'text', 'value' (int|null)]] oldest first (only with the comment field, else [];
|
||||||
* 'value' is null unless the setting comment_ratings is on;
|
* 'value' is null unless the setting comment_ratings is on;
|
||||||
* presentation only: participants never get results of scale slides, see PollStateService);
|
* presentation only: participants never get results of scale slides, see PollStateService);
|
||||||
@@ -394,7 +394,7 @@ class ResultsService
|
|||||||
* Distribution and average of a scale.
|
* Distribution and average of a scale.
|
||||||
*
|
*
|
||||||
* @param \App\Model\Entity\Slide $slide Scale slide
|
* @param \App\Model\Entity\Slide $slide Scale slide
|
||||||
* @return array{buckets: list<array{value: int, count: int, percent: float|int}>, average: float|null, min: int, max: int, minLabel: string, maxLabel: string}
|
* @return array{buckets: list<array{value: int, count: int, percent: float|int}>, average: float|null, min: int, max: int, minLabel: string, maxLabel: string, stars: bool}
|
||||||
*/
|
*/
|
||||||
public function scaleResults(Slide $slide): array
|
public function scaleResults(Slide $slide): array
|
||||||
{
|
{
|
||||||
@@ -432,6 +432,7 @@ class ResultsService
|
|||||||
'max' => $max,
|
'max' => $max,
|
||||||
'minLabel' => (string)$slide->setting('min_label'),
|
'minLabel' => (string)$slide->setting('min_label'),
|
||||||
'maxLabel' => (string)$slide->setting('max_label'),
|
'maxLabel' => (string)$slide->setting('max_label'),
|
||||||
|
'stars' => $slide->isStarRating(),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -665,7 +665,9 @@ class VoteService
|
|||||||
$min = (int)$slide->setting('scale_min');
|
$min = (int)$slide->setting('scale_min');
|
||||||
$max = (int)$slide->setting('scale_max');
|
$max = (int)$slide->setting('scale_max');
|
||||||
if ($value === false || $value < $min || $value > $max) {
|
if ($value === false || $value < $min || $value > $max) {
|
||||||
throw new VoteException(__('Bitte wähle einen Wert zwischen {0} und {1}.', $min, $max));
|
throw new VoteException($slide->isStarRating()
|
||||||
|
? __('Bitte vergib zwischen {0} und {1} Sternen.', $min, $max)
|
||||||
|
: __('Bitte wähle einen Wert zwischen {0} und {1}.', $min, $max));
|
||||||
}
|
}
|
||||||
// The optional comment is stored in the same row; ignored if the slide has no comment field.
|
// The optional comment is stored in the same row; ignored if the slide has no comment field.
|
||||||
return [['numeric_value' => $value, 'text_value' => $slide->hasComments() ? self::comment($data) : null]];
|
return [['numeric_value' => $value, 'text_value' => $slide->hasComments() ? self::comment($data) : null]];
|
||||||
|
|||||||
@@ -171,10 +171,12 @@ $bar = function (float $percent, bool $ok = false): string {
|
|||||||
<p>
|
<p>
|
||||||
<?= __('Durchschnitt') ?>:
|
<?= __('Durchschnitt') ?>:
|
||||||
<span class="stat"><?= $r['average'] === null ? '–' : $number((float)$r['average'], 1) ?></span>
|
<span class="stat"><?= $r['average'] === null ? '–' : $number((float)$r['average'], 1) ?></span>
|
||||||
<span class="muted"><?= __('auf einer Skala von {0} bis {1}', (int)$r['min'], (int)$r['max']) ?></span>
|
<span class="muted"><?= !empty($r['stars'])
|
||||||
|
? __('von {0} Sternen', (int)$r['max'])
|
||||||
|
: __('auf einer Skala von {0} bis {1}', (int)$r['min'], (int)$r['max']) ?></span>
|
||||||
</p>
|
</p>
|
||||||
<table>
|
<table>
|
||||||
<thead><tr><th><?= __('Wert') ?></th><th class="num"><?= __('Anzahl') ?></th><th class="num"><?= __('Anteil') ?></th><th></th></tr></thead>
|
<thead><tr><th><?= !empty($r['stars']) ? __('Sterne') : __('Wert') ?></th><th class="num"><?= __('Anzahl') ?></th><th class="num"><?= __('Anteil') ?></th><th></th></tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($r['buckets'] as $i => $bucket) :
|
<?php foreach ($r['buckets'] as $i => $bucket) :
|
||||||
$label = match (true) {
|
$label = match (true) {
|
||||||
@@ -183,7 +185,7 @@ $bar = function (float $percent, bool $ok = false): string {
|
|||||||
default => '',
|
default => '',
|
||||||
}; ?>
|
}; ?>
|
||||||
<tr>
|
<tr>
|
||||||
<td><?= (int)$bucket['value'] ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></td>
|
<td<?= !empty($r['stars']) ? ' class="stars"' : '' ?>><?= h($slide->ratingText((int)$bucket['value'])) ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></td>
|
||||||
<td class="num"><?= (int)$bucket['count'] ?></td>
|
<td class="num"><?= (int)$bucket['count'] ?></td>
|
||||||
<td class="num"><?= $number((float)$bucket['percent']) ?> %</td>
|
<td class="num"><?= $number((float)$bucket['percent']) ?> %</td>
|
||||||
<td class="bar"><?= $bar((float)$bucket['percent']) ?></td>
|
<td class="bar"><?= $bar((float)$bucket['percent']) ?></td>
|
||||||
@@ -200,7 +202,7 @@ $bar = function (float $percent, bool $ok = false): string {
|
|||||||
<?php foreach ($r['comments'] as $comment) : ?>
|
<?php foreach ($r['comments'] as $comment) : ?>
|
||||||
<li>
|
<li>
|
||||||
<?= nl2br(h($comment['text'])) ?>
|
<?= nl2br(h($comment['text'])) ?>
|
||||||
<?php if ($comment['value'] !== null) : ?><span class="muted">(<?= __('Bewertung {0}', (int)$comment['value']) ?>)</span><?php endif; ?>
|
<?php if ($comment['value'] !== null) : ?><span class="muted">(<?= __('Bewertung {0}', h($slide->ratingText((int)$comment['value']))) ?>)</span><?php endif; ?>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ol>
|
</ol>
|
||||||
|
|||||||
@@ -280,15 +280,28 @@ $countdown = function (?int $remaining): string {
|
|||||||
</p>
|
</p>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php elseif ($slide->type === 'scale') : ?>
|
<?php elseif ($slide->type === 'scale') :
|
||||||
<div class="scale"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
$maxValue = (int)$slide->setting('scale_max'); ?>
|
||||||
<?php for ($v = (int)$slide->setting('scale_min'); $v <= (int)$slide->setting('scale_max'); $v++) : ?>
|
<?php if ($slide->isStarRating()) : ?>
|
||||||
<label class="scale__step">
|
<div class="stars<?= $maxValue > 6 ? ' stars--many' : '' ?>" role="radiogroup" aria-label="<?= __('Bewertung in Sternen') ?>"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||||
<input type="radio" name="value" value="<?= $v ?>" required>
|
<?php for ($v = 1; $v <= $maxValue; $v++) : ?>
|
||||||
<span><?= $v ?></span>
|
<label class="stars__star">
|
||||||
</label>
|
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||||
<?php endfor; ?>
|
<span class="stars__icon" aria-hidden="true">★</span>
|
||||||
</div>
|
<span class="sr-only"><?= __('{0} von {1} Sternen', $v, $maxValue) ?></span>
|
||||||
|
</label>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</div>
|
||||||
|
<?php else : ?>
|
||||||
|
<div class="scale"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||||
|
<?php for ($v = (int)$slide->setting('scale_min'); $v <= $maxValue; $v++) : ?>
|
||||||
|
<label class="scale__step">
|
||||||
|
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||||
|
<span><?= $v ?></span>
|
||||||
|
</label>
|
||||||
|
<?php endfor; ?>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
<div class="scale__labels">
|
<div class="scale__labels">
|
||||||
<span><?= h((string)$slide->setting('min_label')) ?></span>
|
<span><?= h((string)$slide->setting('min_label')) ?></span>
|
||||||
<span><?= h((string)$slide->setting('max_label')) ?></span>
|
<span><?= h((string)$slide->setting('max_label')) ?></span>
|
||||||
|
|||||||
@@ -43,12 +43,12 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
|||||||
<p class="scale-average">
|
<p class="scale-average">
|
||||||
<?= __('Durchschnitt') ?>:
|
<?= __('Durchschnitt') ?>:
|
||||||
<strong><?= h($this->Number->format((float)$scale['average'], ['places' => 1, 'precision' => 1, 'locale' => 'de_DE'])) ?></strong>
|
<strong><?= h($this->Number->format((float)$scale['average'], ['places' => 1, 'precision' => 1, 'locale' => 'de_DE'])) ?></strong>
|
||||||
<span class="muted">/ <?= (int)$scale['max'] ?></span>
|
<span class="muted"><?= $slide->isStarRating() ? __('von {0} Sternen', (int)$scale['max']) : '/ ' . (int)$scale['max'] ?></span>
|
||||||
</p>
|
</p>
|
||||||
<table class="scale-table">
|
<table class="scale-table">
|
||||||
<caption class="sr-only"><?= __('Verteilung der Bewertungen') ?></caption>
|
<caption class="sr-only"><?= __('Verteilung der Bewertungen') ?></caption>
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th scope="col"><?= __('Wert') ?></th><th scope="col"><?= __('Anzahl') ?></th><th scope="col"><?= __('Anteil') ?></th></tr>
|
<tr><th scope="col"><?= $slide->isStarRating() ? __('Sterne') : __('Wert') ?></th><th scope="col"><?= __('Anzahl') ?></th><th scope="col"><?= __('Anteil') ?></th></tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($scale['buckets'] as $i => $bucket) :
|
<?php foreach ($scale['buckets'] as $i => $bucket) :
|
||||||
@@ -58,7 +58,7 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
|||||||
default => '',
|
default => '',
|
||||||
}; ?>
|
}; ?>
|
||||||
<tr>
|
<tr>
|
||||||
<th scope="row"><?= (int)$bucket['value'] ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></th>
|
<th scope="row"><?= $this->element('rating', ['slide' => $slide, 'value' => (int)$bucket['value']]) ?><?php if ($label !== '') : ?> <span class="muted">(<?= h($label) ?>)</span><?php endif; ?></th>
|
||||||
<td><?= (int)$bucket['count'] ?></td>
|
<td><?= (int)$bucket['count'] ?></td>
|
||||||
<td>
|
<td>
|
||||||
<span class="scale-table__bar" style="width: <?= (float)$bucket['percent'] ?>%" aria-hidden="true"></span>
|
<span class="scale-table__bar" style="width: <?= (float)$bucket['percent'] ?>%" aria-hidden="true"></span>
|
||||||
@@ -79,7 +79,7 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
|||||||
$created = new DateTime($comment['created']); ?>
|
$created = new DateTime($comment['created']); ?>
|
||||||
<li>
|
<li>
|
||||||
<?= h($comment['text']) ?>
|
<?= h($comment['text']) ?>
|
||||||
<time datetime="<?= h($comment['created']) ?>"><?= __('Bewertung {0}', $comment['value']) ?> · <?= h($created->i18nFormat('dd.MM.yyyy, HH:mm')) ?></time>
|
<time datetime="<?= h($comment['created']) ?>"><?= __('Bewertung') ?> <?= $this->element('rating', ['slide' => $slide, 'value' => (int)$comment['value']]) ?> · <?= h($created->i18nFormat('dd.MM.yyyy, HH:mm')) ?></time>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ol>
|
</ol>
|
||||||
|
|||||||
@@ -148,14 +148,25 @@ $optionsError = $slide->getError('options_text');
|
|||||||
'checked' => (bool)$settings['allow_downvotes'],
|
'checked' => (bool)$settings['allow_downvotes'],
|
||||||
]) ?>
|
]) ?>
|
||||||
<?php elseif ($slide->type === 'scale') : ?>
|
<?php elseif ($slide->type === 'scale') : ?>
|
||||||
|
<?php $stars = $settings['style'] === \App\Model\Entity\Slide::SCALE_STARS; ?>
|
||||||
|
<fieldset class="scale-style" data-scale-style>
|
||||||
|
<legend><?= __('Darstellung') ?></legend>
|
||||||
|
<?= $this->Form->radio('settings.style', [
|
||||||
|
['value' => \App\Model\Entity\Slide::SCALE_NUMBERS, 'text' => __('Zahlen (z. B. 1 bis 10)')],
|
||||||
|
['value' => \App\Model\Entity\Slide::SCALE_STARS, 'text' => __('Sterne (wie bei einer Produktbewertung)')],
|
||||||
|
], ['value' => $settings['style']]) ?>
|
||||||
|
</fieldset>
|
||||||
<div class="grid grid--2 grid--tight">
|
<div class="grid grid--2 grid--tight">
|
||||||
<?= $this->Form->control('settings.scale_min', [
|
<?= $this->Form->control('settings.scale_min', [
|
||||||
'type' => 'select', 'options' => [0 => '0', 1 => '1'],
|
'type' => 'select', 'options' => [0 => '0', 1 => '1'],
|
||||||
'label' => __('Von'), 'value' => $settings['scale_min'],
|
'label' => __('Von'), 'value' => $settings['scale_min'],
|
||||||
|
'templateVars' => ['attrs' => $stars ? ' hidden' : ''],
|
||||||
|
'templates' => ['inputContainer' => '<div class="input {{type}}{{required}}" data-scale-min{{attrs}}>{{content}}</div>'],
|
||||||
]) ?>
|
]) ?>
|
||||||
<?= $this->Form->control('settings.scale_max', [
|
<?= $this->Form->control('settings.scale_max', [
|
||||||
'type' => 'select', 'options' => array_combine(range(2, 10), range(2, 10)),
|
'type' => 'select', 'options' => array_combine(range(2, 10), range(2, 10)),
|
||||||
'label' => __('Bis'), 'value' => $settings['scale_max'],
|
'label' => $stars ? __('Anzahl Sterne') : __('Bis'), 'value' => $settings['scale_max'],
|
||||||
|
'data-label-numbers' => __('Bis'), 'data-label-stars' => __('Anzahl Sterne'),
|
||||||
]) ?>
|
]) ?>
|
||||||
<?= $this->Form->control('settings.min_label', [
|
<?= $this->Form->control('settings.min_label', [
|
||||||
'label' => __('Beschriftung links (optional)'), 'maxlength' => 60,
|
'label' => __('Beschriftung links (optional)'), 'maxlength' => 60,
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* A scale rating: the number, or stars with a text alternative for screen readers.
|
||||||
|
*
|
||||||
|
* @var \App\View\AppView $this
|
||||||
|
* @var \App\Model\Entity\Slide $slide Scale slide
|
||||||
|
* @var int $value Rating
|
||||||
|
*/
|
||||||
|
if (!$slide->isStarRating()) {
|
||||||
|
echo (int)$value;
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
?><span class="rating-stars" aria-hidden="true"><?= h($slide->ratingText((int)$value)) ?></span><span class="sr-only"><?= __('{0} von {1} Sternen', (int)$value, (int)$slide->setting('scale_max')) ?></span>
|
||||||
@@ -46,6 +46,7 @@
|
|||||||
ol.list, ul.list { margin: 1mm 0 0; padding-left: 6mm; }
|
ol.list, ul.list { margin: 1mm 0 0; padding-left: 6mm; }
|
||||||
ol.list li, ul.list li { margin-bottom: 1.2mm; }
|
ol.list li, ul.list li { margin-bottom: 1.2mm; }
|
||||||
.stat { font-size: 12pt; font-weight: bold; }
|
.stat { font-size: 12pt; font-weight: bold; }
|
||||||
|
td.stars { color: #c27c00; letter-spacing: 1pt; }
|
||||||
.empty { color: #5d6280; font-style: italic; }
|
.empty { color: #5d6280; font-style: italic; }
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -0,0 +1,156 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Test\TestCase\Controller;
|
||||||
|
|
||||||
|
use App\Model\Entity\Poll;
|
||||||
|
use App\Model\Entity\Slide;
|
||||||
|
use App\Model\Table\SlidesTable;
|
||||||
|
use App\Service\VoteException;
|
||||||
|
use App\Service\VoteService;
|
||||||
|
use App\Test\TestCase\PlenarioTestTrait;
|
||||||
|
use Cake\TestSuite\IntegrationTestTrait;
|
||||||
|
use Cake\TestSuite\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Scale slides shown as a star rating (style "stars"): always from 1 star to scale_max stars.
|
||||||
|
*/
|
||||||
|
class StarRatingTest extends TestCase
|
||||||
|
{
|
||||||
|
use IntegrationTestTrait;
|
||||||
|
use PlenarioTestTrait;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var list<string>
|
||||||
|
*/
|
||||||
|
protected array $fixtures = ['app.Polls', 'app.Slides', 'app.SlideOptions', 'app.Responses'];
|
||||||
|
|
||||||
|
protected function setUp(): void
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
$this->enableCsrfToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param array<string, mixed> $settings Extra settings
|
||||||
|
* @return array{0: \App\Model\Entity\Poll, 1: string, 2: \App\Model\Entity\Slide}
|
||||||
|
*/
|
||||||
|
protected function starSlide(array $settings = []): array
|
||||||
|
{
|
||||||
|
[$poll, $token] = $this->createPoll();
|
||||||
|
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, [
|
||||||
|
'settings' => $settings + ['style' => Slide::SCALE_STARS, 'scale_max' => 5],
|
||||||
|
]);
|
||||||
|
|
||||||
|
return [$this->goLive($poll, $slide), $token, $slide];
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function hash(string $char, Poll $poll): string
|
||||||
|
{
|
||||||
|
return VoteService::participantHash(str_repeat($char, 32), $poll->id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSettingIsSanitized(): void
|
||||||
|
{
|
||||||
|
$stars = SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['style' => 'stars', 'scale_min' => '0', 'scale_max' => '5']);
|
||||||
|
$this->assertSame(Slide::SCALE_STARS, $stars['style']);
|
||||||
|
$this->assertSame(1, $stars['scale_min'], 'Stars always start at one star');
|
||||||
|
|
||||||
|
$this->assertSame(Slide::SCALE_NUMBERS, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, [])['style']);
|
||||||
|
$this->assertSame(Slide::SCALE_NUMBERS, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['style' => 'hearts'])['style']);
|
||||||
|
$this->assertSame(0, SlidesTable::sanitizeSettings(Slide::TYPE_SCALE, ['scale_min' => '0'])['scale_min']);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testExistingScalesStayNumbers(): void
|
||||||
|
{
|
||||||
|
[$poll] = $this->createPoll();
|
||||||
|
$slide = $this->createSlide($poll, Slide::TYPE_SCALE, ['settings' => ['scale_min' => 1, 'scale_max' => 5]]);
|
||||||
|
|
||||||
|
$this->assertFalse($slide->isStarRating());
|
||||||
|
$this->assertSame('4', $slide->ratingText(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testRatingText(): void
|
||||||
|
{
|
||||||
|
[, , $slide] = $this->starSlide();
|
||||||
|
|
||||||
|
$this->assertTrue($slide->isStarRating());
|
||||||
|
$this->assertSame('★★★★☆', $slide->ratingText(4));
|
||||||
|
$this->assertSame('★☆☆☆☆', $slide->ratingText(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFormSavesStarStyle(): void
|
||||||
|
{
|
||||||
|
[$poll, $token] = $this->createPoll();
|
||||||
|
$this->post("/admin/$token/slides/add?type=scale", [
|
||||||
|
'type' => 'scale',
|
||||||
|
'question' => 'Wie gefällt dir das Produkt?',
|
||||||
|
'settings' => ['style' => 'stars', 'scale_min' => '0', 'scale_max' => '5'],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$slide = $this->slidesTable()->find()->where(['poll_id' => $poll->id])->firstOrFail();
|
||||||
|
$this->assertTrue($slide->isStarRating());
|
||||||
|
$this->assertSame(1, $slide->setting('scale_min'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEditFormOffersStyle(): void
|
||||||
|
{
|
||||||
|
[, $token, $slide] = $this->starSlide();
|
||||||
|
|
||||||
|
$this->get("/admin/$token/slides/{$slide->id}/edit");
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertResponseContains('data-scale-style');
|
||||||
|
$this->assertResponseContains('Anzahl Sterne');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testParticipantSeesStars(): void
|
||||||
|
{
|
||||||
|
[$poll] = $this->starSlide();
|
||||||
|
|
||||||
|
$this->get('/p/' . $poll->join_code);
|
||||||
|
$this->assertResponseContains('class="stars"');
|
||||||
|
$this->assertResponseContains('1 von 5 Sternen');
|
||||||
|
$this->assertResponseContains('5 von 5 Sternen');
|
||||||
|
$this->assertResponseNotContains('value="0"');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testZeroStarsAreRejected(): void
|
||||||
|
{
|
||||||
|
[$poll, , $slide] = $this->starSlide();
|
||||||
|
|
||||||
|
$this->expectException(VoteException::class);
|
||||||
|
$this->expectExceptionMessage('Sternen');
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), ['value' => 0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPresenterGetsStarFlag(): void
|
||||||
|
{
|
||||||
|
[$poll, $token, $slide] = $this->starSlide();
|
||||||
|
$votes = new VoteService();
|
||||||
|
$votes->submit($poll, $slide, $this->hash('a', $poll), ['value' => 5]);
|
||||||
|
$votes->submit($poll, $slide, $this->hash('b', $poll), ['value' => 4]);
|
||||||
|
|
||||||
|
$this->get("/admin/$token/state");
|
||||||
|
$results = json_decode((string)$this->_response->getBody(), true)['results'];
|
||||||
|
|
||||||
|
$this->assertTrue($results['stars']);
|
||||||
|
$this->assertSame(1, $results['min']);
|
||||||
|
$this->assertEquals(4.5, $results['average']);
|
||||||
|
$this->assertSame([1, 2, 3, 4, 5], array_column($results['buckets'], 'value'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testEvaluationAndExportShowStars(): void
|
||||||
|
{
|
||||||
|
[$poll, $token, $slide] = $this->starSlide(['comments' => true, 'comment_ratings' => true]);
|
||||||
|
(new VoteService())->submit($poll, $slide, $this->hash('a', $poll), ['value' => 4, 'comment' => 'Gut']);
|
||||||
|
|
||||||
|
$this->get("/admin/$token/slides/{$slide->id}/answers");
|
||||||
|
$this->assertResponseOk();
|
||||||
|
$this->assertResponseContains('★★★★☆');
|
||||||
|
$this->assertResponseContains('4 von 5 Sternen');
|
||||||
|
|
||||||
|
$html = $this->exportHtml($token);
|
||||||
|
$this->assertStringContainsString('von 5 Sternen', $html);
|
||||||
|
$this->assertStringContainsString('Bewertung ★★★★☆', $html);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,6 +30,8 @@
|
|||||||
--qa: #1f6bb0; /* Q&A accent, AA contrast with white text */
|
--qa: #1f6bb0; /* Q&A accent, AA contrast with white text */
|
||||||
--notice-bg: #fff6e0;
|
--notice-bg: #fff6e0;
|
||||||
--notice-ink: #6b4a00;
|
--notice-ink: #6b4a00;
|
||||||
|
--star: #d48500; /* star rating, 3:1 against light surfaces */
|
||||||
|
--star-empty: #c3c8da;
|
||||||
color-scheme: light;
|
color-scheme: light;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,6 +52,8 @@
|
|||||||
--shadow: none;
|
--shadow: none;
|
||||||
--notice-bg: #3a2f12;
|
--notice-bg: #3a2f12;
|
||||||
--notice-ink: #f3d98f;
|
--notice-ink: #f3d98f;
|
||||||
|
--star: #ffc233;
|
||||||
|
--star-empty: #464a66;
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -67,6 +71,8 @@
|
|||||||
--shadow: none;
|
--shadow: none;
|
||||||
--notice-bg: #3a2f12;
|
--notice-bg: #3a2f12;
|
||||||
--notice-ink: #f3d98f;
|
--notice-ink: #f3d98f;
|
||||||
|
--star: #ffc233;
|
||||||
|
--star-empty: #464a66;
|
||||||
color-scheme: dark;
|
color-scheme: dark;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -298,12 +304,12 @@ textarea { resize: vertical; }
|
|||||||
.order-option__pos { min-width: 2em; text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
|
.order-option__pos { min-width: 2em; text-align: right; font-weight: 700; color: var(--muted); font-variant-numeric: tabular-nums; }
|
||||||
.order-options.error .order-options__list input[type=text] { border-color: var(--danger); }
|
.order-options.error .order-options__list input[type=text] { border-color: var(--danger); }
|
||||||
|
|
||||||
/* dashboard: PDF export, choice between public and complete version */
|
/* radio cards: PDF export (public/complete version), scale style (numbers/stars) */
|
||||||
.export-choice { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
|
.export-choice, .scale-style { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
|
||||||
.export-choice legend { font-weight: 600; margin-bottom: 4px; }
|
.export-choice legend, .scale-style legend { font-weight: 600; margin-bottom: 4px; }
|
||||||
.export-choice label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; }
|
.export-choice label, .scale-style label { display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px; border: 2px solid var(--border); border-radius: 8px; cursor: pointer; }
|
||||||
.export-choice label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
|
.export-choice label:has(input:checked), .scale-style label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
|
||||||
.export-choice input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
|
.export-choice input, .scale-style input { width: 18px; height: 18px; margin: 2px 0 0; flex: none; accent-color: var(--primary); }
|
||||||
.export-choice strong { display: block; }
|
.export-choice strong { display: block; }
|
||||||
.export-choice .hint { display: block; margin: 2px 0 0; }
|
.export-choice .hint { display: block; margin: 2px 0 0; }
|
||||||
|
|
||||||
@@ -352,6 +358,20 @@ textarea { resize: vertical; }
|
|||||||
.scale__step input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
|
.scale__step input:checked + span { border-color: var(--primary); background: var(--primary); color: #fff; }
|
||||||
.scale__step input:focus-visible + span { outline: 3px solid var(--primary-soft); }
|
.scale__step input:focus-visible + span { outline: 3px solid var(--primary-soft); }
|
||||||
.scale__labels { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
|
.scale__labels { display: flex; justify-content: space-between; font-size: .85rem; color: var(--muted); }
|
||||||
|
/* star rating: stars up to the checked (or hovered) one are filled; :has() keeps the DOM order 1..n for arrow keys */
|
||||||
|
.stars { display: flex; justify-content: center; margin: 20px 0 6px; }
|
||||||
|
.stars__star { position: relative; padding: 0 4px; cursor: pointer; font-size: clamp(2.4rem, 13vw, 3.4rem); line-height: 1; color: var(--star); }
|
||||||
|
.stars--many .stars__star { padding: 0 1px; font-size: clamp(1.5rem, 7.5vw, 2.4rem); }
|
||||||
|
.stars__star input { position: absolute; inset: 0; width: 100%; height: 100%; margin: 0; opacity: 0; cursor: pointer; }
|
||||||
|
.stars__icon { display: block; transition: color .15s, transform .15s; }
|
||||||
|
/* :where() keeps these weaker than the hover preview below */
|
||||||
|
:where(.stars:not(:has(input:checked))) .stars__star, :where(.stars__star:has(input:checked)) ~ .stars__star { color: var(--star-empty); }
|
||||||
|
.stars__star:has(input:focus-visible) .stars__icon { outline: 3px solid var(--primary); outline-offset: 2px; border-radius: 6px; }
|
||||||
|
@media (hover: hover) {
|
||||||
|
.stars:hover .stars__star { color: var(--star); }
|
||||||
|
.stars .stars__star:hover ~ .stars__star { color: var(--star-empty); }
|
||||||
|
.stars__star:hover .stars__icon { transform: scale(1.12); }
|
||||||
|
}
|
||||||
.done { font-size: 1.1rem; font-weight: 600; color: var(--ok); }
|
.done { font-size: 1.1rem; font-weight: 600; color: var(--ok); }
|
||||||
.waiting { padding: 48px 24px; }
|
.waiting { padding: 48px 24px; }
|
||||||
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); margin: 0 auto 24px; animation: pulse 1.6s infinite; }
|
.pulse { width: 18px; height: 18px; border-radius: 50%; background: var(--primary); margin: 0 auto 24px; animation: pulse 1.6s infinite; }
|
||||||
@@ -432,6 +452,12 @@ textarea { resize: vertical; }
|
|||||||
.average__track { position: relative; height: 12px; border-radius: 99px; background: linear-gradient(90deg, var(--bg), var(--c1)); box-shadow: inset 0 0 0 1px var(--border); }
|
.average__track { position: relative; height: 12px; border-radius: 99px; background: linear-gradient(90deg, var(--bg), var(--c1)); box-shadow: inset 0 0 0 1px var(--border); }
|
||||||
.average__marker { position: absolute; top: 50%; width: 1.6em; height: 1.6em; margin: -.8em 0 0 -.8em; border-radius: 50%; background: var(--c1); border: .25em solid var(--bg); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); transition: left .6s ease; }
|
.average__marker { position: absolute; top: 50%; width: 1.6em; height: 1.6em; margin: -.8em 0 0 -.8em; border-radius: 50%; background: var(--c1); border: .25em solid var(--bg); box-shadow: 0 1px 4px rgba(0, 0, 0, .35); transition: left .6s ease; }
|
||||||
.average__ends { display: flex; justify-content: space-between; margin-top: 8px; font-size: .85rem; font-weight: 700; color: var(--muted); }
|
.average__ends { display: flex; justify-content: space-between; margin-top: 8px; font-size: .85rem; font-weight: 700; color: var(--muted); }
|
||||||
|
/* star rating results: average as partly filled stars, bars from most to fewest stars */
|
||||||
|
.star-meter { position: relative; display: inline-block; font-size: 2.6rem; line-height: 1; letter-spacing: .08em; white-space: nowrap; }
|
||||||
|
.star-meter__base { color: var(--star-empty); }
|
||||||
|
.star-meter__fill { position: absolute; top: 0; left: 0; overflow: hidden; color: var(--star); transition: width .6s ease; }
|
||||||
|
.bar--star .bar__fill { background: var(--star); }
|
||||||
|
.stars-legend { margin: 10px 0 0; font-size: .85rem; color: var(--muted); }
|
||||||
|
|
||||||
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; }
|
.cloud { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .2em .6em; line-height: 1.15; padding: 8px; }
|
||||||
.cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; }
|
.cloud__word { font-weight: 800; color: var(--c0); transition: font-size .6s ease; }
|
||||||
@@ -576,6 +602,7 @@ button.qa-steps__step:hover:not(:disabled) { color: var(--text); border-color: v
|
|||||||
.scale-table th, .scale-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
|
.scale-table th, .scale-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
|
||||||
.scale-table td:last-child { width: 50%; }
|
.scale-table td:last-child { width: 50%; }
|
||||||
.scale-table__bar { display: block; height: 6px; min-width: 2px; margin-bottom: 4px; border-radius: 3px; background: var(--c2); }
|
.scale-table__bar { display: block; height: 6px; min-width: 2px; margin-bottom: 4px; border-radius: 3px; background: var(--c2); }
|
||||||
|
.rating-stars { color: var(--star); letter-spacing: .05em; white-space: nowrap; }
|
||||||
|
|
||||||
/* ---------------------------------------------------------------- presenter */
|
/* ---------------------------------------------------------------- presenter */
|
||||||
/* Dark by default (beamer); the presenter's own switch can make it light (data-theme="light"). */
|
/* Dark by default (beamer); the presenter's own switch can make it light (data-theme="light"). */
|
||||||
@@ -588,6 +615,8 @@ body.present {
|
|||||||
--stage-glow: #2a1f6e;
|
--stage-glow: #2a1f6e;
|
||||||
--stage-ok: #3ddc97; /* brighter green for contrast on the dark stage */
|
--stage-ok: #3ddc97; /* brighter green for contrast on the dark stage */
|
||||||
--overlay-bg: rgba(8, 9, 20, .92);
|
--overlay-bg: rgba(8, 9, 20, .92);
|
||||||
|
--star: #ffc233;
|
||||||
|
--star-empty: #3a3d60;
|
||||||
background: radial-gradient(1200px 600px at 10% -10%, var(--stage-glow) 0%, transparent 60%), var(--bg);
|
background: radial-gradient(1200px 600px at 10% -10%, var(--stage-glow) 0%, transparent 60%), var(--bg);
|
||||||
color: var(--text);
|
color: var(--text);
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@@ -602,6 +631,8 @@ body.present {
|
|||||||
--stage-glow: #dcd8ff;
|
--stage-glow: #dcd8ff;
|
||||||
--stage-ok: var(--ok);
|
--stage-ok: var(--ok);
|
||||||
--overlay-bg: rgba(245, 246, 251, .95);
|
--overlay-bg: rgba(245, 246, 251, .95);
|
||||||
|
--star: #d48500;
|
||||||
|
--star-empty: #c3c8da;
|
||||||
}
|
}
|
||||||
.stage__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: clamp(1rem, 1.6vw, 1.4rem); color: var(--muted); }
|
.stage__top { display: flex; justify-content: space-between; align-items: center; gap: 16px; font-size: clamp(1rem, 1.6vw, 1.4rem); color: var(--muted); }
|
||||||
.stage__top strong { color: var(--text); }
|
.stage__top strong { color: var(--text); }
|
||||||
@@ -627,6 +658,9 @@ body.present {
|
|||||||
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
|
.stage .average__label, .stage .average__count, .stage .average__ends { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
|
||||||
.stage .average__track { height: .7em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
|
.stage .average__track { height: .7em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
|
||||||
.stage .average__ends { margin-top: 4px; }
|
.stage .average__ends { margin-top: 4px; }
|
||||||
|
.stage .star-meter { font-size: clamp(2.4rem, 5.5vw, 5rem); }
|
||||||
|
.stage .bars--stars { gap: 1.2vh; }
|
||||||
|
.stage .stars-legend { font-size: clamp(.85rem, 1.2vw, 1.1rem); }
|
||||||
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
|
.stage .cloud { font-size: clamp(1.4rem, 2.6vw, 2.6rem); }
|
||||||
.stage .answers { columns: 340px; }
|
.stage .answers { columns: 340px; }
|
||||||
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
|
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
|
||||||
|
|||||||
+95
-3
@@ -302,6 +302,7 @@
|
|||||||
paused: false,
|
paused: false,
|
||||||
timer: null,
|
timer: null,
|
||||||
items: [],
|
items: [],
|
||||||
|
format: String,
|
||||||
node: null,
|
node: null,
|
||||||
// Countdown of the comment shown (drives the progress bar across re-renders).
|
// Countdown of the comment shown (drives the progress bar across re-renders).
|
||||||
startedAt: 0,
|
startedAt: 0,
|
||||||
@@ -315,8 +316,10 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Array} items comments, oldest first
|
* @param {Array} items comments, oldest first
|
||||||
|
* @param {Function} format turns a rating into display text (number or stars)
|
||||||
*/
|
*/
|
||||||
render: function (items) {
|
render: function (items, format) {
|
||||||
|
Comments.format = format || String;
|
||||||
// A different first comment means a different slide (or a reset): start over.
|
// A different first comment means a different slide (or a reset): start over.
|
||||||
var key = String(items[0].id);
|
var key = String(items[0].id);
|
||||||
if (key !== Comments.key) {
|
if (key !== Comments.key) {
|
||||||
@@ -443,7 +446,7 @@
|
|||||||
'Kommentar ' + (Comments.index + 1) + ' von ' + Comments.items.length;
|
'Kommentar ' + (Comments.index + 1) + ' von ' + Comments.items.length;
|
||||||
text.textContent = item.text;
|
text.textContent = item.text;
|
||||||
var value = node.querySelector('[data-comment-value]');
|
var value = node.querySelector('[data-comment-value]');
|
||||||
value.textContent = item.value === null || item.value === undefined ? '' : 'Bewertung: ' + item.value;
|
value.textContent = item.value === null || item.value === undefined ? '' : 'Bewertung: ' + Comments.format(item.value);
|
||||||
value.hidden = value.textContent === '';
|
value.hidden = value.textContent === '';
|
||||||
// Only announce changes the viewer triggered, not every automatic rotation.
|
// Only announce changes the viewer triggered, not every automatic rotation.
|
||||||
node.setAttribute('aria-live', Comments.paused ? 'polite' : 'off');
|
node.setAttribute('aria-live', Comments.paused ? 'polite' : 'off');
|
||||||
@@ -529,6 +532,9 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
scale: function (results) {
|
scale: function (results) {
|
||||||
|
if (results.stars) {
|
||||||
|
return Results.stars(results);
|
||||||
|
}
|
||||||
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
|
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
|
||||||
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
||||||
var hasAverage = results.average !== null;
|
var hasAverage = results.average !== null;
|
||||||
@@ -575,10 +581,68 @@
|
|||||||
]),
|
]),
|
||||||
gauge
|
gauge
|
||||||
]);
|
]);
|
||||||
var comments = results.comments && results.comments.length ? Comments.render(results.comments) : null;
|
var comments = results.comments && results.comments.length ? Comments.render(results.comments, String) : null;
|
||||||
return el('div', { class: 'scale-results' }, [average, columns, labels, comments]);
|
return el('div', { class: 'scale-results' }, [average, columns, labels, comments]);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Star rating (scale with stars): average as partly filled stars, distribution as
|
||||||
|
* horizontal bars from most to fewest stars, like a product rating.
|
||||||
|
*/
|
||||||
|
stars: function (results) {
|
||||||
|
var max = Math.max.apply(null, results.buckets.map(function (b) { return b.count; }).concat([1]));
|
||||||
|
var total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
||||||
|
var hasAverage = results.average !== null;
|
||||||
|
var averageText = hasAverage
|
||||||
|
? Number(results.average).toLocaleString('de-DE', { minimumFractionDigits: 1, maximumFractionDigits: 1 })
|
||||||
|
: '–';
|
||||||
|
var row = Array(results.max + 1).join('★');
|
||||||
|
var meter = el('div', {
|
||||||
|
class: 'star-meter',
|
||||||
|
role: 'img',
|
||||||
|
'aria-label': 'Durchschnitt ' + averageText + ' von ' + results.max + ' Sternen'
|
||||||
|
}, [
|
||||||
|
// Same glyphs twice: the filled layer is clipped to the average.
|
||||||
|
el('span', { class: 'star-meter__base', 'aria-hidden': 'true', text: row }),
|
||||||
|
el('span', {
|
||||||
|
class: 'star-meter__fill',
|
||||||
|
'aria-hidden': 'true',
|
||||||
|
style: 'width:' + (hasAverage ? results.average / results.max * 100 : 0) + '%',
|
||||||
|
text: row
|
||||||
|
})
|
||||||
|
]);
|
||||||
|
var average = el('div', { class: 'average average--stars' }, [
|
||||||
|
el('div', { class: 'average__figure' }, [
|
||||||
|
el('span', { class: 'average__label', text: 'Durchschnitt' }),
|
||||||
|
el('span', { class: 'average__value' }, [
|
||||||
|
el('strong', { text: averageText }),
|
||||||
|
el('span', { class: 'average__of', text: ' von ' + results.max })
|
||||||
|
]),
|
||||||
|
el('span', { class: 'average__count', text: total + (total === 1 ? ' Bewertung' : ' Bewertungen') })
|
||||||
|
]),
|
||||||
|
meter
|
||||||
|
]);
|
||||||
|
var bars = el('div', { class: 'bars bars--stars' }, results.buckets.slice().reverse().map(function (bucket) {
|
||||||
|
return el('div', { class: 'bar bar--star' }, [
|
||||||
|
el('div', { class: 'bar__label', text: bucket.value + (bucket.value === 1 ? ' Stern' : ' Sterne') }),
|
||||||
|
el('div', { class: 'bar__track' }, [
|
||||||
|
el('div', { class: 'bar__fill', style: 'width:' + (bucket.count / max * 100) + '%' })
|
||||||
|
]),
|
||||||
|
el('div', { class: 'bar__value', text: formatNumber(bucket.percent) + ' % (' + bucket.count + ')' })
|
||||||
|
]);
|
||||||
|
}));
|
||||||
|
var labels = results.minLabel || results.maxLabel
|
||||||
|
? el('p', { class: 'stars-legend', text: '1 Stern: ' + (results.minLabel || '–') + ' · ' + results.max + ' Sterne: ' + (results.maxLabel || '–') })
|
||||||
|
: null;
|
||||||
|
var comments = results.comments && results.comments.length
|
||||||
|
? Comments.render(results.comments, function (value) {
|
||||||
|
return row.slice(0, value) + Array(results.max - value + 1).join('☆')
|
||||||
|
+ ' (' + value + ' von ' + results.max + ')';
|
||||||
|
})
|
||||||
|
: null;
|
||||||
|
return el('div', { class: 'scale-results' }, [average, bars, labels, comments]);
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* options: {mine: [keys], down: [keys], onUpvote: fn(word)|null, onDownvote: fn(word)|null}
|
* options: {mine: [keys], down: [keys], onUpvote: fn(word)|null, onDownvote: fn(word)|null}
|
||||||
* Counts are shown as "+up" and "−down" (down only when > 0 or clickable).
|
* Counts are shown as "+up" and "−down" (down only when > 0 or clickable).
|
||||||
@@ -2196,6 +2260,33 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ------------------------------------------------------------------ scale style (slide form)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Stars always start at one star: hide "Von" and call "Bis" the number of stars.
|
||||||
|
* Without JS both fields stay visible and the server ignores "Von" for stars.
|
||||||
|
*/
|
||||||
|
function initScaleStyle(fieldset) {
|
||||||
|
var form = fieldset.form || fieldset.closest('form');
|
||||||
|
var min = form.querySelector('[data-scale-min]');
|
||||||
|
var max = form.querySelector('[data-label-stars]');
|
||||||
|
var maxLabel = max && form.querySelector('label[for="' + max.id + '"]');
|
||||||
|
|
||||||
|
function update() {
|
||||||
|
var checked = fieldset.querySelector('input[type=radio]:checked');
|
||||||
|
var stars = checked !== null && checked.value === 'stars';
|
||||||
|
if (min) {
|
||||||
|
min.hidden = stars;
|
||||||
|
}
|
||||||
|
if (maxLabel) {
|
||||||
|
maxLabel.textContent = max.getAttribute(stars ? 'data-label-stars' : 'data-label-numbers');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fieldset.addEventListener('change', update);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------------------------------------------------------ theme switch
|
// ------------------------------------------------------------------ theme switch
|
||||||
|
|
||||||
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
|
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
|
||||||
@@ -2264,6 +2355,7 @@
|
|||||||
document.querySelectorAll('[data-sortable]').forEach(initSortable);
|
document.querySelectorAll('[data-sortable]').forEach(initSortable);
|
||||||
document.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
|
document.querySelectorAll('[data-order-options]').forEach(initOrderOptions);
|
||||||
document.querySelectorAll('[data-order-form]').forEach(initOrderForm);
|
document.querySelectorAll('[data-order-form]').forEach(initOrderForm);
|
||||||
|
document.querySelectorAll('[data-scale-style]').forEach(initScaleStyle);
|
||||||
|
|
||||||
// Prevent double submits of vote forms.
|
// Prevent double submits of vote forms.
|
||||||
document.querySelectorAll('.vote-form').forEach(function (form) {
|
document.querySelectorAll('.vote-form').forEach(function (form) {
|
||||||
|
|||||||
Reference in new issue
Block a user