2024-09-09 10:29:41 +02:00
|
|
|
<script lang="ts">
|
2024-10-16 08:49:19 +02:00
|
|
|
import AdvancedTable from '$lib/components/advanced-table.svelte';
|
2024-09-09 10:29:41 +02:00
|
|
|
import { Badge } from '$lib/components/ui/badge';
|
|
|
|
|
import * as Table from '$lib/components/ui/table';
|
2025-03-20 19:57:41 +01:00
|
|
|
import { m } from '$lib/paraglide/messages';
|
2024-09-09 10:29:41 +02:00
|
|
|
import AuditLogService from '$lib/services/audit-log-service';
|
|
|
|
|
import type { AuditLog } from '$lib/types/audit-log.type';
|
2025-03-10 12:37:16 +01:00
|
|
|
import type { Paginated, SearchPaginationSortRequest } from '$lib/types/pagination.type';
|
2024-09-09 10:29:41 +02:00
|
|
|
|
2025-03-10 12:37:16 +01:00
|
|
|
let {
|
|
|
|
|
auditLogs,
|
2025-04-03 10:11:49 -05:00
|
|
|
isAdmin = false,
|
2025-03-10 12:37:16 +01:00
|
|
|
requestOptions
|
2025-04-03 10:11:49 -05:00
|
|
|
}: {
|
|
|
|
|
auditLogs: Paginated<AuditLog>;
|
|
|
|
|
isAdmin?: boolean;
|
|
|
|
|
requestOptions: SearchPaginationSortRequest;
|
|
|
|
|
} = $props();
|
2024-09-09 10:29:41 +02:00
|
|
|
|
|
|
|
|
const auditLogService = new AuditLogService();
|
|
|
|
|
|
|
|
|
|
function toFriendlyEventString(event: string) {
|
|
|
|
|
const words = event.split('_');
|
|
|
|
|
const capitalizedWords = words.map((word) => {
|
|
|
|
|
return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
|
|
|
|
|
});
|
|
|
|
|
return capitalizedWords.join(' ');
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-10-16 08:49:19 +02:00
|
|
|
<AdvancedTable
|
|
|
|
|
items={auditLogs}
|
2025-03-10 12:37:16 +01:00
|
|
|
{requestOptions}
|
2025-04-03 10:11:49 -05:00
|
|
|
onRefresh={async (options) =>
|
|
|
|
|
isAdmin
|
|
|
|
|
? (auditLogs = await auditLogService.listAllLogs(options))
|
|
|
|
|
: (auditLogs = await auditLogService.list(options))}
|
2025-01-11 20:14:12 +01:00
|
|
|
columns={[
|
2025-03-20 19:57:41 +01:00
|
|
|
{ label: m.time(), sortColumn: 'createdAt' },
|
2025-05-07 16:43:24 +02:00
|
|
|
...(isAdmin ? [{ label: 'Username' }] : []),
|
2025-03-20 19:57:41 +01:00
|
|
|
{ label: m.event(), sortColumn: 'event' },
|
|
|
|
|
{ label: m.approximate_location(), sortColumn: 'city' },
|
|
|
|
|
{ label: m.ip_address(), sortColumn: 'ipAddress' },
|
|
|
|
|
{ label: m.device(), sortColumn: 'device' },
|
|
|
|
|
{ label: m.client() }
|
2025-01-11 20:14:12 +01:00
|
|
|
]}
|
2024-10-16 08:49:19 +02:00
|
|
|
withoutSearch
|
|
|
|
|
>
|
|
|
|
|
{#snippet rows({ item })}
|
|
|
|
|
<Table.Cell>{new Date(item.createdAt).toLocaleString()}</Table.Cell>
|
2025-04-03 10:11:49 -05:00
|
|
|
{#if isAdmin}
|
|
|
|
|
<Table.Cell>
|
|
|
|
|
{#if item.username}
|
|
|
|
|
{item.username}
|
|
|
|
|
{:else}
|
|
|
|
|
Unknown User
|
|
|
|
|
{/if}
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
{/if}
|
2024-10-16 08:49:19 +02:00
|
|
|
<Table.Cell>
|
2025-05-21 12:15:27 -05:00
|
|
|
<Badge class="rounded-full" variant="outline">{toFriendlyEventString(item.event)}</Badge>
|
2024-10-16 08:49:19 +02:00
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell
|
2025-03-20 19:57:41 +01:00
|
|
|
>{item.city && item.country ? `${item.city}, ${item.country}` : m.unknown()}</Table.Cell
|
2024-10-16 08:49:19 +02:00
|
|
|
>
|
|
|
|
|
<Table.Cell>{item.ipAddress}</Table.Cell>
|
|
|
|
|
<Table.Cell>{item.device}</Table.Cell>
|
|
|
|
|
<Table.Cell>{item.data.clientName}</Table.Cell>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</AdvancedTable>
|