Give the machine console its own session with PIN sign-in, make counters cumulative

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]>
This commit is contained in:
2026-11-29 09:58:11 +02:00
co-authored by Claude Sonnet 5.5
parent 87e38260dc
commit 32c33e2a64
55 changed files with 1660 additions and 194 deletions
@@ -19,9 +19,11 @@ use Livewire\Component;
/**
* A machine's counters, maintenance items and maintenance history on its
* page (spec 19.5). Anyone using the machine records counter readings and
* maintenance done (the reading prefilled); management keeps the items
* and cancels mistaken records. The history is filtered by item and days.
* page (spec 19.5). Anyone using the machine records how much of a
* counter a job used (counters are cumulative) and maintenance done;
* management keeps the items and cancels mistaken records. The history is
* filtered by item and days. Without counters and maintenance items the
* sections are left out, except the add button for management.
*/
new class extends Component
{
@@ -31,17 +33,15 @@ new class extends Component
public int $machineId;
/**
* Readings typed, by counter id.
* Usage typed, by counter id.
*
* @var array<int, string>
*/
public array $readings = [];
public array $usage = [];
#[Locked]
public ?int $recordingItemId = null;
public string $recordReading = '';
public string $recordNote = '';
public string $historyItem = '';
@@ -100,37 +100,36 @@ new class extends Component
}
}
public function saveReading(int $counterId, MachineMaintenance $maintenance): void
public function saveUsage(int $counterId, MachineMaintenance $maintenance): void
{
$this->authorize('machines.use');
$this->resetErrorBag('readings.'.$counterId);
$this->resetErrorBag('usage.'.$counterId);
$counter = collect($this->machine->counters)->firstWhere('id', $counterId) ?? abort(404);
$usage = $this->usage[$counterId] ?? '';
try {
$milli = $maintenance->recordReading($counterId, $this->readings[$counterId] ?? '', (int) auth()->id());
$milli = $maintenance->recordUsage($counterId, $usage, (int) auth()->id());
} catch (InvalidReading) {
$this->addError('readings.'.$counterId, __('machines.maintenance.errors.reading'));
$this->addError('usage.'.$counterId, __('machines.maintenance.errors.usage'));
return;
} catch (CounterNotFound) {
abort(404);
}
$this->message = __('machines.maintenance.reading_saved', ['counter' => $counter->name, 'reading' => $this->reading($milli), 'unit' => __('machines.counter_units.'.$counter->unit->value)]);
unset($this->readings[$counterId], $this->machine, $this->items);
$this->message = $this->usageSaved($counter, $usage, $milli);
unset($this->usage[$counterId], $this->machine, $this->items);
}
public function startRecord(int $itemId): void
{
$this->authorize('machines.use');
$item = $this->item($itemId);
$this->recordingItemId = $itemId;
$this->recordReading = $item->readingMilli === null ? '' : str_replace("\u{00A0}", '', $this->reading($item->readingMilli));
$this->recordingItemId = $this->item($itemId)->id;
$this->recordNote = '';
$this->resetErrorBag();
$this->js("setTimeout(() => document.getElementById('record-reading')?.focus() ?? document.getElementById('record-note')?.focus())");
$this->js("setTimeout(() => document.getElementById('record-note')?.focus())");
}
public function cancelRecording(): void
@@ -147,11 +146,7 @@ new class extends Component
$item = $this->item((int) $this->recordingItemId);
try {
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id(), $item->counterId === null ? '' : $this->recordReading, $this->recordNote);
} catch (InvalidReading) {
$this->addError('recordReading', __('machines.maintenance.errors.reading'));
return;
$result = $maintenance->recordMaintenance($item->id, (int) auth()->id(), $this->recordNote);
} catch (MaintenanceItemNotFound) {
abort(404);
}
@@ -231,17 +226,17 @@ new class extends Component
@endif
</p>
</div>
<form wire:submit="saveReading({{ $counter->id }})" class="flex flex-wrap items-end gap-2" novalidate>
<form wire:submit="saveUsage({{ $counter->id }})" class="flex flex-wrap items-end gap-2" novalidate>
<div class="w-40">
<x-input
id="reading-{{ $counter->id }}"
wire:model="readings.{{ $counter->id }}"
id="usage-{{ $counter->id }}"
wire:model="usage.{{ $counter->id }}"
inputmode="decimal"
:label="__('machines.maintenance.new_reading', ['unit' => __('machines.counter_units.'.$counter->unit->value)])"
:label="__('machines.maintenance.usage', ['unit' => __('machines.counter_units.'.$counter->unit->value)])"
autocomplete="off"
/>
</div>
<x-button submit sm :text="__('machines.maintenance.save_reading')" :aria-label="__('machines.maintenance.save_reading_named', ['counter' => $counter->name])" />
<x-button submit sm :text="__('machines.maintenance.save_usage')" :aria-label="__('machines.maintenance.save_usage_named', ['counter' => $counter->name])" />
</form>
</li>
@endforeach
@@ -249,6 +244,9 @@ new class extends Component
</section>
@endif
@php($hasMaintenance = $this->machine->counters !== [] || $this->items !== [])
@if ($hasMaintenance || auth()->user()?->can('machines.manage'))
<section aria-labelledby="maintenance-heading" class="space-y-3">
<h2 id="maintenance-heading" class="text-xl font-semibold">{{ __('machines.maintenance.items') }}</h2>
@can('machines.manage')
@@ -292,11 +290,6 @@ new class extends Component
@if ($item->isActive)
@if ($recordingItemId === $item->id)
<form wire:submit="record" class="flex flex-wrap items-end gap-2" novalidate>
@if ($item->counterId !== null)
<div class="w-40">
<x-input id="record-reading" wire:model="recordReading" inputmode="decimal" :label="__('machines.maintenance.reading_at', ['counter' => (string) $item->counterName])" autocomplete="off" />
</div>
@endif
<div class="min-w-48 flex-1">
<x-input id="record-note" wire:model="recordNote" :label="__('machines.maintenance.note')" autocomplete="off" maxlength="2000" />
</div>
@@ -312,7 +305,9 @@ new class extends Component
</ul>
@endif
</section>
@endif
@if ($hasMaintenance)
<section aria-labelledby="history-heading" class="space-y-3">
<h2 id="history-heading" class="text-xl font-semibold">{{ __('machines.maintenance.history') }}</h2>
<div class="grid gap-3 sm:grid-cols-3">
@@ -358,6 +353,7 @@ new class extends Component
</ul>
@endif
</section>
@endif
@can('machines.manage')
<x-confirm-dialog id="cancel-record-dialog" :title="__('machines.maintenance.cancel_title')">