From 9f1650572c93b73192828a1f7e586b5fc0efcc95 Mon Sep 17 00:00:00 2001 From: salam Date: Sat, 5 Sep 2026 08:19:49 +0200 Subject: [PATCH] wip --- app/Livewire/BoardDispatcher.php | 98 ++++++-- .../views/livewire/board-dispatcher.blade.php | 215 +++++++++++------- 2 files changed, 206 insertions(+), 107 deletions(-) diff --git a/app/Livewire/BoardDispatcher.php b/app/Livewire/BoardDispatcher.php index c753ee09..82134b37 100644 --- a/app/Livewire/BoardDispatcher.php +++ b/app/Livewire/BoardDispatcher.php @@ -8,21 +8,25 @@ class BoardDispatcher extends Component { public array $lists = []; + public string $boardVersion = ''; + public function mount() { - $this->lists['source-attack'] = [ - ['id' => '1', 'name' => 'Source Item A', 'origin' => 'source-attack'], - ['id' => '2', 'name' => 'Source Item B', 'origin' => 'source-attack'], + $this->boardVersion = uniqid(); + + $this->lists['source-1'] = [ + ['id' => '1', 'name' => 'Source Item A', 'origin' => 'source-1'], + ['id' => '2', 'name' => 'Source Item B', 'origin' => 'source-1'], ]; - $this->lists['source-midfield'] = [ - ['id' => '3', 'name' => 'Source Item C', 'origin' => 'source-midfield'], + $this->lists['source-2'] = [ + ['id' => '3', 'name' => 'Source Item C', 'origin' => 'source-2'], ]; - $this->lists['source-defence'] = [ - ['id' => '4', 'name' => 'Source Item D', 'origin' => 'source-defence'], - ['id' => '5', 'name' => 'Source Item E', 'origin' => 'source-defence'], + $this->lists['source-3'] = [ + ['id' => '4', 'name' => 'Source Item D', 'origin' => 'source-3'], + ['id' => '5', 'name' => 'Source Item E', 'origin' => 'source-3'], ]; - $this->lists['source-goalkeeper'] = [ - ['id' => '6', 'name' => 'Source Item F', 'origin' => 'source-goalkeeper'], + $this->lists['source-4'] = [ + ['id' => '6', 'name' => 'Source Item F', 'origin' => 'source-4'], ]; for ($i = 1; $i <= 21; $i++) { @@ -35,29 +39,35 @@ class BoardDispatcher extends Component $itemId = (string) $itemId; $newIndex = (int) $newIndex; - // Abbrechen falls kein Ziel vorhanden ist oder die Position unverändert blieb - if (! $toList || $fromList === $toList) { + if (! $toList || $fromList === $toList || ! isset($this->lists[$fromList]) || ! isset($this->lists[$toList])) { + $this->boardVersion = uniqid(); + + return; + } + + // Limit-Guard: Wenn das Ziel bereits ein Element enthält, abbrechen + if (count($this->lists[$toList]) >= 1) { + $this->boardVersion = uniqid(); + return; } $foundItem = null; - // 1. Element aus der alten Liste entfernen - if (isset($this->lists[$fromList])) { - foreach ($this->lists[$fromList] as $key => $item) { - if ((string) $item['id'] === $itemId) { - $foundItem = $item; - unset($this->lists[$fromList][$key]); - $this->lists[$fromList] = array_values($this->lists[$fromList]); // Array-Keys korrigieren - break; - } + foreach ($this->lists[$fromList] as $key => $item) { + if ((string) $item['id'] === $itemId) { + $foundItem = $item; + unset($this->lists[$fromList][$key]); + $this->lists[$fromList] = array_values($this->lists[$fromList]); + break; } } - // 2. Element in die neue Zielliste am exakten Index einfügen - if ($foundItem && isset($this->lists[$toList])) { + if ($foundItem) { array_splice($this->lists[$toList], $newIndex, 0, [$foundItem]); } + + $this->boardVersion = uniqid(); } public function returnToOrigin($itemId, $currentListId) @@ -65,6 +75,8 @@ class BoardDispatcher extends Component $itemId = (string) $itemId; if (! isset($this->lists[$currentListId])) { + $this->boardVersion = uniqid(); + return; } @@ -80,8 +92,46 @@ class BoardDispatcher extends Component } if ($foundItem && isset($this->lists[$foundItem['origin']])) { - array_unshift($this->lists[$foundItem['origin']], $foundItem); + // Nur zurücklegen, wenn die Quelle wirklich frei ist + if (count($this->lists[$foundItem['origin']]) < 1) { + array_unshift($this->lists[$foundItem['origin']], $foundItem); + } else { + // Ausfallsicherheit gegen Datenverlust: Zurück in die Bucht schieben + array_unshift($this->lists[$currentListId], $foundItem); + } } + + $this->boardVersion = uniqid(); + } + + public function resetBoard() + { + // Alle 21 Zielbays durchlaufen + for ($i = 1; $i <= 21; $i++) { + $bayKey = "dest-{$i}"; + + if (isset($this->lists[$bayKey]) && ! empty($this->lists[$bayKey])) { + foreach ($this->lists[$bayKey] as $item) { + $targetOrigin = $item['origin']; + + // Element zurück in sein Original-Quell-Tab schieben + if (isset($this->lists[$targetOrigin])) { + array_unshift($this->lists[$targetOrigin], $item); + } + } + + // Die Zielbucht komplett leeren + $this->lists[$bayKey] = []; + } + } + + // Falls Sie die boardVersion-Logik nutzen, erneuern wir sie hier für den DOM-Refresh: + if (property_exists($this, 'boardVersion')) { + $this->boardVersion = uniqid(); + } + + // Falls Sie die Javascript-Event/ignore-Logik nutzen, feuern wir das Refresh-Event: + $this->dispatch('refreshBoard', lists: $this->lists); } public function render() diff --git a/resources/views/livewire/board-dispatcher.blade.php b/resources/views/livewire/board-dispatcher.blade.php index 37206298..e696bd28 100644 --- a/resources/views/livewire/board-dispatcher.blade.php +++ b/resources/views/livewire/board-dispatcher.blade.php @@ -1,112 +1,119 @@ -
+ x-data="{ activeTab: '{{ collect(array_keys($lists))->first(fn($key) => str_starts_with($key, 'source-')) }}' }" + id="dispatcher-board-root"> - -
- -
- - - + +
+
+ @foreach($lists as $listId => $items) @if(str_starts_with($listId, 'source-')) - - -
- {{ ucwords(str_replace('source-', '', $listId)) }} - - + class="cursor-pointer !px-2 !py-1 !min-h-0 text-[11px] font-medium tracking-tight rounded-md"> +
+ {{ str_replace('source-', 'S', $listId) }} + {{ count($items) }} - +
- @endif @endforeach - -
- -
+ +
+ + + - @foreach($lists as $listId => $items) - @if(str_starts_with($listId, 'source-')) -
- - -
- - @foreach($items as $item) -
- {{ $item['name'] }} - - - -
- @endforeach -
-
-
- @endif - @endforeach + // 💡 ERST JETZT DEN SERVER-RESET AUSFÜHREN + $wire.resetBoard(); + } + " + class="cursor-pointer" + /> + + +
- -
+ +
+
Available Sources
+ @foreach($lists as $listId => $items) + @if(str_starts_with($listId, 'source-')) +
+ + +
+ + @foreach($items as $item) +
+ {{ $item['name'] }} + + + +
+ @endforeach +
+
+
+ @endif + @endforeach +
+ + +
Target Destination Slots (21)
- -
+
@foreach($lists as $listId => $items) @if(str_starts_with($listId, 'dest-'))
Bay {{ str_replace('dest-', '', $listId) }} - - {{ count($items) }} - + {{ count($items) }}
- -
+ +
@foreach($items as $item)
@@ -114,16 +121,15 @@
- + - @@ -137,3 +143,46 @@
+ + +@script + +@endscript