Files
Toiminnanohjaus/app/Modules/Jobs/Presentation/Livewire/⚡calendar.blade.php
T
petriandClaude Sonnet 5.5 f906f9a43f Add notifications: header bell, task start run and assignment notices
A new Notifications module shows a bell beside the profile menu with the
number of unseen notifications and a panel of the last 7 days; opening
it marks them seen, and each notification links to its job or task.

- A daily run at 14.00 (notifications:task-starts) tells the assignee
  and members of tasks that start by the next working day, skipping
  holidays and days off, done tasks and archived jobs.
- Jobs publishes PeopleAddedToTask and PeopleAddedToJob when someone
  else makes a user a task's assignee or member or gives them a role on
  a job; those users are notified at once. UpdateTask and ScheduleTask
  now take the acting user.
- A notification link to #task-<id> opens that task card on the job page.

Also: simplifying job fields per service unit (K31) moves to the end of
phase 4, and the workflow template browser test waits for Livewire's
progress bar before its last accessibility check.

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
2026-11-25 08:28:01 +02:00

850 lines
38 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Jobs\Application\Contracts\TaskCalendarQueries;
use App\Modules\Jobs\Application\DTOs\CalendarBar;
use App\Modules\Jobs\Application\DTOs\CalendarRow;
use App\Modules\Jobs\Application\DTOs\CalendarTask;
use App\Modules\Jobs\Application\Services\TaskCalendarLayout;
use App\Modules\Jobs\Application\Services\TaskPlanner;
use App\Modules\Jobs\Application\UseCases\ChangeTaskStatus;
use App\Modules\Jobs\Application\UseCases\ClearTaskSchedule;
use App\Modules\Jobs\Application\UseCases\ScheduleTask;
use App\Modules\Jobs\Domain\Enums\TaskStatus;
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
use App\Modules\Shared\Application\UseCases\HolidayCalendar;
use App\Modules\Users\Application\Contracts\UserAccountQueries;
use App\Modules\Users\Domain\Enums\Role;
use Carbon\CarbonImmutable;
use Illuminate\Support\Facades\Gate;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Url;
use Livewire\Component;
/**
* The task calendar (Gantt): two weeks from today, one row per person
* and a bar per task. Bars move and resize by dragging; every bar is also
* a button that opens a dialog for the same changes with the keyboard.
*/
new class extends Component
{
private const int DAYS = 14;
#[Url(except: '')]
public string $from = '';
#[Url(as: 'unit', except: '')]
public string $serviceUnit = '';
#[Url(except: false)]
public bool $mine = false;
#[Locked]
public string $statusMessage = '';
#[Locked]
public ?int $dialogTaskId = null;
#[Locked]
public ?int $dialogJobId = null;
#[Locked]
public ?int $dialogUserId = null;
#[Locked]
public string $dialogTitle = '';
#[Locked]
public string $dialogStatus = '';
public string $plannedFrom = '';
public string $plannedTo = '';
public string $assignee = '';
public string $status = '';
public function mount(): void
{
$this->authorize('jobs.view');
}
public function isSubcontractor(): bool
{
return auth()->user()?->role === Role::Subcontractor;
}
public function startDate(): CarbonImmutable
{
$start = $this->from === '' ? null : CarbonImmutable::createFromFormat('!Y-m-d', $this->from);
return $start instanceof CarbonImmutable && $start->format('Y-m-d') === $this->from ? $start : CarbonImmutable::today();
}
/**
* @return list<string>
*/
#[Computed]
public function days(): array
{
$start = $this->startDate();
return array_map(fn (int $offset): string => $start->addDays($offset)->format('Y-m-d'), range(0, self::DAYS - 1));
}
/**
* Holidays in use on the shown days, date => name.
*
* @return array<string, string>
*/
#[Computed]
public function holidays(): array
{
$names = [];
foreach (app(HolidayCalendar::class)->between($this->days[0], $this->days[self::DAYS - 1]) as $holiday) {
if ($holiday->active) {
$names[$holiday->date] = $holiday->key === null ? (string) $holiday->name : __('holidays.names.'.$holiday->key);
}
}
return $names;
}
/**
* Rows: the signed-in user first, then the others by name, then tasks
* without an assignee. A subcontractor sees only their own row.
*
* @return list<array{id: ?int, name: string}>
*/
#[Computed]
public function people(): array
{
$userId = (int) auth()->id();
$own = ['id' => $userId, 'name' => (string) auth()->user()?->name];
if ($this->isSubcontractor() || $this->mine) {
return [$own];
}
$others = [];
foreach (app(UserAccountQueries::class)->activeUserOptions() as $user) {
if ($user->id !== $userId) {
$others[] = ['id' => $user->id, 'name' => $user->name];
}
}
return [$own, ...$others, ['id' => null, 'name' => __('jobs.calendar.no_assignee')]];
}
/**
* @return list<CalendarRow>
*/
#[Computed]
public function rows(): array
{
$queries = app(TaskCalendarQueries::class);
$first = $this->days[0];
$last = $this->days[self::DAYS - 1];
$userIds = array_values(array_filter(array_column($this->people, 'id')));
return TaskCalendarLayout::build(
$this->days,
$this->people,
$queries->scheduledTasks($first, $last, $this->serviceUnitId(), $this->onlyAssigneeUserId()),
$queries->openMinutesByUser($userIds, $first, $last),
);
}
/**
* @return list<CalendarTask>
*/
#[Computed]
public function unscheduled(): array
{
$tasks = app(TaskCalendarQueries::class)->unscheduledOpenTasks($this->serviceUnitId(), $this->onlyAssigneeUserId());
if ($this->mine) {
$userId = (int) auth()->id();
$tasks = array_values(array_filter($tasks, fn (CalendarTask $task): bool => $task->assignmentOf($userId) !== null));
}
return $tasks;
}
/**
* Names of the people on the rows, user id => name, for assignee lists.
*
* @return array<int, string>
*/
#[Computed]
public function userNames(): array
{
$names = [];
foreach (app(UserAccountQueries::class)->activeUserOptions() as $user) {
$names[$user->id] = $user->name;
}
return $names;
}
#[Computed]
public function capacityMinutes(): int
{
return app(TaskPlanner::class)->capacityMinutes();
}
public function canManage(): bool
{
return Gate::allows('jobs.manage-tasks', 0);
}
public function showPrevious(): void
{
$this->moveRange(-self::DAYS);
}
public function showNext(): void
{
$this->moveRange(self::DAYS);
}
public function showToday(): void
{
$this->from = '';
$this->refresh();
$this->statusMessage = $this->showingMessage();
}
/**
* A bar was dropped (drag and drop). Without an end, the task gets as
* many working days as its estimate needs.
*/
public function reschedule(int $taskId, int $jobId, ?int $fromUserId, ?int $toUserId, string $plannedFrom, ?string $plannedTo, ScheduleTask $scheduleTask): void
{
$this->authorize('jobs.manage-tasks', $jobId);
$this->schedule($scheduleTask, $taskId, $jobId, $fromUserId, $toUserId, $plannedFrom, $plannedTo);
}
/**
* Opens the dialog of a bar or an unscheduled task (keyboard alternative to dragging).
*/
public function openDialog(int $taskId, ?int $userId): void
{
$task = $this->findTask($taskId);
if ($task === null) {
$this->statusMessage = __('jobs.calendar.not_changed');
return;
}
$this->authorize('jobs.update-task-status', $task->jobId);
$this->resetErrorBag();
$this->dialogTaskId = $task->taskId;
$this->dialogJobId = $task->jobId;
$this->dialogUserId = $userId;
$this->dialogTitle = __('jobs.calendar.dialog_task', ['title' => $task->title, 'job' => $task->jobNumber]);
$this->dialogStatus = $task->status->value;
$this->plannedFrom = $task->plannedFrom ?? CarbonImmutable::today()->format('Y-m-d');
$this->plannedTo = $task->plannedTo ?? '';
$this->assignee = $userId === null ? '' : (string) $userId;
$this->status = $task->status->value;
$this->js("document.getElementById('task-schedule-dialog').showModal()");
}
public function saveDialog(ScheduleTask $scheduleTask, ChangeTaskStatus $changeTaskStatus): void
{
if ($this->dialogTaskId === null || $this->dialogJobId === null) {
return;
}
$this->authorize('jobs.update-task-status', $this->dialogJobId);
$taskId = $this->dialogTaskId;
$jobId = $this->dialogJobId;
$task = $this->findTask($taskId);
$toUserId = $this->dialogUserId;
$messages = [];
if (Gate::allows('jobs.manage-tasks', $jobId)) {
$this->validate([
'plannedFrom' => ['required', 'date_format:Y-m-d'],
'plannedTo' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:plannedFrom'],
'assignee' => ['nullable', 'integer'],
], [
'plannedFrom.*' => __('jobs.calendar.errors.from'),
'plannedTo.*' => __('jobs.calendar.errors.to'),
]);
$toUserId = $this->assignee === '' ? null : (int) $this->assignee;
if (! $this->schedule($scheduleTask, $taskId, $jobId, $this->dialogUserId, $toUserId, $this->plannedFrom, $this->plannedTo === '' ? null : $this->plannedTo)) {
return;
}
$messages[] = $this->statusMessage;
}
$status = TaskStatus::tryFrom($this->status);
if ($status !== null && $status->value !== $this->dialogStatus) {
try {
$changeTaskStatus->execute($jobId, $taskId, $status);
} catch (TaskNotFound) {
$this->statusMessage = __('jobs.calendar.not_changed');
return;
}
$this->refresh();
$messages[] = __('jobs.calendar.status_changed', ['title' => $task->title ?? '', 'status' => __('jobs.tasks.statuses.'.$status->value)]);
}
$this->statusMessage = implode(' ', $messages);
$this->closeDialogAndFocus($taskId, $toUserId);
}
public function clearSchedule(ClearTaskSchedule $clearTaskSchedule): void
{
if ($this->dialogTaskId === null || $this->dialogJobId === null) {
return;
}
$this->authorize('jobs.manage-tasks', $this->dialogJobId);
$task = $this->findTask($this->dialogTaskId);
try {
$clearTaskSchedule->execute($this->dialogJobId, $this->dialogTaskId);
} catch (TaskNotFound) {
$this->statusMessage = __('jobs.calendar.not_changed');
return;
}
$this->refresh();
$this->statusMessage = __('jobs.calendar.cleared', ['title' => $task->title ?? '']);
$taskId = $this->dialogTaskId;
$this->js("document.getElementById('task-schedule-dialog').close(); document.getElementById('unscheduled-{$taskId}')?.focus()");
}
public function updatedServiceUnit(): void
{
$this->refresh();
}
public function updatedMine(): void
{
$this->refresh();
}
public function dayLabel(string $date): string
{
$day = CarbonImmutable::createFromFormat('!Y-m-d', $date);
return $day instanceof CarbonImmutable ? __('holidays.weekdays.'.$day->dayOfWeekIso).' '.$day->format('j.n.') : $date;
}
public function isDayOff(string $date): bool
{
$day = CarbonImmutable::createFromFormat('!Y-m-d', $date);
return isset($this->holidays[$date]) || ($day instanceof CarbonImmutable && $day->dayOfWeekIso >= 6);
}
public function hours(int $minutes): string
{
if ($minutes === 0) {
return '0';
}
return rtrim(rtrim(number_format($minutes / 60, 2, ',', ''), '0'), ',');
}
public function shortDate(string $date): string
{
$day = CarbonImmutable::createFromFormat('!Y-m-d', $date);
return $day instanceof CarbonImmutable ? $day->format('j.n.Y') : $date;
}
public function barLabel(CalendarBar $bar): string
{
return __('jobs.calendar.bar_label', [
'title' => $bar->task->title,
'job' => $bar->task->jobNumber.' '.$bar->task->jobName,
'status' => __('jobs.tasks.statuses.'.$bar->task->status->value),
'from' => $this->shortDate($bar->from),
'to' => $this->shortDate($bar->to),
'hours' => $bar->minutes > 0 ? __('jobs.calendar.bar_hours', ['hours' => $this->hours($bar->minutes)]) : '',
]).($bar->late ? ', '.__('jobs.late') : '');
}
/**
* The person an unscheduled task is moved from when it is dropped on a
* row: its assignee, who the person on the row replaces.
*/
public function onlyAssignee(CalendarTask $task): ?int
{
return $task->assignment?->userId;
}
public function render(): mixed
{
return $this->view()->title(__('jobs.calendar.title'));
}
private function schedule(ScheduleTask $scheduleTask, int $taskId, int $jobId, ?int $fromUserId, ?int $toUserId, string $plannedFrom, ?string $plannedTo): bool
{
$task = $this->findTask($taskId);
try {
$result = $scheduleTask->execute($jobId, $taskId, $fromUserId, $toUserId, $plannedFrom, $plannedTo, (int) auth()->id());
} catch (CustomerJobNotFound|TaskNotFound|InvalidArgumentException) {
$this->statusMessage = __('jobs.calendar.not_changed');
return false;
} catch (PlanEndsBeforeStart) {
$this->addError('plannedTo', __('jobs.calendar.errors.to'));
$this->statusMessage = __('jobs.calendar.errors.to');
return false;
} catch (InvalidTaskReference) {
$this->statusMessage = __('jobs.calendar.inactive_person');
return false;
}
$this->refresh();
$this->statusMessage = __($result->extended ? 'jobs.calendar.moved_extended' : 'jobs.calendar.moved', [
'title' => $task->title ?? '',
'person' => $toUserId === null ? __('jobs.calendar.no_assignee') : ($this->userNames[$toUserId] ?? ''),
'from' => $this->shortDate($result->plannedFrom),
'to' => $this->shortDate($result->plannedTo),
]);
return true;
}
private function closeDialogAndFocus(int $taskId, ?int $userId): void
{
$key = $taskId.'-'.($userId ?? 'none');
$this->js("document.getElementById('task-schedule-dialog').close();"
."const bar = document.getElementById('bar-{$key}');"
."(bar && bar.offsetParent !== null ? bar : document.getElementById('agenda-bar-{$key}'))?.focus();");
}
private function findTask(int $taskId): ?CalendarTask
{
foreach ($this->rows as $row) {
foreach ($row->bars as $bar) {
if ($bar->task->taskId === $taskId) {
return $bar->task;
}
}
}
foreach ($this->unscheduled as $task) {
if ($task->taskId === $taskId) {
return $task;
}
}
return null;
}
private function moveRange(int $days): void
{
$this->from = $this->startDate()->addDays($days)->format('Y-m-d');
$this->refresh();
$this->statusMessage = $this->showingMessage();
}
private function showingMessage(): string
{
return __('jobs.calendar.showing', ['from' => $this->shortDate($this->days[0]), 'to' => $this->shortDate($this->days[self::DAYS - 1])]);
}
private function refresh(): void
{
unset($this->days, $this->holidays, $this->people, $this->rows, $this->unscheduled);
}
private function serviceUnitId(): ?int
{
return $this->serviceUnit === '' ? null : (int) $this->serviceUnit;
}
private function onlyAssigneeUserId(): ?int
{
return $this->isSubcontractor() ? (int) auth()->id() : null;
}
};
?>
@php
$canManage = $this->canManage();
$days = $this->days;
$capacity = $this->hours($this->capacityMinutes);
$columns = 'grid-template-columns: 11rem repeat('.count($days).', minmax(0, 1fr));';
@endphp
<div class="mx-auto max-w-[120rem] space-y-6 p-4 sm:p-6">
<div class="space-y-1">
<h1 class="text-2xl font-semibold">{{ __('jobs.calendar.title') }}</h1>
<p class="max-w-3xl text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.calendar.intro') }}</p>
</div>
<div class="flex flex-wrap items-end gap-4">
<div class="flex flex-wrap gap-2">
<x-button subtle color="black" icon="chevron-left" wire:click="showPrevious" :text="__('jobs.calendar.previous')" />
<x-button subtle color="black" wire:click="showToday" :text="__('jobs.calendar.today')" />
<x-button subtle color="black" icon="chevron-right" position="right" wire:click="showNext" :text="__('jobs.calendar.next')" />
</div>
<div class="w-full sm:w-64">
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
<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>
</div>
@if ($this->isSubcontractor())
<p class="pb-2 text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.calendar.subcontractor_note') }}</p>
@else
<div class="pb-2">
<x-checkbox id="calendar-only-mine" wire:model.live="mine" :label="__('jobs.calendar.only_mine')" />
</div>
@endif
</div>
<p role="status" aria-live="polite" class="min-h-5 text-sm font-medium">{{ $statusMessage }}</p>
<section aria-labelledby="calendar-range-heading" class="space-y-3">
<h2 id="calendar-range-heading" class="text-lg font-semibold">
{{ __('jobs.calendar.range', ['from' => $this->shortDate($days[0]), 'to' => $this->shortDate($days[count($days) - 1])]) }}
</h2>
{{-- Desktop: the Gantt grid. Dragging is a pointer shortcut; every bar is a button that opens the dialog. --}}
<div
class="hidden lg:block"
x-data="taskCalendar(@js($canManage))"
x-on:pointermove.window="track($event)"
x-on:pointerup.window="drop($event)"
x-on:keydown.escape.window="cancel(); closeInfo()"
x-on:task-calendar-place.window="begin($event.detail.event, 'place', $event.detail.bar)"
>
<div class="grid border-b border-zinc-300 text-sm dark:border-zinc-600" style="{{ $columns }}" aria-hidden="true">
<div></div>
@foreach ($days as $index => $day)
<div
wire:key="head-{{ $day }}"
@class([
'border-l border-zinc-200 px-1 py-2 text-center dark:border-zinc-700',
'bg-zinc-200 dark:bg-zinc-950' => $this->isDayOff($day),
])
>
<div @class(['font-semibold' => $day === now()->format('Y-m-d')])>{{ $this->dayLabel($day) }}</div>
@if ($day === now()->format('Y-m-d'))
<div class="text-xs font-semibold">{{ __('jobs.calendar.today_marker') }}</div>
@endif
@isset($this->holidays[$day])
<div class="truncate text-xs" title="{{ $this->holidays[$day] }}">{{ $this->holidays[$day] }}</div>
@endisset
</div>
@endforeach
</div>
{{-- The day headings for screen readers, since the visual header above is hidden from them. --}}
<p class="sr-only">
@foreach ($days as $day)
@isset($this->holidays[$day])
{{ $this->dayLabel($day) }}: {{ __('jobs.calendar.holiday') }} {{ $this->holidays[$day] }}.
@endisset
@endforeach
</p>
@foreach ($this->rows as $row)
@php($rowKey = $row->userId ?? 'none')
<section
wire:key="row-{{ $rowKey }}"
aria-labelledby="row-{{ $rowKey }}-name"
class="grid border-b border-zinc-200 dark:border-zinc-700"
style="{{ $columns }} grid-template-rows: auto repeat({{ $row->lanes }}, 3rem);"
>
<h3
id="row-{{ $rowKey }}-name"
class="px-2 py-2 text-sm font-semibold break-words"
style="grid-column: 1; grid-row: 1 / span {{ $row->lanes + 1 }};"
>{{ $row->name }}</h3>
@foreach ($days as $index => $day)
@php($booked = $row->minutesByDay[$day] ?? 0)
<div
wire:key="cell-{{ $rowKey }}-{{ $day }}"
data-calendar-day="{{ $day }}"
data-calendar-user="{{ $row->userId ?? '' }}"
x-bind:class="isTarget('{{ $day }}', '{{ $row->userId ?? '' }}') && 'outline-2 -outline-offset-2 outline-blue-700 dark:outline-blue-300'"
@class([
'min-h-12 border-l border-zinc-200 dark:border-zinc-700',
'bg-zinc-200 dark:bg-zinc-950' => $this->isDayOff($day),
])
style="grid-column: {{ $index + 2 }}; grid-row: 1 / span {{ $row->lanes + 1 }};"
></div>
{{-- The day's booked time on its own grid line, above the task bars. --}}
@if ($row->userId !== null && ($booked > 0 || ! $this->isDayOff($day)))
<div
wire:key="load-{{ $rowKey }}-{{ $day }}"
@class([
'pointer-events-none px-1 pt-1 text-right text-xs whitespace-nowrap',
'font-semibold' => $booked > $this->capacityMinutes,
'text-zinc-600 dark:text-zinc-300' => $booked === 0,
])
style="grid-column: {{ $index + 2 }}; grid-row: 1;"
>
<span class="sr-only">{{ $this->dayLabel($day) }}:</span>
{{ __('jobs.calendar.load', ['booked' => $this->hours($booked), 'capacity' => $capacity]) }}
@if ($booked > $this->capacityMinutes)
<x-icon name="exclamation-triangle" class="inline size-3" aria-hidden="true" />
{{ __('jobs.calendar.over_capacity') }}
@endif
</div>
@endif
@endforeach
@foreach ($row->bars as $bar)
<button
type="button"
id="bar-{{ $bar->key() }}"
wire:key="bar-{{ $bar->key() }}"
aria-label="{{ $this->barLabel($bar) }}"
aria-describedby="bar-info-{{ $bar->key() }}"
x-on:mouseenter="showInfo($el, 'bar-info-{{ $bar->key() }}')"
x-on:mouseleave="hideInfo('bar-info-{{ $bar->key() }}')"
x-on:focus="showInfo($el, 'bar-info-{{ $bar->key() }}')"
x-on:blur="hideInfo('bar-info-{{ $bar->key() }}', 0)"
x-on:pointerdown="begin($event, 'move', @js(['task' => $bar->task->taskId, 'job' => $bar->task->jobId, 'user' => $bar->userId, 'from' => $bar->from, 'to' => $bar->to]))"
x-on:click="if (! consumeDrag()) $wire.openDialog({{ $bar->task->taskId }}, {{ $bar->userId ?? 'null' }})"
@class([
'relative z-10 mx-0.5 my-1 flex min-w-0 touch-none flex-col justify-center overflow-hidden border px-2 text-left text-xs leading-tight select-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:focus-visible:outline-blue-300',
'cursor-grab' => $canManage,
'border-primary-300 bg-primary-100 text-primary-950 dark:border-primary-600 dark:bg-primary-900 dark:text-white' => $bar->task->status !== TaskStatus::Done,
'border-zinc-300 bg-zinc-100 text-zinc-800 dark:border-zinc-600 dark:bg-zinc-700 dark:text-zinc-100' => $bar->task->status === TaskStatus::Done,
'rounded-l-md' => $bar->from >= $days[0],
'rounded-r-md' => $bar->to <= $days[count($days) - 1],
])
style="grid-column: {{ $bar->start + 2 }} / span {{ $bar->span }}; grid-row: {{ $bar->lane + 2 }};"
>
<span class="truncate font-semibold">{{ $bar->task->title }}</span>
<span class="flex min-w-0 items-center gap-1 truncate">
@if ($bar->late)
<x-icon name="exclamation-triangle" class="size-3 shrink-0" aria-hidden="true" />
<span class="font-semibold">{{ __('jobs.late') }}</span>
@endif
<span class="truncate">{{ $bar->task->jobNumber }} · {{ __('jobs.tasks.statuses.'.$bar->task->status->value) }}@if ($bar->minutes > 0) · {{ $this->hours($bar->minutes) }} h @endif</span>
</span>
@if ($canManage)
<span
class="absolute inset-y-0 left-0 w-2 cursor-ew-resize"
aria-hidden="true"
x-on:pointerdown.stop="begin($event, 'start', @js(['task' => $bar->task->taskId, 'job' => $bar->task->jobId, 'user' => $bar->userId, 'from' => $bar->from, 'to' => $bar->to]))"
></span>
<span
class="absolute inset-y-0 right-0 w-2 cursor-ew-resize"
aria-hidden="true"
x-on:pointerdown.stop="begin($event, 'end', @js(['task' => $bar->task->taskId, 'job' => $bar->task->jobId, 'user' => $bar->userId, 'from' => $bar->from, 'to' => $bar->to]))"
></span>
@endif
</button>
{{-- The job's basic details on hover and focus (WCAG 1.4.13: hoverable, Escape closes it). --}}
<div
id="bar-info-{{ $bar->key() }}"
wire:key="bar-info-{{ $bar->key() }}"
popover="manual"
role="tooltip"
x-on:mouseenter="keepInfo()"
x-on:mouseleave="hideInfo('bar-info-{{ $bar->key() }}')"
class="m-0 w-80 max-w-[calc(100vw-1rem)] rounded-lg border border-zinc-300 bg-white p-3 text-left text-sm text-zinc-900 shadow-lg dark:border-zinc-600 dark:bg-zinc-800 dark:text-white"
style="inset: auto;"
>
<p class="font-semibold break-words">{{ $bar->task->title }}</p>
<dl class="mt-2 grid grid-cols-[max-content_1fr] gap-x-3 gap-y-1">
<dt class="font-medium">{{ __('jobs.calendar.info.job') }}</dt>
<dd class="break-words">{{ $bar->task->jobNumber }} {{ $bar->task->jobName }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.customer') }}</dt>
<dd class="break-words">{{ $bar->task->customerName ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.job_status') }}</dt>
<dd>{{ $bar->task->jobStatus === null ? __('jobs.not_set') : __('jobs.statuses.'.$bar->task->jobStatus->value) }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.job_due_on') }}</dt>
<dd>{{ $bar->task->jobDueOn === null ? __('jobs.not_set') : $this->shortDate($bar->task->jobDueOn) }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.responsible') }}</dt>
<dd class="break-words">{{ $bar->task->responsibleName ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.work_type') }}</dt>
<dd class="break-words">{{ $bar->task->workTypeName ?? __('jobs.not_set') }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.due_on') }}</dt>
<dd>{{ $bar->task->dueOn === null ? __('jobs.not_set') : $this->shortDate($bar->task->dueOn) }}</dd>
<dt class="font-medium">{{ __('jobs.calendar.info.schedule') }}</dt>
<dd>
{{ $this->shortDate($bar->from) }}–{{ $this->shortDate($bar->to) }}@if ($bar->minutes > 0), {{ $this->hours($bar->minutes) }} h @endif
@if ($bar->late)
<span class="inline-flex items-center gap-1 font-semibold">
<x-icon name="exclamation-triangle" class="size-4" aria-hidden="true" />{{ __('jobs.late') }}
</span>
@endif
</dd>
</dl>
@if ($bar->task->description !== null)
<p class="mt-2 line-clamp-3 break-words whitespace-pre-line text-zinc-700 dark:text-zinc-200">{{ $bar->task->description }}</p>
@endif
</div>
@endforeach
</section>
@endforeach
</div>
{{-- Phones and narrow windows: the same tasks as a list per person. --}}
<div class="space-y-4 lg:hidden">
@foreach ($this->rows as $row)
@php($rowKey = $row->userId ?? 'none')
<section wire:key="agenda-{{ $rowKey }}" aria-labelledby="agenda-{{ $rowKey }}-name" class="space-y-2 rounded-lg border border-zinc-200 p-3 dark:border-zinc-700">
<h3 id="agenda-{{ $rowKey }}-name" class="font-semibold break-words">{{ $row->name }}</h3>
@if ($row->bars === [])
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.calendar.no_tasks') }}</p>
@else
<ul class="space-y-2">
@foreach ($row->bars as $bar)
<li wire:key="agenda-bar-{{ $bar->key() }}">
<button
type="button"
id="agenda-bar-{{ $bar->key() }}"
wire:click="openDialog({{ $bar->task->taskId }}, {{ $bar->userId ?? 'null' }})"
class="flex w-full flex-col gap-1 rounded-md border border-zinc-300 p-2 text-left text-sm focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:border-zinc-600 dark:focus-visible:outline-blue-300"
>
<span class="font-semibold break-words">{{ $bar->task->title }}</span>
<span>{{ $this->shortDate($bar->from) }}–{{ $this->shortDate($bar->to) }}@if ($bar->minutes > 0), {{ $this->hours($bar->minutes) }} h @endif</span>
<span class="break-words">{{ $bar->task->jobNumber }} {{ $bar->task->jobName }} · {{ __('jobs.tasks.statuses.'.$bar->task->status->value) }}</span>
@if ($bar->task->customerName !== null)
<span class="break-words">{{ __('jobs.calendar.info.customer') }}: {{ $bar->task->customerName }}</span>
@endif
@if ($bar->late)
<span class="inline-flex items-center gap-1 font-semibold">
<x-icon name="exclamation-triangle" class="size-4" aria-hidden="true" />{{ __('jobs.late') }}
</span>
@endif
</button>
</li>
@endforeach
</ul>
@endif
</section>
@endforeach
</div>
</section>
<section aria-labelledby="unscheduled-heading" class="space-y-3" x-data>
<h2 id="unscheduled-heading" class="text-lg font-semibold">{{ __('jobs.calendar.unscheduled') }}</h2>
@if ($this->unscheduled === [])
<p class="text-sm">{{ __('jobs.calendar.unscheduled_none') }}</p>
@else
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.calendar.unscheduled_intro') }}</p>
<ul class="grid gap-2 sm:grid-cols-2 xl:grid-cols-4">
@foreach ($this->unscheduled as $task)
<li
wire:key="unscheduled-{{ $task->taskId }}"
@if ($canManage)
x-on:pointerdown="$dispatch('task-calendar-place', { event: $event, bar: @js(['task' => $task->taskId, 'job' => $task->jobId, 'user' => $this->onlyAssignee($task), 'from' => null, 'to' => null]) })"
@endif
@class([
'flex flex-col gap-1 rounded-md border border-zinc-300 p-2 text-sm select-none dark:border-zinc-600',
'lg:cursor-grab lg:touch-none' => $canManage,
])
>
<span class="font-semibold break-words">{{ $task->title }}</span>
<span class="break-words">{{ $task->jobNumber }} {{ $task->jobName }}</span>
<span class="break-words">
{{ $task->assignment === null ? __('jobs.calendar.no_assignee') : ($this->userNames[$task->assignment->userId] ?? '') }}
@if ($task->estimatedHours !== null) · {{ str_replace('.', ',', $task->estimatedHours) }} h @endif
</span>
@if ($task->dueOn !== null)
<span>{{ __('jobs.tasks.fields.due_on') }}: <x-jobs.due-date :date="$task->dueOn" :status="$task->status" /></span>
@endif
<div>
<x-button
sm
subtle
color="black"
id="unscheduled-{{ $task->taskId }}"
wire:click="openDialog({{ $task->taskId }}, {{ $this->onlyAssignee($task) ?? 'null' }})"
x-on:pointerdown.stop
:text="__('jobs.calendar.schedule')"
:aria-label="__('jobs.calendar.schedule_named', ['title' => $task->title])"
/>
</div>
</li>
@endforeach
</ul>
@endif
</section>
<x-confirm-dialog id="task-schedule-dialog" :title="__('jobs.calendar.dialog_title')">
<p class="font-medium break-words">{{ $dialogTitle }}</p>
<form id="task-schedule-form" wire:submit="saveDialog" class="mt-4 space-y-4" novalidate>
@if ($dialogJobId !== null && Gate::allows('jobs.manage-tasks', $dialogJobId))
<x-input wire:model="plannedFrom" type="date" :label="__('jobs.calendar.fields.from')" required />
<x-input wire:model="plannedTo" type="date" :label="__('jobs.calendar.fields.to')" :hint="__('jobs.calendar.fields.to_hint')" />
<x-select.native wire:model="assignee" :label="__('jobs.calendar.fields.assignee')" :aria-label="__('jobs.calendar.fields.assignee')" :hint="__('jobs.calendar.fields.assignee_hint')">
<option value="">{{ __('jobs.calendar.no_assignee') }}</option>
@foreach ($this->userNames as $userId => $name)
<option value="{{ $userId }}">{{ $name }}</option>
@endforeach
</x-select.native>
@endif
<x-select.native wire:model="status" :label="__('jobs.calendar.fields.status')" :aria-label="__('jobs.calendar.fields.status')">
@foreach (TaskStatus::cases() as $option)
<option value="{{ $option->value }}">{{ __('jobs.tasks.statuses.'.$option->value) }}</option>
@endforeach
</x-select.native>
@if ($dialogJobId !== null)
<p class="flex flex-wrap gap-x-4 gap-y-1">
<x-link :href="route('jobs.show', $dialogJobId).'#tasks'" navigate>{{ __('jobs.calendar.open_job') }}</x-link>
@if (Gate::allows('jobs.manage-tasks', $dialogJobId) && $dialogTaskId !== null)
<x-link :href="route('jobs.tasks.edit', [$dialogJobId, $dialogTaskId])" navigate>{{ __('jobs.calendar.edit_task') }}</x-link>
@endif
</p>
@endif
</form>
<x-slot:actions>
@if ($dialogJobId !== null && Gate::allows('jobs.manage-tasks', $dialogJobId))
<x-button subtle color="black" wire:click="clearSchedule" :text="__('jobs.calendar.clear')" />
@endif
<x-button wire:click="saveDialog" :text="__('jobs.calendar.save')" />
</x-slot:actions>
</x-confirm-dialog>
</div>