Skip to content

Commit

Permalink
merge develop into main
Browse files Browse the repository at this point in the history
  • Loading branch information
mckenziearts committed Jan 11, 2025
2 parents 4dbee6e + aabc17a commit ed5f911
Show file tree
Hide file tree
Showing 70 changed files with 1,130 additions and 1,257 deletions.
44 changes: 34 additions & 10 deletions app/Filament/Resources/ArticleResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
use App\Actions\Article\ApprovedArticleAction;
use App\Filament\Resources\ArticleResource\Pages;
use App\Models\Article;
use Awcodes\FilamentBadgeableColumn\Components\Badge;
use Awcodes\FilamentBadgeableColumn\Components\BadgeableColumn;
use Filament\Resources\Resource;
use Filament\Support\Enums\MaxWidth;
use Filament\Tables;
Expand Down Expand Up @@ -67,16 +69,38 @@ public static function table(Table $table): Table
->label('Soumission')
->placeholder('N/A')
->date(),
Tables\Columns\TextColumn::make('approved_at')
->label('Approbation')
->placeholder('N/A')
->date()
->toggleable(),
Tables\Columns\TextColumn::make('declined_at')
->label('Décliner')
->placeholder('N/A')
->date()
->toggleable(isToggledHiddenByDefault: true),
BadgeableColumn::make('status')
->label('Statut')
->getStateUsing(function ($record) {
if ($record->approved_at) {
return $record->approved_at->format('d/m/Y');
}

if ($record->declined_at) {
return $record->declined_at->format('d/m/Y');
}

return '';
})
->prefixBadges(function ($record) {
if ($record->approved_at) {
return [
Badge::make('Approuvé')
->color('success'),
];
}

if ($record->declined_at) {
return [
Badge::make('Décliné')
->color('danger'),
];
}

return '';
})
->searchable()
->sortable(),
])
->actions([
ActionGroup::make([
Expand Down
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'),
];
}
}
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,
],
],
];
}
}
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 app/Filament/Resources/UserResource/Widgets/UserActivityWidget.php
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 app/Filament/Resources/UserResource/Widgets/UserChartWidget.php
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,
],
],
];
}
}
Loading

0 comments on commit ed5f911

Please sign in to comment.