catalogQueries = $catalogQueries; } public function mount(): void { $this->authorize('catalog.manage'); } /** * @return list */ #[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; } }; ?>

{{ __('catalog.title') }}

{{ __('catalog.intro') }}

@if (session('status')) @endif

{{ $statusMessage }}

@foreach ($this->tree as $node) @php($unit = $node->serviceUnit)

{{ $unit->name }} @unless ($unit->isActive) ({{ __('catalog.inactive') }}) @endunless

@if ($unit->isShared)

{{ __('catalog.shared') }}

@endif @foreach ($node->services as $serviceNode) @php($service = $serviceNode->service)

{{ $service->name }} @unless ($service->isActive) ({{ __('catalog.inactive') }}) @endunless

@endforeach @if ($node->workTypes !== [] || $node->services === []) @endif
@unless ($unit->isShared) @endunless
@endforeach