Let participants withdraw their own word cloud terms
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
3a8962976e
commit
ad5223906c
7 files changed
+154
-6
No files matched your search
@@ -134,6 +134,9 @@ tests/ PHPUnit; PlenarioTestTrait erzeugt Testdaten, Fixtures
|
|||||||
Downvotes (`vote=down`, Setting `allow_downvotes`, nur zusammen mit Upvotes): Zeile mit `numeric_value = VoteService::DOWNVOTE` (-1),
|
Downvotes (`vote=down`, Setting `allow_downvotes`, nur zusammen mit Upvotes): Zeile mit `numeric_value = VoteService::DOWNVOTE` (-1),
|
||||||
nur auf fremde, vorhandene Begriffe, ein Rating pro Begriff und Person.
|
nur auf fremde, vorhandene Begriffe, ein Rating pro Begriff und Person.
|
||||||
Wortgröße richtet sich nur nach den Upvotes (`count`), Downvotes stehen separat in `down`.
|
Wortgröße richtet sich nur nach den Upvotes (`count`), Downvotes stehen separat in `down`.
|
||||||
|
`vote=remove` nimmt den eigenen Eintrag zu einem Begriff zurück (genannt/Upvote oder Downvote, `VoteService::removeWord()`,
|
||||||
|
löscht nur Zeilen mit dem eigenen `participant_hash`); Tippfehler = entfernen und neu eingeben, kein Bearbeiten (die Zeile
|
||||||
|
ist zugleich die Stimme). Teilnehmende bekommen dafür `words.own` (eigene Begriffe wie eingegeben) und sehen sie als Chips mit „ד.
|
||||||
- Quiz: Phasen `ready` → `running` → `finished` (`Slide::quizPhase()`). Neue Quiz-Folien starten geschlossen;
|
- Quiz: Phasen `ready` → `running` → `finished` (`Slide::quizPhase()`). Neue Quiz-Folien starten geschlossen;
|
||||||
erst der Presenter startet (`control` open/toggle → `Slide::setVotingOpen()` setzt Start + Deadline aus
|
erst der Presenter startet (`control` open/toggle → `Slide::setVotingOpen()` setzt Start + Deadline aus
|
||||||
`time_limit`, erneutes Öffnen eines laufenden Quiz startet den Timer nicht neu). „Offen“ heißt immer
|
`time_limit`, erneutes Öffnen eines laufenden Quiz startet den Timer nicht neu). „Offen“ heißt immer
|
||||||
|
|||||||
@@ -321,8 +321,8 @@ class PollStateService
|
|||||||
*
|
*
|
||||||
* @param \App\Model\Entity\Slide $slide Word cloud slide
|
* @param \App\Model\Entity\Slide $slide Word cloud slide
|
||||||
* @param string $participantHash Participant hash
|
* @param string $participantHash Participant hash
|
||||||
* @return array{mine: list<string>, down: list<string>, allowUpvotes: bool, allowDownvotes: bool}
|
* @return array{mine: list<string>, down: list<string>, own: list<array{text: string, down: bool}>, allowUpvotes: bool, allowDownvotes: bool}
|
||||||
* `mine` (named/upvoted) and `down` are lower case word keys
|
* `mine` (named/upvoted) and `down` are lower case word keys, `own` the same entries as typed
|
||||||
*/
|
*/
|
||||||
public function wordState(Slide $slide, string $participantHash): array
|
public function wordState(Slide $slide, string $participantHash): array
|
||||||
{
|
{
|
||||||
@@ -330,10 +330,18 @@ class PollStateService
|
|||||||
$mine = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['up'])));
|
$mine = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['up'])));
|
||||||
$down = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['down'])));
|
$down = array_values(array_unique(array_map(VoteService::wordKey(...), $votes['down'])));
|
||||||
$allowUpvotes = (bool)$slide->setting('allow_upvotes');
|
$allowUpvotes = (bool)$slide->setting('allow_upvotes');
|
||||||
|
// Own entries as typed (first spelling per key), oldest first, so they can be withdrawn.
|
||||||
|
$own = [];
|
||||||
|
foreach (['up' => false, 'down' => true] as $kind => $isDown) {
|
||||||
|
foreach ($votes[$kind] as $text) {
|
||||||
|
$own[VoteService::wordKey($text)] ??= ['text' => $text, 'down' => $isDown];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'mine' => $mine,
|
'mine' => $mine,
|
||||||
'down' => $down,
|
'down' => $down,
|
||||||
|
'own' => array_values($own),
|
||||||
'allowUpvotes' => $allowUpvotes,
|
'allowUpvotes' => $allowUpvotes,
|
||||||
'allowDownvotes' => $allowUpvotes && (bool)$slide->setting('allow_downvotes'),
|
'allowDownvotes' => $allowUpvotes && (bool)$slide->setting('allow_downvotes'),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ use Cake\Utility\Security;
|
|||||||
* exists in the cloud is an upvote – both are stored as the same row.
|
* exists in the cloud is an upvote – both are stored as the same row.
|
||||||
* `vote=down` stores a downvote (numeric_value = DOWNVOTE) for an existing
|
* `vote=down` stores a downvote (numeric_value = DOWNVOTE) for an existing
|
||||||
* word of someone else. Each participant rates a word only once (up or down).
|
* word of someone else. Each participant rates a word only once (up or down).
|
||||||
|
* `vote=remove` withdraws the participant's own entry for a word (see removeWord()).
|
||||||
* At most MAX_WORDS_PER_REQUEST terms per request and MAX_WORDS per participant and slide.
|
* At most MAX_WORDS_PER_REQUEST terms per request and MAX_WORDS per participant and slide.
|
||||||
* - checks and insert run in one transaction with the slide row locked (see lockSlide()),
|
* - checks and insert run in one transaction with the slide row locked (see lockSlide()),
|
||||||
* so concurrent or repeated requests cannot store an answer twice.
|
* so concurrent or repeated requests cannot store an answer twice.
|
||||||
@@ -529,6 +530,11 @@ class VoteService
|
|||||||
if (($data['vote'] ?? null) === 'down') {
|
if (($data['vote'] ?? null) === 'down') {
|
||||||
return $this->downvoteRows($slide, self::stringField($data, 'word'), $existing, $downvoted);
|
return $this->downvoteRows($slide, self::stringField($data, 'word'), $existing, $downvoted);
|
||||||
}
|
}
|
||||||
|
if (($data['vote'] ?? null) === 'remove') {
|
||||||
|
$this->removeWord($slide, $participantHash, self::stringField($data, 'word'));
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
$input = array_filter(
|
$input = array_filter(
|
||||||
array_merge((array)($data['words'] ?? []), (array)($data['word'] ?? [])),
|
array_merge((array)($data['words'] ?? []), (array)($data['word'] ?? [])),
|
||||||
@@ -574,6 +580,36 @@ class VoteService
|
|||||||
return array_map(fn(string $word) => ['text_value' => $word], $words);
|
return array_map(fn(string $word) => ['text_value' => $word], $words);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Word cloud: withdraws the participant's own entry for a term – named/upvoted or downvoted –
|
||||||
|
* e.g. to fix a typo by entering it again. Only the participant's own rows are touched; the term
|
||||||
|
* stays in the cloud as long as others named it.
|
||||||
|
*
|
||||||
|
* @param \App\Model\Entity\Slide $slide Slide
|
||||||
|
* @param string $participantHash Participant hash
|
||||||
|
* @param string $word Word to withdraw
|
||||||
|
* @return void
|
||||||
|
* @throws \App\Service\VoteException
|
||||||
|
*/
|
||||||
|
protected function removeWord(Slide $slide, string $participantHash, string $word): void
|
||||||
|
{
|
||||||
|
$key = self::wordKey($word);
|
||||||
|
$ids = [];
|
||||||
|
$own = $this->Responses->find()
|
||||||
|
->select(['id', 'text_value'])
|
||||||
|
->where(['slide_id' => $slide->id, 'participant_hash' => $participantHash, 'text_value IS NOT' => null])
|
||||||
|
->disableHydration();
|
||||||
|
foreach ($own as $row) {
|
||||||
|
if (self::wordKey((string)$row['text_value']) === $key) {
|
||||||
|
$ids[] = $row['id'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($key === '' || $ids === []) {
|
||||||
|
throw new VoteException(__('Diesen Begriff hast du nicht genannt.'));
|
||||||
|
}
|
||||||
|
$this->Responses->deleteAll(['id IN' => $ids]);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \App\Model\Entity\Slide $slide Slide
|
* @param \App\Model\Entity\Slide $slide Slide
|
||||||
* @param string $word Word to downvote
|
* @param string $word Word to downvote
|
||||||
|
|||||||
@@ -218,6 +218,11 @@ $countdown = function (?int $remaining): string {
|
|||||||
<p class="word-message" data-word-message aria-live="polite"></p>
|
<p class="word-message" data-word-message aria-live="polite"></p>
|
||||||
<?= $this->Form->button(__('Begriff senden'), ['class' => 'button button--primary button--block']) ?>
|
<?= $this->Form->button(__('Begriff senden'), ['class' => 'button button--primary button--block']) ?>
|
||||||
<?= $this->Form->end() ?>
|
<?= $this->Form->end() ?>
|
||||||
|
<div class="own-words" data-own-words hidden>
|
||||||
|
<h2 class="own-words__heading"><?= __('Deine Begriffe') ?></h2>
|
||||||
|
<p class="hint"><?= __('Vertippt? Entferne den Begriff mit „ד und gib ihn neu ein.') ?></p>
|
||||||
|
<ul class="own-words__list" data-own-words-list></ul>
|
||||||
|
</div>
|
||||||
<?php elseif ($state['hasResponded']) : ?>
|
<?php elseif ($state['hasResponded']) : ?>
|
||||||
<p class="done">✓ <?= __('Deine Antwort ist angekommen.') ?></p>
|
<p class="done">✓ <?= __('Deine Antwort ist angekommen.') ?></p>
|
||||||
<?php if (VoteService::hasEditableText($slide) && $slide->isVotingOpen()) :
|
<?php if (VoteService::hasEditableText($slide) && $slide->isVotingOpen()) :
|
||||||
|
|||||||
@@ -279,4 +279,49 @@ class VoteServiceTest extends TestCase
|
|||||||
$this->assertEquals($slide->modified, $this->slidesTable()->get($slide->id)->modified);
|
$this->assertEquals($slide->modified, $this->slidesTable()->get($slide->id)->modified);
|
||||||
$this->assertSame($slide->position, $this->slidesTable()->get($slide->id)->position);
|
$this->assertSame($slide->position, $this->slidesTable()->get($slide->id)->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testWordcloudOwnEntryCanBeRemoved(): void
|
||||||
|
{
|
||||||
|
[$poll] = $this->createPoll();
|
||||||
|
$slide = $this->createSlide($poll, Slide::TYPE_WORDCLOUD);
|
||||||
|
$poll = $this->goLive($poll, $slide);
|
||||||
|
$service = new VoteService();
|
||||||
|
$service->submit($poll, $slide, 'p1', ['word' => 'Kafee']);
|
||||||
|
$service->submit($poll, $slide, 'p1', ['word' => 'Tee']);
|
||||||
|
$service->submit($poll, $slide, 'p2', ['word' => 'tee']);
|
||||||
|
$service->submit($poll, $slide, 'p2', ['word' => 'Kafee', 'vote' => 'down']);
|
||||||
|
|
||||||
|
$state = (new PollStateService())->wordState($slide, 'p1');
|
||||||
|
$this->assertSame([['text' => 'Kafee', 'down' => false], ['text' => 'Tee', 'down' => false]], $state['own']);
|
||||||
|
|
||||||
|
// Only the own row goes: "Tee" stays with the other upvote, "Kafee" keeps p2's downvote.
|
||||||
|
$service->submit($poll, $slide, 'p1', ['word' => 'TEE', 'vote' => 'remove']);
|
||||||
|
$service->submit($poll, $slide, 'p1', ['word' => 'Kafee', 'vote' => 'remove']);
|
||||||
|
$results = (new ResultsService())->forSlide($slide);
|
||||||
|
$this->assertSame([['tee', 1, 0]], array_map(fn($w) => [$w['text'], $w['count'], $w['down']], $results['words']));
|
||||||
|
$this->assertSame([], (new PollStateService())->wordState($slide, 'p1')['own']);
|
||||||
|
$this->assertSame(2, $this->fetchTable('Responses')->find()->where(['slide_id' => $slide->id])->count());
|
||||||
|
|
||||||
|
// A downvote can be withdrawn too; afterwards the word can be named again.
|
||||||
|
$service->submit($poll, $slide, 'p2', ['word' => 'kafee', 'vote' => 'remove']);
|
||||||
|
$this->assertSame([['text' => 'tee', 'down' => false]], (new PollStateService())->wordState($slide, 'p2')['own']);
|
||||||
|
$service->submit($poll, $slide, 'p1', ['word' => 'Kaffee']);
|
||||||
|
$this->assertSame(['kaffee'], (new PollStateService())->wordState($slide, 'p1')['mine']);
|
||||||
|
|
||||||
|
// Removing again (or someone else's word) changes nothing.
|
||||||
|
foreach ([['p1', 'Tee'], ['p3', 'Kaffee'], ['p1', '']] as [$participant, $word]) {
|
||||||
|
try {
|
||||||
|
$service->submit($poll, $slide, $participant, ['word' => $word, 'vote' => 'remove']);
|
||||||
|
$this->fail('VoteException expected for ' . $participant . '/' . $word);
|
||||||
|
} catch (VoteException $e) {
|
||||||
|
$this->assertSame('Diesen Begriff hast du nicht genannt.', $e->getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->assertSame(2, $this->fetchTable('Responses')->find()->where(['slide_id' => $slide->id])->count());
|
||||||
|
|
||||||
|
$this->slidesTable()->updateAll(['is_voting_open' => false], ['id' => $slide->id]);
|
||||||
|
$slide = $this->slidesTable()->get($slide->id);
|
||||||
|
$this->expectException(VoteException::class);
|
||||||
|
$service->submit($poll, $slide, 'p1', ['word' => 'Kaffee', 'vote' => 'remove']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -336,6 +336,13 @@ textarea { resize: vertical; }
|
|||||||
.suggestion__meta { font-size: .8rem; color: var(--muted); white-space: nowrap; align-self: center; }
|
.suggestion__meta { font-size: .8rem; color: var(--muted); white-space: nowrap; align-self: center; }
|
||||||
.word-message { min-height: 1.4em; margin: 8px 0 0; font-size: .9rem; color: var(--ok); }
|
.word-message { min-height: 1.4em; margin: 8px 0 0; font-size: .9rem; color: var(--ok); }
|
||||||
.word-message.is-error { color: var(--danger); }
|
.word-message.is-error { color: var(--danger); }
|
||||||
|
.own-words { margin-top: 20px; }
|
||||||
|
.own-words__heading { font-size: 1rem; margin: 0 0 4px; }
|
||||||
|
.own-words__list { list-style: none; padding: 0; margin: 8px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
|
||||||
|
.own-words__item { display: inline-flex; align-items: center; gap: 2px; padding: 2px 2px 2px 12px; border-radius: 999px; background: var(--primary-soft); overflow-wrap: anywhere; }
|
||||||
|
.own-words__item.is-down { background: var(--surface-2); color: var(--muted); }
|
||||||
|
.own-words__remove { min-width: 36px; min-height: 36px; border: 0; border-radius: 999px; background: transparent; color: inherit; font-size: 1.2rem; line-height: 1; cursor: pointer; }
|
||||||
|
.own-words__remove:hover, .own-words__remove:focus-visible { background: var(--border); }
|
||||||
.vote-form textarea { margin: 12px 0 16px; }
|
.vote-form textarea { margin: 12px 0 16px; }
|
||||||
.vote-form .button { margin-top: 12px; }
|
.vote-form .button { margin-top: 12px; }
|
||||||
.scale { display: flex; gap: 6px; margin: 20px 0 6px; }
|
.scale { display: flex; gap: 6px; margin: 20px 0 6px; }
|
||||||
|
|||||||
+48
-4
@@ -1655,6 +1655,7 @@
|
|||||||
function renderResults(state) {
|
function renderResults(state) {
|
||||||
current = state;
|
current = state;
|
||||||
renderQa(state);
|
renderQa(state);
|
||||||
|
renderOwnWords(state);
|
||||||
if (!card || !container) {
|
if (!card || !container) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1702,14 +1703,17 @@
|
|||||||
sending = true;
|
sending = true;
|
||||||
var slideId = wordForm.querySelector('[name=slide_id]').value;
|
var slideId = wordForm.querySelector('[name=slide_id]').value;
|
||||||
var data = { slide_id: slideId, word: text };
|
var data = { slide_id: slideId, word: text };
|
||||||
if (vote === 'down') {
|
if (vote) {
|
||||||
data.vote = 'down';
|
data.vote = vote;
|
||||||
}
|
}
|
||||||
postJson(voteUrl, data).then(function (response) {
|
postJson(voteUrl, data).then(function (response) {
|
||||||
var success = vote === 'down' ? '✓ „' + text + '“ abgelehnt.' : '✓ „' + text + '“ ist angekommen.';
|
var success = {
|
||||||
|
down: '✓ „' + text + '“ abgelehnt.',
|
||||||
|
remove: '✓ „' + text + '“ entfernt.'
|
||||||
|
}[vote] || '✓ „' + text + '“ ist angekommen.';
|
||||||
message.textContent = response.ok ? success : response.message;
|
message.textContent = response.ok ? success : response.message;
|
||||||
message.classList.toggle('is-error', !response.ok);
|
message.classList.toggle('is-error', !response.ok);
|
||||||
if (response.ok && vote !== 'down') {
|
if (response.ok && !vote) {
|
||||||
input.value = '';
|
input.value = '';
|
||||||
closeSuggestions();
|
closeSuggestions();
|
||||||
}
|
}
|
||||||
@@ -1722,6 +1726,46 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Own terms with a remove button (fix a typo by removing and entering again).
|
||||||
|
var ownWords = root.querySelector('[data-own-words]');
|
||||||
|
var ownWordsRendered = '';
|
||||||
|
|
||||||
|
function renderOwnWords(state) {
|
||||||
|
if (!ownWords || !state.words) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var own = state.words.own || [];
|
||||||
|
var key = JSON.stringify(own);
|
||||||
|
if (key === ownWordsRendered) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ownWordsRendered = key;
|
||||||
|
// Keep keyboard focus in the list after removing a term.
|
||||||
|
var hadFocus = ownWords.contains(document.activeElement);
|
||||||
|
var listNode = ownWords.querySelector('[data-own-words-list]');
|
||||||
|
listNode.textContent = '';
|
||||||
|
ownWords.hidden = own.length === 0;
|
||||||
|
own.forEach(function (word) {
|
||||||
|
var label = word.down ? 'Ablehnung von „' + word.text + '“ zurücknehmen' : '„' + word.text + '“ entfernen';
|
||||||
|
var remove = el('button', { type: 'button', class: 'own-words__remove', 'aria-label': label, title: label }, [
|
||||||
|
el('span', { 'aria-hidden': 'true', text: '×' })
|
||||||
|
]);
|
||||||
|
remove.addEventListener('click', function () {
|
||||||
|
sendWord(word.text, 'remove');
|
||||||
|
});
|
||||||
|
listNode.appendChild(el('li', { class: 'own-words__item' + (word.down ? ' is-down' : '') }, [
|
||||||
|
el('span', { text: (word.down ? '− ' : '') + word.text }),
|
||||||
|
remove
|
||||||
|
]));
|
||||||
|
});
|
||||||
|
if (hadFocus) {
|
||||||
|
var next = listNode.querySelector('button') || input;
|
||||||
|
if (next) {
|
||||||
|
next.focus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function applyWordState(state) {
|
function applyWordState(state) {
|
||||||
if (state.version !== version || !state.words) {
|
if (state.version !== version || !state.words) {
|
||||||
// Slide changed or voting closed.
|
// Slide changed or voting closed.
|
||||||
|
|||||||
Reference in new issue
Block a user