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:
@@ -31,6 +31,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property JobKind $kind
|
||||
* @property JobStatus $status
|
||||
* @property Priority $priority
|
||||
* @property int $board_position
|
||||
* @property PaymentBasis|null $payment_basis
|
||||
* @property string|null $estimated_hours
|
||||
* @property string|null $customer_reference
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Eloquent;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Attributes\Table;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* One user's Kanban board settings.
|
||||
*
|
||||
* @property int $id
|
||||
* @property int $user_id
|
||||
* @property string $density
|
||||
* @property string $urgent_threshold
|
||||
* @property array<string, string>|null $column_colors
|
||||
* @property array<string, string>|null $column_sorts
|
||||
*/
|
||||
#[Table('job_board_preferences')]
|
||||
#[Fillable(['user_id', 'density', 'urgent_threshold', 'column_colors', 'column_sorts'])]
|
||||
class JobBoardPreferenceModel extends Model
|
||||
{
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'user_id' => 'integer',
|
||||
'column_colors' => 'array',
|
||||
'column_sorts' => 'array',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,8 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property CarbonImmutable|null $planned_to
|
||||
* @property string|null $estimated_hours
|
||||
* @property int|null $assignee_user_id
|
||||
* @property bool $is_pinned_to_board
|
||||
* @property int $board_position
|
||||
* @property int $created_by
|
||||
*/
|
||||
#[Table('tasks')]
|
||||
@@ -50,6 +52,8 @@ class TaskModel extends Model
|
||||
'planned_from' => 'immutable_date',
|
||||
'planned_to' => 'immutable_date',
|
||||
'assignee_user_id' => 'integer',
|
||||
'is_pinned_to_board' => 'boolean',
|
||||
'board_position' => 'integer',
|
||||
'created_by' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Jobs\Domain\Contracts\BoardRepository;
|
||||
use App\Modules\Jobs\Domain\ValueObjects\BoardPreferences;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\JobBoardPreferenceModel;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Card order and pins are plain column updates: they are board state, not
|
||||
* job details, so they bypass the job entity and its change history.
|
||||
*/
|
||||
class EloquentBoardRepository implements BoardRepository
|
||||
{
|
||||
public function setJobPositions(array $positions): void
|
||||
{
|
||||
foreach ($positions as $jobId => $position) {
|
||||
DB::table('customer_jobs')->where('id', $jobId)->update(['board_position' => $position]);
|
||||
}
|
||||
}
|
||||
|
||||
public function setTaskPositions(array $positions): void
|
||||
{
|
||||
foreach ($positions as $taskId => $position) {
|
||||
DB::table('tasks')->where('id', $taskId)->update(['board_position' => $position]);
|
||||
}
|
||||
}
|
||||
|
||||
public function setTaskPinned(int $taskId, bool $pinned): void
|
||||
{
|
||||
DB::table('tasks')->where('id', $taskId)->update(['is_pinned_to_board' => $pinned]);
|
||||
}
|
||||
|
||||
public function preferencesOf(int $userId): BoardPreferences
|
||||
{
|
||||
$model = JobBoardPreferenceModel::query()->where('user_id', $userId)->first();
|
||||
|
||||
return $model === null
|
||||
? BoardPreferences::defaults()
|
||||
: BoardPreferences::fromStored($model->density, $model->urgent_threshold, $model->column_colors ?? [], $model->column_sorts ?? []);
|
||||
}
|
||||
|
||||
public function savePreferences(int $userId, BoardPreferences $preferences): void
|
||||
{
|
||||
JobBoardPreferenceModel::query()->updateOrCreate(['user_id' => $userId], [
|
||||
'density' => $preferences->density->value,
|
||||
'urgent_threshold' => $preferences->urgentThreshold->value,
|
||||
'column_colors' => $preferences->colorValues(),
|
||||
'column_sorts' => $preferences->sortValues(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -197,7 +197,7 @@ class EloquentCustomerJobQueries implements CustomerJobQueries
|
||||
{
|
||||
return array_values($this->billingInfo(CustomerJobModel::query()
|
||||
->where('payment_basis', PaymentBasis::MonthlyFee)
|
||||
->whereIn('status', [JobStatus::Order, JobStatus::InProduction, JobStatus::OnHold, JobStatus::Done])
|
||||
->whereIn('status', [JobStatus::Order, JobStatus::InProduction, JobStatus::OnHold, JobStatus::Done, JobStatus::Ongoing])
|
||||
->orderBy('number')
|
||||
->get()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,220 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Jobs\Infrastructure\Persistence\Repositories;
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Customers\Application\Contracts\CustomerQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\JobBoardQueries;
|
||||
use App\Modules\Jobs\Application\Contracts\LoggedJobHours;
|
||||
use App\Modules\Jobs\Application\DTOs\BoardCard;
|
||||
use App\Modules\Jobs\Application\DTOs\BoardFilter;
|
||||
use App\Modules\Jobs\Application\DTOs\BoardTask;
|
||||
use App\Modules\Jobs\Domain\Contracts\BoardRepository;
|
||||
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\ValueObjects\BoardPreferences;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\CustomerJobModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\Eloquent\TaskModel;
|
||||
use App\Modules\Jobs\Infrastructure\Persistence\JobInvolvement;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* Customer, user and service unit names and customer colours come from
|
||||
* those modules' query contracts; recorded hours from LoggedJobHours.
|
||||
*/
|
||||
class EloquentJobBoardQueries implements JobBoardQueries
|
||||
{
|
||||
public function __construct(
|
||||
private CustomerQueries $customers,
|
||||
private UserAccountQueries $users,
|
||||
private CatalogQueries $catalog,
|
||||
private LoggedJobHours $hours,
|
||||
private BoardRepository $board,
|
||||
) {}
|
||||
|
||||
public function cards(BoardFilter $filter, string $today): array
|
||||
{
|
||||
$jobs = $this->filteredJobs($filter, $today)->get();
|
||||
|
||||
if ($jobs->isEmpty()) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$jobIds = $jobs->pluck('id')->map(fn ($id): int => (int) $id)->all();
|
||||
$tasks = TaskModel::query()
|
||||
->whereIn('customer_job_id', $jobIds)
|
||||
->orderByRaw('status = ?', [TaskStatus::Done->value])
|
||||
->orderByRaw('due_on IS NULL')
|
||||
->orderBy('due_on')
|
||||
->orderBy('board_position')
|
||||
->orderBy('id')
|
||||
->get();
|
||||
|
||||
$customerIds = $jobs->pluck('customer_id')->unique()->values()->all();
|
||||
$customerNames = $this->customers->namesByIds($customerIds);
|
||||
$customerColors = $this->customers->headerColorsByIds($customerIds);
|
||||
$userNames = $this->users->namesByIds($jobs->pluck('responsible_user_id')
|
||||
->merge($tasks->pluck('assignee_user_id')->filter())
|
||||
->map(fn ($id): int => (int) $id)->unique()->values()->all());
|
||||
$jobQuarters = $this->hours->quartersByJobs($jobIds);
|
||||
$pinnedTasks = $tasks->filter(fn (TaskModel $task): bool => (bool) $task->is_pinned_to_board);
|
||||
$taskQuarters = $this->hours->quartersByTasks($pinnedTasks->pluck('id')->map(fn ($id): int => (int) $id)->values()->all());
|
||||
$serviceUnitNames = $this->firstServiceUnitNames($jobIds);
|
||||
$tasksByJob = $tasks->groupBy('customer_job_id');
|
||||
|
||||
$cards = [];
|
||||
|
||||
foreach ($jobs as $job) {
|
||||
$jobTasks = $tasksByJob->get($job->id) ?? collect();
|
||||
$common = [
|
||||
'customerName' => $customerNames[$job->customer_id] ?? '',
|
||||
'customerColor' => $customerColors[$job->customer_id] ?? null,
|
||||
'serviceUnit' => $serviceUnitNames[$job->id] ?? null,
|
||||
];
|
||||
|
||||
$cards[] = new BoardCard(
|
||||
jobId: $job->id,
|
||||
taskId: null,
|
||||
number: $job->number,
|
||||
title: $job->name,
|
||||
jobName: $job->name,
|
||||
customerId: $job->customer_id,
|
||||
customerName: $common['customerName'],
|
||||
customerHeaderColor: $common['customerColor'],
|
||||
jobStatus: $job->status,
|
||||
taskStatus: null,
|
||||
priority: $job->priority,
|
||||
kind: $job->kind,
|
||||
dueOn: $job->due_on?->format('Y-m-d'),
|
||||
isLate: $this->isLate($job->status, $job->due_on?->format('Y-m-d'), $today),
|
||||
responsibleName: $userNames[$job->responsible_user_id] ?? null,
|
||||
serviceUnitName: $common['serviceUnit'],
|
||||
estimatedHours: $this->hoursText($job->estimated_hours),
|
||||
loggedQuarters: $jobQuarters[$job->id] ?? 0,
|
||||
boardPosition: (int) $job->board_position,
|
||||
billerUserId: $job->biller_user_id,
|
||||
tasks: $jobTasks->map(fn (TaskModel $task): BoardTask => new BoardTask(
|
||||
$task->id,
|
||||
$task->title,
|
||||
$task->status,
|
||||
$task->assignee_user_id === null ? null : ($userNames[$task->assignee_user_id] ?? null),
|
||||
(bool) $task->is_pinned_to_board,
|
||||
$task->due_on?->format('Y-m-d'),
|
||||
))->values()->all(),
|
||||
);
|
||||
|
||||
if ($job->status !== JobStatus::Ongoing) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ($jobTasks as $task) {
|
||||
if (! $task->is_pinned_to_board) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$cards[] = new BoardCard(
|
||||
jobId: $job->id,
|
||||
taskId: $task->id,
|
||||
number: $job->number,
|
||||
title: $task->title,
|
||||
jobName: $job->name,
|
||||
customerId: $job->customer_id,
|
||||
customerName: $common['customerName'],
|
||||
customerHeaderColor: $common['customerColor'],
|
||||
jobStatus: $job->status,
|
||||
taskStatus: $task->status,
|
||||
priority: Priority::Normal,
|
||||
kind: $job->kind,
|
||||
dueOn: $task->due_on?->format('Y-m-d'),
|
||||
isLate: $task->status !== TaskStatus::Done && $task->due_on !== null && $task->due_on->format('Y-m-d') < $today,
|
||||
responsibleName: $task->assignee_user_id === null ? null : ($userNames[$task->assignee_user_id] ?? null),
|
||||
serviceUnitName: $common['serviceUnit'],
|
||||
estimatedHours: $this->hoursText($task->estimated_hours),
|
||||
loggedQuarters: $taskQuarters[$task->id] ?? 0,
|
||||
boardPosition: (int) $task->board_position,
|
||||
billerUserId: $job->biller_user_id,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $cards;
|
||||
}
|
||||
|
||||
public function preferencesOf(int $userId): BoardPreferences
|
||||
{
|
||||
return $this->board->preferencesOf($userId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder<CustomerJobModel>
|
||||
*/
|
||||
private function filteredJobs(BoardFilter $filter, string $today): Builder
|
||||
{
|
||||
$query = CustomerJobModel::query()
|
||||
->where('status', '!=', JobStatus::Archived->value)
|
||||
->whereNull('quick_sale_year');
|
||||
|
||||
foreach (array_filter([$filter->personUserId, $filter->onlyMemberUserId]) as $userId) {
|
||||
JobInvolvement::restrict($query, $userId);
|
||||
}
|
||||
|
||||
if ($filter->serviceUnitId !== null) {
|
||||
$query->whereIn('id', DB::table('customer_job_service_unit')->select('customer_job_id')->where('service_unit_id', $filter->serviceUnitId));
|
||||
}
|
||||
|
||||
if ($filter->onlyUrgent) {
|
||||
$query->whereIn('priority', [Priority::Urgent->value, Priority::Immediate->value]);
|
||||
}
|
||||
|
||||
if ($filter->onlyLate) {
|
||||
$query->whereNotNull('due_on')
|
||||
->where('due_on', '<', $today)
|
||||
->whereIn('status', array_map(
|
||||
fn (JobStatus $status): string => $status->value,
|
||||
array_values(array_filter(JobStatus::openStatuses(), fn (JobStatus $status): bool => $status !== JobStatus::Ongoing)),
|
||||
));
|
||||
}
|
||||
|
||||
return $query->orderBy('board_position')->orderBy('id');
|
||||
}
|
||||
|
||||
/**
|
||||
* A continuing job runs past its due date by nature, so it is never late.
|
||||
*/
|
||||
private function isLate(JobStatus $status, ?string $dueOn, string $today): bool
|
||||
{
|
||||
return $dueOn !== null && $dueOn < $today && $status->isOpen() && $status !== JobStatus::Ongoing;
|
||||
}
|
||||
|
||||
private function hoursText(?string $hours): ?string
|
||||
{
|
||||
return $hours === null ? null : rtrim(rtrim($hours, '0'), '.');
|
||||
}
|
||||
|
||||
/**
|
||||
* The first service unit's name of each job.
|
||||
*
|
||||
* @param list<int> $jobIds
|
||||
* @return array<int, string>
|
||||
*/
|
||||
private function firstServiceUnitNames(array $jobIds): array
|
||||
{
|
||||
/** @var Collection<int, object{customer_job_id: int, service_unit_id: int}> $rows */
|
||||
$rows = DB::table('customer_job_service_unit')
|
||||
->whereIn('customer_job_id', $jobIds)
|
||||
->orderBy('service_unit_id')
|
||||
->get(['customer_job_id', 'service_unit_id']);
|
||||
$names = $this->catalog->serviceUnitNames($rows->pluck('service_unit_id')->map(fn ($id): int => (int) $id)->unique()->values()->all());
|
||||
$first = [];
|
||||
|
||||
foreach ($rows as $row) {
|
||||
$first[(int) $row->customer_job_id] ??= $names[(int) $row->service_unit_id] ?? null;
|
||||
}
|
||||
|
||||
return array_filter($first, fn (?string $name): bool => $name !== null);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user