Add checklists to tasks on the job page
Tasks get an ordered checklist (spec 8.2, phase 3): items are checked done with who and when recorded, also by subcontractors attached to the job; others add, rename, reorder and remove items. Items go with their task. The spec gets a phase 3 chapter (18.1), and open questions move to chapter 19. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -4,7 +4,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
|
|||||||
|
|
||||||
## Project
|
## Project
|
||||||
|
|
||||||
An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), TallStackUI 4 (Blade components, no prefix: `<x-input>`, `<x-button>`), Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared`, `Users`, `Customers`, `Catalog` (service units, services and work types, managed on the Pohjatiedot page; hourly rates, products and the mileage rate on the Hinnasto page, read through `PriceListQueries`, never `CatalogQueries`) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks) `TimeTracking` (hours on tasks: weekly sheet and task booking page) `Expenses` (expenses on jobs with cost, markup and billed amount; reads jobs and prices through its own `ExpenseJobs`/`ExpensePricing` ports) `Billing` (the monthly billing material: a draft of invoices made of done jobs and monthly fee jobs (one line per unbilled month up to the draft's month, each such job an invoice of its own), management's billable hours, and on creation invoice lines with price snapshots, downloadable as a semicolon CSV with amounts in whole cents and the VAT rate in tenths of a percent (`billing.csv`, with consumers' identity codes for those who may see them); reads and marks hours, expenses and jobs through its `BillingJobs`/`BillingHours`/`BillingExpenses`/`BillingPrices` ports, which call those modules' queries and the use cases `MarkJobHoursBilled`, `MarkJobExpensesBilled` and `ChangeJobStatus`) and `Sales` (quick sales of consumer products at the counter, credits and cash days; its `QuickSaleHours` port books product durations through Jobs' `ProvideQuickSaleTask` (the yearly "Pikamyynnit" job) and TimeTracking's `AddTaskHours`)); `/` is still a temporary Livewire demo page behind login (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`, which has the main menu and logout for signed-in users).
|
An ERP / work-management system (*toiminnanohjausjärjestelmä*) for a small (5–10 person) Finnish media/marketing company. Stack: Laravel 13, Livewire 4 (single-file components), TallStackUI 4 (Blade components, no prefix: `<x-input>`, `<x-button>`), Tailwind 4, Vite 8, Pest, Larastan. Domain code lives in modules under `app/Modules` (so far `Shared`, `Users`, `Customers`, `Catalog` (service units, services and work types, managed on the Pohjatiedot page; hourly rates, products and the mileage rate on the Hinnasto page, read through `PriceListQueries`, never `CatalogQueries`) `Jobs` (customer jobs: numbering, members, tags, links, history, tasks, task checklists) `TimeTracking` (hours on tasks: weekly sheet and task booking page) `Expenses` (expenses on jobs with cost, markup and billed amount; reads jobs and prices through its own `ExpenseJobs`/`ExpensePricing` ports) `Billing` (the monthly billing material: a draft of invoices made of done jobs and monthly fee jobs (one line per unbilled month up to the draft's month, each such job an invoice of its own), management's billable hours, and on creation invoice lines with price snapshots, downloadable as a semicolon CSV with amounts in whole cents and the VAT rate in tenths of a percent (`billing.csv`, with consumers' identity codes for those who may see them); reads and marks hours, expenses and jobs through its `BillingJobs`/`BillingHours`/`BillingExpenses`/`BillingPrices` ports, which call those modules' queries and the use cases `MarkJobHoursBilled`, `MarkJobExpensesBilled` and `ChangeJobStatus`) and `Sales` (quick sales of consumer products at the counter, credits and cash days; its `QuickSaleHours` port books product durations through Jobs' `ProvideQuickSaleTask` (the yearly "Pikamyynnit" job) and TimeTracking's `AddTaskHours`)); `/` is still a temporary Livewire demo page behind login (`resources/views/pages/⚡home.blade.php`, layout `resources/views/layouts/app.blade.php`, which has the main menu and logout for signed-in users).
|
||||||
|
|
||||||
- **The specification is `docs/maarittely.md`** (Finnish). It defines roles and the permission table, money visibility, customers, customer jobs (*asiakastyö*) with fields and enum keys, Kanban, tasks, time entries, expenses, the service unit → service → work type hierarchy and pricing, Fennoa billing export, the data model, the phases with phase 1 in detail, and open questions. Read it before designing any domain feature. `määrittely.txt` is the original description with the customer's answers to questions 1–53, referenced as *(K12)* in the spec.
|
- **The specification is `docs/maarittely.md`** (Finnish). It defines roles and the permission table, money visibility, customers, customer jobs (*asiakastyö*) with fields and enum keys, Kanban, tasks, time entries, expenses, the service unit → service → work type hierarchy and pricing, Fennoa billing export, the data model, the phases with phase 1 in detail, and open questions. Read it before designing any domain feature. `määrittely.txt` is the original description with the customer's answers to questions 1–53, referenced as *(K12)* in the spec.
|
||||||
- **Language rule:** code (identifiers, tables, columns, enum keys) is in English; the specification and the UI are in Finnish. Keep UI strings in translation files from the start.
|
- **Language rule:** code (identifiers, tables, columns, enum keys) is in English; the specification and the UI are in Finnish. Keep UI strings in translation files from the start.
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\Contracts;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\DTOs\ChecklistItemSummary;
|
||||||
|
|
||||||
|
interface ChecklistQueries
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The task's checklist in its order; empty when the task belongs to
|
||||||
|
* another job.
|
||||||
|
*
|
||||||
|
* @return list<ChecklistItemSummary>
|
||||||
|
*/
|
||||||
|
public function checklistOf(int $jobId, int $taskId): array;
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\DTOs;
|
||||||
|
|
||||||
|
final readonly class ChecklistItemSummary
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
public int $id,
|
||||||
|
public string $text,
|
||||||
|
public bool $done,
|
||||||
|
) {}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\Services;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Finds a checklist item only through its task and the task's job, so a
|
||||||
|
* page of one job never changes another job's items.
|
||||||
|
*/
|
||||||
|
final readonly class ChecklistItemFinder
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private TaskRepository $tasks,
|
||||||
|
private ChecklistItemRepository $items,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TaskNotFound
|
||||||
|
* @throws ChecklistItemNotFound
|
||||||
|
*/
|
||||||
|
public function find(int $jobId, int $taskId, int $itemId): ChecklistItem
|
||||||
|
{
|
||||||
|
$this->ensureTask($jobId, $taskId);
|
||||||
|
|
||||||
|
return $this->items->findForTask($taskId, $itemId) ?? throw new ChecklistItemNotFound($taskId, $itemId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TaskNotFound
|
||||||
|
*/
|
||||||
|
public function ensureTask(int $jobId, int $taskId): void
|
||||||
|
{
|
||||||
|
if ($this->tasks->findForJob($jobId, $taskId) === null) {
|
||||||
|
throw new TaskNotFound($jobId, $taskId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\UseCases;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||||
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds an item to the end of a task's checklist.
|
||||||
|
*/
|
||||||
|
final class AddChecklistItem
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ChecklistItemFinder $finder,
|
||||||
|
private ChecklistItemRepository $items,
|
||||||
|
private TransactionManager $transactions,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return int The new item's id.
|
||||||
|
*
|
||||||
|
* @throws TaskNotFound
|
||||||
|
* @throws InvalidChecklistItemText
|
||||||
|
*/
|
||||||
|
public function execute(int $jobId, int $taskId, string $text): int
|
||||||
|
{
|
||||||
|
$text = new ChecklistItemText($text);
|
||||||
|
|
||||||
|
return $this->transactions->run(function () use ($jobId, $taskId, $text): int {
|
||||||
|
$this->finder->ensureTask($jobId, $taskId);
|
||||||
|
|
||||||
|
return (int) $this->items->save(ChecklistItem::create($taskId, $text, $this->items->nextSortOrder($taskId)))->id();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\UseCases;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
use App\Modules\Users\Application\Contracts\Clock;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Marks a checklist item done (recording who and when) or not done.
|
||||||
|
*/
|
||||||
|
final class CheckChecklistItem
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ChecklistItemFinder $finder,
|
||||||
|
private ChecklistItemRepository $items,
|
||||||
|
private TransactionManager $transactions,
|
||||||
|
private Clock $clock,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TaskNotFound
|
||||||
|
* @throws ChecklistItemNotFound
|
||||||
|
*/
|
||||||
|
public function execute(int $jobId, int $taskId, int $itemId, bool $done, int $userId): void
|
||||||
|
{
|
||||||
|
$this->transactions->run(function () use ($jobId, $taskId, $itemId, $done, $userId): void {
|
||||||
|
$item = $this->finder->find($jobId, $taskId, $itemId);
|
||||||
|
|
||||||
|
if ($done) {
|
||||||
|
$item->check($userId, $this->clock->now());
|
||||||
|
} else {
|
||||||
|
$item->uncheck();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->items->save($item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\UseCases;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Moves a checklist item one place up or down.
|
||||||
|
*/
|
||||||
|
final class MoveChecklistItem
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ChecklistItemFinder $finder,
|
||||||
|
private ChecklistItemRepository $items,
|
||||||
|
private TransactionManager $transactions,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool False when the item already was first (up) or last (down).
|
||||||
|
*
|
||||||
|
* @throws TaskNotFound
|
||||||
|
* @throws ChecklistItemNotFound
|
||||||
|
*/
|
||||||
|
public function execute(int $jobId, int $taskId, int $itemId, MoveDirection $direction): bool
|
||||||
|
{
|
||||||
|
return $this->transactions->run(function () use ($jobId, $taskId, $itemId, $direction): bool {
|
||||||
|
$item = $this->finder->find($jobId, $taskId, $itemId);
|
||||||
|
$neighbour = $this->items->neighbour($item, $direction);
|
||||||
|
|
||||||
|
if ($neighbour === null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$item->swapOrderWith($neighbour);
|
||||||
|
$this->items->save($item);
|
||||||
|
$this->items->save($neighbour);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\UseCases;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
|
||||||
|
final class RemoveChecklistItem
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ChecklistItemFinder $finder,
|
||||||
|
private ChecklistItemRepository $items,
|
||||||
|
private TransactionManager $transactions,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TaskNotFound
|
||||||
|
* @throws ChecklistItemNotFound
|
||||||
|
*/
|
||||||
|
public function execute(int $jobId, int $taskId, int $itemId): void
|
||||||
|
{
|
||||||
|
$this->transactions->run(function () use ($jobId, $taskId, $itemId): void {
|
||||||
|
$this->items->delete($this->finder->find($jobId, $taskId, $itemId));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Application\UseCases;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||||
|
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||||
|
|
||||||
|
final class RenameChecklistItem
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private ChecklistItemFinder $finder,
|
||||||
|
private ChecklistItemRepository $items,
|
||||||
|
private TransactionManager $transactions,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws TaskNotFound
|
||||||
|
* @throws ChecklistItemNotFound
|
||||||
|
* @throws InvalidChecklistItemText
|
||||||
|
*/
|
||||||
|
public function execute(int $jobId, int $taskId, int $itemId, string $text): void
|
||||||
|
{
|
||||||
|
$text = new ChecklistItemText($text);
|
||||||
|
|
||||||
|
$this->transactions->run(function () use ($jobId, $taskId, $itemId, $text): void {
|
||||||
|
$item = $this->finder->find($jobId, $taskId, $itemId);
|
||||||
|
$item->rename($text);
|
||||||
|
$this->items->save($item);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Domain\Contracts;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||||
|
|
||||||
|
interface ChecklistItemRepository
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Null when the item does not exist or belongs to another task.
|
||||||
|
*/
|
||||||
|
public function findForTask(int $taskId, int $itemId): ?ChecklistItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item next to the given one in the task's order, or null at the end.
|
||||||
|
*/
|
||||||
|
public function neighbour(ChecklistItem $item, MoveDirection $direction): ?ChecklistItem;
|
||||||
|
|
||||||
|
public function nextSortOrder(int $taskId): int;
|
||||||
|
|
||||||
|
public function save(ChecklistItem $item): ChecklistItem;
|
||||||
|
|
||||||
|
public function delete(ChecklistItem $item): void;
|
||||||
|
}
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Domain\Entities;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* One item of a task's checklist (todo), checked done by someone or not.
|
||||||
|
*/
|
||||||
|
final class ChecklistItem
|
||||||
|
{
|
||||||
|
private function __construct(
|
||||||
|
private ?int $id,
|
||||||
|
private int $taskId,
|
||||||
|
private ChecklistItemText $text,
|
||||||
|
private int $sortOrder,
|
||||||
|
private ?DateTimeImmutable $doneAt,
|
||||||
|
private ?int $doneBy,
|
||||||
|
) {}
|
||||||
|
|
||||||
|
public static function create(int $taskId, ChecklistItemText $text, int $sortOrder): self
|
||||||
|
{
|
||||||
|
return new self(null, $taskId, $text, $sortOrder, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function reconstitute(int $id, int $taskId, ChecklistItemText $text, int $sortOrder, ?DateTimeImmutable $doneAt, ?int $doneBy): self
|
||||||
|
{
|
||||||
|
return new self($id, $taskId, $text, $sortOrder, $doneAt, $doneBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function rename(ChecklistItemText $text): void
|
||||||
|
{
|
||||||
|
$this->text = $text;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checking an item that already is done keeps who did it and when.
|
||||||
|
*/
|
||||||
|
public function check(int $userId, DateTimeImmutable $at): void
|
||||||
|
{
|
||||||
|
if ($this->doneAt !== null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->doneAt = $at;
|
||||||
|
$this->doneBy = $userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function uncheck(): void
|
||||||
|
{
|
||||||
|
$this->doneAt = null;
|
||||||
|
$this->doneBy = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function swapOrderWith(self $other): void
|
||||||
|
{
|
||||||
|
[$this->sortOrder, $other->sortOrder] = [$other->sortOrder, $this->sortOrder];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function id(): ?int
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function taskId(): int
|
||||||
|
{
|
||||||
|
return $this->taskId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function text(): ChecklistItemText
|
||||||
|
{
|
||||||
|
return $this->text;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function sortOrder(): int
|
||||||
|
{
|
||||||
|
return $this->sortOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function isDone(): bool
|
||||||
|
{
|
||||||
|
return $this->doneAt !== null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doneAt(): ?DateTimeImmutable
|
||||||
|
{
|
||||||
|
return $this->doneAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function doneBy(): ?int
|
||||||
|
{
|
||||||
|
return $this->doneBy;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Domain\Enums;
|
||||||
|
|
||||||
|
enum MoveDirection: string
|
||||||
|
{
|
||||||
|
case Up = 'up';
|
||||||
|
case Down = 'down';
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||||
|
|
||||||
|
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The checklist item does not exist or belongs to another task or job.
|
||||||
|
*/
|
||||||
|
final class ChecklistItemNotFound extends DomainException
|
||||||
|
{
|
||||||
|
public function __construct(public readonly int $taskId, public readonly int $itemId)
|
||||||
|
{
|
||||||
|
parent::__construct("Checklist item {$itemId} of task {$taskId} was not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Domain\Exceptions;
|
||||||
|
|
||||||
|
use App\Modules\Shared\Domain\Exceptions\DomainException;
|
||||||
|
|
||||||
|
final class InvalidChecklistItemText extends DomainException
|
||||||
|
{
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
parent::__construct('A checklist item must be 1–255 characters.');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Domain\ValueObjects;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||||
|
|
||||||
|
final readonly class ChecklistItemText
|
||||||
|
{
|
||||||
|
public const int MAX_LENGTH = 255;
|
||||||
|
|
||||||
|
public string $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @throws InvalidChecklistItemText
|
||||||
|
*/
|
||||||
|
public function __construct(string $value)
|
||||||
|
{
|
||||||
|
$value = trim(preg_replace('/\s+/u', ' ', $value) ?? $value);
|
||||||
|
|
||||||
|
if ($value === '' || mb_strlen($value) > self::MAX_LENGTH) {
|
||||||
|
throw new InvalidChecklistItemText;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Infrastructure\Persistence\Eloquent;
|
||||||
|
|
||||||
|
use Carbon\CarbonImmutable;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||||
|
use Illuminate\Database\Eloquent\Attributes\Table;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Persistence model of a task's checklist item, used only inside the Jobs
|
||||||
|
* Infrastructure layer.
|
||||||
|
*
|
||||||
|
* @property int $id
|
||||||
|
* @property int $task_id
|
||||||
|
* @property string $text
|
||||||
|
* @property int $sort_order
|
||||||
|
* @property CarbonImmutable|null $done_at
|
||||||
|
* @property int|null $done_by
|
||||||
|
*/
|
||||||
|
#[Table('task_checklist_items')]
|
||||||
|
#[Fillable(['task_id', 'text', 'sort_order', 'done_at', 'done_by'])]
|
||||||
|
class ChecklistItemModel extends Model
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @return array<string, string>
|
||||||
|
*/
|
||||||
|
protected function casts(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'task_id' => 'integer',
|
||||||
|
'sort_order' => 'integer',
|
||||||
|
'done_at' => 'immutable_datetime',
|
||||||
|
'done_by' => 'integer',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
+73
@@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||||
|
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||||
|
use DateTimeImmutable;
|
||||||
|
|
||||||
|
class EloquentChecklistItemRepository implements ChecklistItemRepository
|
||||||
|
{
|
||||||
|
public function findForTask(int $taskId, int $itemId): ?ChecklistItem
|
||||||
|
{
|
||||||
|
$model = ChecklistItemModel::query()->where('task_id', $taskId)->find($itemId);
|
||||||
|
|
||||||
|
return $model === null ? null : $this->toEntity($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function neighbour(ChecklistItem $item, MoveDirection $direction): ?ChecklistItem
|
||||||
|
{
|
||||||
|
$up = $direction === MoveDirection::Up;
|
||||||
|
$model = ChecklistItemModel::query()
|
||||||
|
->where('task_id', $item->taskId())
|
||||||
|
->whereKeyNot($item->id())
|
||||||
|
->where(fn ($query) => $query
|
||||||
|
->where('sort_order', $up ? '<' : '>', $item->sortOrder())
|
||||||
|
->orWhere(fn ($query) => $query->where('sort_order', $item->sortOrder())->where('id', $up ? '<' : '>', $item->id())))
|
||||||
|
->orderBy('sort_order', $up ? 'desc' : 'asc')
|
||||||
|
->orderBy('id', $up ? 'desc' : 'asc')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
return $model === null ? null : $this->toEntity($model);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nextSortOrder(int $taskId): int
|
||||||
|
{
|
||||||
|
return (int) ChecklistItemModel::query()->where('task_id', $taskId)->max('sort_order') + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(ChecklistItem $item): ChecklistItem
|
||||||
|
{
|
||||||
|
$model = $item->id() === null ? new ChecklistItemModel : ChecklistItemModel::query()->findOrFail($item->id());
|
||||||
|
|
||||||
|
$model->fill([
|
||||||
|
'task_id' => $item->taskId(),
|
||||||
|
'text' => $item->text()->value,
|
||||||
|
'sort_order' => $item->sortOrder(),
|
||||||
|
'done_at' => $item->doneAt()?->format('Y-m-d H:i:s'),
|
||||||
|
'done_by' => $item->doneBy(),
|
||||||
|
])->save();
|
||||||
|
|
||||||
|
return $this->toEntity($model->refresh());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(ChecklistItem $item): void
|
||||||
|
{
|
||||||
|
ChecklistItemModel::query()->whereKey($item->id())->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function toEntity(ChecklistItemModel $model): ChecklistItem
|
||||||
|
{
|
||||||
|
return ChecklistItem::reconstitute(
|
||||||
|
$model->id,
|
||||||
|
$model->task_id,
|
||||||
|
new ChecklistItemText($model->text),
|
||||||
|
$model->sort_order,
|
||||||
|
$model->done_at === null ? null : DateTimeImmutable::createFromInterface($model->done_at),
|
||||||
|
$model->done_by,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Contracts\ChecklistQueries;
|
||||||
|
use App\Modules\Jobs\Application\DTOs\ChecklistItemSummary;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||||
|
|
||||||
|
class EloquentChecklistQueries implements ChecklistQueries
|
||||||
|
{
|
||||||
|
public function checklistOf(int $jobId, int $taskId): array
|
||||||
|
{
|
||||||
|
return ChecklistItemModel::query()
|
||||||
|
->where('task_id', $taskId)
|
||||||
|
->whereExists(fn ($query) => $query->selectRaw('1')->from('tasks')
|
||||||
|
->whereColumn('tasks.id', 'task_checklist_items.task_id')
|
||||||
|
->where('tasks.customer_job_id', $jobId))
|
||||||
|
->orderBy('sort_order')
|
||||||
|
->orderBy('id')
|
||||||
|
->get()
|
||||||
|
->map(fn (ChecklistItemModel $model): ChecklistItemSummary => new ChecklistItemSummary($model->id, $model->text, $model->done_at !== null))
|
||||||
|
->values()
|
||||||
|
->all();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,15 +4,19 @@ namespace App\Modules\Jobs\Infrastructure\Providers;
|
|||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
use App\Modules\Customers\Application\Contracts\CustomerRowUsage;
|
use App\Modules\Customers\Application\Contracts\CustomerRowUsage;
|
||||||
|
use App\Modules\Jobs\Application\Contracts\ChecklistQueries;
|
||||||
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
use App\Modules\Jobs\Application\Contracts\CustomerJobQueries;
|
||||||
use App\Modules\Jobs\Application\Contracts\TaskQueries;
|
use App\Modules\Jobs\Application\Contracts\TaskQueries;
|
||||||
use App\Modules\Jobs\Application\Contracts\TaskUsage;
|
use App\Modules\Jobs\Application\Contracts\TaskUsage;
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
||||||
use App\Modules\Jobs\Domain\Contracts\JobNumberSequence;
|
use App\Modules\Jobs\Domain\Contracts\JobNumberSequence;
|
||||||
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||||
use App\Modules\Jobs\Infrastructure\CustomerRowUsageFromJobs;
|
use App\Modules\Jobs\Infrastructure\CustomerRowUsageFromJobs;
|
||||||
use App\Modules\Jobs\Infrastructure\NothingUsesTasks;
|
use App\Modules\Jobs\Infrastructure\NothingUsesTasks;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\DatabaseJobNumberSequence;
|
use App\Modules\Jobs\Infrastructure\Persistence\DatabaseJobNumberSequence;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentChecklistQueries;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentCustomerJobQueries;
|
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentCustomerJobQueries;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentCustomerJobRepository;
|
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentCustomerJobRepository;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentTaskQueries;
|
use App\Modules\Jobs\Infrastructure\Persistence\Repositories\EloquentTaskQueries;
|
||||||
@@ -38,6 +42,8 @@ class JobsServiceProvider extends ServiceProvider
|
|||||||
CustomerRowUsage::class => CustomerRowUsageFromJobs::class,
|
CustomerRowUsage::class => CustomerRowUsageFromJobs::class,
|
||||||
TaskRepository::class => EloquentTaskRepository::class,
|
TaskRepository::class => EloquentTaskRepository::class,
|
||||||
TaskQueries::class => EloquentTaskQueries::class,
|
TaskQueries::class => EloquentTaskQueries::class,
|
||||||
|
ChecklistItemRepository::class => EloquentChecklistItemRepository::class,
|
||||||
|
ChecklistQueries::class => EloquentChecklistQueries::class,
|
||||||
// Replaced by the TimeTracking module, which knows which tasks have time entries.
|
// Replaced by the TimeTracking module, which knows which tasks have time entries.
|
||||||
TaskUsage::class => NothingUsesTasks::class,
|
TaskUsage::class => NothingUsesTasks::class,
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -356,6 +356,8 @@ new class extends Component
|
|||||||
<p class="whitespace-pre-line">{{ $task->description }}</p>
|
<p class="whitespace-pre-line">{{ $task->description }}</p>
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
|
<livewire:jobs::task-checklist :job-id="$job->id" :task-id="$task->id" :task-title="$task->title" :wire:key="'checklist-'.$task->id" />
|
||||||
|
|
||||||
<div class="flex flex-wrap items-end gap-3">
|
<div class="flex flex-wrap items-end gap-3">
|
||||||
@if ($canChangeStatus)
|
@if ($canChangeStatus)
|
||||||
<div class="w-full sm:w-56">
|
<div class="w-full sm:w-56">
|
||||||
|
|||||||
@@ -0,0 +1,364 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Contracts\ChecklistQueries;
|
||||||
|
use App\Modules\Jobs\Application\DTOs\ChecklistItemSummary;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\AddChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\CheckChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\MoveChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\RemoveChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\RenameChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
use Livewire\Attributes\Computed;
|
||||||
|
use Livewire\Attributes\Locked;
|
||||||
|
use Livewire\Component;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A task's checklist on the job page: checking items (also attached
|
||||||
|
* subcontractors) and adding, renaming, ordering and removing them.
|
||||||
|
*/
|
||||||
|
new class extends Component
|
||||||
|
{
|
||||||
|
#[Locked]
|
||||||
|
public int $jobId;
|
||||||
|
|
||||||
|
#[Locked]
|
||||||
|
public int $taskId;
|
||||||
|
|
||||||
|
#[Locked]
|
||||||
|
public string $taskTitle = '';
|
||||||
|
|
||||||
|
public string $newItem = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The item being renamed, if any.
|
||||||
|
*/
|
||||||
|
#[Locked]
|
||||||
|
public ?int $editingItemId = null;
|
||||||
|
|
||||||
|
public string $editingText = '';
|
||||||
|
|
||||||
|
public string $message = '';
|
||||||
|
|
||||||
|
public function mount(int $jobId, int $taskId, string $taskTitle): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.view-job', $jobId);
|
||||||
|
|
||||||
|
$this->jobId = $jobId;
|
||||||
|
$this->taskId = $taskId;
|
||||||
|
$this->taskTitle = $taskTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<ChecklistItemSummary>
|
||||||
|
*/
|
||||||
|
#[Computed]
|
||||||
|
public function items(): array
|
||||||
|
{
|
||||||
|
return app(ChecklistQueries::class)->checklistOf($this->jobId, $this->taskId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check(int $itemId, bool $done, CheckChecklistItem $checkItem): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.update-task-status', $this->jobId);
|
||||||
|
|
||||||
|
$item = $this->item($itemId);
|
||||||
|
|
||||||
|
if ($item === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$checkItem->execute($this->jobId, $this->taskId, $itemId, $done, (int) auth()->id());
|
||||||
|
} catch (TaskNotFound|ChecklistItemNotFound) {
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->refreshItems();
|
||||||
|
$this->message = __($done ? 'jobs.tasks.checklist.checked' : 'jobs.tasks.checklist.unchecked', ['text' => $item->text]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function add(AddChecklistItem $addItem): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||||
|
$this->resetErrorBag();
|
||||||
|
|
||||||
|
if (trim($this->newItem) === '') {
|
||||||
|
$this->addError('newItem', __('jobs.tasks.checklist.errors.text_required'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$addItem->execute($this->jobId, $this->taskId, $this->newItem);
|
||||||
|
} catch (InvalidChecklistItemText) {
|
||||||
|
$this->addError('newItem', __('jobs.tasks.checklist.errors.invalid_text'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (TaskNotFound) {
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->refreshItems();
|
||||||
|
$this->message = __('jobs.tasks.checklist.added', ['text' => trim($this->newItem)]);
|
||||||
|
$this->reset('newItem');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function startRename(int $itemId): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||||
|
|
||||||
|
$item = $this->item($itemId);
|
||||||
|
|
||||||
|
if ($item === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->editingItemId = $item->id;
|
||||||
|
$this->editingText = $item->text;
|
||||||
|
$this->resetErrorBag();
|
||||||
|
$this->js("document.getElementById('checklist-edit-{$item->id}')?.focus()");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function saveRename(RenameChecklistItem $renameItem): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||||
|
$this->resetErrorBag();
|
||||||
|
|
||||||
|
if ($this->editingItemId === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (trim($this->editingText) === '') {
|
||||||
|
$this->addError('editingText', __('jobs.tasks.checklist.errors.text_required'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$renameItem->execute($this->jobId, $this->taskId, $this->editingItemId, $this->editingText);
|
||||||
|
} catch (InvalidChecklistItemText) {
|
||||||
|
$this->addError('editingText', __('jobs.tasks.checklist.errors.invalid_text'));
|
||||||
|
|
||||||
|
return;
|
||||||
|
} catch (TaskNotFound|ChecklistItemNotFound) {
|
||||||
|
$this->cancelRename();
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->refreshItems();
|
||||||
|
$this->message = __('jobs.tasks.checklist.renamed', ['text' => trim($this->editingText)]);
|
||||||
|
$this->cancelRename();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function cancelRename(): void
|
||||||
|
{
|
||||||
|
$itemId = $this->editingItemId;
|
||||||
|
|
||||||
|
$this->reset('editingItemId', 'editingText');
|
||||||
|
$this->resetErrorBag();
|
||||||
|
|
||||||
|
if ($itemId !== null) {
|
||||||
|
$this->js("document.getElementById('checklist-rename-{$itemId}')?.focus()");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function move(int $itemId, string $direction, MoveChecklistItem $moveItem): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||||
|
|
||||||
|
$item = $this->item($itemId);
|
||||||
|
$moveDirection = MoveDirection::tryFrom($direction);
|
||||||
|
|
||||||
|
if ($item === null || $moveDirection === null) {
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$moved = $moveItem->execute($this->jobId, $this->taskId, $itemId, $moveDirection);
|
||||||
|
} catch (TaskNotFound|ChecklistItemNotFound) {
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->refreshItems();
|
||||||
|
$this->message = __(match (true) {
|
||||||
|
$moved && $moveDirection === MoveDirection::Up => 'jobs.tasks.checklist.moved_up',
|
||||||
|
$moved => 'jobs.tasks.checklist.moved_down',
|
||||||
|
$moveDirection === MoveDirection::Up => 'jobs.tasks.checklist.already_first',
|
||||||
|
default => 'jobs.tasks.checklist.already_last',
|
||||||
|
}, ['text' => $item->text]);
|
||||||
|
|
||||||
|
// The item moved in the DOM: keep focus on the same button.
|
||||||
|
$this->js("document.getElementById('checklist-move-{$moveDirection->value}-{$itemId}')?.focus()");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function remove(int $itemId, RemoveChecklistItem $removeItem): void
|
||||||
|
{
|
||||||
|
$this->authorize('jobs.manage-tasks', $this->jobId);
|
||||||
|
|
||||||
|
$item = $this->item($itemId);
|
||||||
|
|
||||||
|
if ($item === null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$removeItem->execute($this->jobId, $this->taskId, $itemId);
|
||||||
|
} catch (TaskNotFound|ChecklistItemNotFound) {
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->editingItemId === $itemId) {
|
||||||
|
$this->reset('editingItemId', 'editingText');
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->refreshItems();
|
||||||
|
$this->message = __('jobs.tasks.checklist.removed', ['text' => $item->text]);
|
||||||
|
|
||||||
|
// The removed item's buttons are gone: move focus to the field for a new item.
|
||||||
|
$this->js("document.getElementById('checklist-new-{$this->taskId}')?.focus()");
|
||||||
|
}
|
||||||
|
|
||||||
|
private function item(int $itemId): ?ChecklistItemSummary
|
||||||
|
{
|
||||||
|
foreach ($this->items as $item) {
|
||||||
|
if ($item->id === $itemId) {
|
||||||
|
return $item;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->notFound();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private function notFound(): void
|
||||||
|
{
|
||||||
|
$this->refreshItems();
|
||||||
|
$this->message = __('jobs.tasks.checklist.not_found');
|
||||||
|
}
|
||||||
|
|
||||||
|
private function refreshItems(): void
|
||||||
|
{
|
||||||
|
unset($this->items);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
?>
|
||||||
|
|
||||||
|
<section aria-labelledby="checklist-{{ $taskId }}-heading" 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)))
|
||||||
|
|
||||||
|
<h4 id="checklist-{{ $taskId }}-heading" class="font-medium">
|
||||||
|
{{ __('jobs.tasks.checklist.title') }}
|
||||||
|
@if ($this->items !== [])
|
||||||
|
<span class="font-normal">{{ __('jobs.tasks.checklist.progress', ['done' => $doneCount, 'total' => count($this->items)]) }}</span>
|
||||||
|
@endif
|
||||||
|
</h4>
|
||||||
|
|
||||||
|
<p role="status" aria-live="polite" class="text-sm">{{ $message }}</p>
|
||||||
|
|
||||||
|
@if ($this->items === [])
|
||||||
|
<p class="text-zinc-600 dark:text-zinc-300">{{ __('jobs.tasks.checklist.empty') }}</p>
|
||||||
|
@else
|
||||||
|
<ul class="space-y-2" aria-label="{{ __('jobs.tasks.checklist.list_of', ['title' => $taskTitle]) }}">
|
||||||
|
@foreach ($this->items as $item)
|
||||||
|
<li wire:key="checklist-item-{{ $item->id }}" class="flex flex-wrap items-center gap-x-3 gap-y-2">
|
||||||
|
@if ($editingItemId === $item->id)
|
||||||
|
<form wire:submit="saveRename" class="flex w-full flex-wrap items-end gap-2">
|
||||||
|
<div class="min-w-0 grow sm:max-w-md">
|
||||||
|
<x-input id="checklist-edit-{{ $item->id }}" wire:model="editingText" :label="__('jobs.tasks.checklist.text')" maxlength="255" />
|
||||||
|
</div>
|
||||||
|
<x-button submit sm icon="check" :text="__('jobs.tasks.checklist.save')" />
|
||||||
|
<x-button wire:click="cancelRename" subtle color="black" sm :text="__('jobs.tasks.checklist.cancel')" />
|
||||||
|
</form>
|
||||||
|
@else
|
||||||
|
@if ($canCheck)
|
||||||
|
<label class="inline-flex min-h-6 min-w-0 grow cursor-pointer items-start gap-2 break-words">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
id="checklist-item-{{ $item->id }}"
|
||||||
|
wire:change="check({{ $item->id }}, $event.target.checked)"
|
||||||
|
@checked($item->done)
|
||||||
|
class="mt-0.5 size-4 shrink-0 rounded border-zinc-400 text-primary-600 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:border-zinc-500 dark:bg-zinc-800"
|
||||||
|
/>
|
||||||
|
<span @class(['line-through' => $item->done])>{{ $item->text }}</span>
|
||||||
|
</label>
|
||||||
|
@else
|
||||||
|
<span class="min-w-0 grow break-words">
|
||||||
|
<span @class(['line-through' => $item->done])>{{ $item->text }}</span>
|
||||||
|
<span class="text-zinc-600 dark:text-zinc-300">({{ $item->done ? __('jobs.tasks.checklist.done') : __('jobs.tasks.checklist.not_done') }})</span>
|
||||||
|
</span>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($canManage)
|
||||||
|
<div class="flex flex-wrap items-center gap-2">
|
||||||
|
<x-button
|
||||||
|
id="checklist-rename-{{ $item->id }}"
|
||||||
|
wire:click="startRename({{ $item->id }})"
|
||||||
|
subtle
|
||||||
|
color="black"
|
||||||
|
sm
|
||||||
|
icon="pencil"
|
||||||
|
:text="__('jobs.edit')"
|
||||||
|
:aria-label="__('jobs.tasks.checklist.rename_named', ['text' => $item->text])"
|
||||||
|
/>
|
||||||
|
<x-button.circle
|
||||||
|
id="checklist-move-up-{{ $item->id }}"
|
||||||
|
wire:click="move({{ $item->id }}, 'up')"
|
||||||
|
subtle
|
||||||
|
color="black"
|
||||||
|
sm
|
||||||
|
icon="arrow-up"
|
||||||
|
:aria-label="__('jobs.tasks.checklist.move_up_named', ['text' => $item->text])"
|
||||||
|
/>
|
||||||
|
<x-button.circle
|
||||||
|
id="checklist-move-down-{{ $item->id }}"
|
||||||
|
wire:click="move({{ $item->id }}, 'down')"
|
||||||
|
subtle
|
||||||
|
color="black"
|
||||||
|
sm
|
||||||
|
icon="arrow-down"
|
||||||
|
:aria-label="__('jobs.tasks.checklist.move_down_named', ['text' => $item->text])"
|
||||||
|
/>
|
||||||
|
<x-button.circle
|
||||||
|
wire:click="remove({{ $item->id }})"
|
||||||
|
subtle
|
||||||
|
color="black"
|
||||||
|
sm
|
||||||
|
icon="trash"
|
||||||
|
:aria-label="__('jobs.tasks.checklist.remove_named', ['text' => $item->text])"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
@endif
|
||||||
|
</li>
|
||||||
|
@endforeach
|
||||||
|
</ul>
|
||||||
|
@endif
|
||||||
|
|
||||||
|
@if ($canManage)
|
||||||
|
<form wire:submit="add" class="flex flex-wrap items-end gap-2">
|
||||||
|
<div class="min-w-0 grow sm:max-w-md">
|
||||||
|
<x-input id="checklist-new-{{ $taskId }}" wire:model="newItem" :label="__('jobs.tasks.checklist.new_item')" maxlength="255" />
|
||||||
|
</div>
|
||||||
|
<x-button submit sm icon="plus" :text="__('jobs.tasks.checklist.add')" :aria-label="__('jobs.tasks.checklist.add_named', ['title' => $taskTitle])" />
|
||||||
|
</form>
|
||||||
|
@endif
|
||||||
|
</section>
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Checklist items (todo) of tasks, in their own order.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::create('task_checklist_items', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->foreignId('task_id')->constrained()->cascadeOnDelete();
|
||||||
|
$table->string('text');
|
||||||
|
$table->unsignedInteger('sort_order');
|
||||||
|
$table->timestamp('done_at')->nullable();
|
||||||
|
$table->foreignId('done_by')->nullable()->constrained('users')->nullOnDelete();
|
||||||
|
$table->timestamps();
|
||||||
|
|
||||||
|
$table->index(['task_id', 'sort_order']);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('task_checklist_items');
|
||||||
|
}
|
||||||
|
};
|
||||||
+9
-2
@@ -407,7 +407,7 @@ Tunnit kirjataan tehtäville, joten perustehtävät ja palveluyksiköiden työte
|
|||||||
Hinnasto ja tuotteet, rahakentät ja henkilökohtaiset näkyvyysoikeudet, kulut, tuntien hyväksyntä ja lukitus, laskuaineiston vienti Fennoaan (CSV/Excel), kuukausilaskutusrivit, pikamyynti.
|
Hinnasto ja tuotteet, rahakentät ja henkilökohtaiset näkyvyysoikeudet, kulut, tuntien hyväksyntä ja lukitus, laskuaineiston vienti Fennoaan (CSV/Excel), kuukausilaskutusrivit, pikamyynti.
|
||||||
|
|
||||||
**Vaihe 3 – tehtävien hallinta**
|
**Vaihe 3 – tehtävien hallinta**
|
||||||
Tehtävien Kanban-sarakkeet asetuksista palveluyksiköittäin, tarkistuslistat, kommentit, kuvat, työnkulkupohjat, kalenterinäkymä, kenttien yksinkertaistus palveluyksiköittäin.
|
Tehtävien Kanban-sarakkeet asetuksista palveluyksiköittäin, tarkistuslistat *(valmis)*, kommentit, kuvat, työnkulkupohjat, kalenterinäkymä, kenttien yksinkertaistus palveluyksiköittäin.
|
||||||
|
|
||||||
**Vaihe 4 – laajennukset**
|
**Vaihe 4 – laajennukset**
|
||||||
Alihankkijoiden näkymät ja rajaukset, raportit, ilmoitukset, Fennoa-rajapinta, PWA.
|
Alihankkijoiden näkymät ja rajaukset, raportit, ilmoitukset, Fennoa-rajapinta, PWA.
|
||||||
@@ -495,7 +495,14 @@ Jokainen sivu täyttää saavutettavuusvaatimukset ja saa selaintestin (vaalea/t
|
|||||||
- Luonnoksella on laskutuskuukausi (oletuksena kuluva kuukausi), johon asti kk-laskutuksen työt laskutetaan; kuukauden vaihto laskee esikatselun uudelleen (5.5).
|
- Luonnoksella on laskutuskuukausi (oletuksena kuluva kuukausi), johon asti kk-laskutuksen työt laskutetaan; kuukauden vaihto laskee esikatselun uudelleen (5.5).
|
||||||
- Muodostetun aineiston sivulla ja Laskutus-listalla on CSV-lataus (luku 12). Tulossa: sarakkeiden sovitus Fennoan tuontimuotoon (avoin kysymys 4).
|
- Muodostetun aineiston sivulla ja Laskutus-listalla on CSV-lataus (luku 12). Tulossa: sarakkeiden sovitus Fennoan tuontimuotoon (avoin kysymys 4).
|
||||||
|
|
||||||
## 18. Avoimet kysymykset
|
## 18. Vaiheen 3 tarkka sisältö
|
||||||
|
|
||||||
|
### 18.1 Tarkistuslistat *(valmis)*
|
||||||
|
- Työn sivulla jokaisen tehtävän kortissa on tarkistuslista edistymisineen ("1/3 tehty"). Kohdan kuittaa tehdyksi tai tekemättömäksi valintaruudulla (myös alihankkija liitettyjen töidensä tehtävissä); kuittaajan ja ajan tieto tallennetaan.
|
||||||
|
- Muut kuin alihankkijat lisäävät kohtia (1–255 merkkiä), muokkaavat niitä rivillä, järjestävät ne Siirrä ylös / Siirrä alas -painikkeilla ja poistavat ne. Kohdan poistoa ei vahvisteta dialogissa; muutokset ilmoitetaan ruudunlukijalle, ja fokus pysyy käytetyssä painikkeessa tai siirtyy lisäyskenttään.
|
||||||
|
- Kohdat poistuvat tehtävän mukana.
|
||||||
|
|
||||||
|
## 19. Avoimet kysymykset
|
||||||
|
|
||||||
1. ~~**Lukitus**~~: ratkaistu – vain johto avaa valmiin työn lukituksen siirtämällä työn aiempaan tilaan, ja avaus näkyy muutoshistoriassa (5.3).
|
1. ~~**Lukitus**~~: ratkaistu – vain johto avaa valmiin työn lukituksen siirtämällä työn aiempaan tilaan, ja avaus näkyy muutoshistoriassa (5.3).
|
||||||
2. **Alihankkijayritys**: onko yrityksellä useita käyttäjätunnuksia, ja tarvitaanko yritys omana tietonaan (nimi, Y-tunnus)?
|
2. **Alihankkijayritys**: onko yrityksellä useita käyttäjätunnuksia, ja tarvitaanko yritys omana tietonaan (nimi, Y-tunnus)?
|
||||||
|
|||||||
@@ -51,6 +51,38 @@ return [
|
|||||||
'in_review' => 'Tarkastettavana',
|
'in_review' => 'Tarkastettavana',
|
||||||
'done' => 'Valmis',
|
'done' => 'Valmis',
|
||||||
],
|
],
|
||||||
|
'checklist' => [
|
||||||
|
'title' => 'Tarkistuslista',
|
||||||
|
'progress' => '(:done/:total tehty)',
|
||||||
|
'list_of' => 'Tarkistuslista: :title',
|
||||||
|
'empty' => 'Ei kohtia.',
|
||||||
|
'done' => 'tehty',
|
||||||
|
'not_done' => 'ei tehty',
|
||||||
|
'new_item' => 'Uusi kohta',
|
||||||
|
'text' => 'Kohdan teksti',
|
||||||
|
'add' => 'Lisää kohta',
|
||||||
|
'add_named' => 'Lisää kohta tehtävälle :title',
|
||||||
|
'save' => 'Tallenna',
|
||||||
|
'cancel' => 'Peruuta',
|
||||||
|
'rename_named' => 'Muokkaa kohtaa :text',
|
||||||
|
'move_up_named' => 'Siirrä ylös: :text',
|
||||||
|
'move_down_named' => 'Siirrä alas: :text',
|
||||||
|
'remove_named' => 'Poista kohta :text',
|
||||||
|
'added' => 'Kohta :text lisätty.',
|
||||||
|
'renamed' => 'Kohta :text tallennettu.',
|
||||||
|
'removed' => 'Kohta :text poistettu.',
|
||||||
|
'checked' => 'Kohta :text merkitty tehdyksi.',
|
||||||
|
'unchecked' => 'Kohta :text merkitty tekemättömäksi.',
|
||||||
|
'moved_up' => 'Kohta :text siirretty ylöspäin.',
|
||||||
|
'moved_down' => 'Kohta :text siirretty alaspäin.',
|
||||||
|
'already_first' => 'Kohta :text on jo ensimmäisenä.',
|
||||||
|
'already_last' => 'Kohta :text on jo viimeisenä.',
|
||||||
|
'not_found' => 'Kohtaa ei löytynyt. Päivitä sivu.',
|
||||||
|
'errors' => [
|
||||||
|
'text_required' => 'Anna kohdan teksti.',
|
||||||
|
'invalid_text' => 'Kohdan teksti voi olla enintään 255 merkkiä.',
|
||||||
|
],
|
||||||
|
],
|
||||||
'errors' => [
|
'errors' => [
|
||||||
'title_required' => 'Anna tehtävän nimi.',
|
'title_required' => 'Anna tehtävän nimi.',
|
||||||
'invalid_title' => 'Nimen pituus voi olla enintään 255 merkkiä.',
|
'invalid_title' => 'Nimen pituus voi olla enintään 255 merkkiä.',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ use App\Models\User;
|
|||||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\ServiceUnitModel;
|
||||||
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||||
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
use App\Modules\Customers\Infrastructure\Persistence\Eloquent\CustomerModel;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
@@ -155,6 +156,8 @@ it('has no accessibility issues on a job with tasks and on the task form', funct
|
|||||||
$task = TaskModel::factory()
|
$task = TaskModel::factory()
|
||||||
->assignedTo([$this->user->id])
|
->assignedTo([$this->user->id])
|
||||||
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä', 'due_on' => now()->subDay()->toDateString(), 'estimated_hours' => 6]);
|
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä', 'due_on' => now()->subDay()->toDateString(), 'estimated_hours' => 6]);
|
||||||
|
ChecklistItemModel::query()->create(['task_id' => $task->id, 'text' => 'Valot', 'sort_order' => 1, 'done_at' => now(), 'done_by' => $this->user->id]);
|
||||||
|
ChecklistItemModel::query()->create(['task_id' => $task->id, 'text' => 'Mikit', 'sort_order' => 2]);
|
||||||
|
|
||||||
$url = match ($page) {
|
$url = match ($page) {
|
||||||
'job page' => route('jobs.show', $this->job->id),
|
'job page' => route('jobs.show', $this->job->id),
|
||||||
@@ -192,3 +195,37 @@ it('changes a task status and removes a task with the keyboard', function () {
|
|||||||
->assertSee('Tehtävä Kuvauspäivä poistettu.')
|
->assertSee('Tehtävä Kuvauspäivä poistettu.')
|
||||||
->assertScript('document.activeElement.id', 'tasks-heading');
|
->assertScript('document.activeElement.id', 'tasks-heading');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('adds, checks, renames, moves and removes checklist items with the keyboard', function () {
|
||||||
|
$this->job->update(['status' => 'order']);
|
||||||
|
$workType = WorkTypeModel::query()->where('name', 'videokuvaus')->sole();
|
||||||
|
$task = TaskModel::factory()
|
||||||
|
->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Kuvauspäivä']);
|
||||||
|
|
||||||
|
$page = visit(route('jobs.show', $this->job->id))
|
||||||
|
->type('#checklist-new-'.$task->id, 'Valot')
|
||||||
|
->keys('#checklist-new-'.$task->id, 'Enter')
|
||||||
|
->assertSee('Kohta Valot lisätty.')
|
||||||
|
->type('#checklist-new-'.$task->id, 'Mikit')
|
||||||
|
->keys('#checklist-new-'.$task->id, 'Enter')
|
||||||
|
->assertSee('Kohta Mikit lisätty.');
|
||||||
|
|
||||||
|
[$lights, $mics] = ChecklistItemModel::query()->orderBy('id')->pluck('id')->all();
|
||||||
|
|
||||||
|
$page->keys('#checklist-item-'.$lights, 'Space')
|
||||||
|
->assertSee('Kohta Valot merkitty tehdyksi.')
|
||||||
|
->assertSee('(1/2 tehty)')
|
||||||
|
->keys('#checklist-rename-'.$lights, 'Enter')
|
||||||
|
->assertScript('document.activeElement.id', 'checklist-edit-'.$lights)
|
||||||
|
->type('#checklist-edit-'.$lights, 'Valot ja jalustat')
|
||||||
|
->keys('#checklist-edit-'.$lights, 'Enter')
|
||||||
|
->assertSee('Kohta Valot ja jalustat tallennettu.')
|
||||||
|
->assertScript('document.activeElement.id', 'checklist-rename-'.$lights)
|
||||||
|
->keys('#checklist-move-up-'.$mics, 'Enter')
|
||||||
|
->assertSee('Kohta Mikit siirretty ylöspäin.')
|
||||||
|
->assertScript('document.activeElement.id', 'checklist-move-up-'.$mics)
|
||||||
|
->keys('[aria-label="Poista kohta Mikit"]', 'Enter')
|
||||||
|
->assertSee('Kohta Mikit poistettu.')
|
||||||
|
->assertScript('document.activeElement.id', 'checklist-new-'.$task->id)
|
||||||
|
->assertNoAccessibilityIssues(level: 2);
|
||||||
|
});
|
||||||
|
|||||||
@@ -0,0 +1,64 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Tests\Fakes;
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Domain\Contracts\ChecklistItemRepository;
|
||||||
|
use App\Modules\Jobs\Domain\Entities\ChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||||
|
|
||||||
|
class InMemoryChecklistItemRepository implements ChecklistItemRepository
|
||||||
|
{
|
||||||
|
/** @var array<int, ChecklistItem> */
|
||||||
|
public array $items = [];
|
||||||
|
|
||||||
|
private int $nextId = 1;
|
||||||
|
|
||||||
|
public function findForTask(int $taskId, int $itemId): ?ChecklistItem
|
||||||
|
{
|
||||||
|
$item = $this->items[$itemId] ?? null;
|
||||||
|
|
||||||
|
return $item !== null && $item->taskId() === $taskId ? clone $item : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function neighbour(ChecklistItem $item, MoveDirection $direction): ?ChecklistItem
|
||||||
|
{
|
||||||
|
$siblings = array_values(array_filter($this->items, fn (ChecklistItem $other): bool => $other->taskId() === $item->taskId()));
|
||||||
|
usort($siblings, fn (ChecklistItem $a, ChecklistItem $b): int => [$a->sortOrder(), $a->id()] <=> [$b->sortOrder(), $b->id()]);
|
||||||
|
$ids = array_map(fn (ChecklistItem $other): ?int => $other->id(), $siblings);
|
||||||
|
$index = array_search($item->id(), $ids, true);
|
||||||
|
$neighbour = $siblings[$direction === MoveDirection::Up ? $index - 1 : $index + 1] ?? null;
|
||||||
|
|
||||||
|
return $neighbour === null ? null : clone $neighbour;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function nextSortOrder(int $taskId): int
|
||||||
|
{
|
||||||
|
$orders = array_map(fn (ChecklistItem $item): int => $item->sortOrder(), array_filter($this->items, fn (ChecklistItem $item): bool => $item->taskId() === $taskId));
|
||||||
|
|
||||||
|
return ($orders === [] ? 0 : max($orders)) + 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save(ChecklistItem $item): ChecklistItem
|
||||||
|
{
|
||||||
|
$id = $item->id() ?? $this->nextId++;
|
||||||
|
$this->items[$id] = ChecklistItem::reconstitute($id, $item->taskId(), $item->text(), $item->sortOrder(), $item->doneAt(), $item->doneBy());
|
||||||
|
|
||||||
|
return clone $this->items[$id];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function delete(ChecklistItem $item): void
|
||||||
|
{
|
||||||
|
unset($this->items[$item->id()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
public function textsOf(int $taskId): array
|
||||||
|
{
|
||||||
|
$items = array_values(array_filter($this->items, fn (ChecklistItem $item): bool => $item->taskId() === $taskId));
|
||||||
|
usort($items, fn (ChecklistItem $a, ChecklistItem $b): int => [$a->sortOrder(), $a->id()] <=> [$b->sortOrder(), $b->id()]);
|
||||||
|
|
||||||
|
return array_map(fn (ChecklistItem $item): string => $item->text()->value, $items);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Models\User;
|
||||||
|
use App\Modules\Catalog\Infrastructure\Persistence\Eloquent\WorkTypeModel;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\ChecklistItemModel;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||||
|
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||||
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||||
|
use Livewire\Livewire;
|
||||||
|
|
||||||
|
uses(RefreshDatabase::class);
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->employee = User::factory()->create();
|
||||||
|
$this->actingAs($this->employee);
|
||||||
|
$this->job = CustomerJobModel::factory()->create(['status' => 'order', 'responsible_user_id' => $this->employee->id]);
|
||||||
|
$workType = WorkTypeModel::query()->where('name', 'graafinen työ')->sole();
|
||||||
|
$this->task = TaskModel::factory()->create(['customer_job_id' => $this->job->id, 'work_type_id' => $workType->id, 'title' => 'Mainoskuvat']);
|
||||||
|
$this->params = ['jobId' => $this->job->id, 'taskId' => $this->task->id, 'taskTitle' => 'Mainoskuvat'];
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return list<string>
|
||||||
|
*/
|
||||||
|
function checklistTexts(int $taskId): array
|
||||||
|
{
|
||||||
|
return ChecklistItemModel::query()->where('task_id', $taskId)->orderBy('sort_order')->orderBy('id')->pluck('text')->all();
|
||||||
|
}
|
||||||
|
|
||||||
|
it('shows the checklist with progress on the job page', function () {
|
||||||
|
ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Valot', 'sort_order' => 1, 'done_at' => now(), 'done_by' => $this->employee->id]);
|
||||||
|
ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Mikit', 'sort_order' => 2]);
|
||||||
|
|
||||||
|
$this->get(route('jobs.show', $this->job->id))
|
||||||
|
->assertOk()
|
||||||
|
->assertSee('Tarkistuslista')
|
||||||
|
->assertSee('(1/2 tehty)')
|
||||||
|
->assertSeeInOrder(['Valot', 'Mikit']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds, checks, renames, moves and removes checklist items', function () {
|
||||||
|
$component = Livewire::test('jobs::task-checklist', $this->params)
|
||||||
|
->set('newItem', ' Valot ')
|
||||||
|
->call('add')
|
||||||
|
->assertHasNoErrors()
|
||||||
|
->assertSet('newItem', '')
|
||||||
|
->assertSee('Kohta Valot lisätty.')
|
||||||
|
->set('newItem', 'Mikit')
|
||||||
|
->call('add');
|
||||||
|
|
||||||
|
[$lights, $mics] = ChecklistItemModel::query()->orderBy('id')->pluck('id')->all();
|
||||||
|
|
||||||
|
$component->call('check', $lights, true)
|
||||||
|
->assertSee('Kohta Valot merkitty tehdyksi.')
|
||||||
|
->assertSee('(1/2 tehty)');
|
||||||
|
|
||||||
|
expect(ChecklistItemModel::query()->find($lights)->done_by)->toBe($this->employee->id);
|
||||||
|
|
||||||
|
$component->call('startRename', $lights)
|
||||||
|
->assertSet('editingItemId', $lights)
|
||||||
|
->set('editingText', 'Valot ja jalustat')
|
||||||
|
->call('saveRename')
|
||||||
|
->assertSee('Kohta Valot ja jalustat tallennettu.')
|
||||||
|
->assertSet('editingItemId', null)
|
||||||
|
->call('move', $mics, 'up')
|
||||||
|
->assertSee('Kohta Mikit siirretty ylöspäin.')
|
||||||
|
->call('move', $mics, 'up')
|
||||||
|
->assertSee('Kohta Mikit on jo ensimmäisenä.');
|
||||||
|
|
||||||
|
expect(checklistTexts($this->task->id))->toBe(['Mikit', 'Valot ja jalustat']);
|
||||||
|
|
||||||
|
$component->call('remove', $mics)->assertSee('Kohta Mikit poistettu.');
|
||||||
|
|
||||||
|
expect(checklistTexts($this->task->id))->toBe(['Valot ja jalustat']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('shows Finnish errors for empty and too long items', function () {
|
||||||
|
Livewire::test('jobs::task-checklist', $this->params)
|
||||||
|
->call('add')
|
||||||
|
->assertHasErrors('newItem')
|
||||||
|
->assertSee('Anna kohdan teksti.')
|
||||||
|
->set('newItem', str_repeat('a', 256))
|
||||||
|
->call('add')
|
||||||
|
->assertSee('Kohdan teksti voi olla enintään 255 merkkiä.');
|
||||||
|
|
||||||
|
expect(ChecklistItemModel::query()->count())->toBe(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not change items of another task through this one', function () {
|
||||||
|
$other = ChecklistItemModel::query()->create(['task_id' => TaskModel::factory()->create()->id, 'text' => 'Vieras', 'sort_order' => 1]);
|
||||||
|
|
||||||
|
Livewire::test('jobs::task-checklist', $this->params)
|
||||||
|
->call('remove', $other->id)
|
||||||
|
->assertSee('Kohtaa ei löytynyt. Päivitä sivu.');
|
||||||
|
|
||||||
|
expect($other->fresh())->not->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('lets an attached subcontractor check items but not manage them', function () {
|
||||||
|
$item = ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Valot', 'sort_order' => 1]);
|
||||||
|
$subcontractor = User::factory()->subcontractor()->create();
|
||||||
|
TaskModel::factory()->assignedTo([$subcontractor->id])->create(['customer_job_id' => $this->job->id, 'work_type_id' => $this->task->work_type_id]);
|
||||||
|
$this->actingAs($subcontractor);
|
||||||
|
|
||||||
|
Livewire::test('jobs::task-checklist', $this->params)
|
||||||
|
->assertDontSee('Lisää kohta')
|
||||||
|
->call('check', $item->id, true)
|
||||||
|
->assertSee('Kohta Valot merkitty tehdyksi.')
|
||||||
|
->call('remove', $item->id)
|
||||||
|
->assertForbidden();
|
||||||
|
|
||||||
|
expect($item->fresh()->done_by)->toBe($subcontractor->id);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('forbids the checklist of a job the subcontractor is not attached to', function () {
|
||||||
|
$this->actingAs(User::factory()->subcontractor()->create());
|
||||||
|
|
||||||
|
Livewire::test('jobs::task-checklist', $this->params)->assertForbidden();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('removes the checklist with its task', function () {
|
||||||
|
ChecklistItemModel::query()->create(['task_id' => $this->task->id, 'text' => 'Valot', 'sort_order' => 1]);
|
||||||
|
|
||||||
|
$this->task->delete();
|
||||||
|
|
||||||
|
expect(ChecklistItemModel::query()->count())->toBe(0);
|
||||||
|
});
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use App\Modules\Jobs\Application\Services\ChecklistItemFinder;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\AddChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\CheckChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\MoveChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\RemoveChecklistItem;
|
||||||
|
use App\Modules\Jobs\Application\UseCases\RenameChecklistItem;
|
||||||
|
use App\Modules\Jobs\Domain\Entities\Task;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\MoveDirection;
|
||||||
|
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\ChecklistItemNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\InvalidChecklistItemText;
|
||||||
|
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||||
|
use App\Modules\Jobs\Domain\ValueObjects\ChecklistItemText;
|
||||||
|
use App\Modules\Jobs\Domain\ValueObjects\TaskTitle;
|
||||||
|
use Tests\Fakes\FakeClock;
|
||||||
|
use Tests\Fakes\FakeTransactionManager;
|
||||||
|
use Tests\Fakes\InMemoryChecklistItemRepository;
|
||||||
|
use Tests\Fakes\InMemoryTaskRepository;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$tasks = new InMemoryTaskRepository;
|
||||||
|
$this->items = new InMemoryChecklistItemRepository;
|
||||||
|
$transactions = new FakeTransactionManager;
|
||||||
|
$finder = new ChecklistItemFinder($tasks, $this->items);
|
||||||
|
|
||||||
|
$this->jobId = 5;
|
||||||
|
$this->taskId = (int) $tasks->save(Task::reconstitute(1, $this->jobId, 11, new TaskTitle('Kuvaus'), null, TaskStatus::Waiting, null, null, [], 10))->id();
|
||||||
|
|
||||||
|
$this->add = new AddChecklistItem($finder, $this->items, $transactions);
|
||||||
|
$this->rename = new RenameChecklistItem($finder, $this->items, $transactions);
|
||||||
|
$this->check = new CheckChecklistItem($finder, $this->items, $transactions, new FakeClock(new DateTimeImmutable('2026-11-24')));
|
||||||
|
$this->move = new MoveChecklistItem($finder, $this->items, $transactions);
|
||||||
|
$this->remove = new RemoveChecklistItem($finder, $this->items, $transactions);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('normalises checklist item text and rejects empty and too long text', function () {
|
||||||
|
expect((new ChecklistItemText(" Tarkista valot \n"))->value)->toBe('Tarkista valot')
|
||||||
|
->and(fn () => new ChecklistItemText(' '))->toThrow(InvalidChecklistItemText::class)
|
||||||
|
->and(fn () => new ChecklistItemText(str_repeat('a', 256)))->toThrow(InvalidChecklistItemText::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('adds items to the end of the task checklist', function () {
|
||||||
|
$this->add->execute($this->jobId, $this->taskId, 'Valot');
|
||||||
|
$this->add->execute($this->jobId, $this->taskId, 'Mikit');
|
||||||
|
|
||||||
|
expect($this->items->textsOf($this->taskId))->toBe(['Valot', 'Mikit']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('does not touch the checklist of a task through another job', function () {
|
||||||
|
$itemId = $this->add->execute($this->jobId, $this->taskId, 'Valot');
|
||||||
|
|
||||||
|
expect(fn () => $this->add->execute(99, $this->taskId, 'Mikit'))->toThrow(TaskNotFound::class)
|
||||||
|
->and(fn () => $this->remove->execute(99, $this->taskId, $itemId))->toThrow(TaskNotFound::class)
|
||||||
|
->and(fn () => $this->remove->execute($this->jobId, $this->taskId, 404))->toThrow(ChecklistItemNotFound::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('checks an item with who and when, keeps them on a second check and clears them on uncheck', function () {
|
||||||
|
$itemId = $this->add->execute($this->jobId, $this->taskId, 'Valot');
|
||||||
|
|
||||||
|
$this->check->execute($this->jobId, $this->taskId, $itemId, true, 10);
|
||||||
|
$this->check->execute($this->jobId, $this->taskId, $itemId, true, 12);
|
||||||
|
$item = $this->items->items[$itemId];
|
||||||
|
|
||||||
|
expect($item->isDone())->toBeTrue()
|
||||||
|
->and($item->doneBy())->toBe(10)
|
||||||
|
->and($item->doneAt()?->format('Y-m-d H:i'))->toBe('2026-11-24 12:00');
|
||||||
|
|
||||||
|
$this->check->execute($this->jobId, $this->taskId, $itemId, false, 10);
|
||||||
|
|
||||||
|
expect($this->items->items[$itemId]->isDone())->toBeFalse()
|
||||||
|
->and($this->items->items[$itemId]->doneBy())->toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renames, moves and removes items', function () {
|
||||||
|
$first = $this->add->execute($this->jobId, $this->taskId, 'Valot');
|
||||||
|
$second = $this->add->execute($this->jobId, $this->taskId, 'Mikit');
|
||||||
|
|
||||||
|
$this->rename->execute($this->jobId, $this->taskId, $first, 'Valot ja jalustat');
|
||||||
|
|
||||||
|
expect($this->move->execute($this->jobId, $this->taskId, $first, MoveDirection::Up))->toBeFalse()
|
||||||
|
->and($this->move->execute($this->jobId, $this->taskId, $second, MoveDirection::Down))->toBeFalse()
|
||||||
|
->and($this->move->execute($this->jobId, $this->taskId, $first, MoveDirection::Down))->toBeTrue()
|
||||||
|
->and($this->items->textsOf($this->taskId))->toBe(['Mikit', 'Valot ja jalustat']);
|
||||||
|
|
||||||
|
$this->remove->execute($this->jobId, $this->taskId, $second);
|
||||||
|
|
||||||
|
expect($this->items->textsOf($this->taskId))->toBe(['Valot ja jalustat']);
|
||||||
|
});
|
||||||
Reference in New Issue
Block a user