Filament moderne (groupes nav, 4 charts, filtres/badges) + Filament Shield (rôles/permissions) + noms exos localisés dans routines
Build & Deploy / build (push) Successful in 19s
Build & Deploy / build (push) Successful in 19s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkoutSessions\Pages;
|
||||
|
||||
use App\Filament\Resources\WorkoutSessions\WorkoutSessionResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateWorkoutSession extends CreateRecord
|
||||
{
|
||||
protected static string $resource = WorkoutSessionResource::class;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkoutSessions\Pages;
|
||||
|
||||
use App\Filament\Resources\WorkoutSessions\WorkoutSessionResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditWorkoutSession extends EditRecord
|
||||
{
|
||||
protected static string $resource = WorkoutSessionResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,15 @@
|
||||
namespace App\Filament\Resources\WorkoutSessions\Pages;
|
||||
|
||||
use App\Filament\Resources\WorkoutSessions\WorkoutSessionResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListWorkoutSessions extends ListRecords
|
||||
{
|
||||
protected static string $resource = WorkoutSessionResource::class;
|
||||
|
||||
// Séances loguées par l'app : aucune action de création manuelle.
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkoutSessions\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Schemas\Schema;
|
||||
use Functional\Tracking\Enums\WorkoutSessionStatus;
|
||||
|
||||
class WorkoutSessionForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('user_id')
|
||||
->relationship('user', 'name')
|
||||
->required(),
|
||||
Select::make('routine_id')
|
||||
->relationship('routine', 'name'),
|
||||
Select::make('program_id')
|
||||
->relationship('program', 'name'),
|
||||
TextInput::make('title'),
|
||||
DateTimePicker::make('started_at')
|
||||
->required(),
|
||||
DateTimePicker::make('ended_at'),
|
||||
Select::make('status')
|
||||
->options(WorkoutSessionStatus::class)
|
||||
->default('active')
|
||||
->required(),
|
||||
Textarea::make('notes')
|
||||
->columnSpanFull(),
|
||||
TextInput::make('total_volume')
|
||||
->numeric(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\WorkoutSessions\Schemas;
|
||||
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
use Functional\Tracking\Enums\WorkoutSessionStatus;
|
||||
|
||||
/**
|
||||
* Fiche de consultation d'une séance (modal "Voir") : données loguées par l'utilisateur/l'app,
|
||||
* jamais créées ni modifiées à la main depuis le back-office.
|
||||
*/
|
||||
class WorkoutSessionInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('user.name')
|
||||
->label('Utilisateur'),
|
||||
TextEntry::make('title')
|
||||
->label('Titre')
|
||||
->placeholder('—'),
|
||||
TextEntry::make('routine.name')
|
||||
->label('Routine')
|
||||
->placeholder('—'),
|
||||
TextEntry::make('program.name')
|
||||
->label('Programme')
|
||||
->placeholder('—'),
|
||||
TextEntry::make('status')
|
||||
->label('Statut')
|
||||
->badge()
|
||||
->color(fn (WorkoutSessionStatus $state): string => match ($state) {
|
||||
WorkoutSessionStatus::Active => 'warning',
|
||||
WorkoutSessionStatus::Completed => 'success',
|
||||
WorkoutSessionStatus::Abandoned => 'danger',
|
||||
}),
|
||||
TextEntry::make('started_at')
|
||||
->label('Débutée le')
|
||||
->dateTime(),
|
||||
TextEntry::make('ended_at')
|
||||
->label('Terminée le')
|
||||
->dateTime()
|
||||
->placeholder('—'),
|
||||
TextEntry::make('total_volume')
|
||||
->label('Volume total')
|
||||
->numeric()
|
||||
->placeholder('—'),
|
||||
TextEntry::make('notes')
|
||||
->label('Notes')
|
||||
->columnSpanFull()
|
||||
->placeholder('—'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,15 +3,20 @@
|
||||
namespace App\Filament\Resources\WorkoutSessions\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Tracking\Enums\WorkoutSessionStatus;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* Table des séances : utilisateur, statut, début, volume total.
|
||||
* Lecture seule + suppression : les séances sont loguées par l'app, jamais créées/éditées ici.
|
||||
*/
|
||||
class WorkoutSessionsTable
|
||||
{
|
||||
@@ -23,6 +28,11 @@ class WorkoutSessionsTable
|
||||
->label('Utilisateur')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('title')
|
||||
->label('Titre')
|
||||
->searchable()
|
||||
->toggleable(isToggledHiddenByDefault: true)
|
||||
->placeholder('—'),
|
||||
TextColumn::make('status')
|
||||
->label('Statut')
|
||||
->badge()
|
||||
@@ -38,15 +48,28 @@ class WorkoutSessionsTable
|
||||
TextColumn::make('total_volume')
|
||||
->label('Volume total')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->placeholder('—'),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('status')
|
||||
->label('Statut')
|
||||
->options(WorkoutSessionStatus::class),
|
||||
Filter::make('started_at')
|
||||
->label('Période')
|
||||
->schema([
|
||||
DatePicker::make('from')->label('Du'),
|
||||
DatePicker::make('until')->label('Au'),
|
||||
])
|
||||
->query(function (Builder $query, array $data): Builder {
|
||||
return $query
|
||||
->when($data['from'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('started_at', '>=', $date))
|
||||
->when($data['until'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('started_at', '<=', $date));
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\WorkoutSessions;
|
||||
|
||||
use App\Filament\Resources\WorkoutSessions\Pages\CreateWorkoutSession;
|
||||
use App\Filament\Resources\WorkoutSessions\Pages\EditWorkoutSession;
|
||||
use App\Filament\Resources\WorkoutSessions\Pages\ListWorkoutSessions;
|
||||
use App\Filament\Resources\WorkoutSessions\Schemas\WorkoutSessionForm;
|
||||
use App\Filament\Resources\WorkoutSessions\Schemas\WorkoutSessionInfolist;
|
||||
use App\Filament\Resources\WorkoutSessions\Tables\WorkoutSessionsTable;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
@@ -13,16 +11,32 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Tracking\Models\WorkoutSession;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Séances loguées par les utilisateurs (via l'app) — consultation + suppression uniquement,
|
||||
* jamais de création/édition manuelle depuis le back-office.
|
||||
*/
|
||||
class WorkoutSessionResource extends Resource
|
||||
{
|
||||
protected static ?string $model = WorkoutSession::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedBolt;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Entraînement';
|
||||
|
||||
protected static ?int $navigationSort = 3;
|
||||
|
||||
protected static ?string $modelLabel = 'séance';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'séances';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'title';
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return WorkoutSessionForm::configure($schema);
|
||||
return WorkoutSessionInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
@@ -30,19 +44,28 @@ class WorkoutSessionResource extends Resource
|
||||
return WorkoutSessionsTable::configure($table);
|
||||
}
|
||||
|
||||
public static function getRelations(): array
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function canEdit(Model $record): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['title', 'user.name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListWorkoutSessions::route('/'),
|
||||
'create' => CreateWorkoutSession::route('/create'),
|
||||
'edit' => EditWorkoutSession::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user