Extra audit filters

This commit is contained in:
Evert Prants 2024-06-10 20:41:31 +03:00
parent 63f54c3338
commit 1b090be2bf
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 34 additions and 3 deletions

View File

@ -141,6 +141,7 @@
"user": "Actor",
"ip": "IP address",
"ua": "User agent",
"flagged": "Flagged",
"createdAt": "Created at"
}
}

View File

@ -13,6 +13,8 @@ export const load = async ({ url, parent }) => {
let actions: AuditAction[] | undefined = undefined;
let user: string | undefined = undefined;
let content: string | undefined = undefined;
let ip: string | undefined = undefined;
let flagged: boolean | undefined = undefined;
if (url.searchParams.has('page')) {
page = Number(url.searchParams.get('page')) || 1;
}
@ -33,9 +35,17 @@ export const load = async ({ url, parent }) => {
content = url.searchParams.get('content') as string;
}
if (url.searchParams.has('ip')) {
ip = url.searchParams.get('ip') as string;
}
if (url.searchParams.has('flagged')) {
flagged = !!url.searchParams.get('flagged');
}
const offset = (page - 1) * limit;
const data = await Audit.searchAudit({ limit, offset, actions, user, content });
const data = await Audit.searchAudit({ limit, offset, actions, user, content, ip, flagged });
return {
...data,
actions: Object.values(AuditAction)

View File

@ -25,7 +25,12 @@
<SplitView>
<FormControl>
<label for="actions">{$t('admin.audit.action')}</label>
<select name="actions" value={$page.url.searchParams.getAll('actions')} multiple>
<select
name="actions"
id="actions"
value={$page.url.searchParams.getAll('actions')}
multiple
>
{#each data.actions as action}
<option value={action}>{action}</option>
{/each}
@ -33,7 +38,22 @@
</FormControl>
<FormControl>
<label for="content">{$t('admin.audit.comment')}</label>
<input name="content" value={$page.url.searchParams.get('content')} />
<input name="content" id="content" value={$page.url.searchParams.get('content')} />
</FormControl>
</SplitView>
<SplitView>
<FormControl>
<label for="flagged">{$t('admin.audit.flagged')}</label>
<input
name="flagged"
id="flagged"
type="checkbox"
checked={!!$page.url.searchParams.get('flagged')}
/>
</FormControl>
<FormControl>
<label for="ip">{$t('admin.audit.ip')}</label>
<input name="ip" id="ip" value={$page.url.searchParams.get('ip')} />
</FormControl>
</SplitView>
<div>