Feature/star rating #43
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
|
||||
`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.
|
||||
- **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
|
||||
(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
|
||||
|
||||
@@ -55,6 +55,12 @@ class Slide extends Entity
|
||||
*/
|
||||
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
|
||||
* 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)
|
||||
// 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)
|
||||
// style: numbers or stars (SCALE_*), stars always start at scale_min = 1
|
||||
self::TYPE_SCALE => [
|
||||
'style' => self::SCALE_NUMBERS,
|
||||
'scale_min' => 1, 'scale_max' => 5, 'min_label' => '', 'max_label' => '', 'private' => false,
|
||||
'comments' => false, 'comment_ratings' => false,
|
||||
],
|
||||
@@ -449,4 +457,31 @@ class Slide extends Entity
|
||||
{
|
||||
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);
|
||||
break;
|
||||
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)));
|
||||
$settings['scale_min'] = $min;
|
||||
$settings['scale_max'] = $max;
|
||||
|
||||
@@ -18,7 +18,7 @@ use Cake\ORM\Locator\LocatorAwareTrait;
|
||||
* weight follows count)
|
||||
* - open: 'answers' => [['text', 'created']] newest first, 'private' (bool);
|
||||
* - 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 [];
|
||||
* 'value' is null unless the setting comment_ratings is on;
|
||||
* presentation only: participants never get results of scale slides, see PollStateService);
|
||||
@@ -394,7 +394,7 @@ class ResultsService
|
||||
* Distribution and average of a scale.
|
||||
*
|
||||
* @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
|
||||
{
|
||||
@@ -432,6 +432,7 @@ class ResultsService
|
||||
'max' => $max,
|
||||
'minLabel' => (string)$slide->setting('min_label'),
|
||||
'maxLabel' => (string)$slide->setting('max_label'),
|
||||
'stars' => $slide->isStarRating(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -665,7 +665,9 @@ class VoteService
|
||||
$min = (int)$slide->setting('scale_min');
|
||||
$max = (int)$slide->setting('scale_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.
|
||||
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>
|
||||
<?= __('Durchschnitt') ?>:
|
||||
<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>
|
||||
<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>
|
||||
<?php foreach ($r['buckets'] as $i => $bucket) :
|
||||
$label = match (true) {
|
||||
@@ -183,7 +185,7 @@ $bar = function (float $percent, bool $ok = false): string {
|
||||
default => '',
|
||||
}; ?>
|
||||
<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"><?= $number((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) : ?>
|
||||
<li>
|
||||
<?= 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>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
|
||||
@@ -280,15 +280,28 @@ $countdown = function (?int $remaining): string {
|
||||
</p>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php elseif ($slide->type === 'scale') : ?>
|
||||
<div class="scale"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||
<?php for ($v = (int)$slide->setting('scale_min'); $v <= (int)$slide->setting('scale_max'); $v++) : ?>
|
||||
<label class="scale__step">
|
||||
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||
<span><?= $v ?></span>
|
||||
</label>
|
||||
<?php endfor; ?>
|
||||
</div>
|
||||
<?php elseif ($slide->type === 'scale') :
|
||||
$maxValue = (int)$slide->setting('scale_max'); ?>
|
||||
<?php if ($slide->isStarRating()) : ?>
|
||||
<div class="stars<?= $maxValue > 6 ? ' stars--many' : '' ?>" role="radiogroup" aria-label="<?= __('Bewertung in Sternen') ?>"<?= $slide->isPrivate() ? ' aria-describedby="private-hint"' : '' ?>>
|
||||
<?php for ($v = 1; $v <= $maxValue; $v++) : ?>
|
||||
<label class="stars__star">
|
||||
<input type="radio" name="value" value="<?= $v ?>" required>
|
||||
<span class="stars__icon" aria-hidden="true">★</span>
|
||||
<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">
|
||||
<span><?= h((string)$slide->setting('min_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">
|
||||
<?= __('Durchschnitt') ?>:
|
||||
<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>
|
||||
<table class="scale-table">
|
||||
<caption class="sr-only"><?= __('Verteilung der Bewertungen') ?></caption>
|
||||
<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>
|
||||
<tbody>
|
||||
<?php foreach ($scale['buckets'] as $i => $bucket) :
|
||||
@@ -58,7 +58,7 @@ $count = $scale !== null ? array_sum(array_column($scale['buckets'], 'count')) :
|
||||
default => '',
|
||||
}; ?>
|
||||
<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>
|
||||
<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']); ?>
|
||||
<li>
|
||||
<?= 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>
|
||||
<?php endforeach; ?>
|
||||
</ol>
|
||||
|
||||
@@ -148,14 +148,25 @@ $optionsError = $slide->getError('options_text');
|
||||
'checked' => (bool)$settings['allow_downvotes'],
|
||||
]) ?>
|
||||
<?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">
|
||||
<?= $this->Form->control('settings.scale_min', [
|
||||
'type' => 'select', 'options' => [0 => '0', 1 => '1'],
|
||||
'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', [
|
||||
'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', [
|
||||
'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 li, ul.list li { margin-bottom: 1.2mm; }
|
||||
.stat { font-size: 12pt; font-weight: bold; }
|
||||
td.stars { color: #c27c00; letter-spacing: 1pt; }
|
||||
.empty { color: #5d6280; font-style: italic; }
|
||||
</style>
|
||||
</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 */
|
||||
--notice-bg: #fff6e0;
|
||||
--notice-ink: #6b4a00;
|
||||
--star: #d48500; /* star rating, 3:1 against light surfaces */
|
||||
--star-empty: #c3c8da;
|
||||
color-scheme: light;
|
||||
}
|
||||
|
||||
@@ -50,6 +52,8 @@
|
||||
--shadow: none;
|
||||
--notice-bg: #3a2f12;
|
||||
--notice-ink: #f3d98f;
|
||||
--star: #ffc233;
|
||||
--star-empty: #464a66;
|
||||
color-scheme: dark;
|
||||
}
|
||||
|
||||
@@ -67,6 +71,8 @@
|
||||
--shadow: none;
|
||||
--notice-bg: #3a2f12;
|
||||
--notice-ink: #f3d98f;
|
||||
--star: #ffc233;
|
||||
--star-empty: #464a66;
|
||||
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-options.error .order-options__list input[type=text] { border-color: var(--danger); }
|
||||
|
||||
/* dashboard: PDF export, choice between public and complete version */
|
||||
.export-choice { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
|
||||
.export-choice 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: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); }
|
||||
/* radio cards: PDF export (public/complete version), scale style (numbers/stars) */
|
||||
.export-choice, .scale-style { border: 0; padding: 0; margin: 0 0 12px; display: grid; gap: 8px; }
|
||||
.export-choice legend, .scale-style legend { font-weight: 600; margin-bottom: 4px; }
|
||||
.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), .scale-style label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
|
||||
.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 .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:focus-visible + span { outline: 3px solid var(--primary-soft); }
|
||||
.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); }
|
||||
.waiting { padding: 48px 24px; }
|
||||
.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__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); }
|
||||
/* 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__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 td:last-child { width: 50%; }
|
||||
.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 */
|
||||
/* 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-ok: #3ddc97; /* brighter green for contrast on the dark stage */
|
||||
--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);
|
||||
color: var(--text);
|
||||
overflow: hidden;
|
||||
@@ -602,6 +631,8 @@ body.present {
|
||||
--stage-glow: #dcd8ff;
|
||||
--stage-ok: var(--ok);
|
||||
--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 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__track { height: .7em; box-shadow: none; background: linear-gradient(90deg, var(--surface-2), var(--c1)); }
|
||||
.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 .answers { columns: 340px; }
|
||||
.stage .quiz-timer { font-size: clamp(3rem, 7vw, 6rem); }
|
||||
|
||||
+95
-3
@@ -302,6 +302,7 @@
|
||||
paused: false,
|
||||
timer: null,
|
||||
items: [],
|
||||
format: String,
|
||||
node: null,
|
||||
// Countdown of the comment shown (drives the progress bar across re-renders).
|
||||
startedAt: 0,
|
||||
@@ -315,8 +316,10 @@
|
||||
|
||||
/**
|
||||
* @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.
|
||||
var key = String(items[0].id);
|
||||
if (key !== Comments.key) {
|
||||
@@ -443,7 +446,7 @@
|
||||
'Kommentar ' + (Comments.index + 1) + ' von ' + Comments.items.length;
|
||||
text.textContent = item.text;
|
||||
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 === '';
|
||||
// Only announce changes the viewer triggered, not every automatic rotation.
|
||||
node.setAttribute('aria-live', Comments.paused ? 'polite' : 'off');
|
||||
@@ -529,6 +532,9 @@
|
||||
},
|
||||
|
||||
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 total = results.buckets.reduce(function (sum, b) { return sum + b.count; }, 0);
|
||||
var hasAverage = results.average !== null;
|
||||
@@ -575,10 +581,68 @@
|
||||
]),
|
||||
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]);
|
||||
},
|
||||
|
||||
/**
|
||||
* 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}
|
||||
* 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
|
||||
|
||||
var THEME_ICONS = { auto: '◐', light: '☀', dark: '☾' };
|
||||
@@ -2264,6 +2355,7 @@
|
||||
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) {
|
||||
|
||||
Reference in new issue
Block a user