Initial commit: Pireon Admin — headless admin panel and public API
Laravel 13 + Filament 5 admin panel and REST API for a non-profit developer collective, backed by the Pireon OAuth identity server. The public site is a separate, server-rendered application consuming /api/public/v1. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
60
app/Filament/Widgets/ContentOverview.php
Normal file
60
app/Filament/Widgets/ContentOverview.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Widgets;
|
||||
|
||||
use App\Enums\PageStatus;
|
||||
use App\Models\Page;
|
||||
use App\Models\User;
|
||||
use Filament\Widgets\StatsOverviewWidget;
|
||||
use Filament\Widgets\StatsOverviewWidget\Stat;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ContentOverview extends StatsOverviewWidget
|
||||
{
|
||||
protected function getStats(): array
|
||||
{
|
||||
return [
|
||||
Stat::make(__('panel.widgets.stats.pages'), Page::query()->count())
|
||||
->icon('heroicon-o-document-text')
|
||||
->color('primary'),
|
||||
|
||||
Stat::make(__('panel.widgets.stats.published'), Page::query()->published()->count())
|
||||
->icon('heroicon-o-check-circle')
|
||||
->color('success'),
|
||||
|
||||
// The metric an editorial team actually acts on: content that is
|
||||
// live in one language but still missing in another.
|
||||
Stat::make(__('panel.widgets.stats.missing_translations'), $this->untranslatedCount())
|
||||
->description(__('panel.widgets.stats.missing_translations_hint'))
|
||||
->icon('heroicon-o-language')
|
||||
->color($this->untranslatedCount() > 0 ? 'warning' : 'gray'),
|
||||
|
||||
Stat::make(__('panel.widgets.stats.users'), User::query()->active()->count())
|
||||
->icon('heroicon-o-users')
|
||||
->color('gray'),
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Pages lacking a title in at least one supported locale.
|
||||
*/
|
||||
protected function untranslatedCount(): int
|
||||
{
|
||||
return Page::query()
|
||||
->where('status', '!=', PageStatus::Archived)
|
||||
->where(function (Builder $query): void {
|
||||
foreach (array_keys(config('locales.supported')) as $locale) {
|
||||
$query->orWhereNull("title->{$locale}")
|
||||
->orWhere("title->{$locale}", '');
|
||||
}
|
||||
})
|
||||
->count();
|
||||
}
|
||||
|
||||
public static function canView(): bool
|
||||
{
|
||||
return auth()->user()?->can('pages.view_any') ?? false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user