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>
This commit is contained in:
1 parent
50010484be
commit
9983d6c01b
8 files changed
+301
-8
No files matched your search
@@ -182,6 +182,46 @@ class AdminControllerTest extends TestCase
|
||||
$this->assertSame(1, $this->slidesTable()->get($first->id)->position);
|
||||
}
|
||||
|
||||
public function testReorderSlidesByDragAndDrop(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
$a = $this->createSlide($poll, Slide::TYPE_OPEN);
|
||||
$b = $this->createSlide($poll, Slide::TYPE_SCALE);
|
||||
$c = $this->createSlide($poll, Slide::TYPE_CHOICE);
|
||||
$positions = fn(): array => array_map(
|
||||
fn($s) => $s->id,
|
||||
$this->slidesTable()->listForPoll($poll->id),
|
||||
);
|
||||
|
||||
$this->get("/admin/$token");
|
||||
$this->assertResponseContains('data-sortable=');
|
||||
$this->assertResponseContains('data-slide-id="' . $a->id . '"');
|
||||
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/slides/reorder", ['ids' => [$c->id, $a->id, $b->id]]);
|
||||
$this->assertResponseOk();
|
||||
$this->assertTrue(json_decode((string)$this->_response->getBody(), true)['ok']);
|
||||
$this->assertSame([$c->id, $a->id, $b->id], $positions());
|
||||
$this->assertSame(1, $this->slidesTable()->get($c->id)->position);
|
||||
|
||||
// Same order again is fine (idempotent).
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/slides/reorder", ['ids' => [$c->id, $a->id, $b->id]]);
|
||||
$this->assertResponseOk();
|
||||
$this->assertSame([$c->id, $a->id, $b->id], $positions());
|
||||
|
||||
// Incomplete, duplicated or foreign ids change nothing.
|
||||
[$other] = $this->createPoll('Andere');
|
||||
$foreign = $this->createSlide($other, Slide::TYPE_OPEN);
|
||||
foreach ([[$a->id, $b->id], [$a->id, $a->id, $b->id], [$a->id, $b->id, $foreign->id], []] as $ids) {
|
||||
$this->configRequest(['headers' => ['Accept' => 'application/json']]);
|
||||
$this->post("/admin/$token/slides/reorder", ['ids' => $ids]);
|
||||
$this->assertResponseCode(409);
|
||||
$this->assertSame([$c->id, $a->id, $b->id], $positions());
|
||||
}
|
||||
$this->assertSame(1, $this->slidesTable()->get($foreign->id)->position);
|
||||
}
|
||||
|
||||
public function testPresentStartsWithFirstSlideAndControlNavigates(): void
|
||||
{
|
||||
[$poll, $token] = $this->createPoll();
|
||||
|
||||
Reference in new issue
Block a user