Files
Toiminnanohjaus/app/Modules/Jobs/Presentation/Livewire/⚡board.blade.php
T
petriandClaude Opus 5.5 fcad0ea939 Make Kanban columns visible in dark mode and stack card titles
Columns had the same dark background as the page, so they now use a
darker background with a border. Card titles show the job number on
the first line next to the drag handle and the name below it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-11-24 06:06:44 +02:00

267 lines
11 KiB
PHP

<?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 border border-zinc-200 bg-zinc-100 p-3 dark:border-zinc-700 dark:bg-zinc-950"
>
<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="relative 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"
>
@if ($canMove)
<x-icon name="bars-3" class="absolute top-3 right-3 size-5 cursor-grab text-zinc-500 dark:text-zinc-400" aria-hidden="true" />
@endif
{{-- TallStackUI's link is a flex row, so one flex-col span keeps the number above the name. --}}
<h3 id="job-card-{{ $job->id }}-title" class="min-w-0 font-medium" wire:sort:ignore>
<x-link :href="route('jobs.show', $job->id)" navigate>
<span class="flex min-w-0 flex-col">
<span class="pr-7">{{ $job->number }}</span>
<span class="[overflow-wrap:anywhere]">{{ $job->name }}</span>
</span>
</x-link>
</h3>
<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>