initial commit
This commit is contained in:
commit
3f64f4a49a
221 files changed
+26665
No files matched your search
@@ -0,0 +1,334 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Rsgrinko\Proton\View;
|
||||
|
||||
use Rsgrinko\Proton\Access\Viewer;
|
||||
use Rsgrinko\Proton\Auth\Auth;
|
||||
use Rsgrinko\Proton\Auth\Csrf;
|
||||
use Rsgrinko\Proton\Http\Response;
|
||||
use Rsgrinko\Proton\Http\Router;
|
||||
use Rsgrinko\Proton\Support\Config;
|
||||
use Rsgrinko\Proton\Support\ProtonException;
|
||||
|
||||
/**
|
||||
* Отрисовка страниц. Шаблоны — обычные PHP-файлы: ни своего языка, ни компиляции,
|
||||
* ни кэша шаблонов, который надо чистить после выкладки.
|
||||
*
|
||||
* Ищутся они сначала в resources/views приложения, потом в framework/View/views —
|
||||
* поэтому любой шаблон ядра (каркас, страницы ошибок, пагинация) можно заменить
|
||||
* своим, просто положив файл с тем же именем.
|
||||
*/
|
||||
final class View
|
||||
{
|
||||
/** @var array<string, mixed> Данные, доступные всем шаблонам */
|
||||
private static array $shared = [];
|
||||
|
||||
/**
|
||||
* Страница внутри общего каркаса.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function render(string $template, array $data = [], string $title = ''): string
|
||||
{
|
||||
return self::partial('layouts/main', [
|
||||
'content' => self::partial($template, $data),
|
||||
'title' => $title !== '' ? $title : (string) Config::get('app.name', 'Proton'),
|
||||
'flash' => self::takeFlash(),
|
||||
'active' => (string) ($data['active'] ?? ''),
|
||||
'viewer' => self::viewer(),
|
||||
'bare' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Страница без шапки и меню — вход, регистрация, первый запуск.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function renderBare(string $template, array $data = [], string $title = ''): string
|
||||
{
|
||||
return self::partial('layouts/main', [
|
||||
'content' => self::partial($template, $data),
|
||||
'title' => $title !== '' ? $title : (string) Config::get('app.name', 'Proton'),
|
||||
'flash' => self::takeFlash(),
|
||||
'active' => '',
|
||||
'viewer' => self::viewer(),
|
||||
'bare' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Готовый HTML-ответ — самый частый случай в контроллере.
|
||||
*
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public static function page(string $template, array $data = [], string $title = '', int $status = 200): Response
|
||||
{
|
||||
return Response::html(self::render($template, $data, $title), $status);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кусок разметки без каркаса.
|
||||
*
|
||||
* @param array<string, mixed> $viewData
|
||||
*/
|
||||
public static function partial(string $viewName, array $viewData = []): string
|
||||
{
|
||||
// Имена переменных с подчёркиванием: на странице может быть своя
|
||||
// переменная $template или $file, и она не должна затирать наши
|
||||
$__file = self::locate($viewName);
|
||||
|
||||
extract(array_merge(self::$shared, $viewData), EXTR_OVERWRITE);
|
||||
|
||||
ob_start();
|
||||
|
||||
include $__file;
|
||||
|
||||
return (string) ob_get_clean();
|
||||
}
|
||||
|
||||
/**
|
||||
* Значение, доступное всем шаблонам, — название приложения, версия, меню.
|
||||
*/
|
||||
public static function share(string $key, mixed $value): void
|
||||
{
|
||||
self::$shared[$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Экранирование для вывода в HTML. Всё, что пришло от пользователя,
|
||||
* печатается только через него.
|
||||
*/
|
||||
public static function e(mixed $value): string
|
||||
{
|
||||
return htmlspecialchars((string) $value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
|
||||
}
|
||||
|
||||
/**
|
||||
* Адрес по имени маршрута: View::route('admin.users.show', ['id' => 5]).
|
||||
* Лишние параметры уходят в query-строку — так удобно тащить фильтры.
|
||||
*
|
||||
* @param array<string, mixed> $params
|
||||
*/
|
||||
public static function route(string $name, array $params = []): string
|
||||
{
|
||||
return Router::url($name, array_filter($params, static fn (mixed $value): bool => $value !== '' && $value !== null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Скрытое поле с токеном. Обязательно в каждой форме, которая что-то меняет:
|
||||
* без него прослойка csrf вернёт 403.
|
||||
*/
|
||||
public static function csrf(): string
|
||||
{
|
||||
return Csrf::field();
|
||||
}
|
||||
|
||||
/**
|
||||
* Скрытое поле метода — браузер умеет только GET и POST.
|
||||
*/
|
||||
public static function method(string $method): string
|
||||
{
|
||||
return '<input type="hidden" name="_method" value="' . self::e(strtoupper($method)) . '">';
|
||||
}
|
||||
|
||||
/**
|
||||
* Сообщение, которое покажется на следующей странице.
|
||||
*/
|
||||
public static function flash(string $message, string $type = 'ok'): void
|
||||
{
|
||||
Auth::startSession();
|
||||
|
||||
$_SESSION['flash'][] = ['message' => $message, 'type' => $type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Одноразовое значение для следующей страницы: свежевыпущенный ключ,
|
||||
* заполненная форма после ошибки.
|
||||
*
|
||||
* @param mixed $value
|
||||
*/
|
||||
public static function stash(string $key, mixed $value): void
|
||||
{
|
||||
Auth::startSession();
|
||||
|
||||
$_SESSION['stash'][$key] = $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Забирает отложенное значение — второй раз его уже не будет.
|
||||
*/
|
||||
public static function takeStash(string $key, mixed $default = null): mixed
|
||||
{
|
||||
Auth::startSession();
|
||||
|
||||
$value = $_SESSION['stash'][$key] ?? $default;
|
||||
|
||||
unset($_SESSION['stash'][$key]);
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Прежнее значение поля формы — чтобы после ошибки не заполнять всё заново.
|
||||
*
|
||||
* @param array<string, mixed> $old
|
||||
*/
|
||||
public static function old(array $old, string $field, mixed $default = ''): mixed
|
||||
{
|
||||
return $old[$field] ?? $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Есть ли у вошедшего право. Пункт меню и кнопку без права не показываем,
|
||||
* но полагаться на это нельзя: доступ закрывает прослойка, разметка лишь
|
||||
* не дразнит.
|
||||
*/
|
||||
public static function can(string $permission): bool
|
||||
{
|
||||
return self::viewer()->can($permission);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<int, string> $permissions
|
||||
*/
|
||||
public static function canAny(array $permissions): bool
|
||||
{
|
||||
return self::viewer()->canAny($permissions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Кто смотрит страницу.
|
||||
*/
|
||||
public static function viewer(): Viewer
|
||||
{
|
||||
return Auth::viewer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Человеческая дата.
|
||||
*/
|
||||
public static function date(?string $value, string $format = 'd.m.Y H:i'): string
|
||||
{
|
||||
if ($value === null || trim($value) === '') {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$timestamp = strtotime($value);
|
||||
|
||||
return $timestamp === false ? $value : date($format, $timestamp);
|
||||
}
|
||||
|
||||
/**
|
||||
* «5 минут назад» — так понятнее, чем голая дата.
|
||||
*/
|
||||
public static function ago(?string $value): string
|
||||
{
|
||||
if ($value === null || trim($value) === '') {
|
||||
return '—';
|
||||
}
|
||||
|
||||
$timestamp = strtotime($value);
|
||||
|
||||
if ($timestamp === false) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
$diff = time() - $timestamp;
|
||||
$suffix = $diff < 0 ? ' вперёд' : ' назад';
|
||||
$diff = abs($diff);
|
||||
|
||||
return match (true) {
|
||||
$diff < 60 => $diff . ' с' . $suffix,
|
||||
$diff < 3600 => (int) ($diff / 60) . ' мин' . $suffix,
|
||||
$diff < 86400 => (int) ($diff / 3600) . ' ч' . $suffix,
|
||||
default => (int) ($diff / 86400) . ' дн' . $suffix,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Браузер и система из строки User-Agent — для списка устройств. Разбор
|
||||
* нарочно грубый: нужно отличить свой телефон от чужого компьютера.
|
||||
*/
|
||||
public static function device(?string $agent): string
|
||||
{
|
||||
$agent = trim((string) $agent);
|
||||
|
||||
if ($agent === '') {
|
||||
return 'браузер неизвестен';
|
||||
}
|
||||
|
||||
// Порядок важен: все они представляются ещё и Chrome
|
||||
$browsers = [
|
||||
'YaBrowser' => 'Яндекс.Браузер',
|
||||
'Edg' => 'Edge',
|
||||
'OPR' => 'Opera',
|
||||
'Firefox' => 'Firefox',
|
||||
'Chrome' => 'Chrome',
|
||||
'Safari' => 'Safari',
|
||||
];
|
||||
|
||||
$browser = 'браузер неизвестен';
|
||||
|
||||
foreach ($browsers as $needle => $label) {
|
||||
if (str_contains($agent, $needle)) {
|
||||
$browser = $label;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (['Android' => 'Android', 'iPhone' => 'iPhone', 'iPad' => 'iPad', 'Windows' => 'Windows', 'Macintosh' => 'macOS', 'Linux' => 'Linux'] as $needle => $system) {
|
||||
if (str_contains($agent, $needle)) {
|
||||
return $browser . ', ' . $system;
|
||||
}
|
||||
}
|
||||
|
||||
return $browser;
|
||||
}
|
||||
|
||||
/**
|
||||
* Кнопка «скопировать» рядом со значением: ключ, идентификатор, команда.
|
||||
* Обязательно type="button" — кнопки стоят и внутри форм.
|
||||
*/
|
||||
public static function copy(string $value, string $title = 'скопировать'): string
|
||||
{
|
||||
return '<button type="button" class="copy" data-copy="' . self::e($value) . '">' . self::e($title) . '</button>';
|
||||
}
|
||||
|
||||
/**
|
||||
* Забирает накопленные сообщения и очищает их.
|
||||
*
|
||||
* @return array<int, array{message: string, type: string}>
|
||||
*/
|
||||
private static function takeFlash(): array
|
||||
{
|
||||
Auth::startSession();
|
||||
|
||||
$flash = $_SESSION['flash'] ?? [];
|
||||
|
||||
$_SESSION['flash'] = [];
|
||||
|
||||
return is_array($flash) ? $flash : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ищет файл шаблона: сначала в приложении, потом в ядре.
|
||||
*/
|
||||
private static function locate(string $viewName): string
|
||||
{
|
||||
$name = trim(str_replace('.', '/', $viewName), '/');
|
||||
|
||||
foreach ([APP_ROOT . '/resources/views/', APP_ROOT . '/framework/View/views/'] as $dir) {
|
||||
$file = $dir . $name . '.php';
|
||||
|
||||
if (is_file($file)) {
|
||||
return $file;
|
||||
}
|
||||
}
|
||||
|
||||
throw new ProtonException('Шаблон не найден: ' . $viewName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @var string $message
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\View\View;
|
||||
?>
|
||||
<div class="card">
|
||||
<h1>Нет доступа</h1>
|
||||
<p class="muted"><?= View::e($message !== '' ? $message : 'Этот раздел вам не доступен.') ?></p>
|
||||
<p><a class="btn" href="<?= View::e(View::route('home')) ?>">На главную</a></p>
|
||||
</div>
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @var string $message
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\View\View;
|
||||
?>
|
||||
<div class="card">
|
||||
<h1>Страница не найдена</h1>
|
||||
<p class="muted"><?= View::e($message !== '' ? $message : 'Такого адреса здесь нет.') ?></p>
|
||||
<p><a class="btn" href="<?= View::e(View::route('home')) ?>">На главную</a></p>
|
||||
</div>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @var string $message
|
||||
* @var string $trace показывается только при включённой отладке
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\View\View;
|
||||
|
||||
$trace = $trace ?? '';
|
||||
?>
|
||||
<div class="card">
|
||||
<h1>Что-то сломалось</h1>
|
||||
<p><?= View::e($message) ?></p>
|
||||
|
||||
<?php if ($trace !== '') { ?>
|
||||
<pre class="break"><?= View::e($trace) ?></pre>
|
||||
<?php } ?>
|
||||
|
||||
<p><a class="btn" href="<?= View::e(View::route('home')) ?>">На главную</a></p>
|
||||
</div>
|
||||
@@ -0,0 +1,418 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Каркас всех страниц: шапка, меню, сообщения и стили.
|
||||
*
|
||||
* Лежит в ядре, но перекрывается приложением: положите свой файл в
|
||||
* resources/views/layouts/main.php — View возьмёт его.
|
||||
*
|
||||
* @var string $content
|
||||
* @var string $title
|
||||
* @var array<int, array{message: string, type: string}> $flash
|
||||
* @var string $active
|
||||
* @var \Rsgrinko\Proton\Access\Viewer $viewer
|
||||
* @var bool $bare страница входа — без шапки и меню
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\Support\Config;
|
||||
use Rsgrinko\Proton\View\View;
|
||||
|
||||
$bare = $bare ?? false;
|
||||
$menu = (array) Config::get('menu', []);
|
||||
$name = (string) Config::get('app.name', 'Proton');
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<title><?= View::e($title) ?> — <?= View::e($name) ?></title>
|
||||
<style>
|
||||
:root {
|
||||
/* Свои части полей и скроллбары браузер рисует по этой подсказке;
|
||||
без неё в тёмной теме они остаются светлыми */
|
||||
color-scheme: light;
|
||||
--bg: #f5f6f8;
|
||||
--panel: #ffffff;
|
||||
--border: #e2e5ea;
|
||||
--text: #1d2129;
|
||||
--muted: #6b7280;
|
||||
--accent: #2563eb;
|
||||
--ok: #15803d;
|
||||
--ok-bg: #dcfce7;
|
||||
--warn: #b45309;
|
||||
--warn-bg: #fef3c7;
|
||||
--err: #b91c1c;
|
||||
--err-bg: #fee2e2;
|
||||
--info-bg: #dbeafe;
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #14161a;
|
||||
--panel: #1c1f25;
|
||||
--border: #2c313a;
|
||||
--text: #e5e7eb;
|
||||
--muted: #9ca3af;
|
||||
--accent: #60a5fa;
|
||||
--ok: #4ade80;
|
||||
--ok-bg: #14321f;
|
||||
--warn: #fbbf24;
|
||||
--warn-bg: #3a2d0c;
|
||||
--err: #f87171;
|
||||
--err-bg: #3b1717;
|
||||
--info-bg: #17293f;
|
||||
}
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; }
|
||||
|
||||
body {
|
||||
margin: 0;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font: 14px/1.5 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
|
||||
}
|
||||
|
||||
a { color: var(--accent); text-decoration: none; }
|
||||
a:hover { text-decoration: underline; }
|
||||
|
||||
header {
|
||||
background: var(--panel);
|
||||
border-bottom: 1px solid var(--border);
|
||||
padding: 0 20px;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.brand { display: flex; align-items: baseline; gap: 12px; padding: 14px 0 10px; }
|
||||
.brand b { font-size: 17px; }
|
||||
.brand span { color: var(--muted); font-size: 12px; }
|
||||
.brand .who { margin-left: auto; display: flex; align-items: center; gap: 10px; }
|
||||
.brand .who form { display: inline; }
|
||||
|
||||
/* Кнопка меню нужна только на узких экранах, разворачивает её чекбокс без единой строки JS */
|
||||
.burger { display: none; }
|
||||
|
||||
.auth { max-width: 400px; margin: 8vh auto 0; }
|
||||
.auth h1 { text-align: center; }
|
||||
|
||||
nav { display: flex; gap: 4px; flex-wrap: wrap; }
|
||||
nav a { padding: 8px 12px; border-radius: 6px 6px 0 0; color: var(--text); font-weight: 500; }
|
||||
nav a:hover { background: var(--bg); text-decoration: none; }
|
||||
nav a.active { background: var(--accent); color: #fff; }
|
||||
|
||||
main { padding: 20px; max-width: 1400px; margin: 0 auto; }
|
||||
|
||||
h1 { font-size: 20px; margin: 0 0 16px; }
|
||||
h2 { font-size: 16px; margin: 0 0 12px; }
|
||||
|
||||
.card {
|
||||
background: var(--panel);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 10px;
|
||||
padding: 16px;
|
||||
margin-bottom: 16px;
|
||||
}
|
||||
|
||||
.card > h2:first-child { margin-top: 0; }
|
||||
|
||||
.grid { display: grid; gap: 16px; }
|
||||
/* Без этого широкая таблица распирает колонку вместо того, чтобы прокручиваться */
|
||||
.grid > * { min-width: 0; }
|
||||
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
|
||||
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
|
||||
|
||||
.stat .value { font-size: 26px; font-weight: 600; }
|
||||
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
|
||||
|
||||
a.card { color: inherit; }
|
||||
a.card:hover { text-decoration: none; border-color: var(--accent); }
|
||||
a.card:hover .value { color: var(--accent); }
|
||||
|
||||
table { width: 100%; border-collapse: collapse; }
|
||||
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
|
||||
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
|
||||
tr:last-child td { border-bottom: none; }
|
||||
.table-wrap { overflow-x: auto; }
|
||||
|
||||
.badge {
|
||||
display: inline-block;
|
||||
padding: 2px 8px;
|
||||
border-radius: 20px;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.badge.ok { background: var(--ok-bg); color: var(--ok); }
|
||||
.badge.warn { background: var(--warn-bg); color: var(--warn); }
|
||||
.badge.error { background: var(--err-bg); color: var(--err); }
|
||||
.badge.info { background: var(--info-bg); color: var(--accent); }
|
||||
.badge.muted { background: var(--border); color: var(--muted); }
|
||||
|
||||
input[type=text], input[type=email], input[type=number], input[type=password],
|
||||
input[type=date], input[type=datetime-local], input[type=search], select, textarea {
|
||||
width: 100%;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
textarea { min-height: 140px; font-family: ui-monospace, Consolas, monospace; font-size: 13px; }
|
||||
|
||||
label { display: block; margin-bottom: 12px; }
|
||||
label > span { display: block; margin-bottom: 4px; color: var(--muted); font-size: 12px; }
|
||||
/* Галочка с подписью — в строку; отдельной строкой их ставит только .row */
|
||||
label.inline { display: flex; align-items: center; gap: 8px; margin: 0; }
|
||||
label.inline > span { margin: 0; color: var(--text); font-size: 14px; }
|
||||
|
||||
button, .btn {
|
||||
display: inline-block;
|
||||
padding: 8px 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: var(--panel);
|
||||
color: var(--text);
|
||||
font: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
button.copy { padding: 2px 8px; font-size: 12px; color: var(--muted); vertical-align: middle; }
|
||||
button.copy:hover { color: var(--text); }
|
||||
|
||||
button:hover, .btn:hover { border-color: var(--accent); text-decoration: none; }
|
||||
button.primary, .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
button.danger, .btn.danger { color: var(--err); }
|
||||
button:disabled, .btn:disabled { cursor: not-allowed; opacity: .6; }
|
||||
|
||||
/* Всё, по чему можно щёлкнуть, должно говорить об этом курсором */
|
||||
a, select, summary, input[type=checkbox], input[type=radio], input[type=submit],
|
||||
input[type=file], label.inline, label.inline > span, .burger, .pagination a { cursor: pointer; }
|
||||
|
||||
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
||||
.row.end { justify-content: flex-end; }
|
||||
.spacer { flex: 1; }
|
||||
|
||||
.filters { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 10px; align-items: end; }
|
||||
.filters label { margin: 0; }
|
||||
.filter-actions { margin-top: 12px; }
|
||||
|
||||
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; word-break: break-word; }
|
||||
.flash.ok { background: var(--ok-bg); color: var(--ok); }
|
||||
.flash.error { background: var(--err-bg); color: var(--err); }
|
||||
|
||||
.muted { color: var(--muted); }
|
||||
.mono { font-family: ui-monospace, Consolas, monospace; font-size: 12px; }
|
||||
.nowrap { white-space: nowrap; }
|
||||
.break { word-break: break-all; white-space: normal; }
|
||||
/* В pre переносы значимы: иначе .break склеивает команду в одну строку */
|
||||
pre.break { white-space: pre-wrap; }
|
||||
.small { font-size: 12px; }
|
||||
.right { text-align: right; }
|
||||
|
||||
pre {
|
||||
background: var(--bg);
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
overflow-x: auto;
|
||||
font-size: 12px;
|
||||
margin: 0;
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
}
|
||||
|
||||
dl.props { display: grid; grid-template-columns: 220px 1fr; gap: 6px 16px; margin: 0; }
|
||||
dl.props dt { color: var(--muted); }
|
||||
dl.props dd { margin: 0; word-break: break-word; }
|
||||
|
||||
.pagination { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
|
||||
.pagination a, .pagination span { padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px; }
|
||||
.pagination .current { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
|
||||
.checks .item { display: flex; gap: 10px; align-items: baseline; padding: 7px 0; border-bottom: 1px solid var(--border); }
|
||||
.checks .item:last-child { border-bottom: none; }
|
||||
.checks .item .title { min-width: 200px; }
|
||||
.checks .item .hint { color: var(--muted); font-size: 12px; }
|
||||
|
||||
/* Планшеты: таблицы ужимаются за счёт второстепенных колонок */
|
||||
@media (max-width: 900px) {
|
||||
.hide-sm { display: none; }
|
||||
}
|
||||
|
||||
/* Телефоны и узкие окна */
|
||||
@media (max-width: 760px) {
|
||||
header { padding: 0 12px; }
|
||||
.brand { padding: 10px 0; gap: 8px; }
|
||||
.brand .tagline { display: none; }
|
||||
.brand .who { margin-left: 0; gap: 8px; }
|
||||
|
||||
/* Меню прячем под кнопку: десяток пунктов в строку не помещается */
|
||||
.burger {
|
||||
display: inline-flex;
|
||||
margin-left: auto;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 40px;
|
||||
height: 34px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
font-size: 18px;
|
||||
line-height: 1;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.menu-toggle:checked ~ .brand .burger { background: var(--accent); border-color: var(--accent); color: #fff; }
|
||||
|
||||
nav { display: none; }
|
||||
.menu-toggle:checked ~ nav { display: flex; flex-direction: column; gap: 2px; padding-bottom: 10px; }
|
||||
nav a { border-radius: 6px; padding: 10px 12px; }
|
||||
|
||||
main { padding: 12px; }
|
||||
h1 { font-size: 18px; }
|
||||
|
||||
.card { padding: 12px; }
|
||||
.grid { gap: 12px; }
|
||||
.grid.cols-2 { grid-template-columns: 1fr; }
|
||||
.grid.cols-4 { grid-template-columns: 1fr 1fr; }
|
||||
.stat .value { font-size: 22px; }
|
||||
|
||||
.filters { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 8px; }
|
||||
.row > label { min-width: 100%; }
|
||||
|
||||
th, td { padding: 6px 8px; }
|
||||
|
||||
/* Скрытые колонки не должны всплыть из-за display:block у ячеек */
|
||||
table.list td.hide-sm { display: none; }
|
||||
|
||||
/* Списки разворачиваем в карточки: иначе колонки сжимаются в столбик из букв */
|
||||
table.list, table.list tbody, table.list tr, table.list td { display: block; width: auto; }
|
||||
table.list tr.head { display: none; }
|
||||
table.list tr { padding: 10px 0; border-bottom: 1px solid var(--border); }
|
||||
table.list tr.head + tr { padding-top: 0; }
|
||||
table.list tr:last-child { border-bottom: none; padding-bottom: 0; }
|
||||
table.list td { border: none; padding: 2px 0; }
|
||||
table.list td:empty { display: none; }
|
||||
|
||||
dl.props { grid-template-columns: 1fr; gap: 0; }
|
||||
dl.props dt { margin-top: 10px; font-size: 12px; }
|
||||
dl.props dt:first-child { margin-top: 0; }
|
||||
|
||||
.checks .item { flex-direction: column; gap: 2px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<?php if (!$bare) { ?>
|
||||
<header>
|
||||
<input type="checkbox" id="menu-toggle" class="menu-toggle" hidden>
|
||||
<div class="brand">
|
||||
<b><?= View::e($name) ?></b>
|
||||
<span class="tagline">на Proton</span>
|
||||
|
||||
<?php if (!$viewer->isGuest()) { ?>
|
||||
<span class="who">
|
||||
<a class="muted small" href="<?= View::e(View::route('profile')) ?>"><?= View::e($viewer->name()) ?></a>
|
||||
<form method="post" action="<?= View::e(View::route('logout')) ?>">
|
||||
<?= View::csrf() ?>
|
||||
<button type="submit">Выйти</button>
|
||||
</form>
|
||||
</span>
|
||||
<?php } else { ?>
|
||||
<span class="who">
|
||||
<a href="<?= View::e(View::route('login')) ?>">Войти</a>
|
||||
</span>
|
||||
<?php } ?>
|
||||
|
||||
<label class="burger" for="menu-toggle" title="Меню" aria-label="Меню">☰</label>
|
||||
</div>
|
||||
<nav>
|
||||
<?php foreach ($menu as $item) { ?>
|
||||
<?php if (($item['permission'] ?? '') === '' || View::can((string) $item['permission'])) { ?>
|
||||
<a href="<?= View::e(View::route((string) $item['route'])) ?>"
|
||||
class="<?= $active === (string) $item['key'] ? 'active' : '' ?>"><?= View::e((string) $item['label']) ?></a>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
</nav>
|
||||
</header>
|
||||
<?php } ?>
|
||||
|
||||
<main<?= $bare ? ' class="auth"' : '' ?>>
|
||||
<?php foreach ($flash as $item) { ?>
|
||||
<div class="flash <?= View::e($item['type']) ?>"><?= View::e($item['message']) ?></div>
|
||||
<?php } ?>
|
||||
|
||||
<?= $content ?>
|
||||
</main>
|
||||
|
||||
<?php /*
|
||||
Единственный скрипт: кнопка «скопировать» и галочка «отметить все». Без
|
||||
буфера обмена браузера первую не сделать никак, а копировать ключ руками
|
||||
приходится каждый раз. Обработчик один на страницу и висит на документе.
|
||||
Всё остальное работает и без JavaScript.
|
||||
*/ ?>
|
||||
<script>
|
||||
document.addEventListener('change', function (event) {
|
||||
var master = event.target.closest('[data-check-all]');
|
||||
|
||||
if (!master) {
|
||||
return;
|
||||
}
|
||||
|
||||
var form = master.closest('form');
|
||||
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
|
||||
Array.prototype.forEach.call(form.querySelectorAll('[data-check-item]'), function (box) {
|
||||
box.checked = master.checked;
|
||||
});
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-copy]');
|
||||
|
||||
if (!button) {
|
||||
return;
|
||||
}
|
||||
|
||||
var text = button.getAttribute('data-copy');
|
||||
var done = function () {
|
||||
var was = button.textContent;
|
||||
button.textContent = 'скопировано';
|
||||
setTimeout(function () { button.textContent = was; }, 1500);
|
||||
};
|
||||
|
||||
if (navigator.clipboard && window.isSecureContext) {
|
||||
navigator.clipboard.writeText(text).then(done);
|
||||
return;
|
||||
}
|
||||
|
||||
// Запасной путь для http и старых браузеров
|
||||
var field = document.createElement('textarea');
|
||||
field.value = text;
|
||||
field.setAttribute('readonly', '');
|
||||
field.style.position = 'fixed';
|
||||
field.style.opacity = '0';
|
||||
document.body.appendChild(field);
|
||||
field.select();
|
||||
|
||||
try {
|
||||
document.execCommand('copy');
|
||||
done();
|
||||
} finally {
|
||||
document.body.removeChild(field);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Разметка постраничной навигации. Общая для всех списков: новый список —
|
||||
* значит и этот кусок к нему.
|
||||
*
|
||||
* @var string $route имя маршрута раздела
|
||||
* @var int $page текущая страница
|
||||
* @var int $pages всего страниц
|
||||
* @var array<string, mixed> $params текущие фильтры — их нужно тащить по страницам
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\View\View;
|
||||
|
||||
$params = $params ?? [];
|
||||
|
||||
if ($pages <= 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Показываем не все страницы, а окно вокруг текущей: на сотне страниц
|
||||
// сплошная лента ссылок бесполезна
|
||||
$from = max(1, $page - 3);
|
||||
$to = min($pages, $page + 3);
|
||||
?>
|
||||
<div class="pagination">
|
||||
<?php if ($page > 1) { ?>
|
||||
<a href="<?= View::e(View::route($route, array_merge($params, ['page' => $page - 1]))) ?>">← назад</a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($from > 1) { ?>
|
||||
<a href="<?= View::e(View::route($route, array_merge($params, ['page' => 1]))) ?>">1</a>
|
||||
<?php if ($from > 2) { ?><span class="muted">…</span><?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php for ($number = $from; $number <= $to; $number++) { ?>
|
||||
<?php if ($number === $page) { ?>
|
||||
<span class="current"><?= $number ?></span>
|
||||
<?php } else { ?>
|
||||
<a href="<?= View::e(View::route($route, array_merge($params, ['page' => $number]))) ?>"><?= $number ?></a>
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($to < $pages) { ?>
|
||||
<?php if ($to < $pages - 1) { ?><span class="muted">…</span><?php } ?>
|
||||
<a href="<?= View::e(View::route($route, array_merge($params, ['page' => $pages]))) ?>"><?= $pages ?></a>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($page < $pages) { ?>
|
||||
<a href="<?= View::e(View::route($route, array_merge($params, ['page' => $page + 1]))) ?>">вперёд →</a>
|
||||
<?php } ?>
|
||||
</div>
|
||||
Reference in new issue
Block a user