initial commit

This commit is contained in:
rsgrinko committed 2026-09-12 23:55:44 +03:00
commit 3f64f4a49a
221 files changed
+26665

No files matched your search

+102
View File
@@ -0,0 +1,102 @@
<?php
declare(strict_types=1);
/**
* Журнал действий.
*
* @var array{items: array<int, \Rsgrinko\Proton\Models\AuditEntry>, total: int, page: int, pages: int, per_page: int} $page
* @var array<string, string> $filters
* @var array<string, string> $actions
*/
use Rsgrinko\Proton\Models\AuditEntry;
use Rsgrinko\Proton\View\View;
?>
<h1>Журнал действий</h1>
<div class="card">
<form method="get" action="<?= View::e(View::route('admin.audit')) ?>">
<div class="filters">
<label>
<span>Действие</span>
<select name="action">
<option value="">любое</option>
<?php foreach ($actions as $code => $label) { ?>
<option value="<?= View::e($code) ?>" <?= $filters['action'] === $code ? 'selected' : '' ?>><?= View::e($label) ?></option>
<?php } ?>
</select>
</label>
<label>
<span>Раздел</span>
<input type="text" name="entity" value="<?= View::e($filters['entity']) ?>" placeholder="user, role, note">
</label>
<label>
<span>Поиск по описанию</span>
<input type="search" name="q" value="<?= View::e($filters['q']) ?>">
</label>
</div>
<div class="filter-actions row">
<button type="submit" class="primary">Показать</button>
<a class="btn" href="<?= View::e(View::route('admin.audit')) ?>">Сбросить</a>
<span class="spacer"></span>
<span class="muted small">Записей: <?= (int) $page['total'] ?></span>
</div>
</form>
</div>
<div class="card">
<?php if ($page['items'] === []) { ?>
<p class="muted">Ничего не нашлось.</p>
<?php } else { ?>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Когда</th>
<th>Кто</th>
<th>Действие</th>
<th>Описание</th>
<th class="hide-sm">Адрес</th>
</tr>
<?php foreach ($page['items'] as $entry) { ?>
<?php $changes = (array) ($entry->changes ?? []); ?>
<tr>
<td class="muted small nowrap"><?= View::e(View::date((string) $entry->raw('created_at'))) ?></td>
<td><?= View::e((string) $entry->raw('user_login') ?: 'система') ?></td>
<td><span class="badge muted"><?= View::e(AuditEntry::label((string) $entry->raw('action'))) ?></span></td>
<td>
<?= View::e((string) $entry->raw('description')) ?>
<div class="muted small"><?= View::e((string) $entry->raw('entity')) ?> <?= View::e((string) $entry->raw('entity_id')) ?></div>
<?php if ($changes !== []) { ?>
<details>
<summary class="small">что изменилось</summary>
<table>
<?php foreach ($changes as $field => $pair) { ?>
<tr>
<td class="muted small"><?= View::e((string) $field) ?></td>
<td class="small break"><?= View::e((string) ($pair[0] ?? '')) ?> → <?= View::e((string) ($pair[1] ?? '')) ?></td>
</tr>
<?php } ?>
</table>
</details>
<?php } ?>
</td>
<td class="hide-sm mono small"><?= View::e((string) $entry->raw('ip')) ?></td>
</tr>
<?php } ?>
</table>
</div>
<?= View::partial('pagination', [
'route' => 'admin.audit',
'page' => $page['page'],
'pages' => $page['pages'],
'params' => $filters,
]) ?>
<?php } ?>
</div>
+77
View File
@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
/**
* Обзор панели.
*
* @var array{users: int, active: int, notes: int, queue: array<string, int>} $stats
* @var string $health
* @var array<int, \Rsgrinko\Proton\Models\AuditEntry> $events
*/
use Rsgrinko\Proton\Models\AuditEntry;
use Rsgrinko\Proton\View\View;
$badge = ['ok' => 'ok', 'warn' => 'warn', 'error' => 'error'][$health] ?? 'muted';
$label = ['ok' => 'всё в порядке', 'warn' => 'есть замечания', 'error' => 'есть проблемы'][$health] ?? $health;
?>
<h1>Панель</h1>
<div class="grid cols-4">
<div class="card stat">
<div class="label">Пользователей</div>
<div class="value"><?= (int) $stats['users'] ?></div>
<div class="muted small">активных: <?= (int) $stats['active'] ?></div>
</div>
<div class="card stat">
<div class="label">Заметок</div>
<div class="value"><?= (int) $stats['notes'] ?></div>
</div>
<div class="card stat">
<div class="label">В очереди</div>
<div class="value"><?= (int) ($stats['queue']['queued'] ?? 0) ?></div>
<div class="muted small">с ошибкой: <?= (int) ($stats['queue']['failed'] ?? 0) ?></div>
</div>
<a class="card stat" href="<?= View::e(View::route('admin.system')) ?>">
<div class="label">Состояние</div>
<div class="value"><span class="badge <?= View::e($badge) ?>"><?= View::e($label) ?></span></div>
<div class="muted small">подробности на странице состояния</div>
</a>
</div>
<div class="card">
<h2>Последние действия</h2>
<?php if ($events === []) { ?>
<p class="muted">Журнал пуст.</p>
<?php } else { ?>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Когда</th>
<th>Кто</th>
<th>Что</th>
</tr>
<?php foreach ($events as $event) { ?>
<tr>
<td class="muted small nowrap"><?= View::e(View::date((string) $event->raw('created_at'))) ?></td>
<td><?= View::e((string) $event->raw('user_login')) ?></td>
<td>
<span class="badge muted"><?= View::e(AuditEntry::label((string) $event->raw('action'))) ?></span>
<?= View::e((string) $event->raw('description')) ?>
</td>
</tr>
<?php } ?>
</table>
</div>
<?php if (View::can('audit.view')) { ?>
<p style="margin-top: 12px;"><a href="<?= View::e(View::route('admin.audit')) ?>">Весь журнал →</a></p>
<?php } ?>
<?php } ?>
</div>
+97
View File
@@ -0,0 +1,97 @@
<?php
declare(strict_types=1);
/**
* Логи: список файлов и последние строки выбранного.
*
* @var array<int, array{name: string, path: string, size: int, mtime: int}> $files
* @var string $current
* @var array<int, array{time: string, level: string, channel: string, message: string, context: string}> $lines
* @var array<string, string> $filters
*/
use Rsgrinko\Proton\Support\Str;
use Rsgrinko\Proton\View\View;
$badges = ['error' => 'error', 'warning' => 'warn', 'info' => 'info', 'debug' => 'muted'];
?>
<h1>Логи</h1>
<div class="card">
<form method="get" action="<?= View::e(View::route('admin.logs')) ?>">
<div class="filters">
<label>
<span>Файл</span>
<select name="file">
<?php foreach ($files as $file) { ?>
<option value="<?= View::e($file['name']) ?>" <?= $current === $file['name'] ? 'selected' : '' ?>>
<?= View::e($file['name']) ?> (<?= View::e(Str::bytes($file['size'])) ?>)
</option>
<?php } ?>
</select>
</label>
<label>
<span>Уровень</span>
<select name="level">
<option value="">любой</option>
<?php foreach (['debug' => 'отладка', 'info' => 'информация', 'warning' => 'предупреждение', 'error' => 'ошибка'] as $code => $label) { ?>
<option value="<?= View::e($code) ?>" <?= $filters['level'] === $code ? 'selected' : '' ?>><?= View::e($label) ?></option>
<?php } ?>
</select>
</label>
<label>
<span>Поиск по строке</span>
<input type="search" name="q" value="<?= View::e($filters['q']) ?>">
</label>
</div>
<div class="filter-actions row">
<button type="submit" class="primary">Показать</button>
<a class="btn" href="<?= View::e(View::route('admin.logs')) ?>">Сбросить</a>
<span class="spacer"></span>
<span class="muted small">Показано строк: <?= count($lines) ?> (последние 500 файла)</span>
</div>
</form>
</div>
<div class="card">
<?php if ($files === []) { ?>
<p class="muted">Файлов логов ещё нет.</p>
<?php } elseif ($lines === []) { ?>
<p class="muted">Под фильтр ничего не подошло.</p>
<?php } else { ?>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Время</th>
<th>Уровень</th>
<th class="hide-sm">Канал</th>
<th>Сообщение</th>
</tr>
<?php foreach ($lines as $line) { ?>
<tr>
<td class="muted small nowrap"><?= View::e($line['time']) ?></td>
<td><span class="badge <?= View::e($badges[$line['level']] ?? 'muted') ?>"><?= View::e($line['level']) ?></span></td>
<td class="hide-sm muted small"><?= View::e($line['channel']) ?></td>
<td>
<?= View::e(Str::limit($line['message'], 200)) ?>
<?php if ($line['context'] !== '') { ?>
<?php /* Контекст с трассой бывает на десятки килобайт: под спойлером
он не распирает таблицу, но остаётся под рукой */ ?>
<details>
<summary class="small">контекст (<?= View::e(Str::bytes(strlen($line['context']))) ?>)</summary>
<pre class="break small"><?= View::e($line['context']) ?></pre>
</details>
<?php } ?>
</td>
</tr>
<?php } ?>
</table>
</div>
<?php } ?>
</div>
+74
View File
@@ -0,0 +1,74 @@
<?php
declare(strict_types=1);
/**
* Карточка роли: название и галочки прав по разделам.
*
* @var \Rsgrinko\Proton\Models\Role $role
* @var array<string, array<string, string>> $groups права по разделам
*/
use Rsgrinko\Proton\View\View;
$isNew = !$role->existsInDatabase();
$action = $isNew ? View::route('admin.roles.create') : View::route('admin.roles.show', ['id' => $role->id()]);
$granted = $role->permissions();
?>
<h1><?= $isNew ? 'Новая роль' : View::e((string) $role->name) ?></h1>
<div class="card">
<form method="post" action="<?= View::e($action) ?>">
<?= View::csrf() ?>
<label>
<span>Название</span>
<input type="text" name="name" value="<?= View::e((string) $role->name) ?>" <?= $isNew ? 'autofocus' : '' ?> required>
</label>
<label>
<span>Описание</span>
<input type="text" name="description" value="<?= View::e((string) $role->description) ?>">
</label>
<?php if ($role->isSystem()) { ?>
<p class="muted small">
Это встроенная роль: её права берутся из кода и включают всё, что появится в дальнейшем.
Менять их нельзя — иначе после нового раздела администратор остался бы без доступа к нему.
</p>
<?php } else { ?>
<h2 style="margin-top: 16px;">Права</h2>
<?php foreach ($groups as $title => $permissions) { ?>
<div class="card">
<h2><?= View::e($title) ?></h2>
<?php foreach ($permissions as $code => $label) { ?>
<label class="inline" style="margin-bottom: 6px;">
<input type="checkbox" name="permissions[]" value="<?= View::e($code) ?>"
<?= in_array($code, $granted, true) ? 'checked' : '' ?>>
<span><?= View::e($label) ?> <span class="muted mono"><?= View::e($code) ?></span></span>
</label>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
<div class="row">
<button type="submit" class="primary">Сохранить</button>
<a class="btn" href="<?= View::e(View::route('admin.roles')) ?>">К списку</a>
</div>
</form>
</div>
<?php if (!$isNew && !$role->isSystem()) { ?>
<div class="card">
<h2>Удаление</h2>
<p class="muted small">Роль удаляется, только если она никому не выдана.</p>
<form method="post" action="<?= View::e(View::route('admin.roles.delete', ['id' => $role->id()])) ?>">
<?= View::csrf() ?>
<button type="submit" class="danger">Удалить роль</button>
</form>
</div>
<?php } ?>
+48
View File
@@ -0,0 +1,48 @@
<?php
declare(strict_types=1);
/**
* Список ролей.
*
* @var array<int, \Rsgrinko\Proton\Models\Role> $roles
*/
use Rsgrinko\Proton\View\View;
?>
<div class="row">
<h1 style="margin: 0;">Роли</h1>
<span class="spacer"></span>
<a class="btn primary" href="<?= View::e(View::route('admin.roles.create')) ?>">Новая роль</a>
</div>
<div class="card" style="margin-top: 16px;">
<p class="muted small">
Роль — набор прав под именем. Пользователю выдаётся одна роль: поменяли её —
поменялось у всех, кому она выдана. Права встроенной роли берутся из кода,
поэтому новый раздел администратору доступен сразу.
</p>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Название</th>
<th class="hide-sm">Описание</th>
<th>Прав</th>
<th>Пользователей</th>
</tr>
<?php foreach ($roles as $role) { ?>
<tr>
<td>
<a href="<?= View::e(View::route('admin.roles.show', ['id' => $role->id()])) ?>"><?= View::e((string) $role->name) ?></a>
<?php if ($role->isSystem()) { ?><span class="badge info">встроенная</span><?php } ?>
</td>
<td class="hide-sm muted small"><?= View::e((string) $role->description) ?></td>
<td><?= count($role->permissions()) ?></td>
<td><?= $role->usersCount() ?></td>
</tr>
<?php } ?>
</table>
</div>
</div>
+168
View File
@@ -0,0 +1,168 @@
<?php
declare(strict_types=1);
/**
* Состояние: самопроверка, очередь, расписание, подписки и обслуживание.
*
* @var array<int, array{level: string, title: string, value: string, hint: string}> $checks
* @var string $health
* @var array<string, int> $queue
* @var array<int, array{name: string, interval: int, at: string, last: string}> $schedule
* @var array<string, int> $events
* @var array<string, string> $settings
* @var string $php
*/
use Rsgrinko\Proton\Support\Diagnostics;
use Rsgrinko\Proton\View\View;
$badges = [Diagnostics::OK => 'ok', Diagnostics::WARN => 'warn', Diagnostics::ERROR => 'error'];
$labels = [Diagnostics::OK => 'в порядке', Diagnostics::WARN => 'внимание', Diagnostics::ERROR => 'проблема'];
?>
<h1>Состояние</h1>
<div class="card">
<h2>Самопроверка</h2>
<div class="checks">
<?php foreach ($checks as $check) { ?>
<div class="item">
<span class="badge <?= View::e($badges[$check['level']] ?? 'muted') ?>"><?= View::e($labels[$check['level']] ?? $check['level']) ?></span>
<span class="title"><?= View::e($check['title']) ?></span>
<span><?= View::e($check['value']) ?></span>
<?php if ($check['hint'] !== '') { ?>
<span class="hint">— <?= View::e($check['hint']) ?></span>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<div class="grid cols-2">
<div class="card">
<h2>Очередь задач</h2>
<div class="table-wrap">
<table>
<?php foreach (['queued' => 'в очереди', 'running' => 'выполняется', 'done' => 'выполнено', 'failed' => 'с ошибкой'] as $status => $label) { ?>
<tr>
<td><?= View::e($label) ?></td>
<td class="right"><?= (int) ($queue[$status] ?? 0) ?></td>
</tr>
<?php } ?>
</table>
</div>
<?php if (View::can('system.manage')) { ?>
<div class="row" style="margin-top: 12px;">
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'queue-retry'])) ?>">
<?= View::csrf() ?>
<button type="submit">Повторить упавшие</button>
</form>
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'queue-purge'])) ?>">
<?= View::csrf() ?>
<button type="submit">Подчистить</button>
</form>
</div>
<?php } ?>
</div>
<div class="card">
<h2>Расписание</h2>
<?php if ($schedule === []) { ?>
<p class="muted small">Задачи объявляются в config/schedule.php.</p>
<?php } else { ?>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Задача</th>
<th>Когда</th>
<th>Последний раз</th>
</tr>
<?php foreach ($schedule as $task) { ?>
<tr>
<td class="mono small"><?= View::e($task['name']) ?></td>
<td class="small"><?= View::e($task['at'] !== '' ? 'ежедневно в ' . $task['at'] : 'раз в ' . $task['interval'] . ' с') ?></td>
<td class="muted small"><?= View::e($task['last'] === '' ? 'ни разу' : View::ago($task['last'])) ?></td>
</tr>
<?php } ?>
</table>
</div>
<?php } ?>
<?php if (View::can('system.manage')) { ?>
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'schedule-run'])) ?>" style="margin-top: 12px;">
<?= View::csrf() ?>
<button type="submit">Выполнить, что пора</button>
</form>
<?php } ?>
</div>
</div>
<div class="grid cols-2">
<div class="card">
<h2>Подписки на события</h2>
<?php if ($events === []) { ?>
<p class="muted small">Подписок нет. Они объявляются в config/events.php.</p>
<?php } else { ?>
<div class="table-wrap">
<table>
<?php foreach ($events as $event => $count) { ?>
<tr>
<td class="mono small"><?= View::e($event) ?></td>
<td class="right"><?= (int) $count ?></td>
</tr>
<?php } ?>
</table>
</div>
<?php } ?>
</div>
<div class="card">
<h2>Обслуживание</h2>
<p class="muted small">
PHP <?= View::e($php) ?>. После выкладки кода воркер нужно перезапускать:
он держит загруженные классы в памяти, и задачи продолжали бы выполняться старым кодом.
</p>
<?php if (View::can('system.manage')) { ?>
<div class="row">
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'worker-restart'])) ?>">
<?= View::csrf() ?>
<button type="submit" class="primary">Перезапустить воркер</button>
</form>
<form method="post" action="<?= View::e(View::route('admin.system.action', ['action' => 'cache-clear'])) ?>">
<?= View::csrf() ?>
<button type="submit">Очистить кэш</button>
</form>
</div>
<?php } else { ?>
<p class="muted small">Кнопки обслуживания доступны с правом system.manage.</p>
<?php } ?>
<?php if ($settings !== []) { ?>
<details style="margin-top: 12px;">
<summary class="small">служебные отметки</summary>
<div class="table-wrap">
<table>
<?php foreach ($settings as $key => $value) { ?>
<tr>
<td class="mono small"><?= View::e($key) ?></td>
<td class="small break"><?= View::e($value) ?></td>
</tr>
<?php } ?>
</table>
</div>
</details>
<?php } ?>
</div>
</div>
+119
View File
@@ -0,0 +1,119 @@
<?php
declare(strict_types=1);
/**
* Ключи доступа к API.
*
* @var array{items: array<int, \Rsgrinko\Proton\Models\ApiToken>, total: int, page: int, pages: int, per_page: int} $page
* @var array<int, string> $owners
* @var array<int, \Rsgrinko\Proton\Models\User> $users
* @var string $issued только что выпущенный ключ — показывается один раз
*/
use Rsgrinko\Proton\View\View;
?>
<h1>Ключи API</h1>
<?php if ($issued !== '') { ?>
<div class="card" style="border-color: var(--accent);">
<h2>Новый ключ</h2>
<p class="muted small">Скопируйте его сейчас: в базе лежит только хеш, показать ключ второй раз будет негде.</p>
<pre class="break"><?= View::e($issued) ?></pre>
<p><?= View::copy($issued, 'скопировать ключ') ?></p>
</div>
<?php } ?>
<div class="card">
<h2>Выпустить ключ</h2>
<form method="post" action="<?= View::e(View::route('admin.tokens.store')) ?>">
<?= View::csrf() ?>
<div class="filters">
<label>
<span>Название</span>
<input type="text" name="name" placeholder="интеграция с 1С">
</label>
<label>
<span>Владелец</span>
<select name="user_id">
<?php foreach ($users as $user) { ?>
<option value="<?= $user->id() ?>"><?= View::e((string) $user->login) ?></option>
<?php } ?>
</select>
</label>
<label>
<span>Разрешённые адреса (через запятую, можно сети)</span>
<input type="text" name="ips" placeholder="127.0.0.1, 10.0.0.0/8">
</label>
</div>
<div class="filter-actions">
<button type="submit" class="primary">Выпустить</button>
</div>
</form>
</div>
<div class="card">
<h2>Выпущенные</h2>
<?php if ($page['items'] === []) { ?>
<p class="muted">Ключей пока нет.</p>
<?php } else { ?>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Название</th>
<th>Ключ</th>
<th class="hide-sm">Владелец</th>
<th class="hide-sm">Адреса</th>
<th>Состояние</th>
<th class="hide-sm">Использован</th>
<th></th>
</tr>
<?php foreach ($page['items'] as $token) { ?>
<tr>
<td><?= View::e((string) $token->name) ?></td>
<td class="mono"><?= View::e($token->mask()) ?></td>
<td class="hide-sm"><?= View::e($owners[(int) $token->raw('user_id')] ?? '—') ?></td>
<td class="hide-sm muted small"><?= View::e((string) $token->raw('allowed_ips') ?: 'без ограничений') ?></td>
<td>
<?php if ((int) $token->raw('active') === 1) { ?>
<span class="badge ok">активен</span>
<?php } else { ?>
<span class="badge muted">отключён</span>
<?php } ?>
</td>
<td class="hide-sm muted small"><?= View::e(View::ago((string) $token->raw('last_used_at'))) ?></td>
<td class="right">
<div class="row end">
<?php if ((int) $token->raw('active') === 1) { ?>
<form method="post" action="<?= View::e(View::route('admin.tokens.revoke', ['id' => $token->id()])) ?>">
<?= View::csrf() ?>
<button type="submit">Отключить</button>
</form>
<?php } ?>
<form method="post" action="<?= View::e(View::route('admin.tokens.delete', ['id' => $token->id()])) ?>">
<?= View::csrf() ?>
<button type="submit" class="danger">Удалить</button>
</form>
</div>
</td>
</tr>
<?php } ?>
</table>
</div>
<?= View::partial('pagination', [
'route' => 'admin.tokens',
'page' => $page['page'],
'pages' => $page['pages'],
'params' => [],
]) ?>
<?php } ?>
</div>
+110
View File
@@ -0,0 +1,110 @@
<?php
declare(strict_types=1);
/**
* Карточка пользователя — она же форма заведения.
*
* @var \Rsgrinko\Proton\Models\User $user
* @var array<int, \Rsgrinko\Proton\Models\Role> $roles
* @var array<int, array{id: string, kind: string, ip: string, agent: string, created: string, last: string, current: bool}> $devices
*/
use Rsgrinko\Proton\Auth\Password;
use Rsgrinko\Proton\View\View;
$isNew = !$user->existsInDatabase();
$action = $isNew ? View::route('admin.users.create') : View::route('admin.users.show', ['id' => $user->id()]);
$hint = $isNew ? 'пусто — придумаем сами' : 'пусто — не менять';
?>
<h1><?= $isNew ? 'Новый пользователь' : View::e((string) $user->login) ?></h1>
<div class="card">
<form method="post" action="<?= View::e($action) ?>">
<?= View::csrf() ?>
<?php if ($isNew) { ?>
<label>
<span>Логин</span>
<input type="text" name="login" autofocus required>
</label>
<?php } ?>
<label>
<span>Имя</span>
<input type="text" name="name" value="<?= View::e((string) $user->name) ?>">
</label>
<label>
<span>Почта</span>
<input type="email" name="email" value="<?= View::e((string) $user->email) ?>">
</label>
<label>
<span>Роль</span>
<select name="role_id">
<?php foreach ($roles as $role) { ?>
<option value="<?= $role->id() ?>" <?= (int) $user->raw('role_id') === $role->id() ? 'selected' : '' ?>>
<?= View::e((string) $role->name) ?>
</option>
<?php } ?>
</select>
</label>
<label>
<span>Пароль (<?= View::e($hint) ?>, от <?= Password::minLength() ?> символов)</span>
<input type="password" name="password" autocomplete="new-password">
</label>
<label class="inline" style="margin-bottom: 12px;">
<input type="checkbox" name="active" value="1" <?= $isNew || $user->isActive() ? 'checked' : '' ?>>
<span>Активен</span>
</label>
<div class="row">
<button type="submit" class="primary">Сохранить</button>
<a class="btn" href="<?= View::e(View::route('admin.users')) ?>">К списку</a>
</div>
</form>
</div>
<?php if (!$isNew) { ?>
<div class="card">
<h2>Устройства</h2>
<?php if ($devices === []) { ?>
<p class="muted">Активных сеансов нет.</p>
<?php } else { ?>
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Устройство</th>
<th class="hide-sm">Адрес</th>
<th>Последний раз</th>
</tr>
<?php foreach ($devices as $device) { ?>
<tr>
<td>
<?= View::e(View::device($device['agent'])) ?>
<div class="muted small"><?= View::e($device['kind']) ?></div>
</td>
<td class="hide-sm mono"><?= View::e($device['ip']) ?></td>
<td class="muted small"><?= View::e(View::ago($device['last'])) ?></td>
</tr>
<?php } ?>
</table>
</div>
<?php } ?>
</div>
<div class="card">
<h2>Удаление</h2>
<p class="muted small">Пользователь исчезнет вместе со своими сеансами. Его записи останутся.</p>
<form method="post" action="<?= View::e(View::route('admin.users.delete', ['id' => $user->id()])) ?>">
<?= View::csrf() ?>
<button type="submit" class="danger">Удалить пользователя</button>
</form>
</div>
<?php } ?>
+78
View File
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
/**
* Список пользователей.
*
* @var array{items: array<int, \Rsgrinko\Proton\Models\User>, total: int, page: int, pages: int, per_page: int} $page
* @var array<int, string> $roles
* @var string $search
*/
use Rsgrinko\Proton\View\View;
?>
<div class="row">
<h1 style="margin: 0;">Пользователи</h1>
<span class="spacer"></span>
<a class="btn primary" href="<?= View::e(View::route('admin.users.create')) ?>">Новый пользователь</a>
</div>
<div class="card" style="margin-top: 16px;">
<form method="get" action="<?= View::e(View::route('admin.users')) ?>">
<div class="filters">
<label>
<span>Поиск по логину или почте</span>
<input type="search" name="q" value="<?= View::e($search) ?>">
</label>
</div>
<div class="filter-actions row">
<button type="submit" class="primary">Искать</button>
<?php if ($search !== '') { ?>
<a class="btn" href="<?= View::e(View::route('admin.users')) ?>">Сбросить</a>
<?php } ?>
<span class="spacer"></span>
<span class="muted small">Всего: <?= (int) $page['total'] ?></span>
</div>
</form>
</div>
<div class="card">
<div class="table-wrap">
<table class="list">
<tr class="head">
<th>Логин</th>
<th class="hide-sm">Имя</th>
<th class="hide-sm">Почта</th>
<th>Роль</th>
<th>Активен</th>
<th class="hide-sm">Последний вход</th>
</tr>
<?php foreach ($page['items'] as $user) { ?>
<tr>
<td><a href="<?= View::e(View::route('admin.users.show', ['id' => $user->id()])) ?>"><?= View::e((string) $user->login) ?></a></td>
<td class="hide-sm"><?= View::e((string) $user->name) ?></td>
<td class="hide-sm muted small"><?= View::e((string) $user->email) ?></td>
<td><?= View::e($roles[(int) $user->raw('role_id')] ?? '—') ?></td>
<td>
<?php if ($user->isActive()) { ?>
<span class="badge ok">да</span>
<?php } else { ?>
<span class="badge muted">нет</span>
<?php } ?>
</td>
<td class="hide-sm muted small"><?= View::e(View::ago((string) $user->raw('last_login_at'))) ?></td>
</tr>
<?php } ?>
</table>
</div>
<?= View::partial('pagination', [
'route' => 'admin.users',
'page' => $page['page'],
'pages' => $page['pages'],
'params' => ['q' => $search],
]) ?>
</div>