Skip to content

Commit bab3745

Browse files
committed
UP
1 parent 976717d commit bab3745

File tree

3 files changed

+49
-89
lines changed

3 files changed

+49
-89
lines changed

resources/views/livewire/column.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class="p-3 flex-1 overflow-y-auto overflow-x-hidden"
4848
@endforeach
4949

5050
@if(isset($column['total']) && $column['total'] > count($column['items']))
51-
<div
51+
<div
5252
x-intersect.full="
5353
if (!isLoadingColumn('{{ $columnId }}')) {
5454
beginLoading('{{ $columnId }}');

src/Filament/Pages/KanbanBoardPage.php

Lines changed: 6 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
namespace Relaticle\Flowforge\Filament\Pages;
44

55
use Filament\Pages\Page;
6-
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
7-
use Illuminate\Database\Eloquent\Model;
8-
use Illuminate\Database\Eloquent\Relations\Relation;
96
use Relaticle\Flowforge\Adapters\KanbanAdapterFactory;
107
use Relaticle\Flowforge\Config\KanbanConfig;
118
use Relaticle\Flowforge\Contracts\KanbanAdapterInterface;
@@ -50,22 +47,11 @@ public function mount(): void
5047
// This method can be overridden by child classes
5148
}
5249

53-
/**
54-
* Set the subject for the Kanban board.
55-
*
56-
* @param EloquentBuilder|Relation|string $subject
57-
*/
58-
public function for(EloquentBuilder|Relation|string $subject): static
59-
{
60-
$this->subject = $subject;
61-
62-
return $this;
63-
}
64-
6550
/**
6651
* Set the field that stores the column value.
6752
*
6853
* @param string $field
54+
* @return KanbanBoardPage
6955
*/
7056
public function columnField(string $field): static
7157
{
@@ -90,6 +76,7 @@ public function columns(array $columns): static
9076
* Set the title field for the Kanban cards.
9177
*
9278
* @param string $field
79+
* @return KanbanBoardPage
9380
*/
9481
public function titleField(string $field): static
9582
{
@@ -146,22 +133,11 @@ public function orderField(string $field): static
146133
return $this;
147134
}
148135

149-
/**
150-
* Set the create form callback for the Kanban board.
151-
*
152-
* @param callable $callback
153-
*/
154-
public function createForm(callable $callback): static
155-
{
156-
$this->config = $this->config->withCreateFormCallback($callback);
157-
158-
return $this;
159-
}
160-
161136
/**
162137
* Set the label for individual cards.
163138
*
164139
* @param string $label
140+
* @return KanbanBoardPage
165141
*/
166142
public function cardLabel(string $label): static
167143
{
@@ -170,22 +146,11 @@ public function cardLabel(string $label): static
170146
return $this;
171147
}
172148

173-
/**
174-
* Set the plural label for collection of cards.
175-
*
176-
* @param string $label
177-
*/
178-
public function pluralCardLabel(string $label): static
179-
{
180-
$this->config = $this->config->withPluralCardLabel($label);
181-
182-
return $this;
183-
}
184-
185149
/**
186150
* Set a custom adapter for the Kanban board.
187151
*
188152
* @param KanbanAdapterInterface $adapter
153+
* @return KanbanBoardPage
189154
*/
190155
public function withCustomAdapter(KanbanAdapterInterface $adapter): static
191156
{
@@ -198,6 +163,7 @@ public function withCustomAdapter(KanbanAdapterInterface $adapter): static
198163
* Register a callback to modify the auto-created adapter.
199164
*
200165
* @param callable $callback
166+
* @return KanbanBoardPage
201167
*/
202168
public function withAdapterCallback(callable $callback): static
203169
{
@@ -240,14 +206,8 @@ public function getAdapter(): KanbanAdapterInterface
240206
return $this->adapter;
241207
}
242208

243-
if (!isset($this->subject)) {
244-
throw new \InvalidArgumentException(
245-
'You must specify a subject using the for() method before getting the adapter.'
246-
);
247-
}
248-
249209
// Create the adapter using the factory
250-
$adapter = KanbanAdapterFactory::create($this->subject, $this->config);
210+
$adapter = KanbanAdapterFactory::create($this->getSubject(), $this->config);
251211

252212
// Apply any custom adapter modifications
253213
if ($this->adapterCallback !== null && is_callable($this->adapterCallback)) {

src/Livewire/KanbanBoard.php

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public function getAdapter(): KanbanAdapterInterface
129129
* @param array<int, string> $searchable The searchable fields
130130
*/
131131
public function mount(
132-
KanbanAdapterInterface $adapter,
133-
?int $initialCardsCount = null,
134-
?int $cardsIncrement = null,
132+
KanbanAdapterInterface $adapter,
133+
?int $initialCardsCount = null,
134+
?int $cardsIncrement = null,
135135
array $searchable = []
136136
): void {
137137
$this->adapter = $adapter;
@@ -184,7 +184,7 @@ public function mount(
184184
protected function resolveColumnColors(): array
185185
{
186186
$adapterColors = $this->adapter->getConfig()->getColumnColors();
187-
187+
188188
if ($adapterColors !== null) {
189189
return $adapterColors;
190190
}
@@ -213,7 +213,7 @@ protected function resolveColumnColors(): array
213213

214214
$colors = [];
215215
$columnKeys = array_keys($this->adapter->getConfig()->getColumnValues());
216-
216+
217217
foreach ($columnKeys as $index => $key) {
218218
$colorIndex = $index % count($defaultColors);
219219
$colors[$key] = $defaultColors[$colorIndex];
@@ -228,7 +228,7 @@ protected function resolveColumnColors(): array
228228
public function createCardForm(Form $form): Form
229229
{
230230
$form = $this->adapter->getCreateForm($form, $this->activeColumn);
231-
231+
232232
return $form->statePath('cardData');
233233
}
234234

@@ -238,7 +238,7 @@ public function createCardForm(Form $form): Form
238238
public function editCardForm(Form $form): Form
239239
{
240240
$form = $this->adapter->getEditForm($form);
241-
241+
242242
return $form->statePath('cardData');
243243
}
244244

@@ -257,13 +257,13 @@ protected function loadColumnsData(): void
257257
{
258258
foreach ($this->columns as $columnId => $column) {
259259
$limit = $this->columnCardLimits[$columnId] ?? 10;
260-
260+
261261
$items = $this->adapter->getItemsForColumn($columnId, $limit);
262262
$this->columnCards[$columnId] = $this->formatItems($items);
263-
263+
264264
// Ensure that items and total keys exist in columns data
265265
$this->columns[$columnId]['items'] = $this->columnCards[$columnId];
266-
266+
267267
// Get the total count
268268
$this->columns[$columnId]['total'] = $this->adapter->getColumnItemsCount($columnId);
269269
}
@@ -302,9 +302,9 @@ public function loadMoreItems(string $columnId, ?int $count = null): void
302302
$count = $count ?? $this->cardsIncrement;
303303
$currentLimit = $this->columnCardLimits[$columnId] ?? 10;
304304
$newLimit = $currentLimit + $count;
305-
305+
306306
$this->columnCardLimits[$columnId] = $newLimit;
307-
307+
308308
$items = $this->adapter->getItemsForColumn($columnId, $newLimit);
309309
$this->columnCards[$columnId] = $this->formatItems($items);
310310
}
@@ -330,11 +330,11 @@ protected function formatItems(Collection $items): array
330330
public function reorderCardsInColumn($columnId, $cardIds): bool
331331
{
332332
$success = $this->adapter->reorderCardsInColumn($columnId, $cardIds);
333-
333+
334334
if ($success) {
335335
$this->refreshBoard();
336336
}
337-
337+
338338
return $success;
339339
}
340340

@@ -350,21 +350,21 @@ public function reorderCardsInColumn($columnId, $cardIds): bool
350350
public function moveCardToColumn($cardId, $fromColumn, $toColumn, $toColumnCardIds): bool
351351
{
352352
$card = $this->adapter->getModelById($cardId);
353-
353+
354354
if (!$card) {
355355
return false;
356356
}
357-
357+
358358
$success = $this->adapter->moveCardToColumn($card, $toColumn);
359-
359+
360360
if ($success && $this->adapter->getConfig()->getOrderField() !== null) {
361361
$success = $this->adapter->reorderCardsInColumn($toColumn, $toColumnCardIds);
362362
}
363-
363+
364364
if ($success) {
365365
$this->refreshBoard();
366366
}
367-
367+
368368
return $success;
369369
}
370370

@@ -377,18 +377,18 @@ public function openCreateForm(string $columnId): void
377377
{
378378
$this->activeColumn = $columnId;
379379
$this->resetCreateForm();
380-
380+
381381
// Pre-set the column field
382382
$columnField = $this->config['columnField'];
383383
$this->cardData[$columnField] = $columnId;
384-
384+
385385
// Apply any order field if needed
386386
$orderField = $this->config['orderField'];
387387
if ($orderField !== null) {
388388
$count = $this->getColumnItemsCount($columnId);
389389
$this->cardData[$orderField] = $count + 1;
390390
}
391-
391+
392392
$this->isCreateModalOpen = true;
393393
}
394394

@@ -402,24 +402,24 @@ public function openEditForm(string|int $cardId, string $columnId): void
402402
{
403403
$this->activeColumn = $columnId;
404404
$this->activeCard = $cardId;
405-
405+
406406
$card = $this->adapter->getModelById($cardId);
407-
407+
408408
if (!$card) {
409409
Notification::make()
410410
->title('Card not found')
411411
->danger()
412412
->send();
413-
413+
414414
return;
415415
}
416-
416+
417417
$this->resetEditForm();
418-
418+
419419
// Fill form with card data
420420
$this->editCardForm->fill($card->toArray());
421421
$this->cardData = $card->toArray();
422-
422+
423423
$this->isEditModalOpen = true;
424424
}
425425

@@ -429,20 +429,20 @@ public function openEditForm(string|int $cardId, string $columnId): void
429429
public function createCard(): void
430430
{
431431
$data = $this->createCardForm->getState();
432-
432+
433433
// Ensure column field is set
434434
$columnField = $this->config['columnField'];
435435
if (!isset($data[$columnField])) {
436436
$data[$columnField] = $this->activeColumn;
437437
}
438-
438+
439439
$card = $this->adapter->createCard($data);
440-
440+
441441
if ($card) {
442442
$this->refreshBoard();
443443
$this->resetCreateForm();
444444
$this->isCreateModalOpen = false;
445-
445+
446446
Notification::make()
447447
->title('Card created')
448448
->success()
@@ -471,23 +471,23 @@ public function updateCard(): void
471471
{
472472
$data = $this->editCardForm->getState();
473473
$card = $this->adapter->getModelById($this->activeCard);
474-
474+
475475
if (!$card) {
476476
Notification::make()
477477
->title('Card not found')
478478
->danger()
479479
->send();
480-
480+
481481
return;
482482
}
483-
483+
484484
$success = $this->adapter->updateCard($card, $data);
485-
485+
486486
if ($success) {
487487
$this->refreshBoard();
488488
$this->resetEditForm();
489489
$this->isEditModalOpen = false;
490-
490+
491491
Notification::make()
492492
->title('Card updated')
493493
->success()
@@ -528,22 +528,22 @@ public function confirmDelete(string|int $cardId, string $columnId): void
528528
public function deleteCard(): void
529529
{
530530
$card = $this->adapter->getModelById($this->activeCard);
531-
531+
532532
if (!$card) {
533533
Notification::make()
534534
->title('Card not found')
535535
->danger()
536536
->send();
537-
537+
538538
return;
539539
}
540-
540+
541541
$success = $this->adapter->deleteCard($card);
542-
542+
543543
if ($success) {
544544
$this->refreshBoard();
545545
$this->isDeleteConfirmOpen = false;
546-
546+
547547
Notification::make()
548548
->title('Card deleted')
549549
->success()

0 commit comments

Comments
 (0)