Add machines with day-by-day work lists for job tasks
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Machines\Presentation\Livewire\Concerns;
|
||||
|
||||
use Carbon\CarbonImmutable;
|
||||
|
||||
/**
|
||||
* Formatting shared by the machine pages and the machine console.
|
||||
*/
|
||||
trait FormatsMachines
|
||||
{
|
||||
/**
|
||||
* "24.11.2026" for "2026-11-24"; "24.11.2026 klo 14.05" for "2026-11-24 14:05".
|
||||
*/
|
||||
public function dateLabel(string $value): string
|
||||
{
|
||||
return strlen($value) > 10
|
||||
? CarbonImmutable::createFromFormat('Y-m-d H:i', $value)->format('j.n.Y \k\l\o H.i')
|
||||
: CarbonImmutable::createFromFormat('!Y-m-d', $value)->format('j.n.Y');
|
||||
}
|
||||
|
||||
/**
|
||||
* "ti 24.11." for "2026-11-24".
|
||||
*/
|
||||
public function shortDay(string $value): string
|
||||
{
|
||||
$date = CarbonImmutable::createFromFormat('!Y-m-d', $value)->locale(app()->getLocale());
|
||||
|
||||
return $date->isoFormat('dd').' '.$date->format('j.n.');
|
||||
}
|
||||
|
||||
public function quarters(int $quarters): string
|
||||
{
|
||||
return rtrim(rtrim(number_format($quarters / 4, 2, ',', ''), '0'), ',');
|
||||
}
|
||||
|
||||
/**
|
||||
* A counter reading in thousandths, e.g. "20 000" or "12,5".
|
||||
*/
|
||||
public function reading(int $milli): string
|
||||
{
|
||||
$whole = intdiv(abs($milli), 1000);
|
||||
$fraction = rtrim(str_pad((string) (abs($milli) % 1000), 3, '0', STR_PAD_LEFT), '0');
|
||||
|
||||
return ($milli < 0 ? '-' : '').number_format($whole, 0, ',', "\u{00A0}").($fraction === '' ? '' : ','.$fraction);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
||||
use App\Modules\Machines\Application\DTOs\MachineData;
|
||||
use App\Modules\Machines\Application\UseCases\SaveMachine;
|
||||
use App\Modules\Machines\Domain\Enums\CounterUnit;
|
||||
use App\Modules\Machines\Domain\Enums\MachineType;
|
||||
use App\Modules\Machines\Domain\Exceptions\InvalidCounter;
|
||||
use App\Modules\Machines\Domain\Exceptions\InvalidMachineName;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNameTaken;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNeedsServiceUnit;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNotFound;
|
||||
use App\Modules\Users\Application\Contracts\UserAccountQueries;
|
||||
use App\Modules\Users\Application\DTOs\UserOption;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* Add page (no {machine}) and edit page (with {machine}) of a machine
|
||||
* (management, spec 19.4–19.5): name, type, description, service units
|
||||
* among those that use stock, the responsible person and the counters.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
#[Locked]
|
||||
public ?int $machineId = null;
|
||||
|
||||
/**
|
||||
* Units the stored machine has, offered even after the setting is off.
|
||||
*
|
||||
* @var list<int>
|
||||
*/
|
||||
#[Locked]
|
||||
public array $storedUnitIds = [];
|
||||
|
||||
#[Locked]
|
||||
public bool $isActive = true;
|
||||
|
||||
public string $name = '';
|
||||
|
||||
public string $type = 'printer';
|
||||
|
||||
public string $description = '';
|
||||
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
public array $serviceUnitIds = [];
|
||||
|
||||
public string $responsibleUserId = '';
|
||||
|
||||
/**
|
||||
* @var list<array{key: int, id: ?int, name: string, unit: string}>
|
||||
*/
|
||||
public array $counters = [];
|
||||
|
||||
public int $nextKey = 1;
|
||||
|
||||
#[Locked]
|
||||
public string $message = '';
|
||||
|
||||
public function mount(MachineQueries $machines, ?int $machine = null): void
|
||||
{
|
||||
$this->authorize('machines.manage');
|
||||
|
||||
if ($machine === null) {
|
||||
$stockUnits = app(CatalogQueries::class)->stockServiceUnitIds();
|
||||
$this->serviceUnitIds = count($stockUnits) === 1 ? [(string) $stockUnits[0]] : [];
|
||||
$this->suggestCounters(announce: false);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$summary = $machines->findMachine($machine) ?? abort(404);
|
||||
|
||||
$this->machineId = $summary->id;
|
||||
$this->isActive = $summary->isActive;
|
||||
$this->name = $summary->name;
|
||||
$this->type = $summary->type->value;
|
||||
$this->description = (string) $summary->description;
|
||||
$this->serviceUnitIds = array_map('strval', $summary->serviceUnitIds);
|
||||
$this->storedUnitIds = $summary->serviceUnitIds;
|
||||
$this->responsibleUserId = (string) ($summary->responsibleUserId ?? '');
|
||||
|
||||
foreach ($summary->counters as $counter) {
|
||||
$this->counters[] = ['key' => $this->nextKey++, 'id' => $counter->id, 'name' => $counter->name, 'unit' => $counter->unit->value];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{value: int, label: string}>
|
||||
*/
|
||||
#[Computed]
|
||||
public function unitOptions(): array
|
||||
{
|
||||
$ids = array_values(array_unique(array_merge(app(CatalogQueries::class)->stockServiceUnitIds(), $this->storedUnitIds)));
|
||||
$options = [];
|
||||
|
||||
foreach (app(CatalogQueries::class)->serviceUnitNames($ids) as $id => $name) {
|
||||
$options[] = ['value' => $id, 'label' => $name];
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<UserOption>
|
||||
*/
|
||||
#[Computed]
|
||||
public function users(): array
|
||||
{
|
||||
return app(UserAccountQueries::class)->activeUserOptions();
|
||||
}
|
||||
|
||||
public function addCounter(): void
|
||||
{
|
||||
$this->authorize('machines.manage');
|
||||
|
||||
$key = $this->nextKey++;
|
||||
$this->counters[] = ['key' => $key, 'id' => null, 'name' => '', 'unit' => CounterUnit::Piece->value];
|
||||
$this->message = __('machines.form.counter_added', ['number' => count($this->counters)]);
|
||||
$this->js("document.getElementById('counter-{$key}-name')?.focus()");
|
||||
}
|
||||
|
||||
public function removeCounter(int $index): void
|
||||
{
|
||||
$this->authorize('machines.manage');
|
||||
|
||||
if (! isset($this->counters[$index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
array_splice($this->counters, $index, 1);
|
||||
$this->resetErrorBag();
|
||||
$this->message = __('machines.form.counter_removed', ['number' => $index + 1]);
|
||||
$this->js("document.getElementById('add-counter')?.focus()");
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the usual counters of the machine type that are not there yet.
|
||||
*/
|
||||
public function suggestCounters(bool $announce = true): void
|
||||
{
|
||||
$this->authorize('machines.manage');
|
||||
|
||||
$added = 0;
|
||||
$names = array_map(fn (array $counter): string => mb_strtolower($counter['name']), $this->counters);
|
||||
|
||||
foreach ((MachineType::tryFrom($this->type) ?? MachineType::Other)->suggestedCounters() as $suggestion) {
|
||||
$name = __('machines.counter_names.'.$suggestion['name']);
|
||||
|
||||
if (! in_array(mb_strtolower($name), $names, true)) {
|
||||
$this->counters[] = ['key' => $this->nextKey++, 'id' => null, 'name' => $name, 'unit' => $suggestion['unit']->value];
|
||||
$added++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($announce) {
|
||||
$this->message = trans_choice('machines.form.counters_suggested', $added, ['count' => $added]);
|
||||
}
|
||||
}
|
||||
|
||||
public function save(SaveMachine $saveMachine): void
|
||||
{
|
||||
$this->authorize('machines.manage');
|
||||
$this->resetErrorBag();
|
||||
|
||||
$this->validate([
|
||||
'type' => ['required', 'in:'.implode(',', array_column(MachineType::cases(), 'value'))],
|
||||
'description' => ['nullable', 'string', 'max:5000'],
|
||||
'serviceUnitIds' => ['array'],
|
||||
'serviceUnitIds.*' => ['integer'],
|
||||
'responsibleUserId' => ['nullable', 'integer'],
|
||||
'counters.*.unit' => ['required', 'in:'.implode(',', array_column(CounterUnit::cases(), 'value'))],
|
||||
]);
|
||||
|
||||
$data = new MachineData(
|
||||
$this->name,
|
||||
$this->type,
|
||||
$this->description,
|
||||
array_map('intval', $this->serviceUnitIds),
|
||||
$this->responsibleUserId === '' ? null : (int) $this->responsibleUserId,
|
||||
array_map(fn (array $counter): array => ['id' => $counter['id'], 'name' => $counter['name'], 'unit' => $counter['unit']], $this->counters),
|
||||
);
|
||||
|
||||
try {
|
||||
if ($this->machineId === null) {
|
||||
$this->machineId = $saveMachine->add($data);
|
||||
$status = __('machines.form.created', ['name' => trim($this->name)]);
|
||||
} else {
|
||||
$saveMachine->update($this->machineId, $data);
|
||||
$status = __('machines.form.updated', ['name' => trim($this->name)]);
|
||||
}
|
||||
} catch (InvalidMachineName) {
|
||||
$this->addError('name', __('machines.errors.name'));
|
||||
|
||||
return;
|
||||
} catch (MachineNameTaken) {
|
||||
$this->addError('name', __('machines.errors.name_taken'));
|
||||
|
||||
return;
|
||||
} catch (MachineNeedsServiceUnit) {
|
||||
$this->addError('serviceUnitIds', __('machines.errors.service_units'));
|
||||
|
||||
return;
|
||||
} catch (InvalidCounter) {
|
||||
$this->addError('counters', __('machines.errors.counter'));
|
||||
|
||||
return;
|
||||
} catch (MachineNotFound) {
|
||||
abort(404);
|
||||
}
|
||||
|
||||
session()->flash('status', $status);
|
||||
$this->redirectRoute('machines.show', $this->machineId, navigate: true);
|
||||
}
|
||||
|
||||
public function toggleActive(SaveMachine $saveMachine): void
|
||||
{
|
||||
$this->authorize('machines.manage');
|
||||
|
||||
if ($this->machineId === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$saveMachine->setActive($this->machineId, ! $this->isActive);
|
||||
$this->isActive = ! $this->isActive;
|
||||
$this->message = __($this->isActive ? 'machines.form.activated' : 'machines.form.deactivated');
|
||||
}
|
||||
|
||||
public function heading(): string
|
||||
{
|
||||
return __($this->machineId === null ? 'machines.form.create_title' : 'machines.form.edit_title');
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title($this->heading());
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="mx-auto max-w-2xl space-y-6 p-4 sm:p-6">
|
||||
<h1 class="text-2xl font-semibold">{{ $this->heading() }}</h1>
|
||||
|
||||
<p role="status" aria-live="polite" class="text-sm font-medium">{{ $message }}</p>
|
||||
|
||||
<form wire:submit="save" class="space-y-6" novalidate>
|
||||
<x-input id="machine-name" wire:model="name" :label="__('machines.form.name')" autocomplete="off" maxlength="150" required />
|
||||
|
||||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||||
<x-select.native id="machine-type" wire:model="type" :label="__('machines.form.type')" :aria-label="__('machines.form.type')">
|
||||
@foreach (MachineType::cases() as $option)
|
||||
<option value="{{ $option->value }}">{{ __('machines.types.'.$option->value) }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
<x-textarea id="machine-description" wire:model="description" :label="__('machines.form.description')" resize-auto />
|
||||
|
||||
@if ($this->unitOptions === [])
|
||||
<p class="text-sm font-medium">{{ __('machines.form.no_stock_units') }}</p>
|
||||
@else
|
||||
<x-checkbox-group :legend="__('machines.form.service_units')" model="serviceUnitIds" :options="$this->unitOptions" :hint="__('machines.form.service_units_hint')" />
|
||||
@endif
|
||||
|
||||
<x-select.native id="machine-responsible" wire:model="responsibleUserId" :label="__('machines.form.responsible')" :aria-label="__('machines.form.responsible')" :hint="__('machines.form.responsible_hint')">
|
||||
<option value="">{{ __('machines.form.no_responsible') }}</option>
|
||||
@foreach ($this->users as $user)
|
||||
<option value="{{ $user->id }}">{{ $user->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
|
||||
<fieldset class="space-y-3">
|
||||
<legend class="text-lg font-semibold">{{ __('machines.form.counters') }}</legend>
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('machines.form.counters_hint') }}</p>
|
||||
@error('counters')
|
||||
<p role="alert" class="text-sm text-red-700 dark:text-red-400">{{ $message }}</p>
|
||||
@enderror
|
||||
|
||||
@foreach ($counters as $index => $counter)
|
||||
<div wire:key="counter-{{ $counter['key'] }}" class="flex flex-wrap items-end gap-2">
|
||||
<div class="min-w-48 flex-1">
|
||||
<x-input
|
||||
id="counter-{{ $counter['key'] }}-name"
|
||||
wire:model="counters.{{ $index }}.name"
|
||||
:label="__('machines.form.counter_name')"
|
||||
autocomplete="off"
|
||||
maxlength="100"
|
||||
/>
|
||||
</div>
|
||||
<div class="w-32">
|
||||
<x-select.native
|
||||
id="counter-{{ $counter['key'] }}-unit"
|
||||
wire:model="counters.{{ $index }}.unit"
|
||||
:label="__('machines.form.counter_unit')"
|
||||
:aria-label="__('machines.form.counter_unit').': '.__('machines.form.counter_named', ['number' => $index + 1])"
|
||||
>
|
||||
@foreach (CounterUnit::cases() as $unit)
|
||||
<option value="{{ $unit->value }}">{{ __('machines.counter_units.'.$unit->value) }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
</div>
|
||||
<x-button wire:click="removeCounter({{ $index }})" subtle color="black" sm icon="trash" :aria-label="__('machines.form.remove_counter_named', ['number' => $index + 1])" />
|
||||
</div>
|
||||
@endforeach
|
||||
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<x-button id="add-counter" wire:click="addCounter" subtle color="black" sm icon="plus" :text="__('machines.form.add_counter')" />
|
||||
<x-button wire:click="suggestCounters" subtle color="black" sm icon="sparkles" :text="__('machines.form.suggest_counters')" />
|
||||
</div>
|
||||
</fieldset>
|
||||
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<x-button submit :text="__('machines.form.save')" />
|
||||
<x-button :href="$machineId === null ? route('machines.index') : route('machines.show', $machineId)" wire:navigate subtle color="black" :text="__('machines.form.cancel')" />
|
||||
@if ($machineId !== null)
|
||||
<x-button wire:click="toggleActive" subtle color="black" :icon="$isActive ? 'archive-box-x-mark' : 'archive-box-arrow-down'" :text="$isActive ? __('machines.form.deactivate') : __('machines.form.activate')" />
|
||||
@endif
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
@@ -0,0 +1,138 @@
|
||||
<?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>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</section>
|
||||
@empty
|
||||
<p class="text-sm">{{ __('machines.index.none') }}</p>
|
||||
@endforelse
|
||||
</div>
|
||||
@@ -0,0 +1,386 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
||||
use App\Modules\Machines\Application\DTOs\DayLoad;
|
||||
use App\Modules\Machines\Application\DTOs\MachineSummary;
|
||||
use App\Modules\Machines\Application\DTOs\QueueRow;
|
||||
use App\Modules\Machines\Application\UseCases\MachineWorkList;
|
||||
use App\Modules\Machines\Domain\Exceptions\InvalidPlannedDay;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineInactive;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNotForTask;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNotFound;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineTaskNotFound;
|
||||
use App\Modules\Machines\Domain\Exceptions\QueueEntryCompleted;
|
||||
use App\Modules\Machines\Domain\Exceptions\QueueEntryNotFound;
|
||||
use App\Modules\Machines\Presentation\Livewire\Concerns\FormatsMachines;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
use Carbon\CarbonImmutable;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* A machine's page (spec 19.4): its details and the planning view of its
|
||||
* day-by-day work list. The day is chosen with Previous / Today / Next or
|
||||
* a date, and the coming days show their rows and estimated hours. Rows
|
||||
* are moved up and down with buttons, and a task's row can be moved to
|
||||
* another day or machine, or taken off.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use FormatsMachines;
|
||||
|
||||
public const int LOAD_DAYS = 7;
|
||||
|
||||
#[Locked]
|
||||
public int $machineId;
|
||||
|
||||
#[Locked]
|
||||
#[Url(as: 'paiva', except: '')]
|
||||
public string $day = '';
|
||||
|
||||
public string $dayInput = '';
|
||||
|
||||
#[Locked]
|
||||
public ?int $editingEntryId = null;
|
||||
|
||||
public string $editMachineId = '';
|
||||
|
||||
public string $editDay = '';
|
||||
|
||||
#[Locked]
|
||||
public string $message = '';
|
||||
|
||||
public function mount(MachineQueries $machines, Clock $clock, int $machine): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$summary = $machines->findMachine($machine) ?? abort(404);
|
||||
$this->machineId = $summary->id;
|
||||
$this->day = $this->validDay($this->day) ?? $clock->today()->format('Y-m-d');
|
||||
$this->dayInput = $this->day;
|
||||
$this->message = (string) session('status', '');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function machine(): MachineSummary
|
||||
{
|
||||
return app(MachineQueries::class)->findMachine($this->machineId) ?? abort(404);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function today(): string
|
||||
{
|
||||
return app(Clock::class)->today()->format('Y-m-d');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<QueueRow>
|
||||
*/
|
||||
#[Computed]
|
||||
public function rows(): array
|
||||
{
|
||||
return app(MachineQueries::class)->rowsOn($this->machineId, $this->day, $this->today);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<DayLoad>
|
||||
*/
|
||||
#[Computed]
|
||||
public function load(): array
|
||||
{
|
||||
return app(MachineQueries::class)->load($this->machineId, $this->today, self::LOAD_DAYS);
|
||||
}
|
||||
|
||||
/**
|
||||
* Machines a row's task could move to.
|
||||
*
|
||||
* @return list<MachineSummary>
|
||||
*/
|
||||
public function machinesFor(QueueRow $row): array
|
||||
{
|
||||
return $row->task === null ? [] : app(MachineQueries::class)->machinesFor($row->task->allowedServiceUnitIds);
|
||||
}
|
||||
|
||||
public function showDay(string $which): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$current = CarbonImmutable::createFromFormat('!Y-m-d', $this->day);
|
||||
$this->day = match ($which) {
|
||||
'previous' => $current->subDay()->format('Y-m-d'),
|
||||
'next' => $current->addDay()->format('Y-m-d'),
|
||||
'chosen' => $this->validDay($this->dayInput) ?? $this->day,
|
||||
default => $this->today,
|
||||
};
|
||||
$this->dayInput = $this->day;
|
||||
$this->editingEntryId = null;
|
||||
$this->message = '';
|
||||
unset($this->rows);
|
||||
}
|
||||
|
||||
public function showDate(string $date): void
|
||||
{
|
||||
$this->dayInput = $date;
|
||||
$this->showDay('chosen');
|
||||
}
|
||||
|
||||
public function move(int $entryId, string $direction, MachineWorkList $workList): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$row = $this->row($entryId);
|
||||
$up = $direction === 'up';
|
||||
|
||||
try {
|
||||
$moved = $workList->move($entryId, $up);
|
||||
} catch (QueueEntryNotFound|QueueEntryCompleted) {
|
||||
$this->message = __('machines.errors.not_found');
|
||||
unset($this->rows);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$title = $this->rowTitle($row);
|
||||
$this->message = __('machines.show.'.($moved ? ($up ? 'moved_up' : 'moved_down') : ($up ? 'first' : 'last')), ['title' => $title]);
|
||||
unset($this->rows);
|
||||
$this->js("document.getElementById('row-{$entryId}-{$direction}')?.focus()");
|
||||
}
|
||||
|
||||
public function startEdit(int $entryId): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$row = $this->row($entryId);
|
||||
$this->editingEntryId = $entryId;
|
||||
$this->editMachineId = (string) $row->machineId;
|
||||
$this->editDay = $row->isLate ? $this->today : $row->plannedOn;
|
||||
$this->resetErrorBag();
|
||||
$this->js("setTimeout(() => document.getElementById('edit-day')?.focus())");
|
||||
}
|
||||
|
||||
public function cancelEdit(): void
|
||||
{
|
||||
$entryId = $this->editingEntryId;
|
||||
$this->editingEntryId = null;
|
||||
$this->js("document.getElementById('row-{$entryId}-edit')?.focus()");
|
||||
}
|
||||
|
||||
public function reschedule(MachineWorkList $workList): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$row = $this->row((int) $this->editingEntryId);
|
||||
abort_if($row->taskId === null, 404);
|
||||
|
||||
try {
|
||||
$workList->planTask($row->taskId, (int) $this->editMachineId, $this->editDay);
|
||||
} catch (InvalidPlannedDay) {
|
||||
$this->addError('editDay', __('machines.errors.day'));
|
||||
|
||||
return;
|
||||
} catch (MachineNotFound|MachineInactive|MachineNotForTask) {
|
||||
$this->addError('editMachineId', __('machines.errors.machine'));
|
||||
|
||||
return;
|
||||
} catch (MachineTaskNotFound) {
|
||||
$this->message = __('machines.errors.task_done');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$machine = app(MachineQueries::class)->findMachine((int) $this->editMachineId);
|
||||
$this->message = __('machines.task.moved', ['machine' => $machine->name ?? '', 'date' => $this->dateLabel($this->editDay)]);
|
||||
$this->editingEntryId = null;
|
||||
unset($this->rows, $this->load);
|
||||
$this->js("document.getElementById('work-list-status')?.focus()");
|
||||
}
|
||||
|
||||
public function remove(int $entryId, MachineWorkList $workList): void
|
||||
{
|
||||
$this->authorize('machines.use');
|
||||
|
||||
$row = $this->row($entryId);
|
||||
abort_if($row->taskId === null, 404);
|
||||
|
||||
$workList->removeTask($row->taskId);
|
||||
$this->message = __('machines.task.removed');
|
||||
unset($this->rows, $this->load);
|
||||
$this->js("document.getElementById('work-list-status')?.focus()");
|
||||
}
|
||||
|
||||
public function rowTitle(QueueRow $row): string
|
||||
{
|
||||
return $row->task === null ? __('machines.show.order') : $row->task->title;
|
||||
}
|
||||
|
||||
public function render(): mixed
|
||||
{
|
||||
return $this->view()->title($this->machine->name);
|
||||
}
|
||||
|
||||
private function row(int $entryId): QueueRow
|
||||
{
|
||||
return collect($this->rows)->firstWhere('entryId', $entryId) ?? abort(404);
|
||||
}
|
||||
|
||||
private function validDay(string $value): ?string
|
||||
{
|
||||
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $value) !== 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$date = CarbonImmutable::createFromFormat('!Y-m-d', $value);
|
||||
|
||||
return $date !== null && $date->format('Y-m-d') === $value ? $value : null;
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div class="mx-auto max-w-5xl space-y-6 p-4 sm:p-6">
|
||||
@php($machine = $this->machine)
|
||||
|
||||
<div class="space-y-2">
|
||||
<p class="text-sm"><x-link :href="route('machines.index')" navigate>{{ __('machines.show.back') }}</x-link></p>
|
||||
<h1 class="text-2xl font-semibold break-words">{{ $machine->name }}</h1>
|
||||
<p class="text-sm">
|
||||
{{ __('machines.types.'.$machine->type->value) }}
|
||||
· {{ __('machines.show.units', ['units' => implode(', ', $machine->serviceUnitNames)]) }}
|
||||
@if ($machine->responsibleName !== null)
|
||||
· {{ __('machines.index.responsible', ['name' => $machine->responsibleName]) }}
|
||||
@endif
|
||||
@unless ($machine->isActive)
|
||||
· {{ __('machines.index.inactive') }}
|
||||
@endunless
|
||||
</p>
|
||||
@if ($machine->description !== null)
|
||||
<p class="text-sm whitespace-pre-line">{{ $machine->description }}</p>
|
||||
@endif
|
||||
@can('machines.manage')
|
||||
<p><x-button :href="route('machines.edit', $machine->id)" wire:navigate sm icon="pencil" :text="__('machines.show.edit')" /></p>
|
||||
@endcan
|
||||
</div>
|
||||
|
||||
<p id="work-list-status" tabindex="-1" role="status" aria-live="polite" class="text-sm font-medium focus:outline-none">{{ $message }}</p>
|
||||
|
||||
<section aria-labelledby="work-list-heading" class="space-y-4">
|
||||
<h2 id="work-list-heading" class="text-xl font-semibold">{{ __('machines.show.work_list') }}</h2>
|
||||
|
||||
<nav aria-label="{{ __('machines.show.day_navigation') }}" class="flex flex-wrap items-end gap-2">
|
||||
<x-button wire:click="showDay('previous')" subtle color="black" sm icon="chevron-left" :text="__('machines.show.previous_day')" />
|
||||
<x-button wire:click="showDay('today')" subtle color="black" sm :text="__('machines.show.today')" />
|
||||
<x-button wire:click="showDay('next')" subtle color="black" sm icon="chevron-right" position="right" :text="__('machines.show.next_day')" />
|
||||
<form wire:submit="showDay('chosen')" class="flex flex-wrap items-end gap-2">
|
||||
<x-input id="work-list-day" wire:model="dayInput" type="date" :label="__('machines.show.day_field')" />
|
||||
<x-button submit subtle color="black" sm :text="__('machines.show.show_day')" />
|
||||
</form>
|
||||
</nav>
|
||||
|
||||
<div class="space-y-1">
|
||||
<h3 class="font-semibold">{{ __('machines.show.load') }}</h3>
|
||||
<ul class="flex flex-wrap gap-2 text-sm">
|
||||
@foreach ($this->load as $dayLoad)
|
||||
<li wire:key="load-{{ $dayLoad->day }}">
|
||||
<button
|
||||
type="button"
|
||||
wire:click="showDate('{{ $dayLoad->day }}')"
|
||||
class="rounded-md border border-zinc-300 px-2 py-1 hover:bg-zinc-100 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-blue-700 dark:border-zinc-600 dark:hover:bg-zinc-700 @if ($dayLoad->day === $day) font-semibold @endif"
|
||||
@if ($dayLoad->day === $day) aria-current="date" @endif
|
||||
>
|
||||
{{ __('machines.show.load_row', ['date' => $this->shortDay($dayLoad->day), 'rows' => trans_choice('machines.show.rows', $dayLoad->rows, ['count' => $dayLoad->rows]), 'hours' => $this->quarters($dayLoad->estimatedQuarters)]) }}
|
||||
</button>
|
||||
</li>
|
||||
@endforeach
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<h3 class="text-lg font-semibold" aria-live="polite">{{ __('machines.show.day_heading', ['date' => $this->dateLabel($day)]) }}</h3>
|
||||
<p class="text-sm">{{ trans_choice('machines.show.row_count', count($this->rows), ['count' => count($this->rows)]) }}</p>
|
||||
|
||||
@if ($this->rows === [])
|
||||
<p class="text-sm">{{ __('machines.show.none') }}</p>
|
||||
@else
|
||||
<ol class="space-y-3">
|
||||
@foreach ($this->rows as $row)
|
||||
@php($task = $row->task)
|
||||
<li wire:key="row-{{ $row->entryId }}" class="space-y-2 rounded-lg border border-zinc-300 p-3 dark:border-zinc-600">
|
||||
<div class="flex flex-wrap items-start justify-between gap-2">
|
||||
<div class="min-w-0 space-y-1">
|
||||
<p class="font-medium break-words">{{ $this->rowTitle($row) }}</p>
|
||||
@if ($task !== null)
|
||||
<p class="text-sm">{{ $task->jobNumber }} {{ $task->jobName }} · {{ $task->customerName }}</p>
|
||||
<p class="flex flex-wrap gap-x-3 gap-y-1 text-sm text-zinc-700 dark:text-zinc-300">
|
||||
@if ($task->dueOn !== null)
|
||||
<span>{{ __('machines.show.due', ['date' => $this->dateLabel($task->dueOn)]) }}</span>
|
||||
@endif
|
||||
<span>{{ __('machines.show.priority', ['priority' => __('jobs.priorities.'.$task->priority)]) }}</span>
|
||||
<span>{{ __('machines.show.status', ['status' => __('jobs.tasks.statuses.'.$task->status)]) }}</span>
|
||||
</p>
|
||||
@endif
|
||||
@if ($row->isLate)
|
||||
<p class="flex items-center gap-1 text-sm font-medium text-red-700 dark:text-red-400">
|
||||
<x-icon name="exclamation-triangle" class="size-4" aria-hidden="true" />
|
||||
{{ __('machines.show.late', ['date' => CarbonImmutable::parse($row->plannedOn)->format('j.n.')]) }}
|
||||
</p>
|
||||
@endif
|
||||
@if ($task !== null && $task->isOutsidePlan($row->isLate ? $this->today : $row->plannedOn))
|
||||
<p class="flex items-center gap-1 text-sm">
|
||||
<x-icon name="information-circle" class="size-4" aria-hidden="true" />
|
||||
{{ __('machines.show.outside_plan') }}
|
||||
</p>
|
||||
@endif
|
||||
</div>
|
||||
@if ($task !== null)
|
||||
<x-link :href="route('jobs.show', $task->jobId).'#task-'.$task->taskId" navigate class="text-sm">{{ __('machines.show.open_task') }}</x-link>
|
||||
@endif
|
||||
</div>
|
||||
|
||||
@if ($task !== null && ($task->instructions !== null || $task->description !== null))
|
||||
<div class="space-y-1 text-sm">
|
||||
@if ($task->instructions !== null)
|
||||
<details>
|
||||
<summary class="cursor-pointer font-medium">{{ __('machines.show.instructions') }}</summary>
|
||||
<p class="mt-1 whitespace-pre-line">{{ $task->instructions }}</p>
|
||||
</details>
|
||||
@endif
|
||||
@if ($task->description !== null)
|
||||
<details>
|
||||
<summary class="cursor-pointer font-medium">{{ __('machines.show.description') }}</summary>
|
||||
<p class="mt-1 whitespace-pre-line">{{ $task->description }}</p>
|
||||
</details>
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@if ($editingEntryId === $row->entryId)
|
||||
<form wire:submit="reschedule" class="flex flex-wrap items-end gap-2" novalidate>
|
||||
<x-input id="edit-day" wire:model="editDay" type="date" :label="__('machines.task.day')" />
|
||||
<div class="min-w-48">
|
||||
<x-select.native id="edit-machine" wire:model="editMachineId" :label="__('machines.task.machine')" :aria-label="__('machines.task.machine')">
|
||||
@foreach ($this->machinesFor($row) as $option)
|
||||
<option value="{{ $option->id }}">{{ $option->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
</div>
|
||||
<x-button submit sm :text="__('machines.task.save')" />
|
||||
<x-button wire:click="cancelEdit" subtle color="black" sm :text="__('machines.task.cancel')" />
|
||||
</form>
|
||||
@else
|
||||
<div class="flex flex-wrap gap-2">
|
||||
@unless ($row->isLate || $row->isOrder())
|
||||
<x-button id="row-{{ $row->entryId }}-up" wire:click="move({{ $row->entryId }}, 'up')" subtle color="black" sm icon="arrow-up" :aria-label="__('machines.show.up_named', ['title' => $this->rowTitle($row)])" />
|
||||
<x-button id="row-{{ $row->entryId }}-down" wire:click="move({{ $row->entryId }}, 'down')" subtle color="black" sm icon="arrow-down" :aria-label="__('machines.show.down_named', ['title' => $this->rowTitle($row)])" />
|
||||
@endunless
|
||||
@if ($task !== null)
|
||||
<x-button id="row-{{ $row->entryId }}-edit" wire:click="startEdit({{ $row->entryId }})" subtle color="black" sm icon="calendar-days" :text="__('machines.show.reschedule')" :aria-label="__('machines.show.reschedule_named', ['title' => $task->title])" />
|
||||
<x-button wire:click="remove({{ $row->entryId }})" subtle color="black" sm icon="x-mark" :text="__('machines.task.remove')" :aria-label="__('machines.task.remove').': '.$task->title" />
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
</li>
|
||||
@endforeach
|
||||
</ol>
|
||||
@endif
|
||||
</section>
|
||||
</div>
|
||||
@@ -0,0 +1,210 @@
|
||||
<?php
|
||||
|
||||
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
||||
use App\Modules\Machines\Application\Contracts\MachineTasks;
|
||||
use App\Modules\Machines\Application\DTOs\MachineSummary;
|
||||
use App\Modules\Machines\Application\DTOs\MachineTaskInfo;
|
||||
use App\Modules\Machines\Application\DTOs\QueueRow;
|
||||
use App\Modules\Machines\Application\UseCases\MachineWorkList;
|
||||
use App\Modules\Machines\Domain\Exceptions\InvalidPlannedDay;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineInactive;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNotForTask;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineNotFound;
|
||||
use App\Modules\Machines\Domain\Exceptions\MachineTaskNotFound;
|
||||
use App\Modules\Machines\Presentation\Livewire\Concerns\FormatsMachines;
|
||||
use App\Modules\Users\Application\Contracts\Clock;
|
||||
use Livewire\Attributes\Computed;
|
||||
use Livewire\Attributes\Locked;
|
||||
use Livewire\Component;
|
||||
|
||||
/**
|
||||
* A task's machine in its card on the job page (spec 19.4): "Move to
|
||||
* machine" puts the task on a machine's work list for a day (by default
|
||||
* the start of its schedule, else today); the machine and day can be
|
||||
* changed later, and the task taken off. Shown only when the task's
|
||||
* service unit uses stock, or when the task already is on a list.
|
||||
*/
|
||||
new class extends Component
|
||||
{
|
||||
use FormatsMachines;
|
||||
|
||||
#[Locked]
|
||||
public int $jobId;
|
||||
|
||||
#[Locked]
|
||||
public int $taskId;
|
||||
|
||||
#[Locked]
|
||||
public string $taskTitle = '';
|
||||
|
||||
#[Locked]
|
||||
public bool $editing = false;
|
||||
|
||||
public string $machineId = '';
|
||||
|
||||
public string $day = '';
|
||||
|
||||
#[Locked]
|
||||
public string $message = '';
|
||||
|
||||
public function mount(): void
|
||||
{
|
||||
$this->authorize('jobs.view-job', $this->jobId);
|
||||
abort_if($this->task !== null && $this->task->jobId !== $this->jobId, 404);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function task(): ?MachineTaskInfo
|
||||
{
|
||||
return app(MachineTasks::class)->info($this->taskId);
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function row(): ?QueueRow
|
||||
{
|
||||
return app(MachineQueries::class)->rowForTask($this->taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<MachineSummary>
|
||||
*/
|
||||
#[Computed]
|
||||
public function machines(): array
|
||||
{
|
||||
return $this->task === null ? [] : app(MachineQueries::class)->machinesFor($this->task->allowedServiceUnitIds);
|
||||
}
|
||||
|
||||
public function machineName(int $machineId): string
|
||||
{
|
||||
return app(MachineQueries::class)->findMachine($machineId)->name ?? '';
|
||||
}
|
||||
|
||||
public function canPlan(): bool
|
||||
{
|
||||
return $this->task !== null && ! $this->task->isDone && $this->task->allowedServiceUnitIds !== [] && auth()->user()?->can('machines.use') === true;
|
||||
}
|
||||
|
||||
public function startEdit(): void
|
||||
{
|
||||
$this->authorizePlanning();
|
||||
|
||||
$today = app(Clock::class)->today()->format('Y-m-d');
|
||||
$this->editing = true;
|
||||
$this->machineId = (string) ($this->row->machineId ?? ($this->machines[0]->id ?? ''));
|
||||
$this->day = $this->row !== null && ! $this->row->isLate
|
||||
? $this->row->plannedOn
|
||||
: ($this->task?->plannedFrom !== null && $this->task->plannedFrom > $today ? $this->task->plannedFrom : $today);
|
||||
$this->resetErrorBag();
|
||||
$this->js("setTimeout(() => document.getElementById('task-{$this->taskId}-machine')?.focus())");
|
||||
}
|
||||
|
||||
public function cancel(): void
|
||||
{
|
||||
$this->editing = false;
|
||||
$this->js("document.getElementById('task-{$this->taskId}-move')?.focus()");
|
||||
}
|
||||
|
||||
public function save(MachineWorkList $workList): void
|
||||
{
|
||||
$this->authorizePlanning();
|
||||
|
||||
try {
|
||||
$workList->planTask($this->taskId, (int) $this->machineId, $this->day);
|
||||
} catch (InvalidPlannedDay) {
|
||||
$this->addError('day', __('machines.errors.day'));
|
||||
|
||||
return;
|
||||
} catch (MachineNotFound|MachineInactive|MachineNotForTask) {
|
||||
$this->addError('machineId', __('machines.errors.machine'));
|
||||
|
||||
return;
|
||||
} catch (MachineTaskNotFound) {
|
||||
$this->message = __('machines.errors.task_done');
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$this->message = __('machines.task.moved', ['machine' => $this->machineName((int) $this->machineId), 'date' => $this->dateLabel($this->day)]);
|
||||
$this->editing = false;
|
||||
unset($this->row);
|
||||
$this->js("document.getElementById('task-{$this->taskId}-machine-status')?.focus()");
|
||||
}
|
||||
|
||||
public function remove(MachineWorkList $workList): void
|
||||
{
|
||||
$this->authorizePlanning();
|
||||
|
||||
$workList->removeTask($this->taskId);
|
||||
$this->message = __('machines.task.removed');
|
||||
unset($this->row);
|
||||
$this->js("document.getElementById('task-{$this->taskId}-machine-status')?.focus()");
|
||||
}
|
||||
|
||||
private function authorizePlanning(): void
|
||||
{
|
||||
$this->authorize('jobs.view-job', $this->jobId);
|
||||
abort_unless($this->canPlan(), 403);
|
||||
}
|
||||
};
|
||||
?>
|
||||
|
||||
<div>
|
||||
@if ($this->canPlan() || $this->row !== null)
|
||||
<section aria-label="{{ __('machines.task.list_of', ['title' => $taskTitle]) }}" class="space-y-2">
|
||||
<h4 class="font-medium">{{ __('machines.task.title') }}</h4>
|
||||
|
||||
<p id="task-{{ $taskId }}-machine-status" tabindex="-1" role="status" aria-live="polite" class="text-sm focus:outline-none">{{ $message }}</p>
|
||||
|
||||
@if ($this->row !== null)
|
||||
<p class="text-sm">
|
||||
<x-link :href="route('machines.show', ['machine' => $this->row->machineId, 'paiva' => $this->row->plannedOn])" navigate>
|
||||
{{ __('machines.task.on_machine', ['machine' => $this->machineName($this->row->machineId), 'date' => $this->dateLabel($this->row->plannedOn)]) }}
|
||||
</x-link>
|
||||
</p>
|
||||
@if ($this->row->plannedOn < app(Clock::class)->today()->format('Y-m-d'))
|
||||
<p class="flex items-center gap-1 text-sm font-medium text-red-700 dark:text-red-400">
|
||||
<x-icon name="exclamation-triangle" class="size-4" aria-hidden="true" />
|
||||
{{ __('machines.task.late') }}
|
||||
</p>
|
||||
@elseif ($this->task !== null && $this->task->isOutsidePlan($this->row->plannedOn))
|
||||
<p class="flex items-center gap-1 text-sm">
|
||||
<x-icon name="information-circle" class="size-4" aria-hidden="true" />
|
||||
{{ __('machines.show.outside_plan') }}
|
||||
</p>
|
||||
@endif
|
||||
@else
|
||||
<p class="text-sm text-zinc-600 dark:text-zinc-300">{{ __('machines.task.not_on_machine') }}</p>
|
||||
@endif
|
||||
|
||||
@if ($this->canPlan())
|
||||
@if ($editing)
|
||||
@if ($this->machines === [])
|
||||
<p class="text-sm">{{ __('machines.task.no_machines') }}</p>
|
||||
<x-button wire:click="cancel" subtle color="black" sm :text="__('machines.task.cancel')" />
|
||||
@else
|
||||
<form wire:submit="save" class="flex flex-wrap items-end gap-2" novalidate>
|
||||
<div class="min-w-48">
|
||||
{{-- TallStackUI's native select does not tie its label to the control, so aria-label names it. --}}
|
||||
<x-select.native id="task-{{ $taskId }}-machine" wire:model="machineId" :label="__('machines.task.machine')" :aria-label="__('machines.task.machine')">
|
||||
@foreach ($this->machines as $machine)
|
||||
<option value="{{ $machine->id }}">{{ $machine->name }}</option>
|
||||
@endforeach
|
||||
</x-select.native>
|
||||
</div>
|
||||
<x-input id="task-{{ $taskId }}-machine-day" wire:model="day" type="date" :label="__('machines.task.day')" :hint="__('machines.task.day_hint')" />
|
||||
<x-button submit sm :text="__('machines.task.save')" />
|
||||
<x-button wire:click="cancel" subtle color="black" sm :text="__('machines.task.cancel')" />
|
||||
</form>
|
||||
@endif
|
||||
@else
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<x-button id="task-{{ $taskId }}-move" wire:click="startEdit" subtle color="black" sm icon="printer" :text="$this->row === null ? __('machines.task.move') : __('machines.task.change')" />
|
||||
@if ($this->row !== null)
|
||||
<x-button wire:click="remove" subtle color="black" sm icon="x-mark" :text="__('machines.task.remove')" />
|
||||
@endif
|
||||
</div>
|
||||
@endif
|
||||
@endif
|
||||
</section>
|
||||
@endif
|
||||
</div>
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::middleware(['web', 'auth', 'can:machines.use'])
|
||||
->prefix('machines')
|
||||
->name('machines.')
|
||||
->group(function () {
|
||||
Route::livewire('/', 'machines::index')->name('index');
|
||||
|
||||
Route::middleware('can:machines.manage')->group(function () {
|
||||
Route::livewire('/create', 'machines::form')->name('create');
|
||||
Route::livewire('/{machine}/edit', 'machines::form')->whereNumber('machine')->name('edit');
|
||||
});
|
||||
|
||||
Route::livewire('/{machine}', 'machines::show')->whereNumber('machine')->name('show');
|
||||
});
|
||||
Reference in New Issue
Block a user