feat(map): filtros por columna en cabecera (elementos e inspecciones)

Usa la cabecera secundaria de Rappasoft (setSecondaryHeaderEnabled + secondaryHeaderFilter):
- Elementos: Elemento (texto), Capa (select), Fase (select).
- Inspecciones: Fecha (date), Elemento (texto), Resultado (select), Usuario (select);
  Plantilla sin filtro.

Tests: MapTablesTest amplía con filtro de capa funcional. Suite 75 passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-06-19 17:56:40 +02:00
parent 25a59e4413
commit 2dccbe3a14
3 changed files with 80 additions and 10 deletions
+37
View File
@@ -4,10 +4,14 @@ namespace App\Livewire\Projects;
use App\Models\Inspection;
use App\Models\Project;
use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
use Rappasoft\LaravelLivewireTables\Views\Column;
use Rappasoft\LaravelLivewireTables\Views\Filters\DateFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\SelectFilter;
use Rappasoft\LaravelLivewireTables\Views\Filters\TextFilter;
class InspectionTable extends DataTableComponent
{
@@ -20,6 +24,7 @@ class InspectionTable extends DataTableComponent
$this->setPrimaryKey('id')
->setDefaultSort('inspections.created_at', 'desc')
->setSortingPillsEnabled(false)
->setSecondaryHeaderEnabled()
->setAdditionalSelects([
'inspections.id as id',
'inspections.created_at as created_at',
@@ -48,9 +53,11 @@ class InspectionTable extends DataTableComponent
return [
Column::make('Fecha', 'created_at')
->sortable()
->secondaryHeaderFilter('fecha')
->format(fn ($value, $row) => $row->created_at?->format('d/m/Y') ?? '—'),
Column::make('Elemento')
->secondaryHeaderFilter('elemento')
->label(fn ($row) => $row->feature?->name
? '<span class="font-medium">' . e($row->feature->name) . '</span>'
: '<span class="text-base-content/30 text-xs">—</span>')
@@ -61,12 +68,14 @@ class InspectionTable extends DataTableComponent
Column::make('Resultado', 'result')
->sortable()
->secondaryHeaderFilter('resultado')
->format(fn ($value) => $value
? '<span class="badge badge-sm badge-outline">' . e($value) . '</span>'
: '<span class="text-base-content/30 text-xs">—</span>')
->html(),
Column::make('Usuario')
->secondaryHeaderFilter('usuario')
->label(fn ($row) => e($row->user?->name ?? '—')),
Column::make('Acciones')
@@ -80,4 +89,32 @@ class InspectionTable extends DataTableComponent
->html(),
];
}
public function filters(): array
{
$results = Inspection::where('project_id', $this->projectId)
->whereNotNull('result')->distinct()->orderBy('result')
->pluck('result', 'result')->toArray();
$users = User::whereIn('id', Inspection::where('project_id', $this->projectId)
->whereNotNull('user_id')->distinct()->pluck('user_id'))
->orderBy('name')->pluck('name', 'id')->toArray();
return [
DateFilter::make('Fecha', 'fecha')
->filter(fn (Builder $query, string $value) => $query->whereDate('inspections.created_at', $value)),
TextFilter::make('Elemento', 'elemento')
->config(['placeholder' => 'Buscar elemento…'])
->filter(fn (Builder $query, string $value) => $query->whereHas('feature', fn ($f) => $f->where('name', 'like', '%' . $value . '%'))),
SelectFilter::make('Resultado', 'resultado')
->options(['' => 'Todos'] + $results)
->filter(fn (Builder $query, string $value) => $query->where('inspections.result', $value)),
SelectFilter::make('Usuario', 'usuario')
->options(['' => 'Todos'] + $users)
->filter(fn (Builder $query, string $value) => $query->where('inspections.user_id', $value)),
];
}
}