- A task now has one optional assignee (tasks.assignee_user_id), whose calendar row it is on and whose days its estimate books, and members (task_members) who see it among their own jobs and in the weekly sheet but get no bookings. A migration moves existing assignees over: the one with most booked time becomes the assignee, the others members. - Adding tasks from a workflow template asks for each step's assignee and, by default, schedules tasks with a due date to end on it, booking the estimate backwards from the due date (not before today); what does not fit runs past the due date and is reported as late. - The task calendar leaves quick sale tasks out of the unscheduled list, shows a bar's job details in a popover on hover and focus, and shows the day load on its own grid line. - The template table stacks its cells on narrow screens to reflow at 320 px. Co-Authored-By: Claude Opus 5.5 <[email protected]>
134 lines
5.3 KiB
PHP
134 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Jobs\Presentation\Livewire\Forms;
|
|
|
|
use App\Modules\Jobs\Application\DTOs\NamedId;
|
|
use App\Modules\Jobs\Application\DTOs\TaskData;
|
|
use App\Modules\Jobs\Application\DTOs\TaskSummary;
|
|
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;
|
|
use Livewire\Form;
|
|
|
|
/**
|
|
* Task form shared by the add and edit pages.
|
|
*/
|
|
class TaskForm extends Form
|
|
{
|
|
public string $title = '';
|
|
|
|
public string $work_type_id = '';
|
|
|
|
public string $status = TaskStatus::Waiting->value;
|
|
|
|
public string $due_on = '';
|
|
|
|
public string $estimated_hours = '';
|
|
|
|
public string $planned_from = '';
|
|
|
|
public string $planned_to = '';
|
|
|
|
public string $description = '';
|
|
|
|
public string $assignee_user_id = '';
|
|
|
|
/** @var list<string> */
|
|
public array $member_user_ids = [];
|
|
|
|
public function fillFromSummary(TaskSummary $task): void
|
|
{
|
|
$this->title = $task->title;
|
|
$this->work_type_id = (string) $task->workType->id;
|
|
$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_id = $task->assignee === null ? '' : (string) $task->assignee->id;
|
|
$this->member_user_ids = array_map(fn (NamedId $user): string => (string) $user->id, $task->members);
|
|
}
|
|
|
|
public function toData(): TaskData
|
|
{
|
|
$this->validate();
|
|
|
|
return new TaskData(
|
|
title: $this->title,
|
|
workTypeId: (int) $this->work_type_id,
|
|
status: $this->status,
|
|
description: trim($this->description) === '' ? null : $this->description,
|
|
dueOn: $this->due_on === '' ? null : $this->due_on,
|
|
estimatedHours: trim($this->estimated_hours) === '' ? null : $this->estimated_hours,
|
|
assigneeUserId: $this->assignee_user_id === '' ? null : (int) $this->assignee_user_id,
|
|
memberUserIds: array_map('intval', $this->member_user_ids),
|
|
plannedFrom: $this->planned_from === '' ? null : $this->planned_from,
|
|
plannedTo: $this->planned_from === '' || $this->planned_to === '' ? null : $this->planned_to,
|
|
);
|
|
}
|
|
|
|
public function showDomainError(DomainException $exception): void
|
|
{
|
|
[$field, $key] = match (true) {
|
|
$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 => [match ($exception->field) {
|
|
'work_type' => 'work_type_id',
|
|
'assignee' => 'assignee_user_id',
|
|
default => 'member_user_ids',
|
|
}, 'jobs.errors.invalid_reference'],
|
|
default => throw $exception,
|
|
};
|
|
|
|
$this->addError($field, __($key));
|
|
}
|
|
|
|
/**
|
|
* @return array<string, array<int, mixed>>
|
|
*/
|
|
protected function rules(): array
|
|
{
|
|
return [
|
|
'title' => ['required', 'string', 'max:255'],
|
|
'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_id' => ['nullable', 'integer'],
|
|
'member_user_ids' => ['array'],
|
|
'member_user_ids.*' => ['integer'],
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function messages(): array
|
|
{
|
|
return [
|
|
'title.required' => __('jobs.tasks.errors.title_required'),
|
|
'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'),
|
|
'description.max' => __('jobs.errors.too_long', ['max' => 10000]),
|
|
];
|
|
}
|
|
}
|