refactor: Consolidate journalist statistics into OverviewStats widget, removing dedicated JournalistMetricsStats and JournalistUkwChart widgets and their permissions.
This commit is contained in:
parent
98d30a80e6
commit
69e3db9ce3
@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Journalist;
|
||||
use App\Models\PartnerMedia;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
use Filament\Widgets\StatsOverviewWidget as BaseWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
|
||||
class JournalistMetricsStats extends BaseWidget
|
||||
{
|
||||
use HasWidgetShield, InteractsWithPageFilters;
|
||||
|
||||
protected static ?int $sort = 7;
|
||||
|
||||
protected int|string|array $columnSpan = 1;
|
||||
|
||||
protected function getStats(): array
|
||||
{
|
||||
$startDate = $this->filters['startDate'] ?? null;
|
||||
$endDate = $this->filters['endDate'] ?? null;
|
||||
|
||||
$totalJournalists = Journalist::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
->count();
|
||||
|
||||
$totalMedia = PartnerMedia::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
->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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Models\Journalist;
|
||||
use BezhanSalleh\FilamentShield\Traits\HasWidgetShield;
|
||||
use Filament\Widgets\ChartWidget;
|
||||
use Filament\Widgets\Concerns\InteractsWithPageFilters;
|
||||
|
||||
class JournalistUkwChart extends ChartWidget
|
||||
{
|
||||
use HasWidgetShield, InteractsWithPageFilters;
|
||||
|
||||
protected ?string $heading = 'Status Sertifikasi UKW Jurnalis';
|
||||
|
||||
protected static ?int $sort = 6;
|
||||
|
||||
protected int|string|array $columnSpan = 1;
|
||||
|
||||
protected function getData(): array
|
||||
{
|
||||
$startDate = $this->filters['startDate'] ?? null;
|
||||
$endDate = $this->filters['endDate'] ?? null;
|
||||
|
||||
$certified = Journalist::whereNotNull('ukw_certificate')
|
||||
->where('ukw_certificate', '!=', '')
|
||||
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
->count();
|
||||
|
||||
$notCertified = Journalist::where(function ($query) {
|
||||
$query->whereNull('ukw_certificate')
|
||||
->orWhere('ukw_certificate', '');
|
||||
})
|
||||
->when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
->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';
|
||||
}
|
||||
}
|
||||
@ -27,6 +27,16 @@ protected function getStats(): array
|
||||
$startDate = $this->filters['startDate'] ?? null;
|
||||
$endDate = $this->filters['endDate'] ?? null;
|
||||
|
||||
$totalJournalists = Journalist::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
->count();
|
||||
|
||||
$totalMedia = PartnerMedia::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
->count();
|
||||
|
||||
$average = $totalMedia > 0 ? round($totalJournalists / $totalMedia, 1) : 0;
|
||||
|
||||
return [
|
||||
Stat::make('Total Perusahaan', Company::when($startDate, fn ($q) => $q->whereDate('created_at', '>=', $startDate))
|
||||
->when($endDate, fn ($q) => $q->whereDate('created_at', '<=', $endDate))
|
||||
@ -72,6 +82,11 @@ protected function getStats(): array
|
||||
->description('Total traffic')
|
||||
->descriptionIcon(Heroicon::ChartBar)
|
||||
->color('info'),
|
||||
|
||||
Stat::make('Rata-rata Jurnalis / Media', $average)
|
||||
->description('Rasio sebaran jurnalis')
|
||||
->descriptionIcon(Heroicon::Users)
|
||||
->color('primary'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@ -134,12 +134,8 @@ public function run(): void
|
||||
"Replicate:IssueManagement",
|
||||
"Reorder:IssueManagement",
|
||||
|
||||
"View:JournalistMetricsStats",
|
||||
|
||||
"View:JournalistRegistrationChart",
|
||||
|
||||
"View:JournalistUkwChart",
|
||||
|
||||
"ViewAny:Location",
|
||||
"View:Location",
|
||||
"Create:Location",
|
||||
@ -395,12 +391,8 @@ public function run(): void
|
||||
"Replicate:IssueManagement",
|
||||
"Reorder:IssueManagement",
|
||||
|
||||
"View:JournalistMetricsStats",
|
||||
|
||||
"View:JournalistRegistrationChart",
|
||||
|
||||
"View:JournalistUkwChart",
|
||||
|
||||
"ViewAny:Location",
|
||||
"View:Location",
|
||||
"Create:Location",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user