Add customer job Kanban board
Phase 1, item 6: - New page /jobs/board: one column per Kanban status (archived left out), one card per job with number, name, customer, priority and due date. Filters for my jobs (default), priority and service unit; subcontractors see only their own cards and cannot move them. - Cards move by dragging (Livewire wire:sort across column groups) or with each card's status select, which works with the keyboard. Moves go through ChangeJobStatus, so they are recorded in the job history; the result is announced and focus returns to the moved card. - Billing statuses only for management and the job's biller: the jobs.set-billing-status gate now takes the biller's user id. - Column links with counts at the top; columns wrap with the screen width, so there is no sideways scrolling. - CustomerJobQueries::board() and the biller on job summaries. - Menu link and a link from the job list; spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -23,6 +23,14 @@ interface CustomerJobQueries
|
||||
*/
|
||||
public function paginate(JobListFilter $filter, int $perPage = 25): LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* The Kanban board: every Kanban status (archived left out) with its
|
||||
* jobs by due date, empty statuses included.
|
||||
*
|
||||
* @return array<string, list<CustomerJobSummary>>
|
||||
*/
|
||||
public function board(JobListFilter $filter, int $limitPerStatus = 100): array;
|
||||
|
||||
public function findDetails(int $id): ?CustomerJobDetails;
|
||||
|
||||
/**
|
||||
|
||||
@@ -22,5 +22,6 @@ final readonly class CustomerJobSummary
|
||||
public Priority $priority,
|
||||
public ?string $dueOn,
|
||||
public string $responsibleName,
|
||||
public ?int $billerUserId = null,
|
||||
) {}
|
||||
}
|
||||
|
||||
+49
-3
@@ -15,6 +15,7 @@ use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
@@ -37,11 +38,55 @@ class EloquentCustomerJobQueries implements CustomerJobQueries
|
||||
->orderByDesc('id')
|
||||
->paginate($perPage);
|
||||
|
||||
$models = collect($page->items());
|
||||
$toSummary = $this->summaryMapper(collect($page->items()));
|
||||
|
||||
return $page->through($toSummary);
|
||||
}
|
||||
|
||||
public function board(JobListFilter $filter, int $limitPerStatus = 100): array
|
||||
{
|
||||
$board = [];
|
||||
|
||||
foreach (JobStatus::kanbanStatuses() as $status) {
|
||||
$board[$status->value] = [];
|
||||
}
|
||||
|
||||
$models = $this->filtered(new JobListFilter(
|
||||
search: $filter->search,
|
||||
priority: $filter->priority,
|
||||
serviceUnitId: $filter->serviceUnitId,
|
||||
mineForUserId: $filter->mineForUserId,
|
||||
onlyMemberUserId: $filter->onlyMemberUserId,
|
||||
))
|
||||
->orderByRaw('due_on IS NULL')
|
||||
->orderBy('due_on')
|
||||
->orderByDesc('id')
|
||||
->get();
|
||||
|
||||
$toSummary = $this->summaryMapper($models);
|
||||
|
||||
foreach ($models as $model) {
|
||||
if (isset($board[$model->status->value]) && count($board[$model->status->value]) < $limitPerStatus) {
|
||||
$board[$model->status->value][] = $toSummary($model);
|
||||
}
|
||||
}
|
||||
|
||||
return $board;
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns job rows into summaries, with customer and user names looked up
|
||||
* once for all rows.
|
||||
*
|
||||
* @param Collection<int, CustomerJobModel> $models
|
||||
* @return \Closure(CustomerJobModel): CustomerJobSummary
|
||||
*/
|
||||
private function summaryMapper(Collection $models): \Closure
|
||||
{
|
||||
$customerNames = $this->customers->namesByIds($models->pluck('customer_id')->unique()->values()->all());
|
||||
$userNames = $this->users->namesByIds($models->pluck('responsible_user_id')->unique()->values()->all());
|
||||
|
||||
return $page->through(fn (CustomerJobModel $model): CustomerJobSummary => new CustomerJobSummary(
|
||||
return fn (CustomerJobModel $model): CustomerJobSummary => new CustomerJobSummary(
|
||||
$model->id,
|
||||
$model->number,
|
||||
$model->name,
|
||||
@@ -51,7 +96,8 @@ class EloquentCustomerJobQueries implements CustomerJobQueries
|
||||
$model->priority,
|
||||
$model->due_on?->format('Y-m-d'),
|
||||
$userNames[$model->responsible_user_id] ?? '',
|
||||
));
|
||||
$model->biller_user_id,
|
||||
);
|
||||
}
|
||||
|
||||
public function findDetails(int $id): ?CustomerJobDetails
|
||||
|
||||
@@ -5,7 +5,6 @@ namespace App\Modules\Jobs\Infrastructure\Providers;
|
||||
use App\Models\User;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerRowUsage;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobDetails;
|
||||
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\JobNumberSequence;
|
||||
use App\Modules\Jobs\Infrastructure\CustomerRowUsageFromJobs;
|
||||
@@ -57,7 +56,8 @@ class JobsServiceProvider extends ServiceProvider
|
||||
Gate::define('jobs.archive', $isManager);
|
||||
|
||||
// "Lasku luotu" and "Laskutettu" are set when invoicing: management or the job's biller.
|
||||
Gate::define('jobs.set-billing-status', fn (User $user, ?CustomerJobDetails $job = null): bool => $isManager($user)
|
||||
|| ($job !== null && $job->biller?->id === $user->id));
|
||||
// The argument is the job's biller (user id), when known.
|
||||
Gate::define('jobs.set-billing-status', fn (User $user, ?int $billerUserId = null): bool => $isManager($user)
|
||||
|| ($billerUserId !== null && $billerUserId === $user->id));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,263 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\CustomerJobSummary;
|
||||
use App\Modules\Jobs\Application\DTOs\JobListFilter;
|
||||
use App\Modules\Jobs\Application\UseCases\ChangeJobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* The customer job Kanban board: one column per status, one card per job.
|
||||
* A card moves by dragging (wire:sort) or with its status select, which
|
||||
* works with the keyboard and a screen reader.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
#[Url(except: true)]
|
||||
public bool $mine = true;
|
||||
|
||||
#[Url(except: '')]
|
||||
public string $priority = '';
|
||||
|
||||
#[Url(as: 'unit', except: '')]
|
||||
public string $serviceUnit = '';
|
||||
|
||||
public string $statusMessage = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->authorize('jobs.view');
|
||||
}
|
||||
|
||||
public function isSubcontractor(): bool
|
||||
{
|
||||
return auth()->user()?->role === Role::Subcontractor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, list<CustomerJobSummary>>
|
||||
*/
|
||||
#[Computed]
|
||||
public function board(): array
|
||||
{
|
||||
$userId = (int) auth()->id();
|
||||
|
||||
return app(CustomerJobQueries::class)->board(new JobListFilter(
|
||||
priority: Priority::tryFrom($this->priority)?->value,
|
||||
serviceUnitId: $this->serviceUnit === '' ? null : (int) $this->serviceUnit,
|
||||
mineForUserId: $this->mine && ! $this->isSubcontractor() ? $userId : null,
|
||||
onlyMemberUserId: $this->isSubcontractor() ? $userId : null,
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Statuses a card can be moved to by this user.
|
||||
*
|
||||
* @return list<JobStatus>
|
||||
*/
|
||||
public function statusesFor(CustomerJobSummary $job): array
|
||||
{
|
||||
return array_values(array_filter(
|
||||
JobStatus::kanbanStatuses(),
|
||||
fn (JobStatus $status): bool => $status === $job->status
|
||||
|| ! $status->isBillingStatus()
|
||||
|| Gate::allows('jobs.set-billing-status', [$job->billerUserId]),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* A card's status select changed.
|
||||
*/
|
||||
public function moveJob(int $jobId, string $status, ChangeJobStatus $changeStatus): void
|
||||
{
|
||||
$this->move($jobId, $status, $changeStatus);
|
||||
}
|
||||
|
||||
/**
|
||||
* A card was dropped into another column (wire:sort). The position
|
||||
* inside the column does not matter: cards are ordered by due date.
|
||||
*/
|
||||
public function moveDropped(int|string $jobId, int $position, string $status, ChangeJobStatus $changeStatus): void
|
||||
{
|
||||
$this->move((int) $jobId, $status, $changeStatus);
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title(__('jobs.board.title'));
|
||||
}
|
||||
|
||||
private function move(int $jobId, string $statusValue, ChangeJobStatus $changeStatus): void
|
||||
{
|
||||
$this->authorize('jobs.manage');
|
||||
|
||||
$status = JobStatus::tryFrom($statusValue);
|
||||
$job = $this->findCard($jobId);
|
||||
|
||||
if ($status === null || $status === JobStatus::Archived || $job === null) {
|
||||
$this->statusMessage = __('jobs.board.not_moved');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($status->isBillingStatus() && $status !== $job->status && ! Gate::allows('jobs.set-billing-status', [$job->billerUserId])) {
|
||||
$this->statusMessage = __('jobs.board.billing_not_allowed', ['job' => $job->number.' '.$job->name, 'status' => __('jobs.statuses.'.$status->value)]);
|
||||
unset($this->board);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
$changeStatus->execute($jobId, $status, (int) auth()->id());
|
||||
} catch (CustomerJobNotFound) {
|
||||
$this->statusMessage = __('jobs.board.not_moved');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->board);
|
||||
$this->statusMessage = __('jobs.board.moved', ['job' => $job->number.' '.$job->name, 'status' => __('jobs.statuses.'.$status->value)]);
|
||||
|
||||
$this->js("document.getElementById('job-status-{$jobId}')?.focus()");
|
||||
}
|
||||
|
||||
private function findCard(int $jobId): ?CustomerJobSummary
|
||||
{
|
||||
foreach ($this->board as $jobs) {
|
||||
foreach ($jobs as $job) {
|
||||
if ($job->id === $jobId) {
|
||||
return $job;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
@php($canMove = Gate::allows('jobs.manage'))
|
||||
|
||||
<div class="mx-auto max-w-[120rem] space-y-6 p-4 sm:p-6">
|
||||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||||
<h1 class="text-2xl font-semibold">{{ __('jobs.board.title') }}</h1>
|
||||
|
||||
<x-link :href="route('jobs.index')" navigate>{{ __('jobs.board.show_list') }}</x-link>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-4 sm:grid-cols-2 lg:grid-cols-3">
|
||||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||||
<x-select.native wire:model.live="priority" :label="__('jobs.fields.priority')" :aria-label="__('jobs.fields.priority')">
|
||||
<option value="">{{ __('jobs.list.all_priorities') }}</option>
|
||||
@foreach (Priority::cases() as $option)
|
||||
<option value="{{ $option->value }}">{{ __('jobs.priorities.'.$option->value) }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
<x-select.native wire:model.live="serviceUnit" :label="__('jobs.fields.service_units')" :aria-label="__('jobs.fields.service_units')">
|
||||
<option value="">{{ __('jobs.list.all_service_units') }}</option>
|
||||
@foreach (app(CatalogQueries::class)->activeServiceUnits() as $unit)
|
||||
<option value="{{ $unit->id }}">{{ $unit->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
@if ($this->isSubcontractor())
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.list.subcontractor_note') }}</p>
|
||||
@else
|
||||
<div class="flex items-end pb-2">
|
||||
<x-checkbox id="board-only-mine" wire:model.live="mine" :label="__('jobs.list.only_mine')" />
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<p role="status" aria-live="polite" class="min-h-5 text-sm font-medium">{{ $statusMessage }}</p>
|
||||
|
||||
<nav aria-label="{{ __('jobs.board.columns') }}">
|
||||
<ul class="flex flex-wrap gap-x-4 gap-y-1 text-sm">
|
||||
@foreach ($this->board as $status => $jobs)
|
||||
<li>
|
||||
<x-link :href="'#column-'.$status">
|
||||
{{ __('jobs.statuses.'.$status) }} ({{ count($jobs) }})
|
||||
</x-link>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</nav>
|
||||
|
||||
<div class="grid gap-4 [grid-template-columns:repeat(auto-fill,minmax(15rem,1fr))]">
|
||||
@foreach ($this->board as $status => $jobs)
|
||||
<section
|
||||
id="column-{{ $status }}"
|
||||
wire:key="column-{{ $status }}"
|
||||
aria-labelledby="column-{{ $status }}-heading"
|
||||
class="flex min-w-0 flex-col rounded-lg bg-zinc-100 p-3 dark:bg-zinc-800"
|
||||
>
|
||||
<h2 id="column-{{ $status }}-heading" class="mb-3 flex items-baseline justify-between gap-2 text-base font-semibold">
|
||||
{{ __('jobs.statuses.'.$status) }}
|
||||
<span class="text-sm font-normal">{{ trans_choice('jobs.board.count', count($jobs), ['count' => count($jobs)]) }}</span>
|
||||
</h2>
|
||||
|
||||
<ul
|
||||
@if ($canMove)
|
||||
wire:sort="moveDropped"
|
||||
wire:sort:group="jobs"
|
||||
wire:sort:group-id="{{ $status }}"
|
||||
@endif
|
||||
class="flex min-h-16 flex-1 flex-col gap-3"
|
||||
>
|
||||
@forelse ($jobs as $job)
|
||||
<li wire:key="job-card-{{ $job->id }}" @if ($canMove) wire:sort:item="{{ $job->id }}" @endif>
|
||||
<article
|
||||
aria-labelledby="job-card-{{ $job->id }}-title"
|
||||
class="space-y-2 rounded-md border border-zinc-200 bg-white p-3 text-sm shadow-sm dark:border-zinc-600 dark:bg-zinc-900"
|
||||
>
|
||||
<div class="flex items-start justify-between gap-2">
|
||||
<h3 id="job-card-{{ $job->id }}-title" class="min-w-0 font-medium break-words" wire:sort:ignore>
|
||||
<x-link :href="route('jobs.show', $job->id)" navigate>
|
||||
<span class="whitespace-nowrap">{{ $job->number }}</span> {{ $job->name }}
|
||||
</x-link>
|
||||
</h3>
|
||||
@if ($canMove)
|
||||
<x-icon name="bars-3" class="size-5 shrink-0 cursor-grab text-zinc-500 dark:text-zinc-400" aria-hidden="true" />
|
||||
@endif
|
||||
</div>
|
||||
|
||||
<p class="break-words text-zinc-700 dark:text-zinc-300">{{ $job->customerName }}</p>
|
||||
|
||||
<div class="flex flex-wrap gap-x-4 gap-y-1">
|
||||
<x-jobs.priority :priority="$job->priority" />
|
||||
<x-jobs.due-date :date="$job->dueOn" :status="$job->status" />
|
||||
</div>
|
||||
|
||||
@if ($canMove)
|
||||
<div wire:sort:ignore>
|
||||
<x-select.native
|
||||
id="job-status-{{ $job->id }}"
|
||||
wire:change="moveJob({{ $job->id }}, $event.target.value)"
|
||||
:label="__('jobs.fields.status')"
|
||||
:aria-label="__('jobs.board.status_of', ['job' => $job->number.' '.$job->name])"
|
||||
>
|
||||
@foreach ($this->statusesFor($job) as $option)
|
||||
<option value="{{ $option->value }}" @selected($option === $job->status)>{{ __('jobs.statuses.'.$option->value) }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
</div>
|
||||
@endif
|
||||
</article>
|
||||
</li>
|
||||
@empty
|
||||
<li wire:key="empty-{{ $status }}" class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.board.empty') }}</li>
|
||||
@endforelse
|
||||
</ul>
|
||||
</section>
|
||||
@endforeach
|
||||
</div>
|
||||
</div>
|
||||
@@ -249,7 +249,7 @@ new class extends Component
|
||||
if ($status->isBillingStatus()) {
|
||||
$details = $this->jobId === null ? null : app(CustomerJobQueries::class)->findDetails($this->jobId);
|
||||
|
||||
return Gate::allows('jobs.set-billing-status', [$details]);
|
||||
return Gate::allows('jobs.set-billing-status', [$details?->biller?->id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -99,7 +99,10 @@ new class extends Component
|
||||
|
||||
<div class="mx-auto max-w-7xl space-y-6 p-4 sm:p-6">
|
||||
<div class="flex flex-wrap items-center justify-between gap-4">
|
||||
<h1 class="text-2xl font-semibold">{{ __('jobs.title') }}</h1>
|
||||
<div class="flex flex-wrap items-baseline gap-x-4 gap-y-1">
|
||||
<h1 class="text-2xl font-semibold">{{ __('jobs.title') }}</h1>
|
||||
<x-link :href="route('jobs.board')" navigate>{{ __('jobs.board.link') }}</x-link>
|
||||
</div>
|
||||
|
||||
@can('jobs.manage')
|
||||
<div class="flex flex-wrap gap-2">
|
||||
|
||||
@@ -9,6 +9,7 @@ Route::middleware(['web', 'auth', 'can:jobs.view'])
|
||||
Route::livewire('/', 'jobs::index')->name('index');
|
||||
Route::livewire('/create', 'jobs::form')->middleware('can:jobs.manage')->name('create');
|
||||
Route::livewire('/quick', 'jobs::quick')->middleware('can:jobs.manage')->name('quick');
|
||||
Route::livewire('/board', 'jobs::board')->name('board');
|
||||
Route::livewire('/{job}', 'jobs::show')->whereNumber('job')->name('show');
|
||||
Route::livewire('/{job}/edit', 'jobs::form')->whereNumber('job')->middleware('can:jobs.manage')->name('edit');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user