-
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
1,130 additions
and
1,257 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
app/Filament/Resources/ArticleResource/Widgets/ArticleStatsOverview.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ArticleResource\Widgets; | ||
|
||
use App\Models\Article; | ||
use Filament\Widgets\StatsOverviewWidget as BaseWidget; | ||
use Filament\Widgets\StatsOverviewWidget\Stat; | ||
use Flowframe\Trend\Trend; | ||
use Flowframe\Trend\TrendValue; | ||
|
||
final class ArticleStatsOverview extends BaseWidget | ||
{ | ||
protected static ?string $pollingInterval = null; | ||
|
||
protected ?string $heading = 'Article'; | ||
|
||
protected function getColumns(): int | ||
{ | ||
return 2; | ||
} | ||
|
||
protected function getStats(): array | ||
{ | ||
$currentWeekStart = now()->startOfWeek(); | ||
$currentWeekEnd = now()->endOfWeek(); | ||
|
||
return [ | ||
Stat::make('Total Article', Article::query()->published()->count()) | ||
->icon('heroicon-o-newspaper') | ||
->chart( | ||
Trend::query(Article::query()->published()) | ||
->between( | ||
start: $currentWeekStart, | ||
end: $currentWeekEnd, | ||
)->perDay() | ||
->count() | ||
->map(fn (TrendValue $value) => $value->aggregate)->toArray() | ||
)->description(__('Total des articles postés')), | ||
|
||
Stat::make( | ||
'Article récent publié', | ||
Article::query() | ||
->recent() | ||
->whereBetween('created_at', [ | ||
$currentWeekStart, | ||
$currentWeekEnd, | ||
])->count() | ||
) | ||
->chart( | ||
Trend::query(Article::query()) | ||
->between( | ||
start: $currentWeekStart, | ||
end: $currentWeekEnd, | ||
) | ||
->perDay() | ||
->count() | ||
->map(fn (TrendValue $value) => $value->aggregate) | ||
->toArray() | ||
)->icon('heroicon-o-newspaper') | ||
->color('primary') | ||
->description('Total des articles Postés de la semaine'), | ||
]; | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
app/Filament/Resources/ArticleResource/Widgets/MostLikedPostsChart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ArticleResource\Widgets; | ||
|
||
use App\Models\Article; | ||
use Filament\Widgets\ChartWidget; | ||
use Illuminate\Support\Str; | ||
|
||
final class MostLikedPostsChart extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Article le plus aimé'; | ||
|
||
protected static ?string $maxHeight = '200px'; | ||
|
||
protected int|string|array $columnSpan = 'full'; | ||
|
||
protected int $titleLength = 30; | ||
|
||
protected function getData(): array | ||
{ | ||
$articles = Article::published() | ||
->popular() | ||
->limit(10) | ||
->get(); | ||
|
||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Total aimé', | ||
'data' => $articles->pluck('reactions_count')->toArray(), | ||
], | ||
], | ||
'labels' => $articles->pluck('title') | ||
->map(fn ($title) => Str::limit($title, $this->titleLength, '...')) | ||
->toArray(), | ||
]; | ||
} | ||
|
||
protected function getType(): string | ||
{ | ||
return 'bar'; | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'scales' => [ | ||
'y' => [ | ||
'beginAtZero' => true, | ||
], | ||
], | ||
]; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
app/Filament/Resources/ArticleResource/Widgets/MostViewedPostsChart.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\ArticleResource\Widgets; | ||
|
||
use App\Models\Article; | ||
use CyrildeWit\EloquentViewable\Support\Period; | ||
use Filament\Widgets\ChartWidget; | ||
use Illuminate\Support\Str; | ||
|
||
final class MostViewedPostsChart extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Article le plus vu cette semaine'; | ||
|
||
protected static ?string $maxHeight = '200px'; | ||
|
||
protected int|string|array $columnSpan = 'full'; | ||
|
||
protected int $titleLength = 10; | ||
|
||
protected function getData(): array | ||
{ | ||
$articles = Article::withViewsCount(Period::create(now()->startOfWeek(), now()->endOfWeek())) // @phpstan-ignore-line | ||
->published() | ||
->orderByDesc('views_count') | ||
->orderByDesc('published_at') | ||
->limit(10) | ||
->get(); | ||
|
||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Article le plus vu', | ||
'data' => $articles->pluck('views_count')->toArray(), | ||
], | ||
], | ||
'labels' => $articles->pluck('title') | ||
->map(fn ($title) => Str::limit($title, $this->titleLength, '...')) | ||
->toArray(), | ||
]; | ||
} | ||
|
||
protected function getType(): string | ||
{ | ||
return 'bar'; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
app/Filament/Resources/UserResource/Widgets/UserActivityWidget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\UserResource\Widgets; | ||
|
||
use App\Models\User; | ||
use Filament\Widgets\ChartWidget; | ||
use Illuminate\Database\Eloquent\Builder; | ||
|
||
final class UserActivityWidget extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Les utilisateurs les plus actifs cette semaine'; | ||
|
||
protected int|string|array $columnSpan = 'full'; | ||
|
||
protected static ?string $maxHeight = '200px'; | ||
|
||
protected function getData(): array | ||
{ | ||
$users = User::with('activities') | ||
->withCount('activities') | ||
->verifiedUsers() | ||
->whereHas('activities', fn (Builder $query) => $query->whereBetween('created_at', [ | ||
now()->startOfWeek(), | ||
now()->endOfWeek(), | ||
])) | ||
->orderByDesc('activities_count') | ||
->limit(10) | ||
->get(); | ||
|
||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Total des activités', | ||
'data' => $users->pluck('activities_count')->toArray(), | ||
], | ||
], | ||
'labels' => $users->pluck('name')->toArray(), | ||
]; | ||
} | ||
|
||
protected function getType(): string | ||
{ | ||
return 'bar'; | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'scales' => [ | ||
'y' => [ | ||
'beginAtZero' => true, | ||
], | ||
], | ||
]; | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
app/Filament/Resources/UserResource/Widgets/UserChartWidget.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Filament\Resources\UserResource\Widgets; | ||
|
||
use App\Models\User; | ||
use Filament\Widgets\ChartWidget; | ||
use Flowframe\Trend\Trend; | ||
use Flowframe\Trend\TrendValue; | ||
|
||
final class UserChartWidget extends ChartWidget | ||
{ | ||
protected static ?string $heading = 'Création de compte'; | ||
|
||
protected int|string|array $columnSpan = 'full'; | ||
|
||
protected static ?string $maxHeight = '200px'; | ||
|
||
public ?string $filter = 'week'; | ||
|
||
protected function getColumns(): int | ||
{ | ||
return 2; | ||
} | ||
|
||
protected function getFilters(): array | ||
{ | ||
return [ | ||
'week' => 'Last Week', | ||
'month' => 'Last Month', | ||
'3months' => 'Last 3 Months', | ||
]; | ||
} | ||
|
||
protected function getData(): array | ||
{ | ||
match ($this->filter) { // @phpstan-ignore-line | ||
'week' => $data = Trend::model(User::class) | ||
->between( | ||
start: now()->subWeeks(), | ||
end: now() | ||
) | ||
->perDay() | ||
->count(), | ||
|
||
'month' => $data = Trend::model(User::class) | ||
->between( | ||
start: now()->subMonth(), | ||
end: now() | ||
) | ||
->perDay() | ||
->count(), | ||
|
||
'3months' => $data = Trend::model(User::class) | ||
->between( | ||
start: now()->subMonths(3), | ||
end: now() | ||
) | ||
->perMonth() | ||
->count(), | ||
}; | ||
|
||
return [ | ||
'datasets' => [ | ||
[ | ||
'label' => 'Compte créé', | ||
'data' => $data->map(fn (TrendValue $value) => $value->aggregate), // @phpstan-ignore-line | ||
], | ||
], | ||
'labels' => $data->map(fn (TrendValue $value) => $value->date), // @phpstan-ignore-line | ||
]; | ||
} | ||
|
||
protected function getType(): string | ||
{ | ||
return 'line'; | ||
} | ||
|
||
protected function getOptions(): array | ||
{ | ||
return [ | ||
'scales' => [ | ||
'y' => [ | ||
'beginAtZero' => true, | ||
], | ||
], | ||
]; | ||
} | ||
} |
Oops, something went wrong.