Корзина, массовые действия в списках и история записи в карточке
This commit is contained in:
1 parent
20f3d79552
commit
00bba5abfa
23 files changed
+936
No files matched your search
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* Панель массовых действий над списком.
|
||||
*
|
||||
* Работает в паре с формой вокруг таблицы: в каждой строке галочка
|
||||
* `ids[]` с атрибутом data-check-item, здесь — «отметить все» и выбор действия.
|
||||
* Отметить все и посчитать отмеченное умеет каркас страницы.
|
||||
*
|
||||
* @var array<string, string> $actions код => подпись
|
||||
* @var string $confirm вопрос перед отправкой
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\View\View;
|
||||
|
||||
$confirm = $confirm ?? 'Выполнить действие над отмеченными записями?';
|
||||
?>
|
||||
<div class="row bulk-bar">
|
||||
<label class="inline">
|
||||
<input type="checkbox" data-check-all>
|
||||
<span class="muted small">отметить все</span>
|
||||
</label>
|
||||
|
||||
<select name="action" required>
|
||||
<option value="">действие с отмеченными</option>
|
||||
<?php foreach ($actions as $code => $label) { ?>
|
||||
<option value="<?= View::e($code) ?>"><?= View::e($label) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
|
||||
<button type="submit" data-confirm="<?= View::e($confirm) ?>">Выполнить</button>
|
||||
|
||||
<span class="muted small" data-check-count>ничего не отмечено</span>
|
||||
</div>
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* История записи: что с ней делали и кто.
|
||||
*
|
||||
* Берёт журнал действий по паре «раздел + id», поэтому работает для любой
|
||||
* записи, которую пишут через `Audit::created|updated|deleted|action`.
|
||||
*
|
||||
* <?= View::partial('history', ['entity' => 'user', 'id' => $user->id()]) ?>
|
||||
*
|
||||
* @var string $entity раздел журнала: user, role, note
|
||||
* @var int|string $id запись
|
||||
* @var int $limit сколько показывать
|
||||
*/
|
||||
|
||||
use Rsgrinko\Proton\Models\AuditEntry;
|
||||
use Rsgrinko\Proton\View\View;
|
||||
|
||||
$limit = $limit ?? 10;
|
||||
|
||||
// Право смотреть журнал есть не у всех: кто его не имеет, историю не увидит
|
||||
if (!View::can('audit.view')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$entries = AuditEntry::query()
|
||||
->where('entity', $entity)
|
||||
->where('entity_id', (string) $id)
|
||||
->orderBy('id', 'desc')
|
||||
->limit($limit)
|
||||
->get();
|
||||
?>
|
||||
<div class="card">
|
||||
<h2>История</h2>
|
||||
|
||||
<?php if ($entries === []) { ?>
|
||||
<p class="muted small">Записей в журнале нет.</p>
|
||||
<?php } else { ?>
|
||||
<div class="table-wrap">
|
||||
<table class="list">
|
||||
<?php foreach ($entries as $entry) { ?>
|
||||
<?php $changes = (array) ($entry->changes ?? []); ?>
|
||||
<tr>
|
||||
<td class="muted small nowrap"><?= View::e(View::date((string) $entry->raw('created_at'))) ?></td>
|
||||
<td class="small"><?= View::e((string) $entry->raw('user_login') ?: 'система') ?></td>
|
||||
<td>
|
||||
<span class="badge muted"><?= View::e(AuditEntry::label((string) $entry->raw('action'))) ?></span>
|
||||
<?= View::e((string) $entry->raw('description')) ?>
|
||||
|
||||
<?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>
|
||||
</tr>
|
||||
<?php } ?>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<p class="muted small">
|
||||
<a href="<?= View::e(View::route('admin.audit', ['entity' => $entity])) ?>">весь журнал раздела</a>
|
||||
</p>
|
||||
<?php } ?>
|
||||
</div>
|
||||
@@ -220,6 +220,8 @@ $unread = $viewer->isGuest() ? 0 : UserNotification::unreadFor($viewer->id());
|
||||
.chart .col.empty { background: var(--border); }
|
||||
.chart-legend { display: flex; justify-content: space-between; }
|
||||
|
||||
.bulk-bar { margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
|
||||
|
||||
a.sort { color: inherit; text-decoration: none; white-space: nowrap; }
|
||||
a.sort:hover { text-decoration: underline; }
|
||||
a.sort .arrow { margin-left: 4px; color: var(--accent); }
|
||||
@@ -398,6 +400,44 @@ $unread = $viewer->isGuest() ? 0 : UserNotification::unreadFor($viewer->id());
|
||||
Array.prototype.forEach.call(form.querySelectorAll('[data-check-item]'), function (box) {
|
||||
box.checked = master.checked;
|
||||
});
|
||||
|
||||
countChecked(form);
|
||||
});
|
||||
|
||||
// Счётчик отмеченного: без него непонятно, над сколькими записями
|
||||
// сработает массовое действие
|
||||
document.addEventListener('change', function (event) {
|
||||
var box = event.target.closest('[data-check-item]');
|
||||
|
||||
if (box) {
|
||||
countChecked(box.closest('form'));
|
||||
}
|
||||
});
|
||||
|
||||
function countChecked(form) {
|
||||
if (!form) {
|
||||
return;
|
||||
}
|
||||
|
||||
var label = form.querySelector('[data-check-count]');
|
||||
|
||||
if (!label) {
|
||||
return;
|
||||
}
|
||||
|
||||
var count = form.querySelectorAll('[data-check-item]:checked').length;
|
||||
|
||||
label.textContent = count === 0 ? 'ничего не отмечено' : 'отмечено: ' + count;
|
||||
}
|
||||
|
||||
// Опасное действие переспрашивает: массовое удаление промахом мыши
|
||||
// не отменить
|
||||
document.addEventListener('click', function (event) {
|
||||
var button = event.target.closest('[data-confirm]');
|
||||
|
||||
if (button && !window.confirm(button.getAttribute('data-confirm'))) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
document.addEventListener('click', function (event) {
|
||||
|
||||
Reference in new issue
Block a user