2024-09-13 17:04:04 +02:00
|
|
|
<script lang="ts">
|
|
|
|
|
import WebsiteEditor from "$lib/components/WebsiteEditor.svelte";
|
|
|
|
|
import DateTime from "$lib/components/DateTime.svelte";
|
|
|
|
|
import Modal from "$lib/components/Modal.svelte";
|
2024-10-05 21:15:26 +02:00
|
|
|
import type { PageServerData, ActionData } from "./$types";
|
2024-09-13 17:04:04 +02:00
|
|
|
import { page } from "$app/stores";
|
|
|
|
|
import { tables } from "$lib/db-schema";
|
2024-09-27 16:59:29 +02:00
|
|
|
import { previewContent } from "$lib/runes.svelte";
|
2024-10-03 18:51:30 +02:00
|
|
|
import DOMPurify from "isomorphic-dompurify";
|
2024-10-05 21:15:26 +02:00
|
|
|
import { enhanceForm } from "$lib/utils";
|
|
|
|
|
import { enhance } from "$app/forms";
|
|
|
|
|
import { sending } from "$lib/runes.svelte";
|
|
|
|
|
import LoadingSpinner from "$lib/components/LoadingSpinner.svelte";
|
2024-10-19 21:01:45 +02:00
|
|
|
import Pagination from "$lib/components/Pagination.svelte";
|
2024-09-13 17:04:04 +02:00
|
|
|
|
2024-10-05 21:15:26 +02:00
|
|
|
const { data, form }: { data: PageServerData; form: ActionData } = $props();
|
2024-09-13 17:04:04 +02:00
|
|
|
|
|
|
|
|
let resources = $state({});
|
|
|
|
|
|
|
|
|
|
if (data.website.content_type === "Blog") {
|
2024-09-17 22:44:16 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2024-10-25 19:23:38 +02:00
|
|
|
const { user, change_log, docs_category, ...restTables } = tables;
|
2024-09-13 17:04:04 +02:00
|
|
|
resources = restTables;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (data.website.content_type === "Docs") {
|
2024-09-17 22:44:16 +02:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
2024-10-25 19:23:38 +02:00
|
|
|
const { user, change_log, ...restTables } = tables;
|
2024-09-13 17:04:04 +02:00
|
|
|
resources = restTables;
|
|
|
|
|
}
|
2024-09-15 21:37:32 +02:00
|
|
|
|
2024-09-27 16:59:29 +02:00
|
|
|
previewContent.value = data.home.main_content;
|
2024-09-13 17:04:04 +02:00
|
|
|
</script>
|
|
|
|
|
|
2024-10-05 21:15:26 +02:00
|
|
|
{#if sending.value}
|
|
|
|
|
<LoadingSpinner />
|
|
|
|
|
{/if}
|
|
|
|
|
|
2024-09-13 17:04:04 +02:00
|
|
|
<WebsiteEditor
|
|
|
|
|
id={data.website.id}
|
|
|
|
|
contentType={data.website.content_type}
|
|
|
|
|
title={data.website.title}
|
|
|
|
|
>
|
2024-10-05 21:15:26 +02:00
|
|
|
<section id="logs">
|
2024-09-13 17:04:04 +02:00
|
|
|
<hgroup>
|
|
|
|
|
<h2>
|
|
|
|
|
<a href="#logs">Logs</a>
|
|
|
|
|
</h2>
|
|
|
|
|
<p>
|
2024-09-15 21:37:32 +02:00
|
|
|
<strong>{data.resultChangeLogCount.toLocaleString("en", { useGrouping: true })}</strong>
|
|
|
|
|
<small>result(s)</small>
|
2024-09-13 17:04:04 +02:00
|
|
|
</p>
|
|
|
|
|
</hgroup>
|
|
|
|
|
<details>
|
|
|
|
|
<summary>Filter</summary>
|
|
|
|
|
<form method="GET">
|
|
|
|
|
<label>
|
|
|
|
|
Username:
|
|
|
|
|
<input
|
|
|
|
|
list="users-{data.website.id}"
|
2024-10-19 17:55:02 +02:00
|
|
|
name="user"
|
|
|
|
|
value={$page.url.searchParams.get("user")}
|
2024-09-13 17:04:04 +02:00
|
|
|
/>
|
|
|
|
|
<datalist id="users-{data.website.id}">
|
|
|
|
|
<option value={data.website.user.username}></option>
|
|
|
|
|
{#each data.collaborators as { user: { username } }}
|
|
|
|
|
<option value={username}></option>
|
|
|
|
|
{/each}
|
|
|
|
|
</datalist>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Resource:
|
2024-10-19 17:55:02 +02:00
|
|
|
<select name="resource">
|
2024-09-13 17:04:04 +02:00
|
|
|
<option value="all">Show all</option>
|
|
|
|
|
{#each Object.keys(resources) as resource}
|
|
|
|
|
<option
|
|
|
|
|
value={resource}
|
2024-10-19 17:55:02 +02:00
|
|
|
selected={resource === $page.url.searchParams.get("resource")}>{resource}</option
|
2024-09-13 17:04:04 +02:00
|
|
|
>
|
|
|
|
|
{/each}
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
|
|
|
|
<label>
|
|
|
|
|
Operation:
|
2024-10-19 17:55:02 +02:00
|
|
|
<select name="operation">
|
2024-09-13 17:04:04 +02:00
|
|
|
<option value="all">Show all</option>
|
2024-10-19 17:55:02 +02:00
|
|
|
<option value="insert" selected={"insert" === $page.url.searchParams.get("operation")}
|
2024-09-13 17:04:04 +02:00
|
|
|
>Insert</option
|
|
|
|
|
>
|
2024-10-19 17:55:02 +02:00
|
|
|
<option value="update" selected={"update" === $page.url.searchParams.get("operation")}
|
2024-09-13 17:04:04 +02:00
|
|
|
>Update</option
|
|
|
|
|
>
|
2024-10-19 17:55:02 +02:00
|
|
|
<option value="delete" selected={"delete" === $page.url.searchParams.get("operation")}
|
2024-09-13 17:04:04 +02:00
|
|
|
>Delete</option
|
|
|
|
|
>
|
|
|
|
|
</select>
|
|
|
|
|
</label>
|
2024-10-19 17:55:02 +02:00
|
|
|
<input type="hidden" name="page" value={1} />
|
2024-10-25 19:23:38 +02:00
|
|
|
<button type="submit">Apply</button>
|
2024-09-13 17:04:04 +02:00
|
|
|
</form>
|
|
|
|
|
</details>
|
|
|
|
|
<div class="scroll-container">
|
|
|
|
|
<table>
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th>User</th>
|
|
|
|
|
<th>Resource</th>
|
|
|
|
|
<th>Operation</th>
|
2024-10-19 17:55:02 +02:00
|
|
|
<th>Date & Time</th>
|
2024-09-13 17:04:04 +02:00
|
|
|
<th>Changes</th>
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
2024-10-26 23:12:56 +02:00
|
|
|
{#each data.changeLog as { id, table_name, operation, tstamp, old_value, new_value, user_id, username } (id)}
|
2024-09-13 17:04:04 +02:00
|
|
|
<tr>
|
2024-09-14 15:12:08 +02:00
|
|
|
<td>
|
|
|
|
|
<span style:text-decoration={user_id ? "" : "line-through"}>
|
|
|
|
|
{username}
|
|
|
|
|
</span>
|
|
|
|
|
</td>
|
2024-09-13 17:04:04 +02:00
|
|
|
<td>{table_name}</td>
|
|
|
|
|
<td>{operation}</td>
|
|
|
|
|
<td>
|
|
|
|
|
<DateTime date={tstamp} />
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<Modal id="log-{id}" text="Show" isWider={true}>
|
|
|
|
|
{@const oldValue = JSON.stringify(old_value, null, 2)}
|
|
|
|
|
{@const newValue = JSON.stringify(new_value, null, 2)}
|
|
|
|
|
|
|
|
|
|
<hgroup>
|
|
|
|
|
<h3>Log changes</h3>
|
2024-10-05 21:15:26 +02:00
|
|
|
<p>{table_name} — {operation} — User "{username}"</p>
|
2024-09-13 17:04:04 +02:00
|
|
|
</hgroup>
|
|
|
|
|
|
2024-10-05 21:15:26 +02:00
|
|
|
{#if old_value && new_value}
|
|
|
|
|
<h4>Difference</h4>
|
|
|
|
|
<form action="?/computeDiff" method="POST" use:enhance={enhanceForm()}>
|
|
|
|
|
<input type="hidden" name="id" value={id} />
|
|
|
|
|
<button type="submit">Compute diff</button>
|
|
|
|
|
</form>
|
|
|
|
|
{#if form?.logId === id && form?.currentDiff}
|
|
|
|
|
<pre style="white-space: pre-wrap">{@html DOMPurify.sanitize(
|
|
|
|
|
form.currentDiff,
|
|
|
|
|
{ ALLOWED_TAGS: ["ins", "del"] }
|
|
|
|
|
)}</pre>
|
|
|
|
|
{/if}
|
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if new_value && !old_value}
|
|
|
|
|
<h4>New value</h4>
|
2024-10-06 02:01:15 +02:00
|
|
|
<pre style="white-space: pre-wrap">{DOMPurify.sanitize(newValue)}</pre>
|
2024-10-05 21:15:26 +02:00
|
|
|
{/if}
|
|
|
|
|
|
|
|
|
|
{#if old_value && !new_value}
|
|
|
|
|
<h4>Old value</h4>
|
2024-10-06 02:01:15 +02:00
|
|
|
<pre style="white-space: pre-wrap">{DOMPurify.sanitize(oldValue)}</pre>
|
2024-10-05 21:15:26 +02:00
|
|
|
{/if}
|
2024-09-13 17:04:04 +02:00
|
|
|
</Modal>
|
|
|
|
|
</td>
|
|
|
|
|
</tr>
|
|
|
|
|
{/each}
|
|
|
|
|
</tbody>
|
|
|
|
|
</table>
|
2024-09-17 21:27:41 +02:00
|
|
|
</div>
|
2024-10-19 21:01:45 +02:00
|
|
|
<Pagination
|
|
|
|
|
commonFilters={["user", "resource", "operation"]}
|
|
|
|
|
resultCount={data.resultChangeLogCount}
|
|
|
|
|
/>
|
2024-09-13 17:04:04 +02:00
|
|
|
</section>
|
|
|
|
|
</WebsiteEditor>
|