feat: Add Filament widgets for journalist metrics, registration trend, and UKW certification status.

This commit is contained in:
Yoga Pangestu 2026-01-29 10:19:40 +07:00
parent 2a7b1cf875
commit a44c7181fd
3 changed files with 121 additions and 0 deletions

View File

@ -0,0 +1,31 @@
<?php
namespace App\Filament\Widgets;
use App\Models\Journalist;
use App\Models\PartnerMedia;
use Filament\Support\Icons\Heroicon;
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
use Filament\Widgets\StatsOverviewWidget\Stat;
class JournalistMetricsStats extends BaseWidget
{
protected static ?int $sort = 7;
protected int|string|array $columnSpan = 1;
protected function getStats(): array
{
$totalJournalists = Journalist::count();
$totalMedia = PartnerMedia::count();
$average = $totalMedia > 0 ? round($totalJournalists / $totalMedia, 1) : 0;
return [
Stat::make('Rata-rata Jurnalis / Media', $average)
->description('Rasio sebaran jurnalis')
->descriptionIcon(Heroicon::Users)
->color('primary'),
];
}
}

View File

@ -0,0 +1,47 @@
<?php
namespace App\Filament\Widgets;
use App\Models\Journalist;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\Facades\DB;
class JournalistRegistrationChart extends ChartWidget
{
protected ?string $heading = 'Tren Pertambahan Jurnalis';
protected static ?int $sort = 8;
protected int|string|array $columnSpan = 'full';
protected function getData(): array
{
$data = Journalist::query()
->select(
DB::raw('COUNT(*) as count'),
DB::raw("DATE_FORMAT(created_at, '%Y-%m') as month")
)
->where('created_at', '>=', now()->subMonths(6))
->groupBy('month')
->orderBy('month')
->get();
return [
'datasets' => [
[
'label' => 'Jurnalis Baru',
'data' => $data->pluck('count')->toArray(),
'fill' => 'start',
'borderColor' => '#6366F1',
'backgroundColor' => 'rgba(99, 102, 241, 0.1)',
],
],
'labels' => $data->pluck('month')->map(fn ($m) => \Carbon\Carbon::createFromFormat('Y-m', $m)->translatedFormat('M Y'))->toArray(),
];
}
protected function getType(): string
{
return 'line';
}
}

View File

@ -0,0 +1,43 @@
<?php
namespace App\Filament\Widgets;
use App\Models\Journalist;
use Filament\Widgets\ChartWidget;
class JournalistUkwChart extends ChartWidget
{
protected ?string $heading = 'Status Sertifikasi UKW Jurnalis';
protected static ?int $sort = 6;
protected int|string|array $columnSpan = 1;
protected function getData(): array
{
$certified = Journalist::whereNotNull('ukw_certificate')
->where('ukw_certificate', '!=', '')
->count();
$notCertified = Journalist::where(function ($query) {
$query->whereNull('ukw_certificate')
->orWhere('ukw_certificate', '');
})->count();
return [
'datasets' => [
[
'label' => 'Jumlah Jurnalis',
'data' => [$certified, $notCertified],
'backgroundColor' => ['#10B981', '#EF4444'],
],
],
'labels' => ['Sudah Sertifikasi UKW', 'Belum Sertifikasi UKW'],
];
}
protected function getType(): string
{
return 'doughnut';
}
}