Build & Deploy / build (push) Successful in 18s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
71 lines
2.2 KiB
PHP
71 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\Exercises\Tables;
|
|
|
|
use Filament\Actions\ViewAction;
|
|
use Filament\Tables\Columns\ImageColumn;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Filters\SelectFilter;
|
|
use Filament\Tables\Table;
|
|
use Functional\Exercises\Models\Exercise;
|
|
|
|
/**
|
|
* Table du catalogue d'exercices : thumbnail + métadonnées, filtrable et consultable.
|
|
*/
|
|
class ExercisesTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
ImageColumn::make('image_url')
|
|
->label('Aperçu')
|
|
->square(),
|
|
TextColumn::make('name')
|
|
->label('Nom')
|
|
->searchable()
|
|
->sortable(),
|
|
TextColumn::make('body_part')
|
|
->label('Partie du corps')
|
|
->badge()
|
|
->sortable(),
|
|
TextColumn::make('equipment')
|
|
->label('Équipement')
|
|
->badge(),
|
|
TextColumn::make('target')
|
|
->label('Muscle cible')
|
|
->badge(),
|
|
])
|
|
->filters([
|
|
SelectFilter::make('body_part')
|
|
->label('Partie du corps')
|
|
->options(fn (): array => self::distinctOptions('body_part')),
|
|
SelectFilter::make('equipment')
|
|
->label('Équipement')
|
|
->options(fn (): array => self::distinctOptions('equipment')),
|
|
SelectFilter::make('target')
|
|
->label('Muscle cible')
|
|
->options(fn (): array => self::distinctOptions('target')),
|
|
])
|
|
->recordActions([
|
|
ViewAction::make(),
|
|
])
|
|
->defaultSort('name');
|
|
}
|
|
|
|
/**
|
|
* Valeurs distinctes d'une colonne pour alimenter un filtre (clé = valeur = libellé brut).
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
private static function distinctOptions(string $column): array
|
|
{
|
|
return Exercise::query()
|
|
->whereNotNull($column)
|
|
->distinct()
|
|
->orderBy($column)
|
|
->pluck($column, $column)
|
|
->all();
|
|
}
|
|
}
|