Give tasks one assignee and members, and schedule template tasks to due dates
- 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]>
This commit is contained in:
@@ -12,6 +12,8 @@ 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 App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
@@ -19,7 +21,8 @@ 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.
|
||||
* due date, estimate and assignee (the adder by default) for each; tasks
|
||||
* with a due date are scheduled to end on it unless that is turned off.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
@@ -38,10 +41,12 @@ new class extends Component
|
||||
/**
|
||||
* One row per step of the chosen template, in step order.
|
||||
*
|
||||
* @var list<array{due_on: string, estimated_hours: string}>
|
||||
* @var list<array{due_on: string, estimated_hours: string, assignee_user_id: string}>
|
||||
*/
|
||||
public array $rows = [];
|
||||
|
||||
public bool $scheduleToDueDates = true;
|
||||
|
||||
public function mount(CustomerJobQueries $jobQueries, int $job): void
|
||||
{
|
||||
$details = $jobQueries->findDetails($job);
|
||||
@@ -85,6 +90,18 @@ new class extends Component
|
||||
], $this->templates);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{value: int, label: string}>
|
||||
*/
|
||||
#[Computed]
|
||||
public function userOptions(): array
|
||||
{
|
||||
return array_map(fn ($user): array => [
|
||||
'value' => $user->id,
|
||||
'label' => $user->role === Role::Subcontractor ? $user->name.' ('.__('users.roles.subcontractor').')' : $user->name,
|
||||
], app(UserAccountQueries::class)->activeUserOptions());
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function selectedTemplate(): ?WorkflowTemplateDetails
|
||||
{
|
||||
@@ -103,7 +120,7 @@ new class extends Component
|
||||
public function updatedTemplateId(): void
|
||||
{
|
||||
$this->resetErrorBag();
|
||||
$this->rows = array_map(fn (): array => ['due_on' => '', 'estimated_hours' => ''], $this->selectedTemplate?->steps ?? []);
|
||||
$this->rows = array_map(fn (): array => ['due_on' => '', 'estimated_hours' => '', 'assignee_user_id' => (string) auth()->id()], $this->selectedTemplate?->steps ?? []);
|
||||
}
|
||||
|
||||
public function add(AddTasksFromWorkflowTemplate $addTasks): void
|
||||
@@ -116,6 +133,8 @@ new class extends Component
|
||||
'rows' => ['array'],
|
||||
'rows.*.due_on' => ['nullable', 'date_format:Y-m-d'],
|
||||
'rows.*.estimated_hours' => ['nullable', 'regex:/^\s*\d{1,5}([.,]\d{1,2})?\s*$/'],
|
||||
'rows.*.assignee_user_id' => ['nullable', 'integer'],
|
||||
'scheduleToDueDates' => ['boolean'],
|
||||
],
|
||||
[
|
||||
'templateId.required' => __('jobs.tasks.from_template.choose'),
|
||||
@@ -129,10 +148,11 @@ new class extends Component
|
||||
$schedules = array_map(fn (array $row): TemplateTaskSchedule => new TemplateTaskSchedule(
|
||||
$row['due_on'] === '' ? null : $row['due_on'],
|
||||
trim($row['estimated_hours']) === '' ? null : $row['estimated_hours'],
|
||||
$row['assignee_user_id'] === '' ? null : (int) $row['assignee_user_id'],
|
||||
), $this->rows);
|
||||
|
||||
try {
|
||||
$count = $addTasks->execute($this->jobId, (int) $this->templateId, (int) auth()->id(), $schedules);
|
||||
$result = $addTasks->execute($this->jobId, (int) $this->templateId, (int) auth()->id(), $schedules, $this->scheduleToDueDates);
|
||||
} catch (CustomerJobNotFound) {
|
||||
abort(404);
|
||||
} catch (TasksNotAllowedYet) {
|
||||
@@ -143,17 +163,39 @@ new class extends Component
|
||||
$this->addError('templateId', __('jobs.errors.invalid_hours'));
|
||||
|
||||
return;
|
||||
} catch (WorkflowTemplateNotAvailable|InvalidTaskReference) {
|
||||
} catch (InvalidTaskReference $exception) {
|
||||
if ($exception->field === 'assignee') {
|
||||
unset($this->userOptions);
|
||||
$this->addError('templateId', __('jobs.errors.invalid_reference'));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
unset($this->templates, $this->options, $this->selectedTemplate);
|
||||
$this->addError('templateId', __('jobs.tasks.from_template.not_available'));
|
||||
|
||||
return;
|
||||
} catch (WorkflowTemplateNotAvailable) {
|
||||
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,
|
||||
$message = trans_choice('jobs.tasks.from_template.added', $result->added, [
|
||||
'count' => $result->added,
|
||||
'name' => $template === null ? '' : $this->labelOf($template),
|
||||
]));
|
||||
]);
|
||||
|
||||
if ($result->scheduled > 0) {
|
||||
$message .= ' '.trans_choice('jobs.tasks.from_template.scheduled', $result->scheduled, ['count' => $result->scheduled]);
|
||||
}
|
||||
|
||||
if ($result->late > 0) {
|
||||
$message .= ' '.trans_choice('jobs.tasks.from_template.late', $result->late, ['count' => $result->late]);
|
||||
}
|
||||
|
||||
session()->flash('status', $message);
|
||||
|
||||
$this->redirect(route('jobs.show', $this->jobId).'#tasks', navigate: true);
|
||||
}
|
||||
@@ -201,23 +243,26 @@ new class extends Component
|
||||
<div class="space-y-2">
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.from_template.schedule_help') }}</p>
|
||||
|
||||
{{-- Below sm the rows stack (each cell on its own line, with its own visible label) so that the page reflows at 320 px. --}}
|
||||
<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>
|
||||
<thead class="max-sm:hidden">
|
||||
<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>
|
||||
<th scope="col" class="px-1 py-2 text-left font-semibold">{{ __('jobs.tasks.fields.estimated_hours') }}</th>
|
||||
<th scope="col" class="py-2 pl-1 text-left font-semibold">{{ __('jobs.tasks.fields.assignee') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tbody class="max-sm:block">
|
||||
@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">
|
||||
<tr wire:key="row-{{ $template->id }}-{{ $index }}" class="border-b border-zinc-200 align-top max-sm:block max-sm:py-2 dark:border-zinc-700">
|
||||
<th scope="row" class="py-2 pr-2 text-left font-normal break-words max-sm:block max-sm:py-0">
|
||||
<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">
|
||||
<td class="px-1 py-2 max-sm:block max-sm:px-0 max-sm:py-1">
|
||||
<span class="block text-xs font-medium sm:hidden" aria-hidden="true">{{ __('jobs.tasks.fields.due_on') }}</span>
|
||||
<input
|
||||
type="date"
|
||||
id="row-{{ $index }}-due-on"
|
||||
@@ -230,7 +275,8 @@ new class extends Component
|
||||
<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">
|
||||
<td class="px-1 py-2 max-sm:block max-sm:px-0 max-sm:py-1">
|
||||
<span class="block text-xs font-medium sm:hidden" aria-hidden="true">{{ __('jobs.tasks.fields.estimated_hours') }}</span>
|
||||
<input
|
||||
type="text"
|
||||
inputmode="decimal"
|
||||
@@ -239,16 +285,40 @@ new class extends Component
|
||||
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"
|
||||
class="w-16 rounded-md border max-sm:w-full 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>
|
||||
<td class="py-2 pl-1 max-sm:block max-sm:py-1 max-sm:pl-0">
|
||||
<span class="block text-xs font-medium sm:hidden" aria-hidden="true">{{ __('jobs.tasks.fields.assignee') }}</span>
|
||||
<select
|
||||
id="row-{{ $index }}-assignee"
|
||||
wire:model="rows.{{ $index }}.assignee_user_id"
|
||||
aria-label="{{ __('jobs.tasks.from_template.assignee_of', ['title' => $step->title]) }}"
|
||||
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"
|
||||
>
|
||||
<option value="">{{ __('jobs.calendar.no_assignee') }}</option>
|
||||
@foreach ($this->userOptions as $user)
|
||||
<option value="{{ $user['value'] }}">{{ $user['label'] }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="space-y-1 pt-2">
|
||||
<x-checkbox
|
||||
id="schedule-to-due-dates"
|
||||
wire:model="scheduleToDueDates"
|
||||
aria-describedby="schedule-to-due-dates-hint"
|
||||
:label="__('jobs.tasks.from_template.schedule_to_due')"
|
||||
/>
|
||||
<p id="schedule-to-due-dates-hint" class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.from_template.schedule_to_due_hint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user