87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Filament\Clusters\Inventory\InventoryCluster;
|
|
use App\Filament\Widgets\Inventory\InventoryKpiHeader;
|
|
use App\Models\Tenant;
|
|
use App\Models\User;
|
|
use App\Services\Auth\CapabilityResolver;
|
|
use App\Services\Inventory\CoverageCapabilitiesResolver;
|
|
use App\Support\Auth\Capabilities;
|
|
use App\Support\Inventory\InventoryPolicyTypeMeta;
|
|
use BackedEnum;
|
|
use Filament\Pages\Page;
|
|
use UnitEnum;
|
|
|
|
class InventoryCoverage extends Page
|
|
{
|
|
protected static string|BackedEnum|null $navigationIcon = 'heroicon-o-table-cells';
|
|
|
|
protected static ?int $navigationSort = 3;
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'Inventory';
|
|
|
|
protected static ?string $navigationLabel = 'Coverage';
|
|
|
|
protected static ?string $cluster = InventoryCluster::class;
|
|
|
|
protected string $view = 'filament.pages.inventory-coverage';
|
|
|
|
public static function canAccess(): bool
|
|
{
|
|
$tenant = Tenant::current();
|
|
$user = auth()->user();
|
|
|
|
if (! $tenant instanceof Tenant || ! $user instanceof User) {
|
|
return false;
|
|
}
|
|
|
|
/** @var CapabilityResolver $resolver */
|
|
$resolver = app(CapabilityResolver::class);
|
|
|
|
return $resolver->isMember($user, $tenant)
|
|
&& $resolver->can($user, $tenant, Capabilities::TENANT_VIEW);
|
|
}
|
|
|
|
protected function getHeaderWidgets(): array
|
|
{
|
|
return [
|
|
InventoryKpiHeader::class,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @var array<int, array<string, mixed>>
|
|
*/
|
|
public array $supportedPolicyTypes = [];
|
|
|
|
/**
|
|
* @var array<int, array<string, mixed>>
|
|
*/
|
|
public array $foundationTypes = [];
|
|
|
|
public function mount(): void
|
|
{
|
|
$resolver = app(CoverageCapabilitiesResolver::class);
|
|
|
|
$this->supportedPolicyTypes = collect(InventoryPolicyTypeMeta::supported())
|
|
->map(function (array $row) use ($resolver): array {
|
|
$type = (string) ($row['type'] ?? '');
|
|
|
|
return array_merge($row, [
|
|
'dependencies' => $type !== '' && $resolver->supportsDependencies($type),
|
|
]);
|
|
})
|
|
->all();
|
|
|
|
$this->foundationTypes = collect(InventoryPolicyTypeMeta::foundations())
|
|
->map(function (array $row): array {
|
|
return array_merge($row, [
|
|
'dependencies' => false,
|
|
]);
|
|
})
|
|
->all();
|
|
}
|
|
}
|