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,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Modules\Machines\Infrastructure\Providers;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Modules\Catalog\Application\Contracts\CatalogQueries;
|
||||
use App\Modules\Jobs\Domain\Events\TaskCompleted;
|
||||
use App\Modules\Machines\Application\Contracts\MachineQueries;
|
||||
use App\Modules\Machines\Application\Contracts\MachineTasks;
|
||||
use App\Modules\Machines\Application\UseCases\MachineWorkList;
|
||||
use App\Modules\Machines\Domain\Contracts\MachineRepository;
|
||||
use App\Modules\Machines\Domain\Contracts\QueueRepository;
|
||||
use App\Modules\Machines\Infrastructure\Adapters\JobsForMachines;
|
||||
use App\Modules\Machines\Infrastructure\Persistence\Repositories\EloquentMachineQueries;
|
||||
use App\Modules\Machines\Infrastructure\Persistence\Repositories\EloquentMachineRepository;
|
||||
use App\Modules\Machines\Infrastructure\Persistence\Repositories\EloquentQueueRepository;
|
||||
use App\Modules\Users\Domain\Enums\Role;
|
||||
use Illuminate\Support\Facades\Event;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Livewire\Livewire;
|
||||
|
||||
/**
|
||||
* Wires the Machines module (machines, their work lists, maintenance and
|
||||
* the machine console, spec 19.4–19.6) into Laravel: bindings, routes, the
|
||||
* `machines::` Livewire namespace and the `machines.*` abilities.
|
||||
*/
|
||||
class MachinesServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* @var array<class-string, class-string>
|
||||
*/
|
||||
public array $bindings = [
|
||||
MachineRepository::class => EloquentMachineRepository::class,
|
||||
QueueRepository::class => EloquentQueueRepository::class,
|
||||
MachineQueries::class => EloquentMachineQueries::class,
|
||||
MachineTasks::class => JobsForMachines::class,
|
||||
];
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
$presentationPath = dirname(__DIR__, 2).'/Presentation';
|
||||
|
||||
Livewire::addNamespace('machines', viewPath: $presentationPath.'/Livewire');
|
||||
|
||||
if (! $this->app->routesAreCached()) {
|
||||
$this->loadRoutesFrom($presentationPath.'/Routes/web.php');
|
||||
}
|
||||
|
||||
// A task marked done elsewhere leaves its machine's work list.
|
||||
Event::listen(TaskCompleted::class, fn (TaskCompleted $event) => app(MachineWorkList::class)->closeTask($event->taskId));
|
||||
|
||||
$staff = fn (User $user): bool => $user->role !== Role::Subcontractor;
|
||||
|
||||
// Moving tasks to machines, the console and maintenance records: everyone but subcontractors (spec 19.9).
|
||||
Gate::define('machines.use', $staff);
|
||||
Gate::define('machines.manage', fn (User $user): bool => in_array($user->role, [Role::Admin, Role::Management], true));
|
||||
Gate::define('machines.menu', fn (User $user): bool => $staff($user) && app(CatalogQueries::class)->stockServiceUnitIds() !== []);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user