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';
|
|
|
|
|
import AuditLogService from '$lib/services/audit-log-service';
|
|
|
|
|
import type { AuditLog } from '$lib/types/audit-log.type';
|
2024-10-16 08:49:19 +02:00
|
|
|
import type { Paginated } from '$lib/types/pagination.type';
|
2024-09-09 10:29:41 +02:00
|
|
|
|
|
|
|
|
let { auditLogs: initialAuditLog }: { auditLogs: Paginated<AuditLog> } = $props();
|
|
|
|
|
let auditLogs = $state<Paginated<AuditLog>>(initialAuditLog);
|
|
|
|
|
|
|
|
|
|
const auditLogService = new AuditLogService();
|
|
|
|
|
|
2024-10-16 08:49:19 +02:00
|
|
|
async function fetchItems(search: string, page: number, limit: number) {
|
|
|
|
|
return await auditLogService.list({
|
|
|
|
|
page,
|
|
|
|
|
limit
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-09-09 10:29:41 +02:00
|
|
|
|
|
|
|
|
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}
|
|
|
|
|
{fetchItems}
|
|
|
|
|
columns={['Time', 'Event', 'Approximate Location', 'IP Address', 'Device', 'Client']}
|
|
|
|
|
withoutSearch
|
|
|
|
|
>
|
|
|
|
|
{#snippet rows({ item })}
|
|
|
|
|
<Table.Cell>{new Date(item.createdAt).toLocaleString()}</Table.Cell>
|
|
|
|
|
<Table.Cell>
|
|
|
|
|
<Badge variant="outline">{toFriendlyEventString(item.event)}</Badge>
|
|
|
|
|
</Table.Cell>
|
|
|
|
|
<Table.Cell
|
|
|
|
|
>{item.city && item.country ? `${item.city}, ${item.country}` : 'Unknown'}</Table.Cell
|
|
|
|
|
>
|
|
|
|
|
<Table.Cell>{item.ipAddress}</Table.Cell>
|
|
|
|
|
<Table.Cell>{item.device}</Table.Cell>
|
|
|
|
|
<Table.Cell>{item.data.clientName}</Table.Cell>
|
|
|
|
|
{/snippet}
|
|
|
|
|
</AdvancedTable>
|