Add the task calendar, holidays, workflow templates and customer removal
Task calendar (/jobs/calendar) replaces per-unit task Kanban columns (K34): a two-week Gantt of tasks per person. Bars move, resize and change person by dragging or through a keyboard dialog. Each task's estimate is booked evenly over working days into task_bookings, and what exceeds the daily maximum (jobs.daily_capacity_hours, 8 h) moves to the next working day. Tasks get planned_from/planned_to on the form. Holidays (/settings/holidays): Finnish public holidays calculated per year, which the admin can take out of use, plus company days off. Also includes the earlier uncommitted work: workflow templates with adding tasks from a template, and removing customers no module refers to. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskTitle;
|
||||
use App\Modules\Jobs\Domain\Exceptions\PlanEndsBeforeStart;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use Illuminate\Validation\Rule;
|
||||
@@ -29,6 +30,10 @@ class TaskForm extends Form
|
||||
|
||||
public string $estimated_hours = '';
|
||||
|
||||
public string $planned_from = '';
|
||||
|
||||
public string $planned_to = '';
|
||||
|
||||
public string $description = '';
|
||||
|
||||
/** @var list<string> */
|
||||
@@ -41,6 +46,8 @@ class TaskForm extends Form
|
||||
$this->status = $task->status->value;
|
||||
$this->due_on = $task->dueOn ?? '';
|
||||
$this->estimated_hours = $task->estimatedHours ?? '';
|
||||
$this->planned_from = $task->plannedFrom ?? '';
|
||||
$this->planned_to = $task->plannedTo ?? '';
|
||||
$this->description = $task->description ?? '';
|
||||
$this->assignee_user_ids = array_map(fn (NamedId $user): string => (string) $user->id, $task->assignees);
|
||||
}
|
||||
@@ -57,6 +64,8 @@ class TaskForm extends Form
|
||||
dueOn: $this->due_on === '' ? null : $this->due_on,
|
||||
estimatedHours: trim($this->estimated_hours) === '' ? null : $this->estimated_hours,
|
||||
assigneeUserIds: array_map('intval', $this->assignee_user_ids),
|
||||
plannedFrom: $this->planned_from === '' ? null : $this->planned_from,
|
||||
plannedTo: $this->planned_from === '' || $this->planned_to === '' ? null : $this->planned_to,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -66,6 +75,7 @@ class TaskForm extends Form
|
||||
$exception instanceof InvalidTaskTitle => ['title', 'jobs.tasks.errors.invalid_title'],
|
||||
$exception instanceof InvalidEstimatedHours => ['estimated_hours', 'jobs.errors.invalid_hours'],
|
||||
$exception instanceof TasksNotAllowedYet => ['title', 'jobs.tasks.not_allowed_yet'],
|
||||
$exception instanceof PlanEndsBeforeStart => ['planned_to', 'jobs.calendar.errors.to'],
|
||||
$exception instanceof InvalidTaskReference => [$exception->field === 'work_type' ? 'work_type_id' : 'assignee_user_ids', 'jobs.errors.invalid_reference'],
|
||||
default => throw $exception,
|
||||
};
|
||||
@@ -83,6 +93,8 @@ class TaskForm extends Form
|
||||
'work_type_id' => ['required', 'integer'],
|
||||
'status' => ['required', Rule::enum(TaskStatus::class)],
|
||||
'due_on' => ['nullable', 'date_format:Y-m-d'],
|
||||
'planned_from' => ['nullable', 'date_format:Y-m-d'],
|
||||
'planned_to' => ['nullable', 'date_format:Y-m-d', 'after_or_equal:planned_from'],
|
||||
'estimated_hours' => ['nullable', 'numeric', 'min:0', 'max:99999'],
|
||||
'description' => ['nullable', 'string', 'max:10000'],
|
||||
'assignee_user_ids' => ['array'],
|
||||
@@ -100,6 +112,9 @@ class TaskForm extends Form
|
||||
'title.max' => __('jobs.tasks.errors.invalid_title'),
|
||||
'work_type_id.required' => __('jobs.tasks.errors.work_type_required'),
|
||||
'due_on.date_format' => __('jobs.errors.invalid_date'),
|
||||
'planned_from.date_format' => __('jobs.errors.invalid_date'),
|
||||
'planned_to.date_format' => __('jobs.errors.invalid_date'),
|
||||
'planned_to.after_or_equal' => __('jobs.calendar.errors.to'),
|
||||
'estimated_hours.numeric' => __('jobs.errors.invalid_hours'),
|
||||
'estimated_hours.min' => __('jobs.errors.invalid_hours'),
|
||||
'estimated_hours.max' => __('jobs.errors.invalid_hours'),
|
||||
|
||||
@@ -0,0 +1,787 @@
|
||||
<?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
|
||||
{
|
||||
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 only assignee, so that the task moves rather than gets a
|
||||
* second assignee.
|
||||
*/
|
||||
public function onlyAssignee(CalendarTask $task): ?int
|
||||
{
|
||||
return count($task->assignments) === 1 ? $task->assignments[0]->userId : null;
|
||||
}
|
||||
|
||||
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);
|
||||
} 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()"
|
||||
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-800' => $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 px-1 pt-1 pb-2 text-right text-xs dark:border-zinc-700',
|
||||
'bg-zinc-200 dark:bg-zinc-800' => $this->isDayOff($day),
|
||||
])
|
||||
style="grid-column: {{ $index + 2 }}; grid-row: 1 / span {{ $row->lanes + 1 }};"
|
||||
>
|
||||
@if ($booked > 0)
|
||||
<span class="sr-only">{{ $this->dayLabel($day) }}:</span>
|
||||
<span @class(['font-semibold' => $booked > $this->capacityMinutes])>
|
||||
{{ __('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
|
||||
</span>
|
||||
@endif
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
@foreach ($row->bars as $bar)
|
||||
<button
|
||||
type="button"
|
||||
id="bar-{{ $bar->key() }}"
|
||||
wire:key="bar-{{ $bar->key() }}"
|
||||
aria-label="{{ $this->barLabel($bar) }}"
|
||||
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>
|
||||
@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->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->assignments === [] ? __('jobs.calendar.no_assignee') : implode(', ', array_map(fn ($assignment) => $this->userNames[$assignment->userId] ?? '', $task->assignments)) }}
|
||||
@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>
|
||||
@@ -313,7 +313,10 @@ new class extends Component
|
||||
|
||||
@can('jobs.manage-tasks', $job->id)
|
||||
@if ($job->status->allowsTasks())
|
||||
<x-button :href="route('jobs.tasks.create', $job->id)" wire:navigate icon="plus" :text="__('jobs.tasks.new')" />
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<x-button :href="route('jobs.tasks.create', $job->id)" wire:navigate icon="plus" :text="__('jobs.tasks.new')" />
|
||||
<x-button :href="route('jobs.tasks.from-template', $job->id)" wire:navigate subtle color="black" icon="queue-list" :text="__('jobs.tasks.from_template.title')" />
|
||||
</div>
|
||||
@endif
|
||||
@endcan
|
||||
</div>
|
||||
@@ -348,6 +351,14 @@ new class extends Component
|
||||
<dd>{{ $task->assignees === [] ? __('jobs.not_set') : collect($task->assignees)->pluck('name')->join(', ') }}</dd>
|
||||
<dt class="font-medium">{{ __('jobs.tasks.fields.due_on') }}</dt>
|
||||
<dd><x-jobs.due-date :date="$task->dueOn" :status="$task->status" /></dd>
|
||||
<dt class="font-medium">{{ __('jobs.tasks.schedule') }}</dt>
|
||||
<dd>
|
||||
@if ($task->plannedFrom === null)
|
||||
{{ __('jobs.not_set') }}
|
||||
@else
|
||||
{{ __('jobs.tasks.schedule_range', ['from' => $this->formatDate($task->plannedFrom), 'to' => $this->formatDate($task->plannedTo)]) }}
|
||||
@endif
|
||||
</dd>
|
||||
<dt class="font-medium">{{ __('jobs.tasks.fields.estimated_hours') }}</dt>
|
||||
<dd>{{ $task->estimatedHours === null ? __('jobs.not_set') : str_replace('.', ',', $task->estimatedHours).' h' }}</dd>
|
||||
</dl>
|
||||
|
||||
@@ -260,7 +260,8 @@ new class extends Component
|
||||
};
|
||||
?>
|
||||
|
||||
<section aria-labelledby="checklist-{{ $taskId }}-heading" class="space-y-2">
|
||||
{{-- Named by the task, so the checklists of a job's tasks are distinguishable landmarks. --}}
|
||||
<section aria-label="{{ __('jobs.tasks.checklist.list_of', ['title' => $taskTitle]) }}" class="space-y-2">
|
||||
@php($canCheck = Gate::allows('jobs.update-task-status', $jobId))
|
||||
@php($canManage = Gate::allows('jobs.manage-tasks', $jobId))
|
||||
@php($doneCount = count(array_filter($this->items, fn ($item) => $item->done)))
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Modules\Jobs\Presentation\Livewire\Forms\TaskForm;
|
||||
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
@@ -130,11 +131,12 @@ new class extends Component
|
||||
|
||||
try {
|
||||
if ($this->taskId === null) {
|
||||
$addTask->execute($this->jobId, $data, (int) auth()->id());
|
||||
session()->flash('status', __('jobs.tasks.created', ['title' => trim($data->title)]));
|
||||
$taskId = $addTask->execute($this->jobId, $data, (int) auth()->id());
|
||||
$message = __('jobs.tasks.created', ['title' => trim($data->title)]);
|
||||
} else {
|
||||
$updateTask->execute($this->jobId, $this->taskId, $data);
|
||||
session()->flash('status', __('jobs.tasks.updated', ['title' => trim($data->title)]));
|
||||
$taskId = $this->taskId;
|
||||
$updateTask->execute($this->jobId, $taskId, $data);
|
||||
$message = __('jobs.tasks.updated', ['title' => trim($data->title)]);
|
||||
}
|
||||
} catch (CustomerJobNotFound|TaskNotFound) {
|
||||
abort(404);
|
||||
@@ -144,6 +146,14 @@ new class extends Component
|
||||
return;
|
||||
}
|
||||
|
||||
$plannedTo = app(TaskQueries::class)->findTask($this->jobId, $taskId)?->plannedTo;
|
||||
|
||||
if ($data->plannedFrom !== null && $plannedTo !== null && $plannedTo !== ($data->plannedTo ?? $data->plannedFrom)) {
|
||||
$message .= ' '.__('jobs.tasks.extended', ['to' => CarbonImmutable::parse($plannedTo)->format('j.n.Y')]);
|
||||
}
|
||||
|
||||
session()->flash('status', $message);
|
||||
|
||||
$this->redirect(route('jobs.show', $this->jobId).'#tasks', navigate: true);
|
||||
}
|
||||
|
||||
@@ -208,6 +218,15 @@ new class extends Component
|
||||
/>
|
||||
</div>
|
||||
|
||||
<fieldset class="space-y-2">
|
||||
<legend class="text-sm font-semibold">{{ __('jobs.tasks.schedule') }}</legend>
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.fields.planned_hint') }}</p>
|
||||
<div class="grid gap-6 sm:grid-cols-2">
|
||||
<x-input wire:model="form.planned_from" type="date" :label="__('jobs.tasks.fields.planned_from')" />
|
||||
<x-input wire:model="form.planned_to" type="date" :label="__('jobs.tasks.fields.planned_to')" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<x-textarea wire:model="form.description" :label="__('jobs.tasks.fields.description')" resize-auto />
|
||||
|
||||
<div class="flex flex-wrap gap-3">
|
||||
|
||||
@@ -0,0 +1,261 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\WorkflowTemplateQueries;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowStepSummary;
|
||||
use App\Modules\Catalog\Application\DTOs\WorkflowTemplateDetails;
|
||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||
use App\Modules\Jobs\Application\DTOs\NamedId;
|
||||
use App\Modules\Jobs\Application\DTOs\TemplateTaskSchedule;
|
||||
use App\Modules\Jobs\Application\UseCases\AddTasksFromWorkflowTemplate;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidEstimatedHours;
|
||||
use App\Modules\Jobs\Domain\Exceptions\InvalidTaskReference;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TasksNotAllowedYet;
|
||||
use App\Modules\Jobs\Domain\Exceptions\WorkflowTemplateNotAvailable;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Adds a job's tasks from a workflow template (työnkulkupohja): one task per
|
||||
* step. Once a template is chosen, a table of its tasks takes an optional
|
||||
* due date and estimate for each.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
#[Locked]
|
||||
public int $jobId;
|
||||
|
||||
#[Locked]
|
||||
public string $jobTitle = '';
|
||||
|
||||
/** @var list<int> */
|
||||
#[Locked]
|
||||
public array $serviceUnitIds = [];
|
||||
|
||||
public string $templateId = '';
|
||||
|
||||
/**
|
||||
* One row per step of the chosen template, in step order.
|
||||
*
|
||||
* @var list<array{due_on: string, estimated_hours: string}>
|
||||
*/
|
||||
public array $rows = [];
|
||||
|
||||
public function mount(CustomerJobQueries $jobQueries, int $job): void
|
||||
{
|
||||
$details = $jobQueries->findDetails($job);
|
||||
|
||||
abort_if($details === null, 404);
|
||||
|
||||
$this->authorize('jobs.manage-tasks', $details->id);
|
||||
abort_unless($details->status->allowsTasks(), 404);
|
||||
|
||||
$this->jobId = $details->id;
|
||||
$this->jobTitle = $details->number.' '.$details->name;
|
||||
$this->serviceUnitIds = array_map(fn (NamedId $unit): int => $unit->id, $details->serviceUnits);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<WorkflowTemplateDetails>
|
||||
*/
|
||||
#[Computed]
|
||||
public function templates(): array
|
||||
{
|
||||
return app(WorkflowTemplateQueries::class)->activeFor($this->serviceUnitIds);
|
||||
}
|
||||
|
||||
/**
|
||||
* The templates as radio options; the description lists the steps.
|
||||
*
|
||||
* @return list<array{label: string, value: string, description: string}>
|
||||
*/
|
||||
#[Computed]
|
||||
public function options(): array
|
||||
{
|
||||
return array_map(fn (WorkflowTemplateDetails $template): array => [
|
||||
'label' => $this->labelOf($template),
|
||||
'value' => (string) $template->id,
|
||||
'description' => __('jobs.tasks.from_template.steps', [
|
||||
'steps' => implode(' → ', array_map(
|
||||
fn (WorkflowStepSummary $step): string => $step->workTypeId === null ? $step->title : $step->title.' ('.$step->workTypeName.')',
|
||||
$template->steps,
|
||||
)),
|
||||
]),
|
||||
], $this->templates);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function selectedTemplate(): ?WorkflowTemplateDetails
|
||||
{
|
||||
foreach ($this->templates as $template) {
|
||||
if ((string) $template->id === $this->templateId) {
|
||||
return $template;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A new template gets empty rows for its steps.
|
||||
*/
|
||||
public function updatedTemplateId(): void
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
$this->rows = array_map(fn (): array => ['due_on' => '', 'estimated_hours' => ''], $this->selectedTemplate?->steps ?? []);
|
||||
}
|
||||
|
||||
public function add(AddTasksFromWorkflowTemplate $addTasks): void
|
||||
{
|
||||
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||
|
||||
$this->validate(
|
||||
[
|
||||
'templateId' => ['required', 'integer'],
|
||||
'rows' => ['array'],
|
||||
'rows.*.due_on' => ['nullable', 'date_format:Y-m-d'],
|
||||
'rows.*.estimated_hours' => ['nullable', 'regex:/^\s*\d{1,5}([.,]\d{1,2})?\s*$/'],
|
||||
],
|
||||
[
|
||||
'templateId.required' => __('jobs.tasks.from_template.choose'),
|
||||
'templateId.integer' => __('jobs.tasks.from_template.not_available'),
|
||||
'rows.*.due_on.date_format' => __('jobs.errors.invalid_date'),
|
||||
'rows.*.estimated_hours.regex' => __('jobs.errors.invalid_hours'),
|
||||
],
|
||||
);
|
||||
|
||||
$template = $this->selectedTemplate;
|
||||
$schedules = array_map(fn (array $row): TemplateTaskSchedule => new TemplateTaskSchedule(
|
||||
$row['due_on'] === '' ? null : $row['due_on'],
|
||||
trim($row['estimated_hours']) === '' ? null : $row['estimated_hours'],
|
||||
), $this->rows);
|
||||
|
||||
try {
|
||||
$count = $addTasks->execute($this->jobId, (int) $this->templateId, (int) auth()->id(), $schedules);
|
||||
} catch (CustomerJobNotFound) {
|
||||
abort(404);
|
||||
} catch (TasksNotAllowedYet) {
|
||||
$this->addError('templateId', __('jobs.tasks.not_allowed_yet'));
|
||||
|
||||
return;
|
||||
} catch (InvalidEstimatedHours) {
|
||||
$this->addError('templateId', __('jobs.errors.invalid_hours'));
|
||||
|
||||
return;
|
||||
} catch (WorkflowTemplateNotAvailable|InvalidTaskReference) {
|
||||
unset($this->templates, $this->options, $this->selectedTemplate);
|
||||
$this->addError('templateId', __('jobs.tasks.from_template.not_available'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
session()->flash('status', trans_choice('jobs.tasks.from_template.added', $count, [
|
||||
'count' => $count,
|
||||
'name' => $template === null ? '' : $this->labelOf($template),
|
||||
]));
|
||||
|
||||
$this->redirect(route('jobs.show', $this->jobId).'#tasks', navigate: true);
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title(__('jobs.tasks.from_template.title').' – '.$this->jobTitle);
|
||||
}
|
||||
|
||||
private function labelOf(WorkflowTemplateDetails $template): string
|
||||
{
|
||||
return __('jobs.tasks.from_template.option', ['name' => $template->name, 'work_type' => $template->workTypeName]);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="mx-auto max-w-2xl space-y-6 p-4 sm:p-6">
|
||||
<div class="space-y-1">
|
||||
<h1 class="text-2xl font-semibold">{{ __('jobs.tasks.from_template.title') }}</h1>
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.job_label') }}: {{ $jobTitle }}</p>
|
||||
</div>
|
||||
|
||||
<p class="text-sm">{{ __('jobs.tasks.from_template.intro') }}</p>
|
||||
|
||||
@if ($this->options === [])
|
||||
@error('templateId')
|
||||
<p role="alert" class="text-sm text-red-700 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
<p>{{ __('jobs.tasks.from_template.none') }}</p>
|
||||
|
||||
<x-button :href="route('jobs.show', $jobId)" wire:navigate subtle color="black" :text="__('jobs.tasks.from_template.back')" />
|
||||
@else
|
||||
<form wire:submit="add" class="space-y-6" novalidate>
|
||||
<x-radio.group
|
||||
id="template"
|
||||
wire:model.live="templateId"
|
||||
:label="__('jobs.tasks.from_template.template')"
|
||||
:options="$this->options"
|
||||
required
|
||||
/>
|
||||
|
||||
@if (($template = $this->selectedTemplate) !== null)
|
||||
{{-- An input grid is a form, so a native table rather than <x-table>. --}}
|
||||
<div class="space-y-2">
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.from_template.schedule_help') }}</p>
|
||||
|
||||
<table class="w-full border-collapse text-sm">
|
||||
<caption class="mb-2 text-left font-medium">{{ __('jobs.tasks.from_template.table_caption', ['name' => $template->name]) }}</caption>
|
||||
<thead>
|
||||
<tr class="border-b border-zinc-200 dark:border-zinc-700">
|
||||
<th scope="col" class="py-2 pr-2 text-left font-semibold">{{ __('jobs.tasks.from_template.task') }}</th>
|
||||
<th scope="col" class="px-1 py-2 text-left font-semibold">{{ __('jobs.tasks.fields.due_on') }}</th>
|
||||
<th scope="col" class="py-2 pl-1 text-left font-semibold">{{ __('jobs.tasks.fields.estimated_hours') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@foreach ($template->steps as $index => $step)
|
||||
<tr wire:key="row-{{ $template->id }}-{{ $index }}" class="border-b border-zinc-200 align-top dark:border-zinc-700">
|
||||
<th scope="row" class="py-2 pr-2 text-left font-normal break-words">
|
||||
<span class="font-medium">{{ $step->title }}</span>
|
||||
<span class="block text-xs text-zinc-600 dark:text-zinc-300">{{ $step->workTypeName }}</span>
|
||||
</th>
|
||||
<td class="px-1 py-2">
|
||||
<input
|
||||
type="date"
|
||||
id="row-{{ $index }}-due-on"
|
||||
wire:model="rows.{{ $index }}.due_on"
|
||||
aria-label="{{ __('jobs.tasks.from_template.due_on_of', ['title' => $step->title]) }}"
|
||||
@error('rows.'.$index.'.due_on') aria-invalid="true" aria-describedby="row-{{ $index }}-due-on-error" @enderror
|
||||
class="w-full min-w-0 rounded-md border border-zinc-500 bg-white px-1 py-1 text-sm dark:border-zinc-400 dark:bg-zinc-800 dark:[color-scheme:dark]"
|
||||
/>
|
||||
@error('rows.'.$index.'.due_on')
|
||||
<p id="row-{{ $index }}-due-on-error" class="mt-1 text-xs text-red-700 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</td>
|
||||
<td class="py-2 pl-1">
|
||||
<input
|
||||
type="text"
|
||||
inputmode="decimal"
|
||||
autocomplete="off"
|
||||
id="row-{{ $index }}-hours"
|
||||
wire:model="rows.{{ $index }}.estimated_hours"
|
||||
aria-label="{{ __('jobs.tasks.from_template.hours_of', ['title' => $step->title]) }}"
|
||||
@error('rows.'.$index.'.estimated_hours') aria-invalid="true" aria-describedby="row-{{ $index }}-hours-error" @enderror
|
||||
class="w-16 rounded-md border border-zinc-500 bg-white px-2 py-1 text-sm dark:border-zinc-400 dark:bg-zinc-800"
|
||||
/>
|
||||
@error('rows.'.$index.'.estimated_hours')
|
||||
<p id="row-{{ $index }}-hours-error" class="mt-1 text-xs text-red-700 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<x-button submit :text="__('jobs.tasks.from_template.submit')" />
|
||||
<x-button :href="route('jobs.show', $jobId)" wire:navigate subtle color="black" :text="__('catalog.cancel')" />
|
||||
</div>
|
||||
</form>
|
||||
@endif
|
||||
</div>
|
||||
@@ -10,8 +10,10 @@ Route::middleware(['web', 'auth', 'can:jobs.view'])
|
||||
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('/calendar', 'jobs::calendar')->name('calendar');
|
||||
Route::livewire('/{job}', 'jobs::show')->whereNumber('job')->name('show');
|
||||
Route::livewire('/{job}/edit', 'jobs::form')->whereNumber('job')->middleware('can:jobs.manage')->name('edit');
|
||||
Route::livewire('/{job}/tasks/create', 'jobs::task-form')->whereNumber('job')->name('tasks.create');
|
||||
Route::livewire('/{job}/tasks/from-template', 'jobs::tasks-from-template')->whereNumber('job')->name('tasks.from-template');
|
||||
Route::livewire('/{job}/tasks/{task}/edit', 'jobs::task-form')->whereNumber(['job', 'task'])->name('tasks.edit');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user