Merge pull request 'Remove up/down buttons for slides' (#9) from refactor/remove-slide-move-buttons into main
Reviewed-on: #9
This commit was merged in pull request #9.
This commit is contained in:
commit
93aeae1884
7 files changed
+4
-60
No files matched your search
@@ -55,7 +55,7 @@ src/
|
|||||||
HomeController Startseite, Anlegen (/create), Bestätigung, Join, Recover
|
HomeController Startseite, Anlegen (/create), Bestätigung, Join, Recover
|
||||||
AdminAppController Basis für /admin/{token}: löst Poll über Token-Hash auf (404 sonst), setzt Privacy-Header
|
AdminAppController Basis für /admin/{token}: löst Poll über Token-Hash auf (404 sonst), setzt Privacy-Header
|
||||||
AdminController Dashboard, Settings, Present, State-JSON, Control, QR, CSV-Export, Token rotieren, Löschen
|
AdminController Dashboard, Settings, Present, State-JSON, Control, QR, CSV-Export, Token rotieren, Löschen
|
||||||
SlidesController Folien-CRUD, Sortieren (↑/↓ und Drag & Drop via `reorder`, JSON), Antworten zurücksetzen
|
SlidesController Folien-CRUD, Sortieren (Drag & Drop/Pfeiltasten via `reorder`, JSON; erfordert JS), Antworten zurücksetzen
|
||||||
ParticipateController /p/{code}: Ansicht, State-JSON, Abstimmen; anonymes Cookie plenario_pid
|
ParticipateController /p/{code}: Ansicht, State-JSON, Abstimmen; anonymes Cookie plenario_pid
|
||||||
Mailer/ PollMailer (adminLink, recovery), Transport/FileTransport (lokal)
|
Mailer/ PollMailer (adminLink, recovery), Transport/FileTransport (lokal)
|
||||||
Model/ Polls → Slides → SlideOptions, Slides → Responses
|
Model/ Polls → Slides → SlideOptions, Slides → Responses
|
||||||
|
|||||||
@@ -63,8 +63,6 @@ return function (RouteBuilder $routes): void {
|
|||||||
->setPatterns($token)->setPass(['id'])->setMethods(['POST']);
|
->setPatterns($token)->setPass(['id'])->setMethods(['POST']);
|
||||||
$admin->connect('/slides/reorder', 'Slides::reorder', ['_name' => 'slides:reorder'])
|
$admin->connect('/slides/reorder', 'Slides::reorder', ['_name' => 'slides:reorder'])
|
||||||
->setPatterns($token)->setMethods(['POST']);
|
->setPatterns($token)->setMethods(['POST']);
|
||||||
$admin->connect('/slides/{id}/move/{direction}', 'Slides::move', ['_name' => 'slides:move'])
|
|
||||||
->setPatterns($token + ['direction' => 'up|down'])->setPass(['id', 'direction'])->setMethods(['POST']);
|
|
||||||
$admin->connect('/slides/{id}/reset', 'Slides::reset', ['_name' => 'slides:reset'])
|
$admin->connect('/slides/{id}/reset', 'Slides::reset', ['_name' => 'slides:reset'])
|
||||||
->setPatterns($token)->setPass(['id'])->setMethods(['POST']);
|
->setPatterns($token)->setPass(['id'])->setMethods(['POST']);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -107,19 +107,6 @@ class SlidesController extends AdminAppController
|
|||||||
return $this->redirect($this->adminUrl());
|
return $this->redirect($this->adminUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $id Slide id
|
|
||||||
* @param string $direction up|down
|
|
||||||
* @return \Cake\Http\Response|null
|
|
||||||
*/
|
|
||||||
public function move(string $id, string $direction): ?Response
|
|
||||||
{
|
|
||||||
$this->request->allowMethod(['post']);
|
|
||||||
$this->Slides->move($this->loadSlide($id), $direction);
|
|
||||||
|
|
||||||
return $this->redirect($this->adminUrl());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves a complete new slide order (drag & drop), expects `ids[]` and answers with JSON.
|
* Saves a complete new slide order (drag & drop), expects `ids[]` and answers with JSON.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -262,38 +262,6 @@ class SlidesTable extends Table
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Swaps the slide with its neighbour.
|
|
||||||
*
|
|
||||||
* @param \App\Model\Entity\Slide $slide Slide to move
|
|
||||||
* @param string $direction 'up' or 'down'
|
|
||||||
* @return bool Whether something changed
|
|
||||||
*/
|
|
||||||
public function move(Slide $slide, string $direction): bool
|
|
||||||
{
|
|
||||||
$this->normalizePositions($slide->poll_id);
|
|
||||||
$slide = $this->get($slide->id);
|
|
||||||
|
|
||||||
$neighbour = $this->find()
|
|
||||||
->where([
|
|
||||||
'poll_id' => $slide->poll_id,
|
|
||||||
'position' . ($direction === 'up' ? ' <' : ' >') => $slide->position,
|
|
||||||
])
|
|
||||||
->orderBy(['position' => $direction === 'up' ? 'DESC' : 'ASC'])
|
|
||||||
->first();
|
|
||||||
if ($neighbour === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (bool)$this->getConnection()->transactional(function () use ($slide, $neighbour): bool {
|
|
||||||
$position = $slide->position;
|
|
||||||
$slide->position = $neighbour->position;
|
|
||||||
$neighbour->position = $position;
|
|
||||||
|
|
||||||
return $this->save($slide) && $this->save($neighbour);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Applies a complete new order (e.g. from drag & drop).
|
* Applies a complete new order (e.g. from drag & drop).
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -101,12 +101,6 @@ $url = fn(string $name, array $params = []) => ['_name' => $name, 'token' => $ad
|
|||||||
]) ?>
|
]) ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<a class="button button--small" href="<?= $this->Url->build($url('slides:edit', ['id' => $slide->id])) ?>"><?= __('Bearbeiten') ?></a>
|
<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) : ?>
|
<?php if ($count > 0) : ?>
|
||||||
<?= $this->Form->postLink(__('Zurücksetzen'), $url('slides:reset', ['id' => $slide->id]), [
|
<?= $this->Form->postLink(__('Zurücksetzen'), $url('slides:reset', ['id' => $slide->id]), [
|
||||||
'class' => 'button button--small',
|
'class' => 'button button--small',
|
||||||
|
|||||||
@@ -167,19 +167,17 @@ class AdminControllerTest extends TestCase
|
|||||||
$this->assertSame($optionA->id, $slide->slide_options[1]->id);
|
$this->assertSame($optionA->id, $slide->slide_options[1]->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testMoveAndDeleteSlides(): void
|
public function testDeleteSlideClosesPositionGap(): void
|
||||||
{
|
{
|
||||||
[$poll, $token] = $this->createPoll();
|
[$poll, $token] = $this->createPoll();
|
||||||
$first = $this->createSlide($poll, Slide::TYPE_OPEN);
|
$first = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||||
$second = $this->createSlide($poll, Slide::TYPE_SCALE);
|
$second = $this->createSlide($poll, Slide::TYPE_SCALE);
|
||||||
|
$third = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||||
$this->post("/admin/$token/slides/{$second->id}/move/up");
|
|
||||||
$this->assertSame(1, $this->slidesTable()->get($second->id)->position);
|
|
||||||
$this->assertSame(2, $this->slidesTable()->get($first->id)->position);
|
|
||||||
|
|
||||||
$this->post("/admin/$token/slides/{$second->id}/delete");
|
$this->post("/admin/$token/slides/{$second->id}/delete");
|
||||||
$this->assertFalse($this->slidesTable()->exists(['id' => $second->id]));
|
$this->assertFalse($this->slidesTable()->exists(['id' => $second->id]));
|
||||||
$this->assertSame(1, $this->slidesTable()->get($first->id)->position);
|
$this->assertSame(1, $this->slidesTable()->get($first->id)->position);
|
||||||
|
$this->assertSame(2, $this->slidesTable()->get($third->id)->position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testReorderSlidesByDragAndDrop(): void
|
public function testReorderSlidesByDragAndDrop(): void
|
||||||
|
|||||||
@@ -133,7 +133,6 @@ h3 { font-size: 1.05rem; margin-top: 1.6em; }
|
|||||||
.button--danger:hover { border-color: var(--danger); }
|
.button--danger:hover { border-color: var(--danger); }
|
||||||
.button--ghost { border-color: transparent; background: transparent; }
|
.button--ghost { border-color: transparent; background: transparent; }
|
||||||
.button--small { padding: 6px 10px; font-size: .85rem; }
|
.button--small { padding: 6px 10px; font-size: .85rem; }
|
||||||
.button--icon { min-width: 32px; }
|
|
||||||
.button--block { width: 100%; padding: 14px; font-size: 1.05rem; }
|
.button--block { width: 100%; padding: 14px; font-size: 1.05rem; }
|
||||||
|
|
||||||
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
|
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: .75rem; font-weight: 700; background: var(--surface-2); color: var(--muted); }
|
||||||
|
|||||||
Reference in new issue
Block a user