Files
Plenario/templates/Admin/index.php
T
gnilebeinandClaude Opus 5.5 9983d6c01b
CI / Deploy / test (push) Successful in 43s
CI / Deploy / deploy (push) Skipped
Add drag and drop sorting for slides
Slides can be reordered on the dashboard by dragging the handle (mouse,
touch and pen via Pointer Events) or with the arrow keys on the focused
handle. The new order is posted as ids[] to slides/reorder, which only
applies a complete, valid order of the poll's own slides. The up/down
buttons stay as no-JS fallback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-07 14:44:10 +01:00

184 lines
10 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
/**
* Admin dashboard of a poll.
*
* @var \App\View\AppView $this
* @var \App\Model\Entity\Poll $poll
* @var string $adminToken
* @var list<\App\Model\Entity\Slide> $slides
* @var array<int, int> $responseCounts
* @var array<string, string> $typeLabels
* @var array<string, string> $typeDescriptions
* @var string $joinUrl
*/
$this->assign('title', $poll->title);
$this->assign('noindex', '1');
$url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $adminToken] + $params;
?>
<div class="admin-head">
<div>
<p class="eyebrow"><?= __('Verwaltung') ?></p>
<h1><?= h($poll->title) ?></h1>
<p class="muted">
<?php if ($poll->is_active) : ?>
<span class="badge badge--ok"><?= __('aktiv') ?></span>
<?php else : ?>
<span class="badge badge--off"><?= __('geschlossen') ?></span>
<?php endif; ?>
<?= __('{0} Folien', count($slides)) ?>
</p>
</div>
<div class="admin-head__actions">
<a class="button button--primary" target="_blank" rel="noopener"
href="<?= $this->Url->build($url('admin:present')) ?>">▶ <?= __('Präsentieren') ?></a>
<a class="button" href="<?= $this->Url->build($url('admin:export')) ?>"><?= __('CSV-Export') ?></a>
</div>
</div>
<div class="notice">
<strong><?= __('Bookmark diese Seite!') ?></strong>
<?= __('Diese URL ist dein Zugang zur Umfrage. Wer sie kennt, kann alles bearbeiten.') ?>
</div>
<div class="grid grid--sidebar">
<section>
<div class="section-head">
<h2><?= __('Folien') ?></h2>
</div>
<?php if ($slides === []) : ?>
<div class="empty">
<p><?= __('Noch keine Folien. Wähle unten einen Typ, um die erste Frage anzulegen.') ?></p>
</div>
<?php endif; ?>
<?php if (count($slides) > 1) : ?>
<p class="muted slide-list__hint" data-sortable-hint hidden><?= __('Tipp: Folien am Griff ⠿ ziehen, um die Reihenfolge zu ändern (oder Griff fokussieren und Pfeiltasten nutzen).') ?></p>
<?php endif; ?>
<ol class="slide-list" data-sortable="<?= h($this->Url->build($url('slides:reorder'))) ?>">
<?php foreach ($slides as $i => $slide) :
$isCurrent = $poll->current_slide_id === $slide->id;
$count = $responseCounts[$slide->id] ?? 0;
?>
<li class="slide-item<?= $isCurrent ? ' slide-item--current' : '' ?>" data-slide-id="<?= $slide->id ?>">
<div class="slide-item__lead">
<button type="button" class="drag-handle" data-drag-handle hidden
aria-label="<?= h(__('Folie „{0}“ verschieben (Pfeiltasten)', $slide->question)) ?>"
title="<?= __('Ziehen zum Sortieren') ?>">⠿</button>
<span class="slide-item__pos" data-position><?= $i + 1 ?></span>
</div>
<div class="slide-item__body">
<div class="slide-item__meta">
<span class="badge badge--type-<?= h($slide->type) ?>"><?= h($slide->typeLabel()) ?></span>
<?php if ($isCurrent) : ?><span class="badge badge--live"><?= __('live') ?></span><?php endif; ?>
<?php if ($slide->isInteractive()) : ?>
<span class="muted"><?= __n('{0} Antwort', '{0} Antworten', $count, $count) ?></span>
<?php if ($slide->isQuiz()) : ?>
<span class="muted">· <?= h([
'ready' => __('Quiz noch nicht gestartet'),
'running' => __('Quiz läuft'),
'finished' => __('Quiz beendet'),
][$slide->quizPhase()]) ?></span>
<?php elseif (!$slide->is_voting_open) : ?><span class="muted">· <?= __('Abstimmung geschlossen') ?></span><?php endif; ?>
<?php endif; ?>
</div>
<a class="slide-item__title" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= h($slide->question) ?></a>
<?php if ($slide->type === 'choice' && $slide->slide_options) : ?>
<p class="slide-item__options muted"><?= h(implode(' · ', array_map(fn($o) => $o->label, $slide->slide_options))) ?></p>
<?php elseif ($slide->isQuiz() && $slide->slide_options) : ?>
<p class="slide-item__options muted"><?= h(implode(' · ', array_map(
fn($o) => $o->is_correct ? '✓ ' . $o->label : $o->label,
$slide->slide_options,
))) ?></p>
<?php endif; ?>
</div>
<div class="slide-item__actions">
<?php if (!$isCurrent) : ?>
<?= $this->Form->postLink(__('Live'), $url('admin:control'), [
'data' => ['action' => 'goto', 'slide_id' => $slide->id],
'class' => 'button button--small',
'title' => __('Diese Folie jetzt den Teilnehmenden zeigen'),
]) ?>
<?php endif; ?>
<a class="button button--small" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= __('Bearbeiten') ?></a>
<?= $this->Form->postLink('↑', $url('slides:move', ['id' => $slide->id, 'direction' => 'up']), [
'class' => 'button button--small button--icon', 'title' => __('Nach oben'),
]) ?>
<?= $this->Form->postLink('↓', $url('slides:move', ['id' => $slide->id, 'direction' => 'down']), [
'class' => 'button button--small button--icon', 'title' => __('Nach unten'),
]) ?>
<?php if ($count > 0) : ?>
<?= $this->Form->postLink(__('Zurücksetzen'), $url('slides:reset', ['id' => $slide->id]), [
'class' => 'button button--small',
'confirm' => __('Alle {0} Antworten dieser Folie löschen?', $count),
]) ?>
<?php endif; ?>
<?= $this->Form->postLink(__('Löschen'), $url('slides:delete', ['id' => $slide->id]), [
'class' => 'button button--small button--danger',
'confirm' => __('Folie „{0}“ inkl. aller Antworten löschen?', $slide->question),
]) ?>
</div>
</li>
<?php endforeach; ?>
</ol>
<p class="sr-only" role="status" aria-live="polite" data-sortable-status></p>
<h3><?= __('Neue Folie') ?></h3>
<div class="type-picker">
<?php foreach ($typeLabels as $type => $label) : ?>
<a class="type-card type-card--<?= h($type) ?>" href="<?= $this->Url->build($url('slides:add', ['?' => ['type' => $type]])) ?>">
<strong><?= h($label) ?></strong>
<span><?= h($typeDescriptions[$type]) ?></span>
</a>
<?php endforeach; ?>
</div>
</section>
<aside class="sidebar">
<section class="card">
<h2><?= __('Teilnahme') ?></h2>
<p class="join-code"><?= h($poll->formattedJoinCode()) ?></p>
<img class="qr" src="<?= $this->Url->build($url('admin:qr')) ?>" alt="<?= __('QR-Code zur Teilnahme') ?>" width="160" height="160">
<div class="copy-field">
<input type="text" readonly value="<?= h($joinUrl) ?>" aria-label="<?= __('Teilnahme-Link') ?>" data-copy-source>
<button type="button" class="button button--small" data-copy><?= __('Kopieren') ?></button>
</div>
</section>
<section class="card">
<h2><?= __('Einstellungen') ?></h2>
<?= $this->Form->create($poll, ['url' => $url('admin:settings'), 'type' => 'post']) ?>
<?= $this->Form->control('title', ['label' => __('Titel'), 'maxlength' => 200]) ?>
<?= $this->Form->control('is_active', [
'type' => 'checkbox',
'label' => __('Umfrage ist aktiv (Teilnehmende können abstimmen)'),
]) ?>
<?= $this->Form->control('show_results_to_participants', [
'type' => 'checkbox',
'label' => __('Teilnehmende sehen Ergebnisse nach ihrer Antwort'),
]) ?>
<?= $this->Form->button(__('Speichern'), ['class' => 'button']) ?>
<?= $this->Form->end() ?>
</section>
<section class="card card--danger">
<h2><?= __('Sicherheit') ?></h2>
<p class="hint"><?= __('Link versehentlich geteilt? Erzeuge einen neuen – der alte wird sofort ungültig.') ?></p>
<?= $this->Form->postLink(__('Neuen Admin-Link erzeugen'), $url('admin:rotate'), [
'class' => 'button button--small',
'confirm' => __('Neuen Admin-Link erzeugen? Der aktuelle Link funktioniert danach nicht mehr.'),
]) ?>
<h3><?= __('Umfrage löschen') ?></h3>
<?= $this->Form->create(null, ['url' => $url('admin:delete')]) ?>
<?= $this->Form->control('confirm_code', [
'label' => __('Zum Bestätigen Code {0} eingeben', $poll->join_code),
'autocomplete' => 'off',
'required' => true,
]) ?>
<?= $this->Form->button(__('Endgültig löschen'), ['class' => 'button button--danger']) ?>
<?= $this->Form->end() ?>
</section>
</aside>
</div>