setPrimaryKey('id') ->setDefaultSort('name', 'asc') ->setSortingPillsEnabled(false) ->setAdditionalSelects(['features.id as id', 'features.layer_id as layer_id']); } public function builder(): Builder { $user = Auth::user(); abort_unless( $user->can('manage all') || Project::whereKey($this->projectId)->whereHas('users', fn ($q) => $q->where('user_id', $user->id))->exists(), 403 ); return Feature::query() ->whereHas('layer.phase', fn ($q) => $q->where('project_id', $this->projectId)) ->with(['layer.phase']); } public function columns(): array { return [ Column::make('Elemento', 'name') ->sortable() ->searchable() ->format(fn ($value) => '' . e($value) . '') ->html(), Column::make('Capa') ->label(fn ($row) => e($row->layer?->name ?? '—')), Column::make('Fase') ->label(fn ($row) => e($row->layer?->phase?->name ?? '—')), Column::make('Progreso', 'progress') ->sortable() ->format(function ($value) { $cls = $value >= 100 ? 'badge-success' : ($value > 0 ? 'badge-warning' : 'badge-ghost'); return '' . (int) $value . '%'; }) ->html(), Column::make('Acciones') ->label(fn ($row) => '
') ->html(), ]; } public function filters(): array { return [ SelectFilter::make('Progreso', 'progress') ->options(['' => 'Progreso: todos', 'pending' => 'Sin iniciar', 'in_progress' => 'En curso', 'done' => 'Completado']) ->filter(function (Builder $query, string $value) { match ($value) { 'pending' => $query->where('features.progress', '=', 0), 'in_progress' => $query->where('features.progress', '>', 0)->where('features.progress', '<', 100), 'done' => $query->where('features.progress', '>=', 100), default => null, }; }), ]; } }