workign kaban board

This commit is contained in:
Mark Gregory
2026-06-17 14:03:54 +01:00
parent 47a67e83dc
commit bfea992994
8 changed files with 140 additions and 47 deletions
+41 -26
View File
@@ -21,6 +21,8 @@ final class KanbanBoard extends Component
public int $refreshNonce = 0;
public bool $isMovingTicket = false;
public function mount(): void
{
$this->board_id = KanbanBoardModel::query()
@@ -34,36 +36,48 @@ final class KanbanBoard extends Component
*/
public function moveTicket(int|string $ticketId, int|string $statusId, WorkflowNotificationService $workflow): void
{
$ticket = Ticket::query()->visibleTo(Auth::user())->findOrFail((int) $ticketId);
$status = Status::query()->findOrFail((int) $statusId);
$board = $this->activeBoard();
$oldStatusName = $ticket->status?->name ?? 'previous status';
$this->authorize('update', $ticket);
if ($board !== null && ! $board->statuses()->whereKey($status->id)->exists()) {
$this->addStatusToBoard($board->id, $status->id);
if ($this->isMovingTicket) {
return;
}
$ticket->forceFill([
'board_id' => $board?->id,
'status_id' => $status->id,
'completed_at' => $status->is_closed ? now() : null,
'last_activity_at' => now(),
])->save();
$this->isMovingTicket = true;
$workflow->dispatch(
$ticket->fresh(['status', 'priority', 'category', 'project', 'team']) ?? $ticket,
$status->is_closed ? 'ticket.closed' : 'ticket.updated',
Auth::user()
);
try {
$ticket = Ticket::query()->visibleTo(Auth::user())->findOrFail((int) $ticketId);
$status = Status::query()->findOrFail((int) $statusId);
$board = $this->activeBoard();
$oldStatusName = $ticket->status?->name ?? 'previous status';
$message = 'Ticket '.$ticket->reference.' moved from '.$oldStatusName.' to '.$status->name.'.';
session()->flash('success', $message);
$this->authorize('update', $ticket);
$this->refreshBoard();
$this->dispatch('helpdesk-kanban-refresh');
$this->dispatch('wms:toast', type: 'success', title: 'Ticket moved', message: $message);
if ($board !== null && ! $board->statuses()->whereKey($status->id)->exists()) {
$this->addStatusToBoard($board->id, $status->id);
}
$ticket->forceFill([
'board_id' => $board?->id,
'status_id' => $status->id,
'completed_at' => $status->is_closed ? now() : null,
'last_activity_at' => now(),
])->save();
$freshTicket = $ticket->fresh(['status', 'priority', 'category', 'project', 'team', 'product', 'tags', 'checklistItems', 'board']) ?? $ticket;
$workflow->dispatch(
$freshTicket,
$status->is_closed ? 'ticket.closed' : 'ticket.updated',
Auth::user()
);
$message = 'Ticket '.$freshTicket->reference.' moved from '.$oldStatusName.' to '.$status->name.'.';
session()->flash('success', $message);
$this->refreshBoard();
$this->dispatch('helpdesk-kanban-moved', ticketId: (int) $freshTicket->id, statusId: (int) $freshTicket->status_id);
$this->dispatch('wms:toast', type: 'success', title: 'Ticket moved', message: $message);
} finally {
$this->isMovingTicket = false;
}
}
/**
@@ -102,7 +116,7 @@ final class KanbanBoard extends Component
session()->flash('success', $message);
$this->refreshBoard();
$this->dispatch('helpdesk-kanban-refresh');
$this->dispatch('helpdesk-kanban-moved', ticketId: (int) $fresh->id, statusId: (int) $fresh->status_id);
$this->dispatch('wms:toast', type: 'success', title: 'Board changed', message: $message);
}
@@ -113,6 +127,7 @@ final class KanbanBoard extends Component
public function refreshBoard(): void
{
$this->refreshNonce++;
unset($this->ticketsByStatus);
}
/**