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:
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\Achievements;
|
||||
|
||||
use App\Filament\Resources\Achievements\Pages\CreateAchievement;
|
||||
use App\Filament\Resources\Achievements\Pages\EditAchievement;
|
||||
use App\Filament\Resources\Achievements\Pages\ListAchievements;
|
||||
use App\Filament\Resources\Achievements\Schemas\AchievementForm;
|
||||
use App\Filament\Resources\Achievements\Schemas\AchievementInfolist;
|
||||
use App\Filament\Resources\Achievements\Tables\AchievementsTable;
|
||||
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\Streaks\Models\Achievement;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Badges débloqués par StreakService aux paliers de streak — consultation + suppression
|
||||
* uniquement, jamais de création/édition manuelle depuis le back-office.
|
||||
*/
|
||||
class AchievementResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Achievement::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedTrophy;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Gamification';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $modelLabel = 'badge';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'badges';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'key';
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return AchievementForm::configure($schema);
|
||||
return AchievementInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
@@ -30,19 +44,28 @@ class AchievementResource extends Resource
|
||||
return AchievementsTable::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 ['key', 'user.name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListAchievements::route('/'),
|
||||
'create' => CreateAchievement::route('/create'),
|
||||
'edit' => EditAchievement::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Achievements\Pages;
|
||||
|
||||
use App\Filament\Resources\Achievements\AchievementResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateAchievement extends CreateRecord
|
||||
{
|
||||
protected static string $resource = AchievementResource::class;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Achievements\Pages;
|
||||
|
||||
use App\Filament\Resources\Achievements\AchievementResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditAchievement extends EditRecord
|
||||
{
|
||||
protected static string $resource = AchievementResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,15 @@
|
||||
namespace App\Filament\Resources\Achievements\Pages;
|
||||
|
||||
use App\Filament\Resources\Achievements\AchievementResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListAchievements extends ListRecords
|
||||
{
|
||||
protected static string $resource = AchievementResource::class;
|
||||
|
||||
// Badges posés par StreakService : aucune action de création manuelle.
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Achievements\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DateTimePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class AchievementForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('user_id')
|
||||
->relationship('user', 'name')
|
||||
->required(),
|
||||
TextInput::make('key')
|
||||
->required(),
|
||||
DateTimePicker::make('earned_at')
|
||||
->required(),
|
||||
TextInput::make('meta'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Achievements\Schemas;
|
||||
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
/**
|
||||
* Fiche de consultation d'un badge débloqué (modal "Voir") : posé par StreakService
|
||||
* aux paliers de streak, jamais créé ni modifié à la main depuis le back-office.
|
||||
*/
|
||||
class AchievementInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('user.name')
|
||||
->label('Utilisateur'),
|
||||
TextEntry::make('key')
|
||||
->label('Badge')
|
||||
->badge(),
|
||||
TextEntry::make('earned_at')
|
||||
->label('Obtenu le')
|
||||
->dateTime(),
|
||||
TextEntry::make('meta')
|
||||
->label('Métadonnées')
|
||||
->columnSpanFull()
|
||||
->placeholder('—'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -3,13 +3,18 @@
|
||||
namespace App\Filament\Resources\Achievements\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\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
/**
|
||||
* Table des badges débloqués : utilisateur, clé du badge, date d'obtention.
|
||||
* Lecture seule + suppression : posé par StreakService, jamais créé/édité ici.
|
||||
*/
|
||||
class AchievementsTable
|
||||
{
|
||||
@@ -24,14 +29,29 @@ class AchievementsTable
|
||||
TextColumn::make('key')
|
||||
->label('Badge')
|
||||
->badge()
|
||||
->searchable(),
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('earned_at')
|
||||
->label('Obtenu le')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('earned_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('earned_at', '>=', $date))
|
||||
->when($data['until'] ?? null, fn (Builder $q, string $date): Builder => $q->whereDate('earned_at', '<=', $date));
|
||||
}),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
|
||||
@@ -25,6 +25,8 @@ class ExerciseResource extends Resource
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Catalogue';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $modelLabel = 'exercice';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'exercices';
|
||||
@@ -47,6 +49,14 @@ class ExerciseResource extends Resource
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['name', 'category', 'body_part', 'target'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -25,18 +25,28 @@ class ExercisesTable
|
||||
->label('Nom')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('category')
|
||||
->label('Catégorie')
|
||||
->badge()
|
||||
->color('gray')
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('body_part')
|
||||
->label('Partie du corps')
|
||||
->badge()
|
||||
->sortable(),
|
||||
TextColumn::make('equipment')
|
||||
->label('Équipement')
|
||||
->badge(),
|
||||
->badge()
|
||||
->toggleable(),
|
||||
TextColumn::make('target')
|
||||
->label('Muscle cible')
|
||||
->badge(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('category')
|
||||
->label('Catégorie')
|
||||
->options(fn (): array => self::distinctOptions('category')),
|
||||
SelectFilter::make('body_part')
|
||||
->label('Partie du corps')
|
||||
->options(fn (): array => self::distinctOptions('body_part')),
|
||||
|
||||
@@ -13,12 +13,21 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Technical\Integrations\Models\Integration;
|
||||
use UnitEnum;
|
||||
|
||||
class IntegrationResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Integration::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowsRightLeft;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Système';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $modelLabel = 'intégration';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'intégrations';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -37,6 +46,14 @@ class IntegrationResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['provider', 'external_user_id', 'user.name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -2,13 +2,17 @@
|
||||
|
||||
namespace App\Filament\Resources\Integrations\Tables;
|
||||
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Technical\Integrations\Enums\IntegrationStatus;
|
||||
use Technical\Integrations\Models\Integration;
|
||||
|
||||
/**
|
||||
* Table des intégrations externes : utilisateur, fournisseur, état, dernière synchro.
|
||||
@@ -27,7 +31,17 @@ class IntegrationsTable
|
||||
TextColumn::make('provider')
|
||||
->label('Fournisseur')
|
||||
->badge()
|
||||
->searchable(),
|
||||
->color(fn (string $state): string => match (strtolower($state)) {
|
||||
'strava' => 'danger',
|
||||
'garmin' => 'info',
|
||||
default => 'gray',
|
||||
})
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('external_user_id')
|
||||
->label('ID externe')
|
||||
->toggleable(isToggledHiddenByDefault: true)
|
||||
->placeholder('—'),
|
||||
TextColumn::make('status')
|
||||
->label('État')
|
||||
->badge()
|
||||
@@ -36,6 +50,11 @@ class IntegrationsTable
|
||||
IntegrationStatus::Revoked => 'gray',
|
||||
IntegrationStatus::Error => 'danger',
|
||||
}),
|
||||
TextColumn::make('connected_at')
|
||||
->label('Connecté le')
|
||||
->dateTime()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('last_synced_at')
|
||||
->label('Dernière synchro')
|
||||
->dateTime()
|
||||
@@ -43,6 +62,9 @@ class IntegrationsTable
|
||||
->placeholder('Jamais'),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('provider')
|
||||
->label('Fournisseur')
|
||||
->options(fn (): array => self::distinctProviders()),
|
||||
SelectFilter::make('status')
|
||||
->label('État')
|
||||
->options(IntegrationStatus::class),
|
||||
@@ -53,8 +75,34 @@ class IntegrationsTable
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
// Révocation groupée : coupe l'accès sans supprimer l'historique de connexion.
|
||||
BulkAction::make('revoke')
|
||||
->label('Révoquer')
|
||||
->icon(Heroicon::OutlinedBoltSlash)
|
||||
->color('danger')
|
||||
->requiresConfirmation()
|
||||
->action(function (Collection $records): void {
|
||||
$records->each(fn (Integration $integration) => $integration->update([
|
||||
'status' => IntegrationStatus::Revoked,
|
||||
]));
|
||||
})
|
||||
->deselectRecordsAfterCompletion(),
|
||||
]),
|
||||
])
|
||||
->defaultSort('last_synced_at', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* Valeurs distinctes de la colonne "provider" pour alimenter le filtre.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private static function distinctProviders(): array
|
||||
{
|
||||
return Integration::query()
|
||||
->distinct()
|
||||
->orderBy('provider')
|
||||
->pluck('provider', 'provider')
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,12 +13,23 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Programs\Models\Program;
|
||||
use UnitEnum;
|
||||
|
||||
class ProgramResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Program::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedCalendarDays;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Entraînement';
|
||||
|
||||
protected static ?int $navigationSort = 2;
|
||||
|
||||
protected static ?string $modelLabel = 'programme';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'programmes';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -37,6 +48,14 @@ class ProgramResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['name', 'slug', 'user.name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Filament\Resources\Programs\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
/**
|
||||
@@ -30,6 +32,11 @@ class ProgramsTable
|
||||
->label('Semaines')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
TextColumn::make('days_per_week')
|
||||
->label('Jours / semaine')
|
||||
->numeric()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
IconColumn::make('is_public')
|
||||
->label('Public')
|
||||
->boolean(),
|
||||
@@ -38,6 +45,16 @@ class ProgramsTable
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('is_public')
|
||||
->label('Visibilité')
|
||||
->trueLabel('Publics')
|
||||
->falseLabel('Privés'),
|
||||
SelectFilter::make('user')
|
||||
->label('Utilisateur')
|
||||
->relationship('user', 'name')
|
||||
->searchable(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
|
||||
@@ -13,12 +13,23 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Routines\Models\Routine;
|
||||
use UnitEnum;
|
||||
|
||||
class RoutineResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Routine::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedClipboardDocumentList;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Entraînement';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $modelLabel = 'routine';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'routines';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -37,6 +48,14 @@ class RoutineResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['name', 'slug', 'user.name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Filament\Resources\Routines\Schemas;
|
||||
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Components\Toggle;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
|
||||
@@ -7,6 +7,8 @@ use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Tables\Columns\IconColumn;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
/**
|
||||
@@ -26,6 +28,11 @@ class RoutinesTable
|
||||
->label('Utilisateur')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('estimated_minutes')
|
||||
->label('Durée (min)')
|
||||
->numeric()
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
IconColumn::make('is_public')
|
||||
->label('Publique')
|
||||
->boolean(),
|
||||
@@ -34,6 +41,16 @@ class RoutinesTable
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
TernaryFilter::make('is_public')
|
||||
->label('Visibilité')
|
||||
->trueLabel('Publiques')
|
||||
->falseLabel('Privées'),
|
||||
SelectFilter::make('user')
|
||||
->label('Utilisateur')
|
||||
->relationship('user', 'name')
|
||||
->searchable(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Streaks\Pages;
|
||||
|
||||
use App\Filament\Resources\Streaks\StreakResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateStreak extends CreateRecord
|
||||
{
|
||||
protected static string $resource = StreakResource::class;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Streaks\Pages;
|
||||
|
||||
use App\Filament\Resources\Streaks\StreakResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditStreak extends EditRecord
|
||||
{
|
||||
protected static string $resource = StreakResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -3,17 +3,15 @@
|
||||
namespace App\Filament\Resources\Streaks\Pages;
|
||||
|
||||
use App\Filament\Resources\Streaks\StreakResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListStreaks extends ListRecords
|
||||
{
|
||||
protected static string $resource = StreakResource::class;
|
||||
|
||||
// Streaks calculés par StreakService : aucune action de création manuelle.
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Streaks\Schemas;
|
||||
|
||||
use Filament\Forms\Components\DatePicker;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
class StreakForm
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
Select::make('user_id')
|
||||
->relationship('user', 'name')
|
||||
->required(),
|
||||
TextInput::make('current_count')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
TextInput::make('longest_count')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
DatePicker::make('last_active_date'),
|
||||
TextInput::make('freezes_available')
|
||||
->required()
|
||||
->numeric()
|
||||
->default(0),
|
||||
DatePicker::make('freeze_last_granted_on'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Streaks\Schemas;
|
||||
|
||||
use Filament\Infolists\Components\TextEntry;
|
||||
use Filament\Schemas\Schema;
|
||||
|
||||
/**
|
||||
* Fiche de consultation d'un streak (modal "Voir") : calculé par StreakService,
|
||||
* jamais créé ni modifié à la main depuis le back-office.
|
||||
*/
|
||||
class StreakInfolist
|
||||
{
|
||||
public static function configure(Schema $schema): Schema
|
||||
{
|
||||
return $schema
|
||||
->components([
|
||||
TextEntry::make('user.name')
|
||||
->label('Utilisateur'),
|
||||
TextEntry::make('current_count')
|
||||
->label('Streak courant')
|
||||
->badge()
|
||||
->color('warning'),
|
||||
TextEntry::make('longest_count')
|
||||
->label('Record')
|
||||
->numeric(),
|
||||
TextEntry::make('freezes_available')
|
||||
->label('Freezes disponibles')
|
||||
->numeric(),
|
||||
TextEntry::make('last_active_date')
|
||||
->label('Dernière activité')
|
||||
->date()
|
||||
->placeholder('—'),
|
||||
TextEntry::make('freeze_last_granted_on')
|
||||
->label('Dernier freeze accordé')
|
||||
->date()
|
||||
->placeholder('—'),
|
||||
TextEntry::make('last_reminded_on')
|
||||
->label('Dernier rappel envoyé')
|
||||
->date()
|
||||
->placeholder('—'),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace App\Filament\Resources\Streaks;
|
||||
|
||||
use App\Filament\Resources\Streaks\Pages\CreateStreak;
|
||||
use App\Filament\Resources\Streaks\Pages\EditStreak;
|
||||
use App\Filament\Resources\Streaks\Pages\ListStreaks;
|
||||
use App\Filament\Resources\Streaks\Schemas\StreakForm;
|
||||
use App\Filament\Resources\Streaks\Schemas\StreakInfolist;
|
||||
use App\Filament\Resources\Streaks\Tables\StreaksTable;
|
||||
use BackedEnum;
|
||||
use Filament\Resources\Resource;
|
||||
@@ -13,16 +11,30 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Streaks\Models\Streak;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* Streaks calculés par StreakService (1 par user) — consultation + suppression uniquement,
|
||||
* jamais de création/édition manuelle depuis le back-office.
|
||||
*/
|
||||
class StreakResource extends Resource
|
||||
{
|
||||
protected static ?string $model = Streak::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedFire;
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Gamification';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $modelLabel = 'streak';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'streaks';
|
||||
|
||||
public static function infolist(Schema $schema): Schema
|
||||
{
|
||||
return StreakForm::configure($schema);
|
||||
return StreakInfolist::configure($schema);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
@@ -30,19 +42,28 @@ class StreakResource extends Resource
|
||||
return StreaksTable::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 ['user.name'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListStreaks::route('/'),
|
||||
'create' => CreateStreak::route('/create'),
|
||||
'edit' => EditStreak::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,13 +3,15 @@
|
||||
namespace App\Filament\Resources\Streaks\Tables;
|
||||
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Actions\ViewAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
|
||||
/**
|
||||
* Table des streaks : régularité par utilisateur (courant, record, freezes, dernière activité).
|
||||
* Lecture seule + suppression : calculé par StreakService, jamais créé/édité ici.
|
||||
*/
|
||||
class StreaksTable
|
||||
{
|
||||
@@ -33,14 +35,16 @@ class StreaksTable
|
||||
TextColumn::make('freezes_available')
|
||||
->label('Freezes dispo')
|
||||
->numeric()
|
||||
->sortable(),
|
||||
->sortable()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('last_active_date')
|
||||
->label('Dernière activité')
|
||||
->date()
|
||||
->sortable(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
ViewAction::make(),
|
||||
DeleteAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
|
||||
@@ -15,25 +15,46 @@ class UserForm
|
||||
return $schema
|
||||
->components([
|
||||
TextInput::make('name')
|
||||
->label('Nom')
|
||||
->required(),
|
||||
TextInput::make('email')
|
||||
->label('Email address')
|
||||
->label('Email')
|
||||
->email()
|
||||
->required(),
|
||||
DateTimePicker::make('email_verified_at'),
|
||||
DateTimePicker::make('email_verified_at')
|
||||
->label('Email vérifié le'),
|
||||
// Requis à la création, laissé vide à l'édition pour ne pas écraser le mot de passe
|
||||
// existant (le cast 'hashed' du modèle User se charge du hachage à la sauvegarde).
|
||||
TextInput::make('password')
|
||||
->label('Mot de passe')
|
||||
->password()
|
||||
->required(),
|
||||
->revealable()
|
||||
->required(fn (string $operation): bool => $operation === 'create')
|
||||
->dehydrated(fn (?string $state): bool => filled($state))
|
||||
->dehydrateStateUsing(fn (?string $state): ?string => filled($state) ? $state : null),
|
||||
TextInput::make('locale')
|
||||
->label('Langue')
|
||||
->required()
|
||||
->default('fr'),
|
||||
Select::make('units')
|
||||
->label('Unités')
|
||||
->options(Units::class)
|
||||
->default('metric')
|
||||
->required(),
|
||||
TextInput::make('timezone'),
|
||||
TextInput::make('avatar_path'),
|
||||
TextInput::make('oidc_sub'),
|
||||
TextInput::make('timezone')
|
||||
->label('Fuseau horaire'),
|
||||
TextInput::make('avatar_path')
|
||||
->label('Avatar (chemin)'),
|
||||
TextInput::make('oidc_sub')
|
||||
->label('Identifiant OIDC'),
|
||||
// Assignation des rôles Spatie (guard 'web') : pilote l'accès au back-office.
|
||||
Select::make('roles')
|
||||
->label('Rôles')
|
||||
->relationship('roles', 'name')
|
||||
->multiple()
|
||||
->preload()
|
||||
->searchable()
|
||||
->columnSpanFull(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,14 +2,22 @@
|
||||
|
||||
namespace App\Filament\Resources\Users\Tables;
|
||||
|
||||
use Filament\Actions\BulkAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DeleteBulkAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\SelectFilter;
|
||||
use Filament\Tables\Filters\TernaryFilter;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Users\Enums\Units;
|
||||
use Illuminate\Database\Eloquent\Collection;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
/**
|
||||
* Table des utilisateurs : identité, préférences d'affichage, date d'inscription.
|
||||
* Table des utilisateurs : identité, rôles, préférences d'affichage, date d'inscription.
|
||||
*/
|
||||
class UsersTable
|
||||
{
|
||||
@@ -25,23 +33,59 @@ class UsersTable
|
||||
->label('Email')
|
||||
->searchable()
|
||||
->sortable(),
|
||||
TextColumn::make('roles.name')
|
||||
->label('Rôles')
|
||||
->badge()
|
||||
->color('primary'),
|
||||
TextColumn::make('locale')
|
||||
->label('Langue')
|
||||
->badge(),
|
||||
->badge()
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('units')
|
||||
->label('Unités')
|
||||
->badge(),
|
||||
TextColumn::make('email_verified_at')
|
||||
->label('Email vérifié')
|
||||
->dateTime()
|
||||
->placeholder('Non vérifié')
|
||||
->toggleable(isToggledHiddenByDefault: true),
|
||||
TextColumn::make('created_at')
|
||||
->label('Inscrit le')
|
||||
->dateTime()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
SelectFilter::make('roles')
|
||||
->label('Rôle')
|
||||
->relationship('roles', 'name'),
|
||||
SelectFilter::make('units')
|
||||
->label('Unités')
|
||||
->options(Units::class),
|
||||
TernaryFilter::make('email_verified_at')
|
||||
->label('Email vérifié')
|
||||
->nullable(),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
])
|
||||
->toolbarActions([
|
||||
BulkActionGroup::make([
|
||||
DeleteBulkAction::make(),
|
||||
// Assignation groupée d'un rôle Spatie sans repasser par chaque fiche.
|
||||
BulkAction::make('assignRole')
|
||||
->label('Assigner un rôle')
|
||||
->icon(Heroicon::OutlinedShieldCheck)
|
||||
->color('primary')
|
||||
->schema([
|
||||
Select::make('role')
|
||||
->label('Rôle')
|
||||
->options(fn (): array => Role::query()->pluck('name', 'name')->all())
|
||||
->required(),
|
||||
])
|
||||
->action(function (Collection $records, array $data): void {
|
||||
$records->each(fn ($user) => $user->assignRole($data['role']));
|
||||
})
|
||||
->deselectRecordsAfterCompletion(),
|
||||
]),
|
||||
])
|
||||
->defaultSort('created_at', 'desc');
|
||||
|
||||
@@ -13,12 +13,23 @@ use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Table;
|
||||
use Functional\Users\Models\User;
|
||||
use UnitEnum;
|
||||
|
||||
class UserResource extends Resource
|
||||
{
|
||||
protected static ?string $model = User::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedRectangleStack;
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedUsers;
|
||||
|
||||
protected static string|UnitEnum|null $navigationGroup = 'Communauté';
|
||||
|
||||
protected static ?int $navigationSort = 1;
|
||||
|
||||
protected static ?string $modelLabel = 'utilisateur';
|
||||
|
||||
protected static ?string $pluralModelLabel = 'utilisateurs';
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
@@ -37,6 +48,14 @@ class UserResource extends Resource
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
public static function getGloballySearchableAttributes(): array
|
||||
{
|
||||
return ['name', 'email'];
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Functional\Exercises\Models\Exercise;
|
||||
|
||||
/**
|
||||
* Répartition du catalogue d'exercices par partie du corps ciblée (doughnut).
|
||||
*/
|
||||
class ExercisesByBodyPartChart extends ChartWidget
|
||||
{
|
||||
protected static ?int $sort = 4;
|
||||
|
||||
protected int|string|array $columnSpan = 1;
|
||||
|
||||
/** Palette "flamme" dégradée pour distinguer les parts sans dépendre de couleurs génériques. */
|
||||
private const PALETTE = [
|
||||
'#f59e0b', '#fb923c', '#f97316', '#ea580c', '#c2410c',
|
||||
'#fbbf24', '#fcd34d', '#fde68a', '#d97706', '#b45309',
|
||||
];
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Exercices par partie du corps';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$countsByBodyPart = Exercise::query()
|
||||
->whereNotNull('body_part')
|
||||
->selectRaw('body_part, COUNT(*) as total')
|
||||
->groupBy('body_part')
|
||||
->orderByDesc('total')
|
||||
->pluck('total', 'body_part');
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'data' => $countsByBodyPart->values()->all(),
|
||||
'backgroundColor' => self::PALETTE,
|
||||
],
|
||||
],
|
||||
'labels' => $countsByBodyPart->keys()->all(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'doughnut';
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,8 @@ use Illuminate\Support\Carbon;
|
||||
*/
|
||||
class StreakFitStatsOverview extends StatsOverviewWidget
|
||||
{
|
||||
protected static ?int $sort = 1;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
$sessionsThisWeek = WorkoutSession::query()
|
||||
@@ -29,7 +31,7 @@ class StreakFitStatsOverview extends StatsOverviewWidget
|
||||
->color('primary'),
|
||||
|
||||
Stat::make('Séances', (string) WorkoutSession::query()->count())
|
||||
->description($sessionsThisWeek . ' cette semaine')
|
||||
->description($sessionsThisWeek.' cette semaine')
|
||||
->descriptionIcon('heroicon-m-fire')
|
||||
->color('warning'),
|
||||
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Functional\Tracking\Models\SetLog;
|
||||
|
||||
/**
|
||||
* Top 8 des exercices les plus loggés (nombre de séries), tous utilisateurs confondus.
|
||||
*/
|
||||
class TopExercisesChart extends ChartWidget
|
||||
{
|
||||
protected static ?int $sort = 5;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
private const TOP_COUNT = 8;
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Top 8 des exercices les plus loggés';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$topExercises = SetLog::query()
|
||||
->join('exercises', 'exercises.id', '=', 'set_logs.exercise_id')
|
||||
->selectRaw('exercises.name as name, COUNT(*) as total')
|
||||
->groupBy('exercises.id', 'exercises.name')
|
||||
->orderByDesc('total')
|
||||
->limit(self::TOP_COUNT)
|
||||
->get();
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Séries loguées',
|
||||
'data' => $topExercises->pluck('total')->all(),
|
||||
'backgroundColor' => '#f97316',
|
||||
'borderRadius' => 4,
|
||||
],
|
||||
],
|
||||
'labels' => $topExercises->pluck('name')->all(),
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Functional\Users\Models\User;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Croissance cumulée des utilisateurs inscrits (ligne).
|
||||
*/
|
||||
class UsersGrowthChart extends ChartWidget
|
||||
{
|
||||
protected static ?int $sort = 3;
|
||||
|
||||
protected int|string|array $columnSpan = 1;
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Croissance des utilisateurs';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$countsByDay = User::query()
|
||||
->selectRaw('DATE(created_at) as day, COUNT(*) as total')
|
||||
->groupBy('day')
|
||||
->orderBy('day')
|
||||
->pluck('total', 'day');
|
||||
|
||||
$labels = [];
|
||||
$data = [];
|
||||
$cumulative = 0;
|
||||
|
||||
foreach ($countsByDay as $day => $total) {
|
||||
$cumulative += (int) $total;
|
||||
$labels[] = Carbon::parse($day)->format('d/m/Y');
|
||||
$data[] = $cumulative;
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Utilisateurs inscrits (cumulé)',
|
||||
'data' => $data,
|
||||
'borderColor' => '#f59e0b',
|
||||
'backgroundColor' => 'rgba(245, 158, 11, 0.15)',
|
||||
'fill' => true,
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'line';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Functional\Tracking\Enums\WorkoutSessionStatus;
|
||||
use Functional\Tracking\Models\WorkoutSession;
|
||||
use Illuminate\Support\Carbon;
|
||||
|
||||
/**
|
||||
* Séances complétées par jour sur les 30 derniers jours (barres).
|
||||
* Permet de repérer les pics/creux d'activité de la communauté.
|
||||
*/
|
||||
class WorkoutSessionsPerDayChart extends ChartWidget
|
||||
{
|
||||
protected static ?int $sort = 2;
|
||||
|
||||
protected int|string|array $columnSpan = 'full';
|
||||
|
||||
public function getHeading(): string
|
||||
{
|
||||
return 'Séances complétées (30 derniers jours)';
|
||||
}
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$start = Carbon::now()->subDays(29)->startOfDay();
|
||||
|
||||
// Nombre de séances complétées par jour, sur la fenêtre glissante de 30 jours.
|
||||
$countsByDay = WorkoutSession::query()
|
||||
->where('status', WorkoutSessionStatus::Completed)
|
||||
->where('started_at', '>=', $start)
|
||||
->selectRaw('DATE(started_at) as day, COUNT(*) as total')
|
||||
->groupBy('day')
|
||||
->pluck('total', 'day');
|
||||
|
||||
$labels = [];
|
||||
$data = [];
|
||||
|
||||
// On matérialise chaque jour (même sans séance) pour un axe continu.
|
||||
for ($offset = 0; $offset < 30; $offset++) {
|
||||
$date = $start->copy()->addDays($offset);
|
||||
$key = $date->format('Y-m-d');
|
||||
|
||||
$labels[] = $date->format('d/m');
|
||||
$data[] = (int) ($countsByDay[$key] ?? 0);
|
||||
}
|
||||
|
||||
return [
|
||||
'datasets' => [
|
||||
[
|
||||
'label' => 'Séances complétées',
|
||||
'data' => $data,
|
||||
'backgroundColor' => '#f59e0b',
|
||||
'borderRadius' => 4,
|
||||
],
|
||||
],
|
||||
'labels' => $labels,
|
||||
];
|
||||
}
|
||||
|
||||
protected function getType(): string
|
||||
{
|
||||
return 'bar';
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,12 @@
|
||||
|
||||
namespace App\Providers\Filament;
|
||||
|
||||
use App\Filament\Widgets\ExercisesByBodyPartChart;
|
||||
use App\Filament\Widgets\StreakFitStatsOverview;
|
||||
use App\Filament\Widgets\TopExercisesChart;
|
||||
use App\Filament\Widgets\UsersGrowthChart;
|
||||
use App\Filament\Widgets\WorkoutSessionsPerDayChart;
|
||||
use BezhanSalleh\FilamentShield\FilamentShieldPlugin;
|
||||
use Filament\Http\Middleware\Authenticate;
|
||||
use Filament\Http\Middleware\AuthenticateSession;
|
||||
use Filament\Http\Middleware\DisableBladeIconComponents;
|
||||
@@ -21,10 +26,11 @@ use Illuminate\View\Middleware\ShareErrorsFromSession;
|
||||
/**
|
||||
* Back-office StreakFit (Filament).
|
||||
*
|
||||
* Thème "flamme" : accent orange/amber sur base claire + dark mode.
|
||||
* Thème "flamme" : accent amber/orange sur base zinc + dark mode.
|
||||
* Navigation regroupée par domaine métier (Catalogue, Communauté, Entraînement,
|
||||
* Gamification, Système), dashboard enrichi de charts (cf. app/Filament/Widgets).
|
||||
* Auth via le guard 'web' standard (compatible avec le flow Sanctum SPA du front) ;
|
||||
* l'accès effectif au panel sera verrouillé quand le model User implémentera
|
||||
* Filament\Models\Contracts\FilamentUser::canAccessPanel().
|
||||
* l'accès effectif au panel est verrouillé par User::canAccessPanel() (hasRole('admin')).
|
||||
*/
|
||||
class AdminPanelProvider extends PanelProvider
|
||||
{
|
||||
@@ -35,17 +41,30 @@ class AdminPanelProvider extends PanelProvider
|
||||
->id('admin')
|
||||
->path('admin')
|
||||
->brandName('StreakFit 🔥')
|
||||
->favicon(asset('favicon.ico'))
|
||||
->login()
|
||||
// Guard web standard : n'interfère pas avec l'auth Sanctum du front.
|
||||
->authGuard('web')
|
||||
// Accent "flamme" : orange en primaire, amber en secondaire (warning).
|
||||
// Accent "flamme" : amber en primaire, orange en secondaire (warning), gris zinc neutre.
|
||||
->colors([
|
||||
'primary' => Color::Orange,
|
||||
'warning' => Color::Amber,
|
||||
'primary' => Color::Amber,
|
||||
'warning' => Color::Orange,
|
||||
'danger' => Color::Red,
|
||||
'success' => Color::Emerald,
|
||||
'gray' => Color::Zinc,
|
||||
])
|
||||
// Dark mode disponible via le sélecteur clair/sombre (activé explicitement, non forcé).
|
||||
->darkMode(condition: true, isForced: false)
|
||||
// Barre latérale repliable sur desktop (gain de place sur les grandes tables).
|
||||
->sidebarCollapsibleOnDesktop()
|
||||
// Ordre d'affichage des groupes de navigation dans la sidebar.
|
||||
->navigationGroups([
|
||||
'Catalogue',
|
||||
'Communauté',
|
||||
'Entraînement',
|
||||
'Gamification',
|
||||
'Système',
|
||||
])
|
||||
// Dark mode disponible via le sélecteur clair/sombre (activé par défaut).
|
||||
->discoverResources(in: app_path('Filament/Resources'), for: 'App\Filament\Resources')
|
||||
->discoverPages(in: app_path('Filament/Pages'), for: 'App\Filament\Pages')
|
||||
->pages([
|
||||
@@ -54,6 +73,17 @@ class AdminPanelProvider extends PanelProvider
|
||||
->discoverWidgets(in: app_path('Filament/Widgets'), for: 'App\Filament\Widgets')
|
||||
->widgets([
|
||||
StreakFitStatsOverview::class,
|
||||
WorkoutSessionsPerDayChart::class,
|
||||
UsersGrowthChart::class,
|
||||
ExercisesByBodyPartChart::class,
|
||||
TopExercisesChart::class,
|
||||
])
|
||||
// Gestion des rôles/permissions (Spatie) via Filament Shield — fournit sa propre
|
||||
// RoleResource, rangée dans "Communauté" à côté de l'utilisateur.
|
||||
->plugins([
|
||||
FilamentShieldPlugin::make()
|
||||
->navigationGroup('Communauté')
|
||||
->navigationSort(2),
|
||||
])
|
||||
->middleware([
|
||||
EncryptCookies::class,
|
||||
|
||||
Reference in New Issue
Block a user