Repo Interface für tests

This commit is contained in:
2026-03-05 08:26:51 +01:00
parent 8f4dd5840d
commit 4b31fc7664
171 changed files with 3518 additions and 2297 deletions

View File

@@ -15,8 +15,8 @@ import './components/app-theme-toggle.js';
import './components/app-contrast-toggle.js';
import './components/app-confirm-actions.js';
import './components/app-details-state.js';
import './components/app-standard-detail-page.js';
import './components/app-tenant-switcher.js';
import './components/app-color-default-toggle.js';
import './components/app-custom-field-options-toggle.js';
import './components/app-tenant-sso-toggle.js';
import './components/app-standard-detail-page.js';

View File

@@ -1,28 +0,0 @@
import { optionalEl, warnOnce } from '../core/app-dom.js';
export function initTemplateFeature(root = document) {
const host = optionalEl('[data-template-feature]');
if (!host) {
return;
}
if (host.dataset.templateFeatureBound === '1') {
return;
}
host.dataset.templateFeatureBound = '1';
const action = host.querySelector('[data-template-action]');
if (!action) {
warnOnce('UI_EL_MISSING', 'Missing [data-template-action]', { module: 'template-feature' });
return;
}
action.addEventListener('click', () => {
host.classList.toggle('is-active');
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => initTemplateFeature());
} else {
initTemplateFeature();
}

View File

@@ -1,73 +0,0 @@
import { warnOnce } from '../core/app-dom.js';
const getEmptyValues = (field) => {
const own = field?.dataset?.filterEmpty || '';
const parent = field?.closest?.('[data-filter-empty]')?.dataset?.filterEmpty || '';
return [own, parent]
.filter(Boolean)
.join(',')
.split(',')
.map((value) => value.trim())
.filter(Boolean);
};
const isFieldActive = (field) => {
if (!field) {return false;}
if (field.disabled) {return false;}
if (field.type === 'hidden') {return false;}
if (field.type === 'checkbox') {return field.checked;}
if (field.tagName === 'SELECT' && field.multiple) {
return Array.from(field.selectedOptions || []).some((option) => option.value);
}
if (field.tagName === 'SELECT') {
const value = String(field.value || '').trim();
const empty = new Set(['', 'all', ...getEmptyValues(field)]);
return value !== '' && !empty.has(value);
}
return String(field.value || '').trim() !== '';
};
const isOptionalActive = (item) => {
const fields = item.matches('input, select, textarea')
? [item]
: Array.from(item.querySelectorAll('input, select, textarea'));
return fields.some(isFieldActive);
};
export function initFilterOverflow(root = document) {
const toolbars = root.querySelectorAll('[data-filter-overflow]');
toolbars.forEach((toolbar) => {
if (toolbar.dataset.filterOverflowBound === '1') {return;}
toolbar.dataset.filterOverflowBound = '1';
const optional = Array.from(toolbar.querySelectorAll('[data-filter-optional]'));
if (!optional.length) {return;}
const toggle = toolbar.querySelector('[data-filter-toggle]');
if (!toggle) {
warnOnce('UI_EL_MISSING', 'Missing filter overflow toggle', { module: 'filter-overflow' });
return;
}
const setExpanded = (expanded) => {
optional.forEach((item) => {
item.hidden = !expanded;
});
toggle.setAttribute('aria-expanded', expanded ? 'true' : 'false');
};
const hasActiveOptional = optional.some(isOptionalActive);
setExpanded(hasActiveOptional);
toggle.addEventListener('click', () => {
const expanded = toggle.getAttribute('aria-expanded') === 'true';
setExpanded(!expanded);
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => initFilterOverflow());
} else {
initFilterOverflow();
}

View File

@@ -1,92 +0,0 @@
export function initToolbarToggles(root = document) {
const toggles = root.querySelectorAll('[data-toolbar-toggle]');
toggles.forEach((toggle) => {
if (toggle.dataset.toolbarBound === '1') {
return;
}
toggle.dataset.toolbarBound = '1';
if (!toggle.hasAttribute('type')) {
toggle.setAttribute('type', 'button');
}
const targetSelector = toggle.dataset.toolbarTarget || toggle.getAttribute('aria-controls');
if (!targetSelector) {
return;
}
const targets = Array.from(root.querySelectorAll(targetSelector)).filter(Boolean);
if (!targets.length) {
return;
}
const labelTarget = toggle.querySelector('[data-toolbar-label]');
const showLabel = toggle.dataset.toolbarTextShow;
const hideLabel = toggle.dataset.toolbarTextHide;
const storageKey =
toggle.dataset.toolbarStorageKey ||
(targets.length === 1 && targets[0].id
? `toolbar:${targets[0].id}`
: `toolbar:${targetSelector}`);
if (!toggle.getAttribute('aria-controls') && targets.length === 1 && targets[0].id) {
toggle.setAttribute('aria-controls', targets[0].id);
}
targets.forEach((target) => {
if (target.dataset.toolbarInitialized === '1') {
return;
}
const initial = target.dataset.toolbarInitial;
if (initial === 'hidden') {
target.hidden = true;
} else if (initial === 'shown') {
target.hidden = false;
}
target.dataset.toolbarInitialized = '1';
});
if (storageKey) {
try {
const stored = localStorage.getItem(storageKey);
if (stored === 'hidden' || stored === 'shown') {
const shouldShow = stored === 'shown';
targets.forEach((target) => {
target.hidden = !shouldShow;
});
}
} catch (error) {
// localStorage not available
}
}
const getExpanded = () => targets.every((target) => !target.hidden);
const setExpanded = (expanded) => {
targets.forEach((target) => {
target.hidden = !expanded;
});
toggle.setAttribute('aria-expanded', expanded ? 'true' : 'false');
if (labelTarget && (showLabel || hideLabel)) {
labelTarget.textContent = expanded ? (hideLabel || labelTarget.textContent) : (showLabel || labelTarget.textContent);
}
if (storageKey) {
try {
localStorage.setItem(storageKey, expanded ? 'shown' : 'hidden');
} catch (error) {
// localStorage not available
}
}
};
setExpanded(getExpanded());
toggle.addEventListener('click', () => {
setExpanded(!getExpanded());
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => initToolbarToggles());
} else {
initToolbarToggles();
}

View File

@@ -0,0 +1,37 @@
import { warnOnce } from './app-dom.js';
export function readPageConfig(configId, root = document) {
const id = `page-config-${String(configId || '').trim()}`;
if (!id || id === 'page-config-') {
warnOnce('UI_CONFIG_INVALID', 'Invalid page config id', { module: 'page-config', configId });
return null;
}
const node = root.getElementById(id);
if (!node) {
warnOnce('UI_CONFIG_MISSING', `Missing page config element: #${id}`, { module: 'page-config', configId });
return null;
}
const raw = String(node.textContent || '').trim();
if (raw === '') {
warnOnce('UI_CONFIG_EMPTY', `Empty page config payload: #${id}`, { module: 'page-config', configId });
return null;
}
try {
const parsed = JSON.parse(raw);
if (!parsed || typeof parsed !== 'object') {
warnOnce('UI_CONFIG_INVALID', `Page config is not an object: #${id}`, { module: 'page-config', configId });
return null;
}
return parsed;
} catch (error) {
warnOnce('UI_CONFIG_PARSE_FAIL', `Failed to parse page config: #${id}`, {
module: 'page-config',
configId,
error,
});
return null;
}
}

View File

@@ -0,0 +1,208 @@
import { initMultiSelect } from '../components/app-multiselect-init.js';
import { initMultiSelectCascade } from '../components/app-multiselect-cascade.js';
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase, escapeHtml, buildBadgeList, gridFilterMultiCsv, gridFilterText } from './app-list-utils.js';
const config = readPageConfig('address-book-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const toolbar = document.querySelector('#address-book-drawer-toolbar');
const saveFilterButton = document.querySelector('[data-address-book-save-filter]');
const saveFilterForm = document.querySelector('#address-book-save-filter-form');
const customFilterInputs = Array.from(document.querySelectorAll('[data-address-book-custom-filter]'));
const tenantDepartmentMap = toolbar?.dataset?.tenantDeptMap
? JSON.parse(toolbar.dataset.tenantDeptMap)
: {};
const uuidIndex = 0;
const normalizeCommaSeparated = (value) => {
if (Array.isArray(value)) {return value.filter(Boolean);}
return String(value || '')
.split(',')
.map((item) => item.trim())
.filter(Boolean);
};
const initialsForName = (name) => {
const parts = String(name || '')
.trim()
.split(/\s+/)
.filter(Boolean);
const chars = parts.slice(0, 2).map((value) => value[0] || '').join('').toUpperCase();
return chars || '?';
};
const customFilters = customFilterInputs.map((input) => {
const param = String(input?.dataset?.addressBookCustomFilterParam || '').trim();
if (!param) {return null;}
if (input.dataset.addressBookCustomFilterType === 'multiselect') {
const targetSelector = input.dataset.addressBookCustomFilterInput || '';
return gridFilterMultiCsv(targetSelector, param, { default: [] });
}
return gridFilterText(input, param, { default: '' });
}).filter(Boolean);
const gridOptions = {
gridjs: window.gridjs,
container: '#address-book-grid',
dataUrl: 'address-book/data',
appBase,
columns: [
{ name: 'UUID', hidden: true },
{
name: labels.name || 'Name',
sort: true,
formatter: (cell) => {
const nameValue = typeof cell === 'object' && cell !== null
? (cell.name ?? '')
: cell;
const avatarUuid = typeof cell === 'object' && cell !== null
? (cell.avatar_uuid ?? '')
: '';
const name = escapeHtml(nameValue || '-');
if (!avatarUuid) {
const initials = escapeHtml(initialsForName(nameValue));
return gridjs.html(`<span class="grid-name-cell"><span class="grid-avatar grid-avatar-placeholder">${initials}</span><span>${name}</span></span>`);
}
const src = new URL(`admin/users/avatar-file?uuid=${avatarUuid}&size=64`, appBase).toString();
const full = new URL(`admin/users/avatar-file?uuid=${avatarUuid}&size=256`, appBase).toString();
return gridjs.html(`<span class="grid-name-cell"><a data-fslightbox="address-book-avatars" href="${full}"><img class="grid-avatar" src="${src}" alt="" loading="lazy"></a><span>${name}</span></span>`);
},
},
{ name: labels.email || 'Email', sort: true },
{ name: labels.phone || 'Phone', sort: false },
{ name: labels.mobile || 'Mobile', sort: false },
{ name: labels.shortDial || 'Short dial', sort: false },
{ name: labels.tenants || 'Tenants', sort: false, formatter: (cell) => gridjs.html(buildBadgeList(cell)) },
{ name: labels.departments || 'Departments', sort: false, formatter: (cell) => gridjs.html(buildBadgeList(cell)) },
{ name: labels.roles || 'Roles', sort: false, formatter: (cell) => gridjs.html(buildBadgeList(cell)) },
],
sortColumns: [null, 'display_name', 'email', null, null, null, null, null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.uuid,
{
name: row.display_name,
avatar_uuid: row.has_avatar ? row.uuid : '',
},
row.email,
row.phone,
row.mobile,
row.short_dial,
row.tenants,
row.departments,
row.roles,
]),
search: gridSearch,
filterSchema,
extraFilters: customFilters,
urlSync: true,
rowDataset: (row) => ({
uuid: row?.cells?.[uuidIndex]?.data,
}),
rowDblClick: {
getUrl: (rowData) => {
const uuid = rowData?.cells?.[uuidIndex]?.data;
return uuid ? new URL(`address-book/view/${uuid}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#address-book-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Address book grid init failed');
}
initMultiSelect().then(() => {
initMultiSelectCascade({
parent: '#address-book-tenant-filter',
child: '#address-book-department-filter',
map: tenantDepartmentMap,
mode: 'disable',
clearInvalid: true,
});
});
const normalizeJoined = (value) => normalizeCommaSeparated(value).join(',');
if (saveFilterButton && saveFilterForm) {
saveFilterButton.addEventListener('click', () => {
if (!gridConfig) {
return;
}
const promptText = saveFilterButton.dataset.saveFilterPrompt || '';
const emptyText = saveFilterButton.dataset.saveFilterEmpty || '';
const enteredName = window.prompt(promptText, '');
if (enteredName === null) {
return;
}
const name = String(enteredName).trim();
if (!name) {
if (emptyText) {
window.alert(emptyText);
}
return;
}
const appliedQuery = new URL(gridConfig.baseUrl()).searchParams;
const state = {
search: String(appliedQuery.get('search') || '').trim(),
tenants: normalizeJoined(appliedQuery.get('tenants') || ''),
departments: normalizeJoined(appliedQuery.get('departments') || ''),
roles: normalizeJoined(appliedQuery.get('roles') || ''),
custom: {},
};
appliedQuery.forEach((value, key) => {
if (!/^(cf_|cfm_|cfd_)/i.test(key)) {
return;
}
const cleanedValue = String(value || '').trim();
if (cleanedValue === '') {
return;
}
state.custom[key] = cleanedValue;
});
const nameInput = saveFilterForm.querySelector('input[name="name"]');
const searchInput = saveFilterForm.querySelector('input[name="search"]');
const tenantsInput = saveFilterForm.querySelector('input[name="tenants"]');
const departmentsInput = saveFilterForm.querySelector('input[name="departments"]');
const rolesInput = saveFilterForm.querySelector('input[name="roles"]');
const extrasContainer = saveFilterForm.querySelector('[data-address-book-save-filter-extra]');
if (!nameInput || !searchInput || !tenantsInput || !departmentsInput || !rolesInput) {
return;
}
nameInput.value = name;
searchInput.value = state.search;
tenantsInput.value = state.tenants;
departmentsInput.value = state.departments;
rolesInput.value = state.roles;
if (extrasContainer) {
extrasContainer.innerHTML = '';
Object.entries(state.custom || {}).forEach(([key, value]) => {
const hidden = document.createElement('input');
hidden.type = 'hidden';
hidden.name = key;
hidden.value = String(value ?? '');
extrasContainer.appendChild(hidden);
});
}
saveFilterForm.requestSubmit();
});
}
}

View File

@@ -0,0 +1,148 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-api-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initApiAuditGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#api-audit-grid',
dataUrl: 'admin/api-audit/data',
appBase,
columns: [
{
name: labels.created || 'Created',
sort: true,
},
{
name: labels.statusCode || 'Status code',
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: labels.method || 'Method',
sort: true,
formatter: (cell) => {
const method = String(cell || '').toUpperCase();
return gridjs.html(`<span class="badge" data-variant="neutral">${method}</span>`);
},
},
{
name: labels.path || 'Path',
sort: true,
},
{
name: labels.durationMs || 'Duration (ms)',
sort: true,
formatter: (cell) => (cell > 0 ? `${cell}` : '-'),
},
{
name: labels.user || 'User',
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: labels.tenant || 'Tenant',
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/tenants/edit/${cell.uuid}`, appBase).toString();
return gridjs.html(`<a href="${url}">${label}</a>`);
},
},
{
name: labels.errorCode || 'Error code',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell)}</code>`) : gridjs.html('-')),
},
{
name: labels.ip || 'IP',
sort: false,
},
{
name: 'ID',
hidden: true,
},
],
sortColumns: ['created_at', 'status_code', 'method', 'path', 'duration_ms', null, null, null, null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{
variant: row.status_badge,
label: String(row.status_code || ''),
},
row.method,
row.path,
row.duration_ms,
{
uuid: row.user_uuid || '',
label: row.user_label || '-',
},
{
uuid: row.tenant_uuid || '',
label: row.tenant_label || '-',
},
row.error_code || '',
row.ip || '',
row.id,
]),
actions: {
enabled: false,
},
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[9]?.data;
return id ? new URL(`admin/api-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#api-audit-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('API audit grid init failed');
return null;
}
return gridConfig;
};
initApiAuditGrid();
}

View File

@@ -0,0 +1,121 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { badgeHtml, getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-departments-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initDepartmentsGrid = () => {
const formatBadge = (value) => badgeHtml(gridjs, value);
const formatCount = (value) => {
const number = Number(value ?? 0);
return Number.isFinite(number) ? number : 0;
};
const statusLabels = {
active: labels.active || 'Active',
inactive: labels.inactive || 'Inactive',
};
const formatStatus = (value) => {
const normalized = String(value ?? '1').toLowerCase();
const isInactive = ['0', 'false', 'inactive'].includes(normalized);
const variant = isInactive ? 'danger' : 'success';
const label = isInactive ? statusLabels.inactive : statusLabels.active;
return gridjs.html(`<span class="badge" data-variant="${variant}">${label}</span>`);
};
const gridOptions = {
gridjs: window.gridjs,
container: '#departments-grid',
dataUrl: 'admin/departments/data',
appBase,
columns: [
{ name: labels.description || 'Description', sort: true },
{
name: labels.status || 'Status',
sort: false,
formatter: (cell) => formatStatus(cell),
},
{ name: labels.code || 'Code', sort: true },
{ name: labels.costCenter || 'Cost center', sort: true },
{
name: labels.activeUsers || 'Active users',
sort: false,
formatter: (cell) => formatCount(cell),
},
{
name: labels.inactiveUsers || 'Inactive users',
sort: false,
formatter: (cell) => formatCount(cell),
},
{
name: labels.created || 'Created',
sort: true,
formatter: (cell) => formatBadge(cell),
},
{
name: labels.modified || 'Modified',
sort: true,
formatter: (cell) => formatBadge(cell),
},
{
name: 'UUID',
hidden: true,
},
],
sortColumns: ['description', null, 'code', 'cost_center', null, null, 'created', 'modified', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.description,
row.active,
row.code,
row.cost_center,
row.active_users ?? 0,
row.inactive_users ?? 0,
row.created,
row.modified,
row.uuid,
]),
actions: { enabled: false },
search: gridSearch,
filterSchema,
urlSync: true,
rowDataset: (row) => ({
uuid: row?.cells?.[8]?.data,
}),
rowDblClick: {
getUrl: (rowData) => {
const uuid = rowData?.cells?.[8]?.data;
return uuid ? new URL(`admin/departments/edit/${uuid}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#department-search'],
preserveFilterParamsOnReset: ['tenant'],
drawer: {
countExcludeParams: ['tenant'],
},
clearMetaOptions: {
preserveFilterParams: ['tenant'],
},
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Departments grid init failed');
return null;
}
return gridConfig;
};
initDepartmentsGrid();
}

View File

@@ -0,0 +1,103 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-import-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const profileLabel = (value) => {
const key = String(value || '').toLowerCase();
if (key === 'users') {return labels.users || 'Users';}
if (key === 'departments') {return labels.departments || 'Departments';}
return key || '-';
};
const gridOptions = {
gridjs: window.gridjs,
container: '#import-audit-grid',
dataUrl: 'admin/import-audit/data',
appBase,
columns: [
{ name: labels.created || 'Created', sort: true },
{
name: labels.status || '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: labels.profile || 'Profile',
sort: true,
formatter: (cell) => profileLabel(cell),
},
{ name: labels.durationMs || 'Duration (ms)', sort: true, formatter: (cell) => (cell > 0 ? `${cell}` : '-') },
{ name: labels.rowsTotal || 'Rows total', sort: true },
{ name: labels.createdCount || 'Created count', sort: true },
{ name: labels.skippedCount || 'Skipped count', sort: true },
{ name: labels.failedCount || 'Failed count', sort: true },
{
name: labels.user || 'User',
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: 'ID', hidden: true },
],
sortColumns: ['started_at', 'status', 'profile_key', 'duration_ms', 'rows_total', 'created_count', 'skipped_count', 'failed_count', null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.started_at,
{ variant: row.status_badge, label: row.status_label || row.status || '' },
row.profile_key,
row.duration_ms,
row.rows_total,
row.created_count,
row.skipped_count,
row.failed_count,
{ uuid: row.user_uuid || '', label: row.user_label || '-' },
row.id,
]),
actions: { enabled: false },
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[9]?.data;
return id ? new URL(`admin/import-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#import-audit-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Import audit grid init failed');
}
}

View File

@@ -0,0 +1,102 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-mail-log-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initMailLogGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#mail-log-grid',
dataUrl: 'admin/mail-log/data',
appBase,
columns: [
{
name: labels.created || 'Created',
sort: true,
},
{
name: labels.status || 'Status',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
const variant = cell.variant || 'neutral';
const label = cell.label || '';
return gridjs.html(`<span class="badge" data-variant="${variant}">${label}</span>`);
},
},
{
name: labels.recipient || 'Recipient',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html(String(cell ?? ''));
}
return gridjs.html(String(cell ?? ''));
},
},
{
name: labels.subject || 'Subject',
sort: true,
},
{
name: labels.template || 'Template',
sort: false,
},
{
name: 'ID',
hidden: true,
},
],
sortColumns: ['created_at', 'status', 'to_email', 'subject', null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{
variant: row.status_badge,
label: row.status_label,
},
row.to_email,
row.subject,
row.template || '-',
row.id,
]),
actions: {
enabled: false,
},
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[5]?.data;
return id ? new URL(`admin/mail-log/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#mail-log-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Mail log grid init failed');
return null;
}
return gridConfig;
};
initMailLogGrid();
}

View File

@@ -0,0 +1,77 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { badgeHtml, getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-permissions-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initPermissionsGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#permissions-grid',
dataUrl: 'admin/permissions/data',
appBase,
columns: [
{ name: labels.description || 'Description', sort: true },
{ name: labels.permissionKey || 'Permission key', sort: true },
{
name: labels.status || 'Status',
sort: true,
formatter: (cell) => cell
? gridjs.html(`<span class="badge" data-variant="success">${labels.active || 'Active'}</span>`)
: gridjs.html(`<span class="badge" data-variant="danger">${labels.inactive || 'Inactive'}</span>`),
},
{
name: labels.system || 'System',
sort: false,
formatter: (cell) => cell
? gridjs.html(`<span class="badge" data-variant="neutral">${labels.system || 'System'}</span>`)
: gridjs.html(''),
},
{ name: labels.created || 'Created', sort: true, formatter: (cell) => badgeHtml(gridjs, cell) },
{ name: 'ID', hidden: true },
],
sortColumns: ['description', 'key', 'active', null, 'created', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.description,
row.key,
row.active,
row.is_system,
row.created,
row.id,
]),
rowDblClick: {
getUrl: (row) => {
const id = row?.cells?.[5]?.data;
return id ? new URL(`admin/permissions/edit/${id}`, appBase).toString() : '';
},
},
search: gridSearch,
filterSchema,
urlSync: true,
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#permission-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Permissions grid init failed');
return null;
}
return gridConfig;
};
initPermissionsGrid();
}

View File

@@ -0,0 +1,126 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { badgeHtml, getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-roles-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initRolesGrid = () => {
const formatBadge = (value) => badgeHtml(gridjs, value);
const formatCount = (value) => {
const number = Number(value ?? 0);
return Number.isFinite(number) ? number : 0;
};
const gridOptions = {
gridjs: window.gridjs,
container: '#roles-grid',
dataUrl: 'admin/roles/data',
appBase,
columns: [
{
name: labels.description || 'Description',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html(String(cell ?? ''));
}
const label = cell.label ?? '';
return gridjs.html(`${label}`);
},
},
{
name: labels.status || 'Status',
sort: true,
formatter: (cell) => cell
? gridjs.html(`<span class="badge" data-variant="success">${labels.active || 'Active'}</span>`)
: gridjs.html(`<span class="badge" data-variant="danger">${labels.inactive || 'Inactive'}</span>`),
},
{
name: labels.code || 'Code',
sort: true,
formatter: (cell) => gridjs.html(String(cell ?? '')),
},
{
name: labels.activeUsers || 'Active users',
sort: false,
formatter: (cell) => formatCount(cell),
},
{
name: labels.inactiveUsers || 'Inactive users',
sort: false,
formatter: (cell) => formatCount(cell),
},
{
name: labels.permissions || 'Permissions',
sort: false,
formatter: (cell) => formatCount(cell),
},
{
name: labels.created || 'Created',
sort: true,
formatter: (cell) => formatBadge(cell),
},
{
name: labels.modified || 'Modified',
sort: true,
formatter: (cell) => formatBadge(cell),
},
{
name: 'UUID',
hidden: true,
},
],
sortColumns: ['description', 'active', 'code', null, null, null, 'created', 'modified', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
{
label: row.description,
is_default: row.is_default ? 1 : 0,
},
row.active,
row.code,
row.active_users ?? 0,
row.inactive_users ?? 0,
row.permission_count ?? 0,
row.created,
row.modified,
row.uuid,
]),
actions: { enabled: false },
search: gridSearch,
filterSchema,
urlSync: true,
rowDataset: (row) => ({
uuid: row?.cells?.[8]?.data,
}),
rowDblClick: {
getUrl: (rowData) => {
const uuid = rowData?.cells?.[8]?.data;
return uuid ? new URL(`admin/roles/edit/${uuid}`, appBase).toString() : '';
},
},
};
const { gridConfig: standardGridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#role-search'],
},
});
if (!standardGridConfig || !standardGridConfig.grid) {
console.warn('Roles grid init failed');
return null;
}
return standardGridConfig;
};
initRolesGrid();
}

View File

@@ -0,0 +1,106 @@
import { createServerGrid } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-scheduled-jobs-edit');
if (config) {
const appBase = getAppBase();
const labels = config.labels ?? {};
const searchConfig = config.search ?? { input: '#scheduled-job-runs-search', param: 'search', debounce: 250 };
const filterConfig = Array.isArray(config.filters) ? config.filters : [
{ input: '#scheduled-job-runs-status-filter', param: 'status' },
{ input: '#scheduled-job-runs-trigger-filter', param: 'trigger_type' },
];
const scheduleTypeInput = document.querySelector('#scheduled-job-schedule-type');
const scheduleTimeWrap = document.querySelector('[data-schedule-time-wrap]');
const scheduleWeekdaysWrap = document.querySelector('[data-schedule-weekdays-wrap]');
const updateScheduleVisibility = () => {
const type = (scheduleTypeInput?.value || 'daily').toLowerCase();
const showTime = type === 'daily' || type === 'weekly';
const showWeekdays = type === 'weekly';
if (scheduleTimeWrap) {
scheduleTimeWrap.hidden = !showTime;
}
if (scheduleWeekdaysWrap) {
scheduleWeekdaysWrap.hidden = !showWeekdays;
}
};
if (scheduleTypeInput) {
scheduleTypeInput.addEventListener('change', updateScheduleVisibility);
updateScheduleVisibility();
}
createServerGrid({
gridjs: window.gridjs,
container: '#scheduled-job-runs-grid',
dataUrl: `admin/scheduled-jobs/runs-data/${config.jobId}`,
appBase,
columns: [
{
name: labels.started || 'Started',
sort: true,
},
{
name: labels.status || '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: labels.trigger || 'Trigger',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return '-';
}
return String(cell.label || '-');
},
},
{
name: labels.durationMs || 'Duration (ms)',
sort: true,
formatter: (cell) => (Number(cell) > 0 ? `${cell}` : '-'),
},
{
name: labels.errorCode || 'Error code',
sort: false,
},
{
name: labels.user || 'User',
sort: false,
},
{
name: labels.runUuid || 'Run UUID',
sort: false,
},
],
sortColumns: ['started_at', 'status', 'trigger_type', 'duration_ms', null, null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.started_at || '-',
{
variant: row.status_badge,
label: row.status_label || row.status || '',
},
{ label: row.trigger_type_label || row.trigger_type || '-' },
row.duration_ms || 0,
row.error_code || '-',
row.actor_label || '-',
row.run_uuid || '-',
]),
actions: {
enabled: false,
},
search: searchConfig,
filters: filterConfig,
urlSync: false,
});
}

View File

@@ -0,0 +1,96 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-scheduled-jobs-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const gridOptions = {
gridjs: window.gridjs,
container: '#scheduled-jobs-grid',
dataUrl: 'admin/scheduled-jobs/data',
appBase,
columns: [
{
name: labels.job || 'Job',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('-');
}
const fallbackLabel = String(cell.job_key || '')
.toLowerCase()
.replace(/_/g, ' ')
.replace(/^./, (char) => char.toUpperCase());
return gridjs.html(cell.label || fallbackLabel || '-');
},
},
{
name: labels.enabled || 'Enabled',
sort: true,
formatter: (cell) => {
const enabled = Number(cell) === 1;
const variant = enabled ? 'success' : 'neutral';
const label = enabled ? (labels.enabled || 'Enabled') : (labels.disabled || 'Disabled');
return gridjs.html(`<span class="badge" data-variant="${variant}">${label}</span>`);
},
},
{ name: labels.nextRun || 'Next run', sort: true },
{ name: labels.schedule || 'Schedule', sort: false },
{ name: labels.lastRun || 'Last run', sort: true },
{
name: labels.status || '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: labels.lastError || 'Last error', sort: false },
{ name: 'ID', hidden: true },
],
sortColumns: ['job_key', 'enabled', 'next_run_at', null, 'last_run_finished_at', 'last_run_status', null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
{ id: row.id, label: row.label || row.job_key, job_key: row.job_key },
row.enabled,
row.next_run_at || '-',
row.schedule_summary || '-',
row.last_run_finished_at || '-',
{ variant: row.last_run_status_badge, label: row.last_run_status_label || row.last_run_status || '' },
row.last_error || '-',
row.id,
]),
actions: { enabled: false },
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[7]?.data;
return id ? new URL(`admin/scheduled-jobs/edit/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#scheduled-jobs-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Scheduled jobs grid init failed');
}
}

View File

@@ -0,0 +1,108 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-system-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initSystemAuditGrid = () => {
const gridOptions = {
gridjs: window.gridjs,
container: '#system-audit-grid',
dataUrl: 'admin/system-audit/data',
appBase,
columns: [
{ name: labels.created || 'Created', sort: true },
{
name: labels.status || '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: labels.event || 'Event', sort: true },
{ name: labels.channel || 'Channel', sort: true },
{
name: labels.actor || '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: labels.targetType || 'Target type', sort: false },
{
name: labels.requestId || 'Request ID',
sort: false,
formatter: (cell) => (cell ? gridjs.html(`<code>${String(cell).slice(0, 8)}</code>`) : gridjs.html('-')),
},
{
name: labels.errorCode || '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: config.gridLang ?? {},
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');
}
}

View File

@@ -0,0 +1,145 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { badgeHtml, escapeHtml, getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-tenants-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const initTenantsGrid = () => {
const formatBadge = (value) => badgeHtml(gridjs, value);
const formatStatus = (value) => {
if (!value || typeof value !== 'object') {
return gridjs.html('-');
}
const variant = String(value.variant || 'neutral');
const label = String(value.label || '-');
return gridjs.html(`<span class="badge" data-variant="${variant}">${label}</span>`);
};
const formatTheme = (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
const themeLabel = escapeHtml(cell.label ?? '');
const label = cell.is_override ? themeLabel : `${themeLabel} (${escapeHtml(labels.default || 'Default')})`;
return gridjs.html(label);
};
const formatSso = (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html('');
}
if (!cell.enabled) {
return gridjs.html(escapeHtml(labels.inactive || 'Inactive'));
}
if (cell.microsoft_only) {
return gridjs.html(escapeHtml(labels.microsoftOnly || 'Microsoft only'));
}
return gridjs.html(escapeHtml(labels.active || 'Active'));
};
const formatCount = (value) => {
const number = Number(value ?? 0);
return Number.isFinite(number) ? number : 0;
};
const gridOptions = {
gridjs: window.gridjs,
container: '#tenants-grid',
dataUrl: 'admin/tenants/data',
appBase,
columns: [
{
name: labels.description || 'Description',
sort: true,
formatter: (cell) => {
if (!cell || typeof cell !== 'object') {
return gridjs.html(String(cell ?? ''));
}
const label = cell.label ?? '';
return gridjs.html(`${label}`);
},
},
{
name: labels.status || 'Status',
sort: false,
formatter: (cell) => formatStatus(cell),
},
{
name: labels.theme || 'Theme',
sort: true,
formatter: (cell) => formatTheme(cell),
},
{
name: labels.sso || 'SSO',
sort: true,
formatter: (cell) => formatSso(cell),
},
{
name: labels.activeUsers || 'Active users',
sort: true,
formatter: (cell) => formatCount(cell),
},
{
name: labels.inactiveUsers || 'Inactive users',
sort: true,
formatter: (cell) => formatCount(cell),
},
{
name: labels.created || 'Created',
sort: true,
formatter: (cell) => formatBadge(cell),
},
{
name: 'UUID',
hidden: true,
},
],
sortColumns: ['description', 'status', 'theme', 'sso', 'active_users', 'inactive_users', 'created', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
{
label: row.description,
is_default: row.is_default ? 1 : 0,
},
{ variant: row.status_badge || 'neutral', label: row.status_label || row.status || '-' },
row.theme ?? null,
row.sso ?? null,
row.active_users ?? 0,
row.inactive_users ?? 0,
row.created,
row.uuid,
]),
actions: { enabled: false },
search: gridSearch,
filterSchema,
urlSync: true,
rowDataset: (row) => ({
uuid: row?.cells?.[7]?.data,
}),
rowDblClick: {
getUrl: (rowData) => {
const uuid = rowData?.cells?.[7]?.data;
return uuid ? new URL(`admin/tenants/edit/${uuid}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#tenant-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Tenants grid init failed');
return null;
}
return gridConfig;
};
initTenantsGrid();
}

View File

@@ -0,0 +1,76 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase } from './app-list-utils.js';
const config = readPageConfig('admin-user-lifecycle-audit-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const filterChipMeta = config.filterChipMeta ?? [];
const labels = config.labels ?? {};
const gridOptions = {
gridjs: window.gridjs,
container: '#user-lifecycle-audit-grid',
dataUrl: 'admin/user-lifecycle-audit/data',
appBase,
columns: [
{ name: labels.created || 'Created', sort: true },
{
name: labels.status || '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: labels.action || 'Action', sort: true },
{ name: labels.trigger || 'Trigger', sort: true },
{ name: labels.targetEmail || 'Target email', sort: false },
{ name: labels.targetUuid || 'Target UUID', sort: false },
{ name: labels.reasonCode || 'Reason code', sort: false },
{ name: labels.restoredAt || 'Restored at', sort: true },
{ name: 'ID', hidden: true },
],
sortColumns: ['created_at', 'status', 'action', 'trigger_type', null, null, null, 'restored_at', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.created_at,
{ variant: row.status_badge, label: row.status_label || row.status || '' },
row.action_label || row.action || '-',
row.trigger_type_label || row.trigger_type || '-',
row.target_user_email || '-',
row.target_user_uuid || '-',
row.reason_code || '-',
row.restored_at || '-',
row.id,
]),
actions: { enabled: false },
search: gridSearch,
filterSchema,
urlSync: true,
rowDblClick: {
getUrl: (rowData) => {
const id = rowData?.cells?.[8]?.data;
return id ? new URL(`admin/user-lifecycle-audit/view/${id}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: filterChipMeta,
watchInputs: ['#user-lifecycle-audit-search'],
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('User lifecycle audit grid init failed');
}
}

View File

@@ -0,0 +1,199 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { initUsersListPage } from './app-users-list.js';
import { bindBulkVisibility } from '../components/app-bulk-selection.js';
import { buildUrl, badgeHtml, getAppBase, escapeHtml, buildBadgeList } from './app-list-utils.js';
import { showAsyncFlash, withLoading } from '../components/app-async-flash.js';
const config = readPageConfig('admin-users-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const usersFilterChipMeta = config.filterChipMeta ?? [];
const currentUserUuid = String(config.currentUserUuid || '');
const canUpdateUsers = config.canUpdateUsers === true;
const canUpdateSelf = config.canUpdateSelf === true;
const csrf = config.csrf ?? null;
const labels = config.labels ?? {};
const buildBulkUrl = (action) => buildUrl(appBase, `admin/users/bulk/${action}`);
const initUsersGrid = () => {
const rowSelection = window.gridjs?.plugins?.selection?.RowSelection;
if (!rowSelection) {
throw new Error('Grid.js RowSelection plugin is not available.');
}
const activeIndex = 6;
const uuidIndex = 2;
const canEditRow = (row) => {
const uuid = row?.cells?.[uuidIndex]?.data;
if (!uuid) {return false;}
if (uuid === currentUserUuid) {
return canUpdateUsers || canUpdateSelf;
}
return canUpdateUsers;
};
const initialsForRow = (row) => {
const first = row?.cells?.[3]?.data ?? '';
const last = row?.cells?.[4]?.data ?? '';
const parts = [first, last]
.map((value) => String(value || '').trim())
.filter(Boolean);
const chars = parts.map((value) => value[0] || '').join('').toUpperCase();
return chars || '?';
};
const columns = [
{
name: labels.avatar || 'Avatar',
sort: false,
formatter: (cell, row) => {
if (!cell) {
const initials = escapeHtml(initialsForRow(row));
return gridjs.html(`<span class="grid-avatar grid-avatar-placeholder">${initials}</span>`);
}
const src = new URL(`admin/users/avatar-file?uuid=${cell}&size=64`, appBase).toString();
const full = new URL(`admin/users/avatar-file?uuid=${cell}&size=256`, appBase).toString();
return gridjs.html(`<a data-fslightbox="user-avatars" href="${full}"><img class="grid-avatar" src="${src}" alt="" loading="lazy"></a>`);
},
},
{ name: 'UUID', hidden: true },
{ name: labels.firstName || 'First name', sort: true },
{ name: labels.lastName || 'Last name', sort: true },
{ name: labels.email || 'Email', sort: true },
{
name: labels.state || 'State',
sort: true,
formatter: (cell) => cell
? gridjs.html(`<span class="badge" data-variant="success">${labels.active || 'Active'}</span>`)
: gridjs.html(`<span class="badge" data-variant="danger">${labels.inactive || 'Inactive'}</span>`),
},
{
name: labels.tenants || 'Tenants',
sort: false,
formatter: (cell) => gridjs.html(buildBadgeList(cell, { primaryTooltip: labels.primaryTenant || '' })),
},
{ name: labels.departments || 'Departments', sort: false, formatter: (cell) => gridjs.html(buildBadgeList(cell)) },
{ name: labels.roles || 'Roles', sort: false, formatter: (cell) => gridjs.html(buildBadgeList(cell)) },
{ name: labels.phone || 'Phone', sort: false },
{ name: labels.mobile || 'Mobile', sort: false },
{ name: labels.shortDial || 'Short dial', sort: false },
{ name: labels.created || 'Created', sort: true, formatter: (cell) => badgeHtml(gridjs, cell) },
{ name: labels.modified || 'Modified', sort: true, formatter: (cell) => badgeHtml(gridjs, cell) },
{
name: labels.lastLogin || 'Last login',
sort: true,
formatter: (cell) => badgeHtml(gridjs, cell || labels.never || 'Never'),
},
{ name: 'ID', hidden: true },
];
const gridOptions = {
gridjs: window.gridjs,
container: '#users-grid',
dataUrl: 'admin/users/data',
appBase,
columns,
sortColumns: [null, null, 'first_name', 'last_name', 'email', 'active', null, null, null, null, null, null, 'created', 'modified', 'last_login_at', null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [
row.has_avatar ? row.uuid : '',
row.uuid,
row.first_name,
row.last_name,
row.email,
row.active,
row.tenants,
row.departments,
row.roles,
row.phone,
row.mobile,
row.short_dial,
row.created,
row.modified,
row.last_login,
row.id,
]),
selection: {
enabled: true,
id: 'selectRow',
component: rowSelection,
selectAllLabel: labels.selectAll || 'Select all',
props: {
id: (row) => row.cell(uuidIndex).data,
},
getSelectedIds: ({ container }) => {
if (!container) {return [];}
return Array.from(container.querySelectorAll('.gridjs-tr-selected'))
.map((row) => row.getAttribute('data-uuid'))
.filter(Boolean);
},
},
search: gridSearch,
filterSchema,
urlSync: true,
rowDataset: (row) => ({
uuid: row?.cells?.[uuidIndex]?.data,
}),
rowDblClick: {
getUrl: (rowData) => {
if (!canEditRow(rowData)) {
return '';
}
const uuid = rowData?.cells?.[uuidIndex]?.data;
return uuid ? new URL(`admin/users/edit/${uuid}`, appBase).toString() : '';
},
},
};
const { gridConfig } = initStandardListPage({
grid: gridOptions,
filters: {
mode: 'drawer',
chipMeta: usersFilterChipMeta,
watchInputs: ['#user-search'],
preserveFilterParamsOnReset: ['tenant'],
drawer: {
countExcludeParams: ['tenant'],
},
clearMetaOptions: {
preserveFilterParams: ['tenant'],
},
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Users grid init failed');
return null;
}
return { ...gridConfig, indices: { activeIndex, uuidIndex } };
};
const gridConfig = initUsersGrid();
initUsersListPage({
gridConfig,
appBase,
csrf,
labels,
buildBulkUrl,
bulkDownloadForms: {
'access-pdf': '#users-access-pdf-bulk-form',
},
resetOptions: {
resetPage: true,
urlHistoryMode: 'push',
preserveFilterParams: ['tenant'],
},
showFlash: showAsyncFlash,
withLoading,
});
bindBulkVisibility({
containerSelector: '#users-grid',
buttonSelector: '[data-users-bulk]',
});
}

View File

@@ -0,0 +1,69 @@
import { initStandardListPage } from '../core/app-grid-factory.js';
import { readPageConfig } from '../core/app-page-config.js';
import { getAppBase, escapeHtml } from './app-list-utils.js';
const config = readPageConfig('search-index');
if (config) {
const appBase = getAppBase();
const gridSearch = config.gridSearch ?? null;
const filterSchema = config.filterSchema ?? [];
const labels = config.labels ?? {};
const renderResult = (cell) => {
const title = escapeHtml(cell?.title ?? '');
const description = escapeHtml(cell?.description ?? '');
const url = cell?.url ?? '#';
const image = cell?.image ?? '';
const icon = escapeHtml(cell?.icon ?? 'bi-search');
const avatar = image
? `<img class="search-result-avatar" src="${image}" alt="" loading="lazy">`
: `<span class="search-result-avatar-placeholder"><i class="bi ${icon}"></i></span>`;
return gridjs.html(`
<div class="search-result-row">
${avatar}
<div class="search-result-content">
<a class="search-result-title" href="${url}">${title}</a>
${description ? `<p class="search-result-desc">${description}</p>` : ''}
</div>
</div>
`);
};
const renderType = (cell) => gridjs.html(`<span class="search-result-type">${escapeHtml(cell ?? '')}</span>`);
const { gridConfig } = initStandardListPage({
grid: {
gridjs: window.gridjs,
container: '#search-results-grid',
dataUrl: 'search/data',
appBase,
columns: [
{
name: labels.result || 'Result',
sort: false,
formatter: (cell) => renderResult(cell),
},
{
name: labels.type || 'Type',
sort: false,
formatter: (cell) => renderType(cell),
},
],
sortColumns: [null, null],
paginationLimit: 10,
language: config.gridLang ?? {},
mapData: (data) => data.data.map((row) => [row, row.type]),
search: gridSearch,
filterSchema,
urlSync: true,
},
filters: {
mode: 'search-only',
},
});
if (!gridConfig || !gridConfig.grid) {
console.warn('Search results grid init failed');
}
}