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:
@@ -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';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user