From bea1fe101a7f62dd45576183871246e25c5f78ff Mon Sep 17 00:00:00 2001 From: rsgrinko Date: Thu, 17 Sep 2026 16:00:47 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9E=D0=B1=D0=B7=D0=BE=D1=80:=20=D0=BA=D0=B0?= =?UTF-8?q?=D1=80=D1=82=D0=BE=D1=87=D0=BA=D0=B8=20=D1=80=D0=BE=D0=BB=D0=B5?= =?UTF-8?q?=D0=B9,=20=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=B9=20API,=20=D0=B2?= =?UTF-8?q?=D0=B5=D0=B1=D1=85=D1=83=D0=BA=D0=BE=D0=B2=20=D0=B8=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BF=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/Support/Widgets.php | 43 +++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/framework/Support/Widgets.php b/framework/Support/Widgets.php index 528b7bf..70c64fa 100644 --- a/framework/Support/Widgets.php +++ b/framework/Support/Widgets.php @@ -6,8 +6,12 @@ namespace Rsgrinko\Proton\Support; use Rsgrinko\Proton\Access\Permission; use Rsgrinko\Proton\Access\Viewer; +use Rsgrinko\Proton\Backup\Backup; use Rsgrinko\Proton\Cache\Cache; +use Rsgrinko\Proton\Models\ApiToken; +use Rsgrinko\Proton\Models\Role; use Rsgrinko\Proton\Models\User; +use Rsgrinko\Proton\Models\Webhook; use Rsgrinko\Proton\Queue\Queue; /** @@ -104,6 +108,34 @@ final class Widgets ]; }); + self::register('roles', 'Роли', Permission::ROLES_MANAGE, static function (): array { + return [ + 'value' => Role::query()->count(), + 'hint' => Role::query()->where('is_system', 0)->count() . ' своих', + 'route' => 'admin.roles', + ]; + }); + + self::register('tokens', 'Ключи API', Permission::USERS_MANAGE, static function (): array { + $expiring = count(ApiToken::expiringWithin(30)); + + return [ + 'value' => ApiToken::query()->where('active', 1)->count(), + 'hint' => $expiring > 0 ? $expiring . ' истекают в этом месяце' : 'сроки в порядке', + 'route' => 'admin.tokens', + ]; + }); + + self::register('webhooks', 'Вебхуки', Permission::WEBHOOKS_MANAGE, static function (): array { + $failing = Webhook::query()->where('active', 1)->where('failures', '>', 0)->count(); + + return [ + 'value' => Webhook::query()->where('active', 1)->count(), + 'hint' => $failing > 0 ? $failing . ' со сбоями' : 'сбоев нет', + 'route' => 'admin.webhooks', + ]; + }); + self::register('queue', 'В очереди', Permission::SYSTEM_MANAGE, static function (): array { $stats = Queue::stats(); @@ -114,6 +146,17 @@ final class Widgets ]; }); + self::register('backups', 'Копии', Permission::SYSTEM_MANAGE, static function (): array { + $files = Backup::files(); + $last = $files[0] ?? null; + + return [ + 'value' => count($files), + 'hint' => $last === null ? 'копий ещё нет' : 'последняя ' . date('d.m в H:i', strtotime((string) $last['created'])), + 'route' => 'admin.backups', + ]; + }); + self::register('health', 'Состояние', Permission::SYSTEM_VIEW, static function (): array { $checks = Diagnostics::run(); $worst = Diagnostics::worst($checks);