authorize('jobs.view-job', $this->jobId); abort_if($this->task !== null && $this->task->jobId !== $this->jobId, 404); } #[Computed] public function task(): ?MachineTaskInfo { return app(MachineTasks::class)->info($this->taskId); } #[Computed] public function row(): ?QueueRow { return app(MachineQueries::class)->rowForTask($this->taskId); } /** * @return list */ #[Computed] public function machines(): array { return $this->task === null ? [] : app(MachineQueries::class)->machinesFor($this->task->allowedServiceUnitIds); } public function machineName(int $machineId): string { return app(MachineQueries::class)->findMachine($machineId)->name ?? ''; } public function canPlan(): bool { return $this->task !== null && ! $this->task->isDone && $this->task->allowedServiceUnitIds !== [] && auth()->user()?->can('machines.use') === true; } public function startEdit(): void { $this->authorizePlanning(); $today = app(Clock::class)->today()->format('Y-m-d'); $this->editing = true; $this->machineId = (string) ($this->row->machineId ?? ($this->machines[0]->id ?? '')); $this->day = $this->row !== null && ! $this->row->isLate ? $this->row->plannedOn : ($this->task?->plannedFrom !== null && $this->task->plannedFrom > $today ? $this->task->plannedFrom : $today); $this->resetErrorBag(); $this->js("setTimeout(() => document.getElementById('task-{$this->taskId}-machine')?.focus())"); } public function cancel(): void { $this->editing = false; $this->js("document.getElementById('task-{$this->taskId}-move')?.focus()"); } public function save(MachineWorkList $workList): void { $this->authorizePlanning(); try { $workList->planTask($this->taskId, (int) $this->machineId, $this->day); } catch (InvalidPlannedDay) { $this->addError('day', __('machines.errors.day')); return; } catch (MachineNotFound|MachineInactive|MachineNotForTask) { $this->addError('machineId', __('machines.errors.machine')); return; } catch (MachineTaskNotFound) { $this->message = __('machines.errors.task_done'); return; } $this->message = __('machines.task.moved', ['machine' => $this->machineName((int) $this->machineId), 'date' => $this->dateLabel($this->day)]); $this->editing = false; unset($this->row); $this->js("document.getElementById('task-{$this->taskId}-machine-status')?.focus()"); } public function remove(MachineWorkList $workList): void { $this->authorizePlanning(); $workList->removeTask($this->taskId); $this->message = __('machines.task.removed'); unset($this->row); $this->js("document.getElementById('task-{$this->taskId}-machine-status')?.focus()"); } private function authorizePlanning(): void { $this->authorize('jobs.view-job', $this->jobId); abort_unless($this->canPlan(), 403); } }; ?>
@if ($this->canPlan() || $this->row !== null)

{{ __('machines.task.title') }}

{{ $message }}

@if ($this->row !== null)

{{ __('machines.task.on_machine', ['machine' => $this->machineName($this->row->machineId), 'date' => $this->dateLabel($this->row->plannedOn)]) }}

@if ($this->row->plannedOn < app(Clock::class)->today()->format('Y-m-d'))

@elseif ($this->task !== null && $this->task->isOutsidePlan($this->row->plannedOn))

@endif @else

{{ __('machines.task.not_on_machine') }}

@endif @if ($this->canPlan()) @if ($editing) @if ($this->machines === [])

{{ __('machines.task.no_machines') }}

@else
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}} @foreach ($this->machines as $machine) @endforeach
@endif @else
@if ($this->row !== null) @endif
@endif @endif
@endif