Files
breadcrumb-the-shire/pages/admin/system-audit/index(default).phtml
2026-03-04 15:56:58 +01:00

151 lines
5.2 KiB
PHTML

<?php
$pageAuth = is_array($viewAuth['page'] ?? null) ? $viewAuth['page'] : [];
$canPurgeSystemAudit = (bool) ($pageAuth['can_purge_system_audit'] ?? false);
$toolbarFilterSchema = is_array($toolbarFilterSchema ?? null) ? $toolbarFilterSchema : [];
$searchToolbarFilterSchema = is_array($searchToolbarFilterSchema ?? null) ? $searchToolbarFilterSchema : [];
$drawerToolbarFilterSchema = is_array($drawerToolbarFilterSchema ?? null) ? $drawerToolbarFilterSchema : [];
$toolbarFilterState = is_array($toolbarFilterState ?? null) ? $toolbarFilterState : [];
$toolbarOptionSets = is_array($toolbarOptionSets ?? null) ? $toolbarOptionSets : [];
$filterChipMeta = is_array($filterChipMeta ?? null) ? $filterChipMeta : [];
$clientFilterSchema = is_array($clientFilterSchema ?? null) ? $clientFilterSchema : [];
$searchConfig = is_array($searchConfig ?? null) ? $searchConfig : null;
?>
<?php
$breadcrumbs = [
['label' => t('Home'), 'path' => 'admin'],
['label' => t('System audit logs')],
];
require templatePath('partials/app-breadcrumb.phtml');
?>
<?php
$listTitle = t('System audit logs');
ob_start();
?>
<?php
$listPurgeEnabled = $canPurgeSystemAudit;
$listPurgeFormId = 'system-audit-purge-form';
$listPurgeAction = 'admin/system-audit/purge';
$listPurgeConfirmMessage = t('Purge expired system audit entries?');
$listPurgeButtonLabel = t('Purge system audit logs');
require templatePath('partials/app-list-purge-action.phtml');
?>
<?php
$listTitleActionsHtml = ob_get_clean();
require templatePath('partials/app-list-titlebar.phtml');
?>
<?php
$filterUiNamespace = 'system-audit';
require templatePath('partials/app-list-filters.phtml');
?>
<div class="app-list-table">
<div id="system-audit-grid"></div>
</div>
<script src="<?php e(asset('vendor/gridjs/gridjs.umd.js')); ?>"></script>
<script type="module">
import { initStandardListPage } from "<?php e(assetVersion('js/core/app-grid-factory.js')); ?>";
import { getAppBase } from "<?php e(assetVersion('js/pages/app-list-utils.js')); ?>";
const appBase = getAppBase();
const gridSearch = <?php gridJsonForJs($searchConfig); ?>;
const filterSchema = <?php gridJsonForJs($clientFilterSchema); ?>;
const filterChipMeta = <?php gridJsonForJs($filterChipMeta); ?>;
const initSystemAuditGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#system-audit-grid',
dataUrl: 'admin/system-audit/data',
appBase,
columns: [
{ name: "<?php e(t('Created')); ?>", sort: true },
{
name: "<?php e(t('Status')); ?>",
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
return gridjs.html(`<span class="badge" data-variant="${cell.variant || 'neutral'}">${cell.label || ''}</span>`);
}
},
{ name: "<?php e(t('Event')); ?>", sort: true },
{ name: "<?php e(t('Channel')); ?>", sort: true },
{
name: "<?php e(t('Actor')); ?>",
sort: false,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
const label = cell.label || '-';
if (!cell.uuid) {
return gridjs.html(label);
}
const url = new URL(`admin/users/edit/${cell.uuid}`, appBase).toString();
return gridjs.html(`<a href="${url}">${label}</a>`);
}
},
{ name: "<?php e(t('Target type')); ?>", sort: false },
{
name: "<?php e(t('Request ID')); ?>",
sort: false,
formatter: (cell) => cell ? gridjs.html(`<code>${String(cell).slice(0, 8)}</code>`) : gridjs.html('-')
},
{
name: "<?php e(t('Error code')); ?>",
sort: false,
formatter: (cell) => cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')
},
{ name: 'ID', hidden: true }
],
sortColumns: ['created_at', 'outcome', 'event_type', 'channel', null, null, null, null, null],
paginationLimit: 10,
language: <?php MintyPHP\Buffer::get('grid_lang'); ?>,
mapData: (data) => data.data.map((row) => [
row.created_at,
{
variant: row.outcome_badge,
label: String(row.outcome_label || row.outcome || '')
},
row.event_type,
row.channel,
{
uuid: row.actor_user_uuid || '',
label: row.actor_user_label || '-'
},
row.target_type || '-',
row.request_id || '',
row.error_code || '',
row.id
]),
actions: {
enabled: false
},
search: gridSearch,
filterSchema,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[8]?.data;
return id ? new URL(`admin/system-audit/view/${id}`, appBase).toString() : '';
}
}
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#system-audit-search']
}
});
return gridConfig;
};
const gridConfig = initSystemAuditGrid();
if (!gridConfig || !gridConfig.grid) {
console.warn('System audit grid init failed');
}
</script>