Darken the dark canvas, add customer colours, the ongoing status and the board model
- Dark theme page background is #5a5e60; text on it is lifted to zinc-200 / primary-100 and TallStackUI's dark labels, hints and checkbox labels are lightened so everything stays at 4.5:1. - Shared HexColor picks white or black text by the higher WCAG contrast; a native-dialog colour picker and a large work dialog component. - Customers get a header colour (customers.header_color), set on the customer page. - New job status Jatkuvat / Kausi (ongoing): open, never late, billed monthly like running jobs. - Kanban model: board columns and views, urgent threshold, per-user board preferences (density, column colours and sort), card positions, tasks of continuing jobs pinned to the board, MoveBoardCard and board queries with logged hours from TimeTracking. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\Contracts;
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\BoardCard;
|
||||
use App\Modules\Jobs\Application\DTOs\BoardFilter;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\BoardPreferences;
|
||||
|
||||
/**
|
||||
* Read side of the Kanban board.
|
||||
*/
|
||||
interface JobBoardQueries
|
||||
{
|
||||
/**
|
||||
* Every card the filter lets through: open and done jobs (not archived,
|
||||
* not the yearly quick-sale job) with their tasks, and tasks of
|
||||
* continuing jobs pinned to the board as cards of their own.
|
||||
*
|
||||
* @param string $today Y-m-d, for late jobs
|
||||
* @return list<BoardCard>
|
||||
*/
|
||||
public function cards(BoardFilter $filter, string $today): array;
|
||||
|
||||
/**
|
||||
* The user's board settings, or the defaults.
|
||||
*/
|
||||
public function preferencesOf(int $userId): BoardPreferences;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\Contracts;
|
||||
|
||||
/**
|
||||
* Hours recorded on jobs and tasks, for the Kanban cards. The TimeTracking
|
||||
* module provides it; Jobs knows nothing about time entries.
|
||||
*/
|
||||
interface LoggedJobHours
|
||||
{
|
||||
/**
|
||||
* Recorded quarter-hours by job id (jobs without hours are left out).
|
||||
*
|
||||
* @param list<int> $jobIds
|
||||
* @return array<int, int>
|
||||
*/
|
||||
public function quartersByJobs(array $jobIds): array;
|
||||
|
||||
/**
|
||||
* Recorded quarter-hours by task id (tasks without hours are left out).
|
||||
*
|
||||
* @param list<int> $taskIds
|
||||
* @return array<int, int>
|
||||
*/
|
||||
public function quartersByTasks(array $taskIds): array;
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\DTOs;
|
||||
|
||||
use App\Modules\Jobs\Domain\Enums\JobKind;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
|
||||
/**
|
||||
* A card on the Kanban board: a customer job, or a task of a continuing
|
||||
* job that is pinned to the board as its own card ($taskId set).
|
||||
*/
|
||||
final readonly class BoardCard
|
||||
{
|
||||
/**
|
||||
* @param list<BoardTask> $tasks the job's tasks (empty on a task card)
|
||||
*/
|
||||
public function __construct(
|
||||
public int $jobId,
|
||||
public ?int $taskId,
|
||||
public string $number,
|
||||
public string $title,
|
||||
public string $jobName,
|
||||
public int $customerId,
|
||||
public string $customerName,
|
||||
public ?string $customerHeaderColor,
|
||||
public JobStatus $jobStatus,
|
||||
public ?TaskStatus $taskStatus,
|
||||
public Priority $priority,
|
||||
public JobKind $kind,
|
||||
public ?string $dueOn,
|
||||
public bool $isLate,
|
||||
public ?string $responsibleName,
|
||||
public ?string $serviceUnitName,
|
||||
public ?string $estimatedHours,
|
||||
public int $loggedQuarters,
|
||||
public int $boardPosition,
|
||||
public ?int $billerUserId,
|
||||
public array $tasks = [],
|
||||
) {}
|
||||
|
||||
public function isTaskCard(): bool
|
||||
{
|
||||
return $this->taskId !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stable key for wire:key and wire:sort:item: "job-12" or "task-34".
|
||||
*/
|
||||
public function key(): string
|
||||
{
|
||||
return $this->isTaskCard() ? 'task-'.$this->taskId : 'job-'.$this->jobId;
|
||||
}
|
||||
|
||||
public function isOngoing(): bool
|
||||
{
|
||||
return $this->jobStatus === JobStatus::Ongoing && ! $this->isTaskCard();
|
||||
}
|
||||
|
||||
public function doneTaskCount(): int
|
||||
{
|
||||
return count(array_filter($this->tasks, fn (BoardTask $task): bool => $task->isDone()));
|
||||
}
|
||||
|
||||
/**
|
||||
* The first open task of a continuing job ("Seuraava vuorossa").
|
||||
*/
|
||||
public function nextOpenTask(): ?BoardTask
|
||||
{
|
||||
foreach ($this->tasks as $task) {
|
||||
if (! $task->isDone()) {
|
||||
return $task;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function responsibleInitials(): string
|
||||
{
|
||||
if ($this->responsibleName === null || trim($this->responsibleName) === '') {
|
||||
return '?';
|
||||
}
|
||||
|
||||
$parts = preg_split('/\s+/', trim($this->responsibleName)) ?: [];
|
||||
$initials = '';
|
||||
|
||||
foreach (array_slice($parts, 0, 2) as $part) {
|
||||
$initials .= mb_strtoupper(mb_substr($part, 0, 1));
|
||||
}
|
||||
|
||||
return $initials;
|
||||
}
|
||||
|
||||
public function responsibleFirstName(): ?string
|
||||
{
|
||||
return $this->responsibleName === null ? null : explode(' ', trim($this->responsibleName))[0];
|
||||
}
|
||||
|
||||
public function loggedHours(): float
|
||||
{
|
||||
return $this->loggedQuarters / 4;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\DTOs;
|
||||
|
||||
/**
|
||||
* Whose cards the Kanban board shows (docs/ui-kanban-board.md 2): one
|
||||
* person's jobs (their own board or another person's), one service line,
|
||||
* or the whole company. Subcontractors are always limited to their jobs.
|
||||
*/
|
||||
final readonly class BoardFilter
|
||||
{
|
||||
public function __construct(
|
||||
/** Jobs this user is responsible for, a member of or does a task of. */
|
||||
public ?int $personUserId = null,
|
||||
public ?int $serviceUnitId = null,
|
||||
/** Restricts everything to jobs the user is a member of (subcontractors). */
|
||||
public ?int $onlyMemberUserId = null,
|
||||
public bool $onlyUrgent = false,
|
||||
public bool $onlyLate = false,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\DTOs;
|
||||
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
|
||||
/**
|
||||
* A task row in a Kanban card's task list.
|
||||
*/
|
||||
final readonly class BoardTask
|
||||
{
|
||||
public function __construct(
|
||||
public int $id,
|
||||
public string $title,
|
||||
public TaskStatus $status,
|
||||
public ?string $assigneeName,
|
||||
public bool $pinnedToBoard,
|
||||
public ?string $dueOn = null,
|
||||
) {}
|
||||
|
||||
public function isDone(): bool
|
||||
{
|
||||
return $this->status === TaskStatus::Done;
|
||||
}
|
||||
|
||||
public function assigneeFirstName(): ?string
|
||||
{
|
||||
return $this->assigneeName === null ? null : explode(' ', trim($this->assigneeName))[0];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\Services;
|
||||
|
||||
use App\Modules\Jobs\Application\DTOs\BoardCard;
|
||||
use App\Modules\Jobs\Domain\Enums\BoardColumn;
|
||||
use App\Modules\Jobs\Domain\Enums\BoardView;
|
||||
use App\Modules\Jobs\Domain\Enums\ColumnSort;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\BoardPreferences;
|
||||
|
||||
/**
|
||||
* Places Kanban cards in the columns of a view and orders each column
|
||||
* (docs/ui-kanban-board.md 3–4):
|
||||
*
|
||||
* - jobs in production go to the urgent column when their priority meets
|
||||
* the user's threshold, to the normal one otherwise;
|
||||
* - continuing jobs only ever stand in "Jatkuvat & Kausi";
|
||||
* - a pinned task stands in Jonossa, Työn alla or Valmis by its status;
|
||||
* - a manual column is in drag order, a due-date column has the earliest
|
||||
* due date on top and cards without one last.
|
||||
*/
|
||||
final class BoardLayout
|
||||
{
|
||||
/**
|
||||
* @param list<BoardCard> $cards
|
||||
* @return array<string, list<BoardCard>> by BoardColumn value, in the view's column order
|
||||
*/
|
||||
public function arrange(array $cards, BoardView $view, BoardPreferences $preferences): array
|
||||
{
|
||||
$columns = [];
|
||||
|
||||
foreach ($view->columns() as $column) {
|
||||
$columns[$column->value] = [];
|
||||
}
|
||||
|
||||
foreach ($cards as $card) {
|
||||
$column = $this->columnOf($card, $view, $preferences);
|
||||
|
||||
if ($column !== null && array_key_exists($column->value, $columns)) {
|
||||
$columns[$column->value][] = $card;
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($columns as $value => $columnCards) {
|
||||
$columns[$value] = $this->sorted($columnCards, $preferences->sortOf(BoardColumn::from($value)));
|
||||
}
|
||||
|
||||
return $columns;
|
||||
}
|
||||
|
||||
public function columnOf(BoardCard $card, BoardView $view, BoardPreferences $preferences): ?BoardColumn
|
||||
{
|
||||
if ($card->isTaskCard()) {
|
||||
return $card->taskStatus === null ? null : BoardColumn::forTask($card->taskStatus);
|
||||
}
|
||||
|
||||
if ($card->jobStatus === JobStatus::Ongoing) {
|
||||
return BoardColumn::Ongoing;
|
||||
}
|
||||
|
||||
return BoardColumn::forJob($card->jobStatus, $card->priority, $preferences->urgentThreshold, $view->gathersQuotes());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<BoardCard> $cards
|
||||
* @return list<BoardCard>
|
||||
*/
|
||||
private function sorted(array $cards, ColumnSort $sort): array
|
||||
{
|
||||
usort($cards, function (BoardCard $a, BoardCard $b) use ($sort): int {
|
||||
if ($sort === ColumnSort::DueDate) {
|
||||
$byDue = ($a->dueOn ?? '9999-12-31') <=> ($b->dueOn ?? '9999-12-31');
|
||||
|
||||
if ($byDue !== 0) {
|
||||
return $byDue;
|
||||
}
|
||||
}
|
||||
|
||||
return [$a->boardPosition, $a->isTaskCard() ? 1 : 0, $a->taskId ?? $a->jobId]
|
||||
<=> [$b->boardPosition, $b->isTaskCard() ? 1 : 0, $b->taskId ?? $b->jobId];
|
||||
});
|
||||
|
||||
return $cards;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Changes a job's priority (e.g. in the board's job editor) and records it.
|
||||
*/
|
||||
final class ChangeJobPriority
|
||||
{
|
||||
public function __construct(
|
||||
private CustomerJobRepository $jobs,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws CustomerJobNotFound
|
||||
*/
|
||||
public function execute(int $jobId, Priority $priority, int $actorUserId): void
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $priority, $actorUserId): void {
|
||||
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
||||
$changes = $job->changePriority($priority);
|
||||
|
||||
if ($changes === []) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->jobs->save($job);
|
||||
$this->jobs->recordChanges($jobId, $actorUserId, $changes);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\BoardRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||
use App\Modules\Jobs\Domain\Enums\BoardColumn;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\Priority;
|
||||
use App\Modules\Jobs\Domain\Enums\TaskStatus;
|
||||
use App\Modules\Jobs\Domain\Enums\UrgentThreshold;
|
||||
use App\Modules\Jobs\Domain\Events\TaskCompleted;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CardCannotMoveThere;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\EventDispatcher;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
|
||||
/**
|
||||
* A Kanban card dropped into a column (docs/ui-kanban-board.md 3):
|
||||
*
|
||||
* - a job dropped into another status's column gets that status;
|
||||
* - a job dropped into "Työn alla • Kiire" gets at least the threshold's
|
||||
* priority, and one dropped into the normal "Työn alla" with an urgent
|
||||
* priority gets the normal priority;
|
||||
* - a pinned task card gets the status of its new column;
|
||||
* - the column's cards get positions in the dropped order.
|
||||
*
|
||||
* Who may set a billing status or open a lock is checked by the caller.
|
||||
*/
|
||||
final class MoveBoardCard
|
||||
{
|
||||
public function __construct(
|
||||
private CustomerJobRepository $jobs,
|
||||
private TaskRepository $tasks,
|
||||
private BoardRepository $board,
|
||||
private TransactionManager $transactions,
|
||||
private EventDispatcher $events,
|
||||
private Clock $clock,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param list<string> $orderedKeys the target column's card keys ("job-12", "task-34") in their new order
|
||||
*
|
||||
* @throws CustomerJobNotFound
|
||||
* @throws TaskNotFound
|
||||
* @throws CardCannotMoveThere
|
||||
*/
|
||||
public function execute(int $jobId, ?int $taskId, BoardColumn $target, array $orderedKeys, UrgentThreshold $threshold, int $actorUserId): void
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $target, $orderedKeys, $threshold, $actorUserId): void {
|
||||
if ($taskId === null) {
|
||||
$this->moveJob($jobId, $target, $threshold, $actorUserId);
|
||||
} else {
|
||||
$this->moveTask($jobId, $taskId, $target);
|
||||
}
|
||||
|
||||
$this->reorder($orderedKeys);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* The status a job gets when dropped into the column: its own when the
|
||||
* column already holds it (e.g. moving between the quote statuses in
|
||||
* "Tarjoukset"), the column's otherwise.
|
||||
*/
|
||||
public static function statusAfterDrop(JobStatus $current, BoardColumn $target): JobStatus
|
||||
{
|
||||
return in_array($current, $target->statuses(), true) ? $current : $target->targetStatus();
|
||||
}
|
||||
|
||||
private function moveJob(int $jobId, BoardColumn $target, UrgentThreshold $threshold, int $actorUserId): void
|
||||
{
|
||||
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
||||
$current = $job->details()->status;
|
||||
|
||||
if (($current === JobStatus::Ongoing) !== $target->isOngoing()) {
|
||||
throw new CardCannotMoveThere;
|
||||
}
|
||||
|
||||
$changes = $job->changeStatus(self::statusAfterDrop($current, $target));
|
||||
$priority = $job->details()->priority;
|
||||
|
||||
if ($target->isUrgentLane() && ! $threshold->includes($priority)) {
|
||||
$changes = [...$changes, ...$job->changePriority($threshold->lowestPriority())];
|
||||
} elseif ($target->isNormalProductionLane() && $threshold->includes($priority)) {
|
||||
$changes = [...$changes, ...$job->changePriority(Priority::Normal)];
|
||||
}
|
||||
|
||||
$job->recordCompletion($this->clock->now());
|
||||
|
||||
if ($changes !== []) {
|
||||
$this->jobs->save($job);
|
||||
$this->jobs->recordChanges($jobId, $actorUserId, $changes);
|
||||
}
|
||||
}
|
||||
|
||||
private function moveTask(int $jobId, int $taskId, BoardColumn $target): void
|
||||
{
|
||||
$status = $target->taskStatus() ?? throw new CardCannotMoveThere;
|
||||
$task = $this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId);
|
||||
$wasDone = $task->status() === TaskStatus::Done;
|
||||
|
||||
if ($task->status() === $status || ($status === TaskStatus::InProgress && $task->status() === TaskStatus::InReview)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$task->changeStatus($status);
|
||||
$this->tasks->save($task);
|
||||
|
||||
if (! $wasDone && $status === TaskStatus::Done) {
|
||||
$this->events->dispatch(new TaskCompleted($taskId, $jobId));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<string> $orderedKeys
|
||||
*/
|
||||
private function reorder(array $orderedKeys): void
|
||||
{
|
||||
$jobPositions = [];
|
||||
$taskPositions = [];
|
||||
|
||||
foreach (array_values($orderedKeys) as $index => $key) {
|
||||
if (preg_match('/^(job|task)-(\d+)$/', $key, $matches) !== 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$position = ($index + 1) * 10;
|
||||
|
||||
if ($matches[1] === 'job') {
|
||||
$jobPositions[(int) $matches[2]] = $position;
|
||||
} else {
|
||||
$taskPositions[(int) $matches[2]] = $position;
|
||||
}
|
||||
}
|
||||
|
||||
$this->board->setJobPositions($jobPositions);
|
||||
$this->board->setTaskPositions($taskPositions);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\BoardRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\CustomerJobRepository;
|
||||
use App\Modules\Jobs\Domain\Contracts\TaskRepository;
|
||||
use App\Modules\Jobs\Domain\Enums\JobStatus;
|
||||
use App\Modules\Jobs\Domain\Exceptions\CustomerJobNotFound;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskCannotBePinned;
|
||||
use App\Modules\Jobs\Domain\Exceptions\TaskNotFound;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Lifts a task of a continuing job onto the Kanban board as a card of its
|
||||
* own ("Nosta putkeen"), or releases it back under the job's card.
|
||||
*/
|
||||
final class PinTaskToBoard
|
||||
{
|
||||
public function __construct(
|
||||
private CustomerJobRepository $jobs,
|
||||
private TaskRepository $tasks,
|
||||
private BoardRepository $board,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @throws CustomerJobNotFound
|
||||
* @throws TaskNotFound
|
||||
* @throws TaskCannotBePinned
|
||||
*/
|
||||
public function execute(int $jobId, int $taskId, bool $pinned): void
|
||||
{
|
||||
$this->transactions->run(function () use ($jobId, $taskId, $pinned): void {
|
||||
$job = $this->jobs->findById($jobId) ?? throw new CustomerJobNotFound($jobId);
|
||||
$this->tasks->findForJob($jobId, $taskId) ?? throw new TaskNotFound($jobId, $taskId);
|
||||
|
||||
if ($pinned && $job->details()->status !== JobStatus::Ongoing) {
|
||||
throw new TaskCannotBePinned;
|
||||
}
|
||||
|
||||
$this->board->setTaskPinned($taskId, $pinned);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Jobs\Application\UseCases;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\BoardRepository;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\BoardPreferences;
|
||||
use App\Modules\Shared\Application\Contracts\TransactionManager;
|
||||
|
||||
/**
|
||||
* Stores one user's Kanban settings. They never change anyone else's board.
|
||||
*/
|
||||
final class SaveBoardPreferences
|
||||
{
|
||||
public function __construct(
|
||||
private BoardRepository $board,
|
||||
private TransactionManager $transactions,
|
||||
) {}
|
||||
|
||||
public function execute(int $userId, BoardPreferences $preferences): void
|
||||
{
|
||||
$this->transactions->run(fn () => $this->board->savePreferences($userId, $preferences));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user