The console under console/ has its own session cookie and console guard (UseConsoleSession), so signing out or changing user there leaves the normal interface alone. Links open it in a new window through a one-time handoff key; a signed-out console asks for a PIN code or password on its own login page. Users set their 4-6 digit PIN on the profile's PIN page, and the console's change user dialog takes it on a keypad; five wrong PINs lock PIN sign-in for 15 minutes. Machine counters are cumulative: users record how much a job used and it is added to the latest reading. A maintenance record restarts the whole counter interval from the reading at the record. Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
140 lines
5.5 KiB
PHP
140 lines
5.5 KiB
PHP
<?php
|
|
|
|
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
|
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
|
use App\Modules\Machines\Application\DTOs\MachineSummary;
|
|
use Illuminate\Support\Facades\Gate;
|
|
use Livewire\Attributes\Computed;
|
|
use Livewire\Attributes\Url;
|
|
use Livewire\Component;
|
|
|
|
/**
|
|
* Machines grouped by service unit (spec 19.4), filtered by unit. Each
|
|
* machine links to its page with the work list.
|
|
*/
|
|
new class extends Component
|
|
{
|
|
#[Url(as: 'yksikko', except: '')]
|
|
public string $unit = '';
|
|
|
|
public bool $includeInactive = false;
|
|
|
|
public function mount(): void
|
|
{
|
|
$this->authorize('machines.use');
|
|
}
|
|
|
|
/**
|
|
* @return array<int, string> Service units that use stock or have machines.
|
|
*/
|
|
#[Computed]
|
|
public function units(): array
|
|
{
|
|
$ids = array_unique(array_merge(
|
|
app(CatalogQueries::class)->stockServiceUnitIds(),
|
|
...array_map(fn (MachineSummary $machine): array => $machine->serviceUnitIds, $this->machines),
|
|
));
|
|
|
|
return app(CatalogQueries::class)->serviceUnitNames(array_values($ids));
|
|
}
|
|
|
|
/**
|
|
* @return list<MachineSummary>
|
|
*/
|
|
#[Computed]
|
|
public function machines(): array
|
|
{
|
|
return app(MachineQueries::class)->machines($this->includeInactive && Gate::allows('machines.manage'));
|
|
}
|
|
|
|
/**
|
|
* Machines by unit name; a shared machine is under each of its units.
|
|
*
|
|
* @return array<string, list<MachineSummary>>
|
|
*/
|
|
public function grouped(): array
|
|
{
|
|
$groups = [];
|
|
|
|
foreach ($this->units as $unitId => $unitName) {
|
|
if ($this->unit !== '' && (int) $this->unit !== $unitId) {
|
|
continue;
|
|
}
|
|
|
|
$machines = array_values(array_filter($this->machines, fn (MachineSummary $machine): bool => in_array($unitId, $machine->serviceUnitIds, true)));
|
|
|
|
if ($machines !== []) {
|
|
$groups[$unitName] = $machines;
|
|
}
|
|
}
|
|
|
|
return $groups;
|
|
}
|
|
|
|
public function updated(): void
|
|
{
|
|
$this->authorize('machines.use');
|
|
unset($this->machines, $this->units);
|
|
}
|
|
|
|
public function render(): mixed
|
|
{
|
|
return $this->view()->title(__('machines.index.title'));
|
|
}
|
|
};
|
|
?>
|
|
|
|
<div class="mx-auto max-w-5xl space-y-6 p-4 sm:p-6">
|
|
<div class="space-y-2">
|
|
<h1 class="text-2xl font-semibold">{{ __('machines.index.title') }}</h1>
|
|
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('machines.index.intro') }}</p>
|
|
@can('machines.manage')
|
|
<p><x-button :href="route('machines.create')" wire:navigate icon="plus" :text="__('machines.index.new')" /></p>
|
|
@endcan
|
|
</div>
|
|
|
|
<div class="flex flex-wrap items-end gap-4">
|
|
<div class="w-full max-w-xs">
|
|
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
|
<x-select.native id="machine-unit" wire:model.live="unit" :label="__('machines.index.unit')" :aria-label="__('machines.index.unit')">
|
|
<option value="">{{ __('machines.index.all_units') }}</option>
|
|
@foreach ($this->units as $unitId => $unitName)
|
|
<option value="{{ $unitId }}">{{ $unitName }}</option>
|
|
@endforeach
|
|
</x-select.native>
|
|
</div>
|
|
@can('machines.manage')
|
|
<x-checkbox id="include-inactive-machines" wire:model.live="includeInactive" :label="__('machines.index.include_inactive')" />
|
|
@endcan
|
|
</div>
|
|
|
|
@forelse ($this->grouped() as $unitName => $machines)
|
|
<section wire:key="unit-{{ md5($unitName) }}" aria-label="{{ $unitName }}" class="space-y-2">
|
|
<h2 class="text-lg font-semibold">{{ $unitName }}</h2>
|
|
<ul class="divide-y divide-zinc-200 rounded-lg border border-zinc-300 dark:divide-zinc-700 dark:border-zinc-600">
|
|
@foreach ($machines as $machine)
|
|
<li wire:key="machine-{{ md5($unitName) }}-{{ $machine->id }}" class="flex flex-wrap items-center justify-between gap-3 p-3">
|
|
<div class="min-w-0 space-y-1">
|
|
<p class="font-medium break-words">
|
|
<x-link :href="route('machines.show', $machine->id)" navigate :aria-label="__('machines.index.open_named', ['name' => $machine->name])">{{ $machine->name }}</x-link>
|
|
</p>
|
|
<p class="text-sm text-zinc-700 dark:text-zinc-300">
|
|
{{ __('machines.types.'.$machine->type->value) }}
|
|
@if ($machine->responsibleName !== null)
|
|
· {{ __('machines.index.responsible', ['name' => $machine->responsibleName]) }}
|
|
@endif
|
|
@unless ($machine->isActive)
|
|
· {{ __('machines.index.inactive') }}
|
|
@endunless
|
|
</p>
|
|
</div>
|
|
<x-link :href="route('console.handoff', ['to' => route('machines.console', $machine->id)])" blank class="text-sm">{{ __('machines.index.console_named', ['name' => $machine->name]) }}<span class="sr-only"> ({{ __('layout.opens_in_new_window') }})</span></x-link>
|
|
</li>
|
|
@endforeach
|
|
</ul>
|
|
</section>
|
|
@empty
|
|
<p class="text-sm">{{ __('machines.index.none') }}</p>
|
|
@endforelse
|
|
</div>
|