- Dark indigo header and tinted page background; the mobile main menu gets its own row, in the same order as the keyboard reaches it. - Page titles with an icon chip (x-page-title, x-page, x-page-header) and card sections (x-panel, the card utility); x-table styled as a card with an indigo header row in AppServiceProvider::styleTables(). - Job and task statuses, late work, unapproved hours and stock states as badges with icon and text (x-status-badge, x-jobs.status, x-jobs.task-status), never colour alone. - Empty lists as x-empty-state; dashboard quick link tiles, week hour bars and trend arrows; Kanban columns and task cards edged by status; calendar today column and bar accents; quick sale, reports and machine console restyled; signed-out pages show the app name. - Focus rings use the primary colour in both themes (white in the header). - Document the components in CLAUDE.md; test the status badges. Co-Authored-By: Claude Opus 5.5 <[email protected]>
213 lines
8.5 KiB
PHP
213 lines
8.5 KiB
PHP
<?php
|
|
|
|
use App\Modules\Inventory\Application\Contracts\StockQueries;
|
|
use App\Modules\Inventory\Application\DTOs\StockGroupSummary;
|
|
use App\Modules\Inventory\Application\UseCases\AddStockItemGroup;
|
|
use App\Modules\Inventory\Application\UseCases\ChangeStockItemGroup;
|
|
use App\Modules\Inventory\Domain\Exceptions\InvalidStockName;
|
|
use App\Modules\Inventory\Domain\Exceptions\StockItemGroupNotFound;
|
|
use App\Modules\Inventory\Domain\Exceptions\StockNameTaken;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Locked;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* Stock item groups (nimikeryhmät, spec 19.1): adding, renaming, ordering
|
|
* with Move up / Move down and taking out of use. Management only.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
public string $newName = '';
|
|
|
|
#[Locked]
|
|
public ?int $editingId = null;
|
|
|
|
public string $editingName = '';
|
|
|
|
#[Locked]
|
|
public string $message = '';
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->authorize('inventory.manage');
|
|
}
|
|
|
|
/**
|
|
* @return list<StockGroupSummary>
|
|
*/
|
|
#[Computed]
|
|
public function groups(): array
|
|
{
|
|
return app(StockQueries::class)->groups();
|
|
}
|
|
|
|
public function add(AddStockItemGroup $addGroup): void
|
|
{
|
|
$this->authorize('inventory.manage');
|
|
|
|
try {
|
|
$addGroup->execute($this->newName);
|
|
} catch (InvalidStockName) {
|
|
$this->addError('newName', __('inventory.errors.name'));
|
|
|
|
return;
|
|
} catch (StockNameTaken) {
|
|
$this->addError('newName', __('inventory.errors.name_taken'));
|
|
|
|
return;
|
|
}
|
|
|
|
$this->message = __('inventory.groups.added', ['name' => trim($this->newName)]);
|
|
$this->newName = '';
|
|
unset($this->groups);
|
|
$this->js("document.getElementById('new-group-name')?.focus()");
|
|
}
|
|
|
|
public function startRename(int $groupId): void
|
|
{
|
|
$this->authorize('inventory.manage');
|
|
|
|
$group = collect($this->groups)->firstWhere('id', $groupId) ?? abort(404);
|
|
$this->editingId = $group->id;
|
|
$this->editingName = $group->name;
|
|
$this->resetErrorBag();
|
|
$this->js("setTimeout(() => document.getElementById('rename-group')?.focus())");
|
|
}
|
|
|
|
public function cancelRename(): void
|
|
{
|
|
$id = $this->editingId;
|
|
$this->editingId = null;
|
|
$this->js("document.getElementById('rename-group-{$id}')?.focus()");
|
|
}
|
|
|
|
public function rename(ChangeStockItemGroup $change): void
|
|
{
|
|
$this->authorize('inventory.manage');
|
|
|
|
try {
|
|
$change->rename((int) $this->editingId, $this->editingName);
|
|
} catch (InvalidStockName) {
|
|
$this->addError('editingName', __('inventory.errors.name'));
|
|
|
|
return;
|
|
} catch (StockNameTaken) {
|
|
$this->addError('editingName', __('inventory.errors.name_taken'));
|
|
|
|
return;
|
|
} catch (StockItemGroupNotFound) {
|
|
$this->message = __('inventory.errors.not_found');
|
|
}
|
|
|
|
$id = $this->editingId;
|
|
$this->message = __('inventory.groups.renamed', ['name' => trim($this->editingName)]);
|
|
$this->editingId = null;
|
|
unset($this->groups);
|
|
$this->js("document.getElementById('rename-group-{$id}')?.focus()");
|
|
}
|
|
|
|
public function move(int $groupId, string $direction, ChangeStockItemGroup $change): void
|
|
{
|
|
$this->authorize('inventory.manage');
|
|
|
|
$group = collect($this->groups)->firstWhere('id', $groupId) ?? abort(404);
|
|
$up = $direction === 'up';
|
|
|
|
try {
|
|
$moved = $change->move($groupId, $up);
|
|
} catch (StockItemGroupNotFound) {
|
|
$this->message = __('inventory.errors.not_found');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->message = __('inventory.groups.'.($moved ? ($up ? 'moved_up' : 'moved_down') : ($up ? 'first' : 'last')), ['name' => $group->name]);
|
|
unset($this->groups);
|
|
}
|
|
|
|
public function toggleActive(int $groupId, ChangeStockItemGroup $change): void
|
|
{
|
|
$this->authorize('inventory.manage');
|
|
|
|
$group = collect($this->groups)->firstWhere('id', $groupId) ?? abort(404);
|
|
|
|
try {
|
|
$change->setActive($groupId, ! $group->isActive);
|
|
} catch (StockItemGroupNotFound) {
|
|
$this->message = __('inventory.errors.not_found');
|
|
|
|
return;
|
|
}
|
|
|
|
$this->message = __($group->isActive ? 'inventory.groups.deactivated' : 'inventory.groups.activated', ['name' => $group->name]);
|
|
unset($this->groups);
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('inventory.groups.title'));
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-3xl space-y-6 p-4 sm:p-6">
|
|
<div class="space-y-2">
|
|
<x-page-title icon="folder">{{ __('inventory.groups.title') }}</x-page-title>
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('inventory.groups.intro') }}</p>
|
|
<p class="text-sm"><x-link :href="route('inventory.index')" navigate>{{ __('inventory.groups.back') }}</x-link></p>
|
|
</div>
|
|
|
|
<p role="status" aria-live="polite" class="text-sm font-medium">{{ $message }}</p>
|
|
|
|
<form wire:submit="add" class="card flex flex-wrap items-end gap-3" novalidate>
|
|
<div class="min-w-0 flex-1">
|
|
<x-input id="new-group-name" wire:model="newName" :label="__('inventory.groups.name')" autocomplete="off" maxlength="150" />
|
|
</div>
|
|
<x-button submit icon="plus" :text="__('inventory.groups.add')" />
|
|
</form>
|
|
|
|
@if ($this->groups === [])
|
|
<x-empty-state icon="archive-box">{{ __('inventory.groups.none') }}</x-empty-state>
|
|
@else
|
|
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-300 dark:divide-zinc-700 dark:border-zinc-600">
|
|
@foreach ($this->groups as $group)
|
|
<li wire:key="group-{{ $group->id }}" class="flex flex-wrap items-center gap-3 p-3">
|
|
@if ($editingId === $group->id)
|
|
<form wire:submit="rename" class="flex w-full flex-wrap items-end gap-2" novalidate>
|
|
<div class="min-w-0 flex-1">
|
|
<x-input id="rename-group" wire:model="editingName" :label="__('inventory.groups.name')" autocomplete="off" maxlength="150" />
|
|
</div>
|
|
<x-button submit :text="__('inventory.groups.save')" />
|
|
<x-button wire:click="cancelRename" subtle color="black" :text="__('inventory.groups.cancel')" />
|
|
</form>
|
|
@else
|
|
<div class="min-w-0 flex-1">
|
|
<p class="font-medium break-words">{{ $group->name }}</p>
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-300">
|
|
{{ trans_choice('inventory.groups.items', $group->itemCount, ['count' => $group->itemCount]) }}
|
|
@unless ($group->isActive)
|
|
· {{ __('inventory.status.inactive') }}
|
|
@endunless
|
|
</p>
|
|
</div>
|
|
<div class="flex flex-wrap gap-1">
|
|
<x-button wire:click="move({{ $group->id }}, 'up')" subtle color="black" sm icon="arrow-up" :aria-label="__('inventory.groups.up_named', ['name' => $group->name])" />
|
|
<x-button wire:click="move({{ $group->id }}, 'down')" subtle color="black" sm icon="arrow-down" :aria-label="__('inventory.groups.down_named', ['name' => $group->name])" />
|
|
<x-button id="rename-group-{{ $group->id }}" wire:click="startRename({{ $group->id }})" subtle color="black" sm icon="pencil" :text="__('inventory.groups.rename')" :aria-label="__('inventory.groups.rename_named', ['name' => $group->name])" />
|
|
<x-button
|
|
wire:click="toggleActive({{ $group->id }})"
|
|
subtle
|
|
color="black"
|
|
sm
|
|
:icon="$group->isActive ? 'archive-box-x-mark' : 'archive-box-arrow-down'"
|
|
:text="$group->isActive ? __('inventory.groups.deactivate') : __('inventory.groups.activate')"
|
|
:aria-label="__($group->isActive ? 'inventory.groups.deactivate_named' : 'inventory.groups.activate_named', ['name' => $group->name])"
|
|
/>
|
|
</div>
|
|
@endif
|
|
</li>
|
|
@endforeach
|
|
</ul>
|
|
@endif
|
|
</div>
|