Files
Toiminnanohjaus/app/Modules/Catalog/Presentation/Livewire/⚡index.blade.php
T
petriandClaude Opus 5.5 f4b58f6b1d 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]>
2026-11-30 06:11:49 +02:00

228 lines
8.5 KiB
PHP

<?php
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
use App\Modules\Catalog\Application\DTOs\ServiceUnitNode;
use App\Modules\Catalog\Application\UseCases\MoveCatalogItem;
use App\Modules\Catalog\Application\UseCases\SetCatalogItemActive;
use App\Modules\Catalog\Domain\Enums\CatalogLevel;
use App\Modules\Catalog\Domain\Enums\MoveDirection;
use App\Modules\Catalog\Domain\Exceptions\CatalogItemNotFound;
use Livewire\Attributes\Computed;
use Livewire\Component;
/**
* Catalog management (pohjatiedot): service units, services and work types.
*/
new class extends Component
{
public bool $showInactive = true;
public string $statusMessage = '';
protected CatalogQueries $catalogQueries;
public function boot(CatalogQueries $catalogQueries): void
{
$this->catalogQueries = $catalogQueries;
}
public function mount(): void
{
$this->authorize('catalog.manage');
}
/**
* @return list<ServiceUnitNode>
*/
#[Computed]
public function tree(): array
{
return $this->catalogQueries->tree($this->showInactive);
}
public function move(string $level, int $id, string $direction, MoveCatalogItem $moveItem): void
{
$this->authorize('catalog.manage');
$catalogLevel = CatalogLevel::from($level);
$moveDirection = MoveDirection::from($direction);
$name = $this->nameOf($catalogLevel, $id);
try {
$moved = $moveItem->execute($catalogLevel, $id, $moveDirection);
} catch (CatalogItemNotFound) {
$this->statusMessage = __('catalog.status.not_found');
return;
}
$this->statusMessage = __(match (true) {
$moved && $moveDirection === MoveDirection::Up => 'catalog.status.moved_up',
$moved => 'catalog.status.moved_down',
$moveDirection === MoveDirection::Up => 'catalog.status.already_first',
default => 'catalog.status.already_last',
}, ['name' => $name]);
// The row moved in the DOM: keep focus on the same button.
$this->js("document.getElementById('move-{$direction}-{$level}-{$id}')?.focus()");
}
public function toggleActive(string $level, int $id, SetCatalogItemActive $setActive): void
{
$this->authorize('catalog.manage');
$catalogLevel = CatalogLevel::from($level);
$active = ! $this->isActive($catalogLevel, $id);
try {
$setActive->execute($catalogLevel, $id, $active);
} catch (CatalogItemNotFound) {
$this->statusMessage = __('catalog.status.not_found');
return;
}
$this->statusMessage = __($active ? 'catalog.status.activated' : 'catalog.status.deactivated', [
'name' => $this->nameOf($catalogLevel, $id),
]);
}
public function render(): mixed
{
return $this->view()->title(__('catalog.title'));
}
private function nameOf(CatalogLevel $level, int $id): string
{
return match ($level) {
CatalogLevel::ServiceUnit => $this->catalogQueries->findServiceUnit($id)?->name,
CatalogLevel::Service => $this->catalogQueries->findService($id)?->name,
CatalogLevel::WorkType => $this->catalogQueries->findWorkType($id)?->name,
} ?? '';
}
private function isActive(CatalogLevel $level, int $id): bool
{
return match ($level) {
CatalogLevel::ServiceUnit => $this->catalogQueries->findServiceUnit($id)?->isActive,
CatalogLevel::Service => $this->catalogQueries->findService($id)?->isActive,
CatalogLevel::WorkType => $this->catalogQueries->findWorkType($id)?->isActive,
} ?? false;
}
};
?>
<div class="mx-auto max-w-5xl space-y-6 p-4 sm:p-6">
<div class="flex flex-wrap items-center justify-between gap-4">
<x-page-title icon="squares-plus">{{ __('catalog.title') }}</x-page-title>
<x-button :href="route('catalog.service-units.create')" wire:navigate icon="plus" :text="__('catalog.actions.add_service_unit')" />
</div>
<div class="space-y-1 text-sm">
<p class="text-zinc-600 dark:text-zinc-200">{{ __('catalog.intro') }}</p>
<p><x-link :href="route('catalog.prices')" navigate>{{ __('catalog.prices_link') }}</x-link></p>
<p><x-link :href="route('catalog.workflow-templates')" navigate>{{ __('catalog.workflows_link') }}</x-link></p>
</div>
@if (session('status'))
<x-alert role="status" color="green" light icon="check-circle" :text="session('status')" />
@endif
<x-checkbox id="show-inactive" wire:model.live="showInactive" :label="__('catalog.show_inactive')" />
<p role="status" aria-live="polite" class="text-sm">{{ $statusMessage }}</p>
@foreach ($this->tree as $node)
@php($unit = $node->serviceUnit)
<section
wire:key="service-unit-{{ $unit->id }}"
aria-labelledby="service-unit-{{ $unit->id }}-heading"
class="card space-y-4"
>
<div class="flex flex-wrap items-center justify-between gap-3">
<h2 id="service-unit-{{ $unit->id }}-heading" class="text-xl font-semibold break-words">
{{ $unit->name }}
@unless ($unit->isActive)
<span class="ml-2 text-sm font-normal">({{ __('catalog.inactive') }})</span>
@endunless
</h2>
<x-catalog.item-actions
level="service_unit"
:id="$unit->id"
:name="$unit->name"
:active="$unit->isActive"
:edit-url="route('catalog.service-units.edit', $unit->id)"
/>
</div>
@if ($unit->isShared)
<p class="text-sm text-zinc-600 dark:text-zinc-200">{{ __('catalog.shared') }}</p>
@endif
@if ($unit->usesStock)
<p class="flex items-center gap-1 text-sm text-zinc-600 dark:text-zinc-200">
<x-icon name="archive-box" class="size-4" aria-hidden="true" />
{{ __('catalog.service_units.uses_stock_on') }}
</p>
@endif
@foreach ($node->services as $serviceNode)
@php($service = $serviceNode->service)
<div wire:key="service-{{ $service->id }}" class="space-y-2 border-l-2 border-zinc-200 pl-4 dark:border-zinc-700">
<div class="flex flex-wrap items-center justify-between gap-3">
<h3 class="text-lg font-medium break-words">
{{ $service->name }}
@unless ($service->isActive)
<span class="ml-2 text-sm font-normal">({{ __('catalog.inactive') }})</span>
@endunless
</h3>
<x-catalog.item-actions
level="service"
:id="$service->id"
:name="$service->name"
:active="$service->isActive"
:edit-url="route('catalog.services.edit', $service->id)"
/>
</div>
<x-catalog.work-type-list :work-types="$serviceNode->workTypes" />
</div>
@endforeach
@if ($node->workTypes !== [] || $node->services === [])
<x-catalog.work-type-list :work-types="$node->workTypes" />
@endif
<div class="flex flex-wrap gap-2">
@unless ($unit->isShared)
<x-button
:href="route('catalog.services.create', $unit->id)"
wire:navigate
subtle
color="black"
sm
icon="plus"
:text="__('catalog.actions.add_service')"
:aria-label="__('catalog.actions.add_service_to', ['name' => $unit->name])"
/>
@endunless
<x-button
:href="route('catalog.work-types.create', $unit->id)"
wire:navigate
subtle
color="black"
sm
icon="plus"
:text="__('catalog.actions.add_work_type')"
:aria-label="__('catalog.actions.add_work_type_to', ['name' => $unit->name])"
/>
</div>
</section>
@endforeach
</div>