Compare commits
148 Commits
f4e1917357
...
developmen
| Author | SHA1 | Date | |
|---|---|---|---|
| 810b020d7d | |||
| 5be89f83fd | |||
| 2a7783004a | |||
| 6f9b386c18 | |||
| b4d9824942 | |||
| 776cc7a1f0 | |||
| eaa75833df | |||
| 30d457f562 | |||
|
|
c1dd9092ea | ||
| 79e0b01796 | |||
| f008cee404 | |||
| bb91162438 | |||
| c078266449 | |||
| 922b840c9a | |||
| 68823d6ced | |||
| 9bb4d23a2d | |||
|
|
e2cd6945f5 | ||
|
|
ba21f797de | ||
|
|
646ff668f7 | ||
| 8b6d35b66f | |||
| e0d6e3cc62 | |||
| 1158c88d43 | |||
| e6add823a5 | |||
| b1c246113c | |||
| 5c76e77766 | |||
| 3aee87aaed | |||
| 97aaf2cd12 | |||
| 9d35079058 | |||
| 73cb398aa0 | |||
| 365fb0f2c7 | |||
| c81196343f | |||
| c7526be3c9 | |||
| b6996902cc | |||
| b3ba6256e0 | |||
| 9d72a99626 | |||
| 320f6d6c8b | |||
| ac79f10153 | |||
| dac1c57c98 | |||
| 4582306dc8 | |||
| 64ff7c6e97 | |||
| e1f207f6fe | |||
| 2e16a0bc03 | |||
| 1c4b154e41 | |||
| b26080f4c1 | |||
| f92bcd5876 | |||
| 939b3174f2 | |||
| 44a9669ea4 | |||
| cc469f67a5 | |||
| 6b22da6a34 | |||
| 808b56934c | |||
| fd907c9851 | |||
| 3c16bc89e5 | |||
| a9e3d8264c | |||
| 332a3e5c15 | |||
| 4fc6da850b | |||
| 36273fd426 | |||
| 793ddb17d6 | |||
| 349d2cea6a | |||
| 23f2feeefb | |||
| 48fe999b5b | |||
| c857041e21 | |||
| e26b36121a | |||
| d3e7a3b4ae | |||
| 35859cf13c | |||
| 416118197b | |||
| 01afbea9a3 | |||
| 549ea896c7 | |||
| 662211e1c3 | |||
| 5082e6d526 | |||
| 9bf85c79e4 | |||
| 3b0b9d724a | |||
| 915153cb62 | |||
| c0a25c7a26 | |||
| b44bac760d | |||
| ddee170aea | |||
| 04b5aaa0dc | |||
| 5128398516 | |||
| 69422d1f92 | |||
| 5d6ac9438d | |||
| 76c2e26e8c | |||
| 0ec9692db3 | |||
| bc53c309df | |||
| 5e3205ae3f | |||
| 5d5f140091 | |||
| bb912841f4 | |||
| e9b42ff85a | |||
| a66f79896a | |||
| cf00f6f12c | |||
| 01eb80f8ab | |||
| 5b9f5e70ec | |||
| 9c6b2ebd4f | |||
| b5ee0bd6a7 | |||
| 59585e26f1 | |||
| 57368ca3e4 | |||
| 468427622f | |||
| 45b5a36d04 | |||
| 4c4be8ba42 | |||
| 45bcce0fb2 | |||
| e288d768bf | |||
| 2863eae3fb | |||
| e1e76612d6 | |||
| 8fbc59499b | |||
| 66b0d1cb3c | |||
| 45a5c46489 | |||
| c93a5c50de | |||
| 2ad5a67340 | |||
| e1694552c9 | |||
| 50a9286895 | |||
| e79d0a1a2d | |||
| 1d2769d114 | |||
| 387a9b21a8 | |||
| 7d0ec1283b | |||
| 0e13744a79 | |||
| f737e4da4c | |||
| f43497d69c | |||
| 59abf0880d | |||
| ca88a541c8 | |||
| 0820622ace | |||
| 67a24f3650 | |||
| f0b133101d | |||
| 7396e15241 | |||
| e1ce9373c0 | |||
| ec537901a6 | |||
| bd0c324705 | |||
| 5e7eeabda5 | |||
| dc44a2f4ce | |||
| 3a6b10e860 | |||
| 0c05cf6661 | |||
| 011c07b753 | |||
| 406e7f8e4d | |||
| b4591d044b | |||
| 5d2cfa6dfd | |||
| 33b40ee29f | |||
| ef5971d41c | |||
| 03835fe624 | |||
| 6377bba1a9 | |||
| 012f7ee3e8 | |||
| bcf24122bc | |||
| 47ca05f2d4 | |||
| 8803187ce1 | |||
| 650cfd0061 | |||
| 38cdaa538a | |||
|
|
2d9acb402d | ||
|
|
a71807c63a | ||
| 78bf7c7dbc | |||
| aeccb684b4 | |||
| 425b1ee8fa | |||
| 6b1a49583e |
@@ -8,11 +8,10 @@ RUN npm i --unsafe-perm
|
|||||||
COPY . ./
|
COPY . ./
|
||||||
COPY config_dev.json ./config.json
|
COPY config_dev.json ./config.json
|
||||||
RUN npm run build
|
RUN npm run build
|
||||||
RUN npm run init-db
|
|
||||||
|
|
||||||
# --- Production stage ---
|
# --- Production stage ---
|
||||||
FROM node:24-alpine
|
FROM node:24-alpine
|
||||||
COPY --from=build /app .
|
COPY --from=build /app .
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["sh", "-c", "ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"]
|
CMD ["sh", "-c", "npm run init-db && ORIGIN=https://tatort-dev.innovation-hub-niedersachsen.de node build/index.js"]
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
# --- Build stage ---
|
# --- Build stage ---
|
||||||
FROM node:22 AS build
|
FROM node:22 AS build
|
||||||
ENV NODE_ENV=production
|
|
||||||
ENV ORIGIN=https://tatort.innovation-hub-niedersachsen.de
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
RUN npm ci
|
RUN npm ci
|
||||||
@@ -11,7 +9,13 @@ RUN npm run build
|
|||||||
|
|
||||||
# --- Production stage ---
|
# --- Production stage ---
|
||||||
FROM node:22-alpine3.20
|
FROM node:22-alpine3.20
|
||||||
COPY --from=build /app .
|
WORKDIR /app
|
||||||
|
ENV NODE_ENV=production
|
||||||
|
ENV ORIGIN=https://tatort.innovation-hub-niedersachsen.de
|
||||||
|
COPY --from=build /app/build ./build
|
||||||
|
COPY --from=build /app/package*.json ./
|
||||||
|
COPY --from=build /app/config.json ./config.json
|
||||||
|
RUN npm ci --omit=dev
|
||||||
ENV HOST=0.0.0.0
|
ENV HOST=0.0.0.0
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
CMD ["sh", "-c", "ORIGIN=https://tatort.innovation-hub-niedersachsen.de node build/index.js"]
|
CMD ["node", "build/index.js"]
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"minio": {
|
"minio": {
|
||||||
"endPoint": "sws3.innovation-hub-niedersachsen.de",
|
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
|
||||||
"port": 443,
|
"port": 443,
|
||||||
"useSSL": true,
|
"useSSL": true,
|
||||||
"accessKey": "wjpKrmaqXra99rX3D61H",
|
"accessKey": "AbCdEfGhIjKlMnOpQrSt",
|
||||||
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
|
"secretKey": "UvWxYz1234567890AbCdEfGhIjKlMnOpQrStUvWx"
|
||||||
},
|
},
|
||||||
"jwt": {
|
"jwt": {
|
||||||
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"minio": {
|
"minio": {
|
||||||
"endPoint": "sws3.innovation-hub-niedersachsen.de",
|
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
|
||||||
"port": 443,
|
"port": 443,
|
||||||
"useSSL": true,
|
"useSSL": true,
|
||||||
"accessKey": "wjpKrmaqXra99rX3D61H",
|
"accessKey": "AbCdEfGhIjKlMnOpQrSt",
|
||||||
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
|
"secretKey": "UvWxYz1234567890AbCdEfGhIjKlMnOpQrStUvWx"
|
||||||
},
|
},
|
||||||
"jwt": {
|
"jwt": {
|
||||||
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
{
|
{
|
||||||
"minio": {
|
"minio": {
|
||||||
"endPoint": "sws3.innovation-hub-niedersachsen.de",
|
"endPoint": "api-s3.innovation-hub-niedersachsen.de",
|
||||||
"port": 443,
|
"port": 443,
|
||||||
"useSSL": true,
|
"useSSL": true,
|
||||||
"accessKey": "wjpKrmaqXra99rX3D61H",
|
"accessKey": "GxKhfnfkNvlDU7qzsz0D",
|
||||||
"secretKey": "fTPi0u0FR6Lv9Y9IKydWv6WM0EA5XrsK008HCt9u"
|
"secretKey": "cqSM5rIRr4MPtqzu2sNKgmB9k2OghPbyxwAWogeM"
|
||||||
},
|
},
|
||||||
"jwt": {
|
"jwt": {
|
||||||
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
"secret": "@S2!q@@wXz$dCQ8JoVsHLpzaJ6JCfB",
|
||||||
|
|||||||
1676
package-lock.json
generated
1676
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,7 @@
|
|||||||
import { decryptToken } from '$lib/auth';
|
import { decryptToken } from '$lib/auth';
|
||||||
import type { Handle } from '@sveltejs/kit';
|
import type { Handle } from '@sveltejs/kit';
|
||||||
|
import { ROUTE_NAMES } from './routes';
|
||||||
|
|
||||||
|
|
||||||
export const handle: Handle = async ({ event, resolve }) => {
|
export const handle: Handle = async ({ event, resolve }) => {
|
||||||
const jwt = event.cookies.get('session');
|
const jwt = event.cookies.get('session');
|
||||||
@@ -9,8 +11,18 @@ export const handle: Handle = async ({ event, resolve }) => {
|
|||||||
return resolve(event);
|
return resolve(event);
|
||||||
}
|
}
|
||||||
} catch (_) {
|
} catch (_) {
|
||||||
event.cookies.delete('session', {path: '/'});
|
event.cookies.delete('session', {path: ROUTE_NAMES.ROOT});
|
||||||
event.locals.user = null;
|
event.locals.user = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (event.url.pathname.startsWith('/api')) {
|
||||||
|
if (!event.locals.user) {
|
||||||
|
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
||||||
|
status: 401,
|
||||||
|
headers: { 'Content-Type': 'application/json' }
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return await resolve(event);
|
return await resolve(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import Database from 'better-sqlite3';
|
import Database from 'better-sqlite3';
|
||||||
import fs from 'fs';
|
import fs from 'fs';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
import { DB_FULLPATH } from '../routes';
|
||||||
|
|
||||||
const fullPath = './src/lib/data/tatort.db';
|
const fullPath = DB_FULLPATH;
|
||||||
const dir = path.dirname(fullPath);
|
const dir = path.dirname(fullPath);
|
||||||
|
|
||||||
if (!fs.existsSync(dir)) {
|
if (!fs.existsSync(dir)) {
|
||||||
|
|||||||
54
src/lib/components/ExpandableForm.svelte
Normal file
54
src/lib/components/ExpandableForm.svelte
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
import { fly, scale, fade } from 'svelte/transition';
|
||||||
|
import { cubicOut } from 'svelte/easing';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
|
let expanded = false;
|
||||||
|
let formContainer: HTMLDivElement;
|
||||||
|
|
||||||
|
async function toggle() {
|
||||||
|
expanded = !expanded;
|
||||||
|
|
||||||
|
if (expanded) {
|
||||||
|
// Wait for DOM to update
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
// Scroll smoothly into view
|
||||||
|
formContainer?.scrollIntoView({ behavior: 'smooth', block: 'start' });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div data-testid="expand-container" class="flex flex-col items-center">
|
||||||
|
<!-- + / × button -->
|
||||||
|
<button
|
||||||
|
data-testid="expand-button"
|
||||||
|
class="flex items-center justify-center w-12 h-12 rounded-full bg-blue-600 text-white text-2xl font-bold hover:bg-blue-700 transition"
|
||||||
|
on:click={toggle}
|
||||||
|
aria-expanded={expanded}
|
||||||
|
aria-label="Add item"
|
||||||
|
>
|
||||||
|
{#if expanded}
|
||||||
|
✕
|
||||||
|
{:else}
|
||||||
|
+
|
||||||
|
{/if}
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<!-- Expandable content below button -->
|
||||||
|
{#if expanded}
|
||||||
|
<div
|
||||||
|
bind:this={formContainer}
|
||||||
|
class="w-full mt-4 flex justify-center"
|
||||||
|
transition:fade
|
||||||
|
>
|
||||||
|
<div
|
||||||
|
in:fly={{ y: 10, duration: 200, easing: cubicOut }}
|
||||||
|
out:scale={{ duration: 150 }}
|
||||||
|
class="w-full max-w-2xl"
|
||||||
|
>
|
||||||
|
<slot />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
<script>
|
<script>
|
||||||
import Profile from "$lib/icons/Profile.svelte";
|
import Profile from "$lib/icons/Profile.svelte";
|
||||||
|
|
||||||
|
import { ROUTE_NAMES } from "../../routes";
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -10,19 +12,19 @@
|
|||||||
<div class="mx-auto max-w-7xl px-6 lg:px-8">
|
<div class="mx-auto max-w-7xl px-6 lg:px-8">
|
||||||
<div class="flex justify-between divide-x divide-gray-900/5 border-x border-gray-900/5">
|
<div class="flex justify-between divide-x divide-gray-900/5 border-x border-gray-900/5">
|
||||||
<a
|
<a
|
||||||
href="/list"
|
href="{ROUTE_NAMES.LIST}"
|
||||||
class="px-4 py-1 -ml-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
class="px-4 py-1 -ml-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||||
>
|
>
|
||||||
© 2023 Innovation Hub Niedersachen
|
© 2023 Innovation Hub Niedersachen
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href="/"
|
href="{ROUTE_NAMES.ROOT}"
|
||||||
class="px-4 py-1 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
class="px-4 py-1 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||||
>
|
>
|
||||||
back
|
back
|
||||||
</a>
|
</a>
|
||||||
<a
|
<a
|
||||||
href="/"
|
href="{ROUTE_NAMES.ROOT}"
|
||||||
class="px-4 py-1 -mr-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
class="px-4 py-1 -mr-4 flex items-center justify-center gap-x-2.5 text-sm font-semibold leading-6 text-gray-500 hover:bg-gray-200 hover:text-gray-700"
|
||||||
>
|
>
|
||||||
<!--icon-->
|
<!--icon-->
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import Chevron from '$lib/icons/Chevron-right.svelte';
|
import Chevron from '$lib/icons/Chevron-right.svelte';
|
||||||
|
|
||||||
|
import { ROUTE_NAMES } from '../../routes';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -11,7 +13,7 @@
|
|||||||
aria-label="Global"
|
aria-label="Global"
|
||||||
>
|
>
|
||||||
<div class="flex w-48">
|
<div class="flex w-48">
|
||||||
<a href="/" class="-m-1.5 p-1.5 w-10">
|
<a href="{ROUTE_NAMES.ROOT}" class="-m-1.5 p-1.5 w-10">
|
||||||
<span class="sr-only">Tatort Niedersachen</span>
|
<span class="sr-only">Tatort Niedersachen</span>
|
||||||
<img class="h-8 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
<img class="h-8 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
||||||
</a>
|
</a>
|
||||||
@@ -19,7 +21,7 @@
|
|||||||
<h1 class="text-3xl text-slate-400 font-bold">Tatort</h1>
|
<h1 class="text-3xl text-slate-400 font-bold">Tatort</h1>
|
||||||
<div class="lg:flex lg:justify-end w-48">
|
<div class="lg:flex lg:justify-end w-48">
|
||||||
{#if data.user}
|
{#if data.user}
|
||||||
<form method="POST" action="/anmeldung?/logout">
|
<form method="POST" action="{ROUTE_NAMES.LOGOUT}">
|
||||||
<input type="hidden" />
|
<input type="hidden" />
|
||||||
<button type="submit" class="text-sm font-semibold leading-6 text-gray-900"
|
<button type="submit" class="text-sm font-semibold leading-6 text-gray-900"
|
||||||
><span
|
><span
|
||||||
|
|||||||
@@ -1,90 +1,116 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import Check from '$lib/icons/Check.svelte';
|
||||||
import Edit from '$lib/icons/Edit.svelte';
|
import Edit from '$lib/icons/Edit.svelte';
|
||||||
import Trash from '$lib/icons/Trash.svelte';
|
import Trash from '$lib/icons/Trash.svelte';
|
||||||
|
import X from '$lib/icons/X.svelte';
|
||||||
import { tick } from 'svelte';
|
import { tick } from 'svelte';
|
||||||
|
|
||||||
interface ListItem {
|
interface ListItem {
|
||||||
name: string;
|
name: string;
|
||||||
token?: string;
|
token?: string;
|
||||||
// add other properties as needed
|
|
||||||
}
|
}
|
||||||
let {
|
|
||||||
list,
|
|
||||||
editedName = $bindable(),
|
|
||||||
currentName,
|
|
||||||
onSave = () => {},
|
|
||||||
onDelete = () => {}
|
|
||||||
} = $props();
|
|
||||||
|
|
||||||
let localName = $state(currentName);
|
// props, old syntax
|
||||||
let wasCancelled = $state(false);
|
export let list: ListItem[] = [];
|
||||||
|
export let currentName: string;
|
||||||
|
export let vorgangToken: string | null;
|
||||||
|
export let onSave: (n: string, o: string, t?: string) => unknown = () => {};
|
||||||
|
export let onDelete: ((n: string) => unknown) | null = () => {};
|
||||||
|
|
||||||
let error: string = $derived(validateName(localName));
|
let localName = currentName;
|
||||||
let isEditing = $state(false);
|
let isEditing = false;
|
||||||
let inputRef: HTMLInputElement;
|
let inputRef: HTMLInputElement | null = null;
|
||||||
|
|
||||||
function validateName(name: string) {
|
$: error = validateName(localName);
|
||||||
const trimmed = name.trim();
|
|
||||||
|
|
||||||
if (!trimmed) {
|
function validateName(name: string): string {
|
||||||
return 'Name darf nicht leer sein.';
|
const trimmed = name?.trim() ?? '';
|
||||||
|
if (!trimmed) return 'Name darf nicht leer sein.';
|
||||||
|
if (list.some((item) => item.name === trimmed && item.name !== currentName)) {
|
||||||
|
return 'Name existiert bereits.';
|
||||||
}
|
}
|
||||||
|
|
||||||
const duplicate = list.some(
|
|
||||||
(item: ListItem) => item.name === trimmed && item.name !== currentName
|
|
||||||
);
|
|
||||||
|
|
||||||
if (duplicate) return 'Name existiert bereits.';
|
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function commitIfValid() {
|
|
||||||
if (!error && !wasCancelled && localName != currentName) {
|
|
||||||
const trimmedName: string = localName.trim();
|
|
||||||
inputRef?.blur();
|
|
||||||
isEditing = false;
|
|
||||||
onSave(trimmedName, currentName);
|
|
||||||
} else {
|
|
||||||
localName = currentName;
|
|
||||||
resetEdit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function resetEdit() {
|
|
||||||
wasCancelled = false;
|
|
||||||
inputRef?.blur();
|
|
||||||
isEditing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function handleKeydown(event: KeyboardEvent) {
|
|
||||||
if (event.key === 'Enter') {
|
|
||||||
event.preventDefault();
|
|
||||||
commitIfValid();
|
|
||||||
} else if (event.key === 'Escape') {
|
|
||||||
event.preventDefault();
|
|
||||||
localName = currentName;
|
|
||||||
resetEdit();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function startEdit() {
|
async function startEdit() {
|
||||||
isEditing = true;
|
isEditing = true;
|
||||||
await tick();
|
await tick();
|
||||||
inputRef?.focus();
|
inputRef?.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cancelEdit() {
|
||||||
|
localName = currentName;
|
||||||
|
isEditing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function commitEdit() {
|
||||||
|
if (!error && localName != currentName) onSave(localName, currentName, vorgangToken);
|
||||||
|
// restore original value
|
||||||
|
if (error) { localName = currentName }
|
||||||
|
|
||||||
|
isEditing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleKeydown(event: KeyboardEvent) {
|
||||||
|
if (event.key === 'Enter') commitEdit();
|
||||||
|
if (event.key === 'Escape') cancelEdit();
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleDeleteClick() {
|
||||||
|
// vorgangToken defined when deleting Vorgang, otherwise Crime
|
||||||
|
onDelete(vorgangToken || currentName);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div>
|
<div data-testid="test-nameItemEditor" class="flex flex-col gap-1">
|
||||||
<input
|
{#if isEditing}
|
||||||
bind:this={inputRef}
|
<div class="flex items-center gap-1">
|
||||||
bind:value={localName}
|
<input
|
||||||
onblur={commitIfValid}
|
data-testid="test-input"
|
||||||
onkeydown={handleKeydown}
|
bind:this={inputRef}
|
||||||
/>
|
bind:value={localName}
|
||||||
<button onclick={startEdit}><Edit /></button>
|
onkeydown={handleKeydown}
|
||||||
<button onclick={() => onDelete(currentName)}><Trash /></button>
|
class="flex-1 border border-gray-300 rounded px-1.5 py-0.5 text-sm focus:outline-none focus:ring-1 focus:ring-blue-500"
|
||||||
{#if error}
|
/>
|
||||||
<p style="color: red;">{error}</p>
|
<button
|
||||||
{/if}
|
data-testid="commit-button"
|
||||||
|
disabled={!!error || localName === currentName}
|
||||||
|
onclick={commitEdit}
|
||||||
|
class="text-gray-500 hover:text-green-600 transition disabled:opacity-40"
|
||||||
|
>
|
||||||
|
<Check class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
data-testid="cancel-button"
|
||||||
|
onclick={cancelEdit}
|
||||||
|
class="text-gray-500 hover:text-red-600 transition"
|
||||||
|
>
|
||||||
|
<X class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
{:else}
|
||||||
|
<div class="flex items-center gap-1">
|
||||||
|
<span class="text-sm font-medium text-gray-900 truncate">{localName}</span>
|
||||||
|
<button
|
||||||
|
data-testid="edit-button"
|
||||||
|
onclick={startEdit}
|
||||||
|
class="text-gray-500 hover:text-blue-600 transition"
|
||||||
|
>
|
||||||
|
<Edit class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
{#if onDelete}
|
||||||
|
<button
|
||||||
|
data-testid="delete-button"
|
||||||
|
onclick={handleDeleteClick}
|
||||||
|
class="text-gray-500 hover:text-red-600 transition"
|
||||||
|
>
|
||||||
|
<Trash class="w-4 h-4" />
|
||||||
|
</button>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if error}
|
||||||
|
<p class="text-xs text-red-500 mt-1">{error}</p>
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<svg
|
<svg
|
||||||
|
data-testid="profile-component"
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
fill="none"
|
fill="none"
|
||||||
viewBox="0 0 24 24"
|
viewBox="0 0 24 24"
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 402 B After Width: | Height: | Size: 435 B |
@@ -1,6 +1,7 @@
|
|||||||
import { dev } from '$app/environment';
|
import { dev } from '$app/environment';
|
||||||
import { fail, redirect, type Cookies, type RequestEvent } from '@sveltejs/kit';
|
import { fail, redirect, type Cookies, type RequestEvent } from '@sveltejs/kit';
|
||||||
import { authenticate } from '$lib/auth';
|
import { authenticate } from '$lib/auth';
|
||||||
|
import { ROUTE_NAMES } from '../../routes';
|
||||||
|
|
||||||
const COOKIE_NAME = 'session';
|
const COOKIE_NAME = 'session';
|
||||||
|
|
||||||
@@ -11,19 +12,20 @@ export const loginUser = async ({ request, cookies }: { request: Request; cookie
|
|||||||
|
|
||||||
const token = authenticate(user, password);
|
const token = authenticate(user, password);
|
||||||
|
|
||||||
if (!token) return fail(400, { user, incorrect: true });
|
if (!token) return fail(400, { user, incorrect: true,
|
||||||
|
message: "Ungültige Zugangsdaten" });
|
||||||
|
|
||||||
cookies.set(COOKIE_NAME, token, {
|
cookies.set(COOKIE_NAME, token, {
|
||||||
path: '/',
|
path: ROUTE_NAMES.ROOT,
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
sameSite: 'strict',
|
sameSite: 'strict',
|
||||||
secure: !dev
|
secure: !dev
|
||||||
});
|
});
|
||||||
return redirect(303, '/');
|
return redirect(303, ROUTE_NAMES.ROOT);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const logoutUser = async (event: RequestEvent) => {
|
export const logoutUser = async (event: RequestEvent) => {
|
||||||
event.cookies.delete(COOKIE_NAME, { path: '/' });
|
event.cookies.delete(COOKIE_NAME, { path: ROUTE_NAMES.ROOT });
|
||||||
event.locals.user = null;
|
event.locals.user = null;
|
||||||
return { success: true };
|
return redirect(303, ROUTE_NAMES.ROOT);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
import Database from 'better-sqlite3';
|
import Database from 'better-sqlite3';
|
||||||
import fs from 'fs';
|
import { DB_FULLPATH } from '../../routes';
|
||||||
import path from 'path';
|
|
||||||
|
|
||||||
const fullPath = './src/lib/data/tatort.db';
|
// make sure the DB is initiated
|
||||||
const dir = path.dirname(fullPath);
|
import '../../init/init_db'
|
||||||
|
|
||||||
if (!fs.existsSync(dir)) {
|
export const db = new Database(DB_FULLPATH);
|
||||||
fs.mkdirSync(dir);
|
|
||||||
}
|
|
||||||
|
|
||||||
export const db = new Database(fullPath);
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { fail } from '@sveltejs/kit';
|
import { fail } from '@sveltejs/kit';
|
||||||
import { BUCKET, client, CONFIGFILENAME, TOKENFILENAME } from '$lib/minio';
|
import { BUCKET, client, CONFIGFILENAME, TOKENFILENAME } from '$lib/minio';
|
||||||
import { checkIfExactDirectoryExists, getContentOfTextObject } from './s3ClientService';
|
import { checkIfExactDirectoryExists, getContentOfTextObject } from './s3ClientService';
|
||||||
|
import { v4 as uuidv4 } from 'uuid';
|
||||||
|
|
||||||
import { db } from './dbService';
|
import { db } from './dbService';
|
||||||
|
|
||||||
@@ -45,6 +46,31 @@ export const getVorgangByToken = (
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Vorgang, using a vorgangName and vorgangPIN
|
||||||
|
* @param vorgangName
|
||||||
|
* @param vorgangPIN
|
||||||
|
* @returns {string || false} vorgangToken if successful
|
||||||
|
*/
|
||||||
|
export const createVorgang = (vorgangName: string, vorgangPIN: string): string | boolean => {
|
||||||
|
const vorgangExists = vorgangNameExists(vorgangName);
|
||||||
|
if (vorgangExists) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const vorgangToken = uuidv4();
|
||||||
|
|
||||||
|
const insertSQLStatement = `INSERT INTO cases (token, name, pin) VALUES (?, ?, ?)`;
|
||||||
|
const statement = db.prepare(insertSQLStatement);
|
||||||
|
const info = statement.run(vorgangToken, vorgangName, vorgangPIN);
|
||||||
|
|
||||||
|
if (info.changes) {
|
||||||
|
return vorgangToken;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get Vorgang
|
* Get Vorgang
|
||||||
* @param vorgangName
|
* @param vorgangName
|
||||||
@@ -208,3 +234,27 @@ export const vorgangPINValidation = function (vorgangToken: string, vorgangPIN:
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change VorgangName or VorgangPIN
|
||||||
|
* @param vorgangToken
|
||||||
|
* @param newValue
|
||||||
|
* @returns {int} number of affected lines
|
||||||
|
*/
|
||||||
|
export const updateVorgangAttrByToken = function (vorgangToken: string,
|
||||||
|
newValue: string,
|
||||||
|
column: string) {
|
||||||
|
const renameSQLStmt = `UPDATE cases set ${column} = ? WHERE token = ?`;
|
||||||
|
const statement = db.prepare(renameSQLStmt);
|
||||||
|
|
||||||
|
let info;
|
||||||
|
|
||||||
|
try {
|
||||||
|
info = statement.run(newValue, vorgangToken);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(`error: ${err}`)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return info.changes;
|
||||||
|
};
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
import { redirect, type ServerLoadEvent } from '@sveltejs/kit';
|
import { type ServerLoadEvent } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from '../anmeldung/$types';
|
import type { PageServerLoad } from '../anmeldung/$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = (event: ServerLoadEvent) => {
|
export const load: PageServerLoad = (event: ServerLoadEvent) => {
|
||||||
if (!event.locals.user && event.url.pathname !== '/anmeldung') throw redirect(303, '/anmeldung');
|
if (event.locals.user) {
|
||||||
return {
|
return {
|
||||||
user: event.locals.user
|
user: event.locals.user
|
||||||
|
};
|
||||||
};
|
}
|
||||||
}
|
};
|
||||||
|
|||||||
@@ -5,6 +5,8 @@
|
|||||||
export let data;
|
export let data;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if data.user?.admin}
|
||||||
|
|
||||||
<div class="h-screen v-screen flex flex-col">
|
<div class="h-screen v-screen flex flex-col">
|
||||||
<div class="flex flex-col h-full">
|
<div class="flex flex-col h-full">
|
||||||
<Header {data}/>
|
<Header {data}/>
|
||||||
@@ -16,3 +18,10 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{:else}
|
||||||
|
|
||||||
|
<div class="h-screen bg-white"><slot /></div>
|
||||||
|
|
||||||
|
|
||||||
|
{/if}
|
||||||
6
src/routes/(angemeldet)/+page.server.ts
Normal file
6
src/routes/(angemeldet)/+page.server.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { loginUser, logoutUser } from '$lib/server/authService';
|
||||||
|
|
||||||
|
export const actions = {
|
||||||
|
login: ({ request, cookies }) => loginUser({ request, cookies }),
|
||||||
|
logout: (event) => logoutUser(event),
|
||||||
|
} as const;
|
||||||
@@ -2,23 +2,28 @@
|
|||||||
import AddProcess from '$lib/icons/Add-Process.svelte';
|
import AddProcess from '$lib/icons/Add-Process.svelte';
|
||||||
import FileRect from '$lib/icons/File-rect.svelte';
|
import FileRect from '$lib/icons/File-rect.svelte';
|
||||||
import ListIcon from '$lib/icons/List-icon.svelte';
|
import ListIcon from '$lib/icons/List-icon.svelte';
|
||||||
|
import Button from '$lib/components/Button.svelte';
|
||||||
|
import ArrowRight from '$lib/icons/Arrow-right.svelte';
|
||||||
|
|
||||||
|
import { ROUTE_NAMES } from '../index.js';
|
||||||
|
|
||||||
export let data;
|
export let data;
|
||||||
|
export let form;
|
||||||
export let outline = true;
|
export let outline = true;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if data.user?.admin}
|
||||||
<div
|
<div
|
||||||
class=" inset-x-0 top-0 -z-10 h-full flex items-center justify-center bg-white shadow-lg ring-1 ring-gray-900/5"
|
class=" inset-x-0 top-0 -z-10 h-full flex items-center justify-center bg-white shadow-lg ring-1 ring-gray-900/5"
|
||||||
>
|
>
|
||||||
<div class="mx-auto flex justify-center max-w-7xl py-10 px-8 w-full">
|
<div class="mx-auto flex justify-center max-w-7xl py-10 px-8 w-full">
|
||||||
{#if data.user.admin}
|
|
||||||
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
||||||
<div
|
<div
|
||||||
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
|
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
|
||||||
>
|
>
|
||||||
<ListIcon class=" group-hover:text-indigo-600" />
|
<ListIcon class=" group-hover:text-indigo-600" />
|
||||||
</div>
|
</div>
|
||||||
<a href="/list" class="mt-6 block font-semibold text-gray-900">
|
<a href="{ROUTE_NAMES.LIST}" class="mt-6 block font-semibold text-gray-900">
|
||||||
Vorgänge
|
Vorgänge
|
||||||
<span class="absolute inset-0"></span>
|
<span class="absolute inset-0"></span>
|
||||||
</a>
|
</a>
|
||||||
@@ -26,28 +31,13 @@
|
|||||||
Verschaffe Dir einen Überblick über alle gespeicherten Tatorte.
|
Verschaffe Dir einen Überblick über alle gespeicherten Tatorte.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
|
||||||
{#if data.user.admin}
|
|
||||||
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
|
||||||
<div
|
|
||||||
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
|
|
||||||
>
|
|
||||||
<AddProcess class=" group-hover:text-indigo-600" />
|
|
||||||
</div>
|
|
||||||
<a href="/upload" class="mt-6 block font-semibold text-gray-900">
|
|
||||||
Hinzufügen
|
|
||||||
<span class="absolute inset-0"></span>
|
|
||||||
</a>
|
|
||||||
<p class="mt-1 text-gray-600">Fügen Sie einem Tatort Bilder hinzu.</p>
|
|
||||||
</div>
|
|
||||||
{/if}
|
|
||||||
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
<div class="group relative rounded-lg p-6 text-sm leading-6 hover:bg-gray-50 w-1/4">
|
||||||
<div
|
<div
|
||||||
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
|
class="flex h-11 w-11 items-center justify-center rounded-lg bg-gray-50 group-hover:bg-white"
|
||||||
>
|
>
|
||||||
<FileRect class=" group-hover:text-indigo-600" {outline} />
|
<FileRect class=" group-hover:text-indigo-600" {outline} />
|
||||||
</div>
|
</div>
|
||||||
<a href="/user-management" class="mt-6 block font-semibold text-gray-900">
|
<a href="{ROUTE_NAMES.USERMGMT}" class="mt-6 block font-semibold text-gray-900">
|
||||||
Benutzerverwaltung
|
Benutzerverwaltung
|
||||||
<span class="absolute inset-0"></span>
|
<span class="absolute inset-0"></span>
|
||||||
</a>
|
</a>
|
||||||
@@ -56,5 +46,64 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{:else}
|
||||||
|
|
||||||
|
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
||||||
|
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
||||||
|
<img class="mx-auto h-10 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
||||||
|
|
||||||
|
<h2 class="mt-10 text-center text-2xl font-bold leading-9 tracking-tight text-gray-900">
|
||||||
|
Willkommen beim 3D Tatort
|
||||||
|
</h2>
|
||||||
|
</div>
|
||||||
|
<div class="w-full max-w-sm mx-auto">
|
||||||
|
<div class="relative mt-5 bg-gray-50 rounded-xl shadow-xl p-3 pt-1">
|
||||||
|
<div class="mt-10">
|
||||||
|
|
||||||
|
<form action="{ROUTE_NAMES.LOGIN}" method="POST">
|
||||||
|
<div>
|
||||||
|
<label for="user" class="text-sm font-medium leading-6 text-gray-900">Name</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input
|
||||||
|
id="user"
|
||||||
|
name="user"
|
||||||
|
type="text"
|
||||||
|
autocomplete="email"
|
||||||
|
required
|
||||||
|
class="rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<label for="password" class="block text-sm font-medium leading-6 text-gray-900"
|
||||||
|
>Passwort</label
|
||||||
|
>
|
||||||
|
<div class="mt-2">
|
||||||
|
<input
|
||||||
|
id="password"
|
||||||
|
name="password"
|
||||||
|
type="password"
|
||||||
|
autocomplete="current-password"
|
||||||
|
required
|
||||||
|
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#if form?.incorrect}
|
||||||
|
<p class="block text-sm leading-6 text-red-900 mt-2">{form.message}</p>
|
||||||
|
{/if}
|
||||||
|
<div class="flex justify-end">
|
||||||
|
<Button type="submit" class="mt-5">Anmelden</Button>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/if}
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,35 @@
|
|||||||
import { getVorgaenge } from '$lib/server/vorgangService';
|
import { createVorgang, getVorgaenge } from '$lib/server/vorgangService';
|
||||||
import type { PageServerLoad } from '../../(token-based)/view/$types';
|
import type { PageServerLoad } from '../../(token-based)/view/$types';
|
||||||
|
import { error, fail } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async (event) => {
|
||||||
|
if (!event.locals.user) {
|
||||||
|
error(404, 'Not Found')
|
||||||
|
}
|
||||||
|
|
||||||
export const load: PageServerLoad = async () => {
|
|
||||||
const vorgangList = getVorgaenge();
|
const vorgangList = getVorgaenge();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
vorgangList
|
vorgangList
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const actions = {
|
||||||
|
default: async ({ request }: { request: Request }) => {
|
||||||
|
const data = await request.formData();
|
||||||
|
const vorgangName: string | null = data.get('vorgang') as string;
|
||||||
|
const vorgangPIN: string | null = data.get('pin') as string;
|
||||||
|
|
||||||
|
const err = {};
|
||||||
|
|
||||||
|
const token = createVorgang(vorgangName, vorgangPIN);
|
||||||
|
if (!token) {
|
||||||
|
err.message = "Der Vorgang konnte nicht angelegt werden"
|
||||||
|
return fail(400, err)
|
||||||
|
} else {
|
||||||
|
// success
|
||||||
|
return { token }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,23 +1,94 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import ExpandableForm from '$lib/components/ExpandableForm.svelte';
|
||||||
import Trash from '$lib/icons/Trash.svelte';
|
import Trash from '$lib/icons/Trash.svelte';
|
||||||
import Folder from '$lib/icons/Folder.svelte';
|
import Folder from '$lib/icons/Folder.svelte';
|
||||||
import EmptyList from '$lib/components/EmptyList.svelte';
|
import EmptyList from '$lib/components/EmptyList.svelte';
|
||||||
|
import NameItemEditor from '$lib/components/NameItemEditor.svelte';
|
||||||
|
import Alert from '$lib/components/Alert.svelte';
|
||||||
|
import Button from '$lib/components/Button.svelte';
|
||||||
|
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||||
|
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
||||||
|
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
||||||
|
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
||||||
|
import { API_ROUTES, ROUTE_NAMES } from '../../index.js';
|
||||||
|
import { invalidateAll } from '$app/navigation';
|
||||||
|
|
||||||
let { data } = $props();
|
let { data, form } = $props();
|
||||||
|
|
||||||
let vorgangList = data.vorgangList;
|
let vorgangList = $state(data.vorgangList);
|
||||||
|
|
||||||
|
// same as `vorgangList` but with one different property to be used
|
||||||
|
// with ´NameItemEditor`
|
||||||
|
const derivedList = $derived.by(
|
||||||
|
() => {
|
||||||
|
return vorgangList.map(
|
||||||
|
({ vorgangName, ...rest }) => (
|
||||||
|
{
|
||||||
|
name: vorgangName,
|
||||||
|
...rest
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let isEmptyList = vorgangList.length === 0;
|
let isEmptyList = vorgangList.length === 0;
|
||||||
|
|
||||||
async function delete_item(ev: Event) {
|
let vorgangName = $state('');
|
||||||
|
let vorgangPIN = $state('');
|
||||||
|
let errorMsg = $state('');
|
||||||
|
|
||||||
|
// reset input fields when submission successful
|
||||||
|
$effect(() => {
|
||||||
|
if (form?.token) {
|
||||||
|
vorgangName = '';
|
||||||
|
vorgangPIN = '';
|
||||||
|
errorMsg = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
async function submitVorgang(ev: Event) {
|
||||||
|
const isValid = inputValid(vorgangName, vorgangPIN);
|
||||||
|
if (!isValid) {
|
||||||
|
ev.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// continue form action on server
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check for required fields
|
||||||
|
* @param vorgangName
|
||||||
|
* @param vorgangPIN
|
||||||
|
* @returns {boolean} Indicates whether input is valid
|
||||||
|
*/
|
||||||
|
function inputValid(vorgangName, vorgangPIN) {
|
||||||
|
if (!(vorgangName || vorgangPIN)) {
|
||||||
|
errorMsg = 'Bitte beide Felder ausfüllen.';
|
||||||
|
return false;
|
||||||
|
} else if (!vorgangName) {
|
||||||
|
errorMsg = 'Bitte einen Vorgangsnamen vergeben.';
|
||||||
|
return false;
|
||||||
|
} else if (!vorgangPIN) {
|
||||||
|
errorMsg = 'Bitte einen Vorgangs-PIN eingeben.';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const existing = vorgangList.some((vorg) => vorg.vorgangName === vorgangName);
|
||||||
|
if (existing) {
|
||||||
|
errorMsg = 'Der Name existiert bereits.';
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function deleteVorgang(vorgangToken: string) {
|
||||||
let delete_item = window.confirm('Bist du sicher?');
|
let delete_item = window.confirm('Bist du sicher?');
|
||||||
|
|
||||||
if (delete_item) {
|
if (delete_item) {
|
||||||
const target = ev.currentTarget as HTMLElement | null;
|
let url = API_ROUTES.VORGANG(vorgangToken);
|
||||||
if (!target) return;
|
|
||||||
let filename = target.id.split('del__')[1];
|
|
||||||
|
|
||||||
let url = `/api/list/${filename}`;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(url, { method: 'DELETE' });
|
const response = await fetch(url, { method: 'DELETE' });
|
||||||
@@ -35,6 +106,46 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Variablen für Modal
|
||||||
|
let open = $state(false);
|
||||||
|
let inProgress = $state(false);
|
||||||
|
let isError = $state(false);
|
||||||
|
|
||||||
|
async function handleSave(newName: string, oldName: string, vorgangToken: string) {
|
||||||
|
open = true;
|
||||||
|
inProgress = true;
|
||||||
|
isError = false;
|
||||||
|
try {
|
||||||
|
const res = await fetch(API_ROUTES.VORGANG(vorgangToken), {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ vorgangToken, oldName, newName })
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Fehler beim Speichern');
|
||||||
|
}
|
||||||
|
await invalidateAll();
|
||||||
|
vorgangList = data.vorgangList;
|
||||||
|
open = false;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('⚠️ Netzwerkfehler beim Speichern', err);
|
||||||
|
isError = true;
|
||||||
|
} finally {
|
||||||
|
inProgress = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
async function closeModal() {
|
||||||
|
open = false;
|
||||||
|
isError = false;
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="-z-10 bg-white">
|
<div class="-z-10 bg-white">
|
||||||
@@ -48,30 +159,21 @@
|
|||||||
{:else}
|
{:else}
|
||||||
{#each vorgangList as vorgangItem}
|
{#each vorgangList as vorgangItem}
|
||||||
<li data-testid="test-list-item">
|
<li data-testid="test-list-item">
|
||||||
|
<div class="flex items-center justify-center gap-3">
|
||||||
<a
|
<a
|
||||||
href="/list/{vorgangItem.vorgangToken}?pin={vorgangItem.vorgangPIN}"
|
href="{ROUTE_NAMES.VORGANG(vorgangItem.vorgangToken)}"
|
||||||
class="flex justify-between gap-x-6 py-5"
|
class="flex flex-col items-center justify-center gap-2 py-4 rounded-lg hover:bg-gray-50 transition text-center"
|
||||||
>
|
>
|
||||||
<div class="flex gap-x-4">
|
<Folder class="w-6 h-6 text-gray-600" />
|
||||||
<Folder />
|
|
||||||
<div class="min-w-0 flex-auto">
|
|
||||||
<span class="text-sm font-semibold leading-6 text-gray-900"
|
|
||||||
>{vorgangItem.vorgangName}</span
|
|
||||||
>
|
|
||||||
<button
|
|
||||||
style="padding: 2px"
|
|
||||||
id="del__{vorgangItem.vorgangToken}"
|
|
||||||
on:click|preventDefault={delete_item}
|
|
||||||
aria-label="Vorgang {vorgangItem.name} löschen"
|
|
||||||
>
|
|
||||||
<Trash />
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
|
||||||
<p class="text-sm leading-6 text-gray-900">Vorgang</p>
|
|
||||||
</div>
|
|
||||||
</a>
|
</a>
|
||||||
|
<NameItemEditor
|
||||||
|
list={derivedList}
|
||||||
|
currentName={vorgangItem.vorgangName}
|
||||||
|
vorgangToken={vorgangItem.vorgangToken}
|
||||||
|
onSave={handleSave}
|
||||||
|
onDelete={deleteVorgang}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
@@ -79,8 +181,84 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
|
<ExpandableForm>
|
||||||
|
<form class="flex flex-col items-center" method="POST">
|
||||||
|
<div class="flex flex-col sm:flex-row sm:space-x-4 w-full max-w-lg">
|
||||||
|
<div class="flex-1">
|
||||||
|
<label for="vorgang" class="block text-sm font-medium leading-6 text-gray-900">
|
||||||
|
<span class="flex"> Vorgangsname </span>
|
||||||
|
</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<div
|
||||||
|
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
bind:value={vorgangName}
|
||||||
|
type="text"
|
||||||
|
name="vorgang"
|
||||||
|
id="vorgang"
|
||||||
|
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex-1 mt-4 sm:mt-0">
|
||||||
|
<label for="pin" class="block text-sm font-medium leading-6 text-gray-900">
|
||||||
|
<span class="flex"> PIN </span>
|
||||||
|
</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<div
|
||||||
|
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
required
|
||||||
|
type="password"
|
||||||
|
bind:value={vorgangPIN}
|
||||||
|
name="pin"
|
||||||
|
id="pin"
|
||||||
|
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{#if errorMsg}
|
||||||
|
<p>{errorMsg}</p>
|
||||||
|
{/if}
|
||||||
|
{#if form?.message}
|
||||||
|
<p>{form.message}</p>
|
||||||
|
{/if}
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
on:click={submitVorgang}
|
||||||
|
class="mt-4 bg-indigo-600 text-white px-6 py-2 rounded hover:bg-indigo-700 transition"
|
||||||
|
>
|
||||||
|
Neuen Vorgang hinzufügen
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</ExpandableForm>
|
||||||
|
|
||||||
|
<Modal {open}
|
||||||
|
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
|
||||||
|
{#if inProgress}
|
||||||
|
<p class="py-2 mb-1">Vorgang läuft...</p>
|
||||||
|
{:else if isError}
|
||||||
|
<Alert class="w-full" type="error">Fehler beim Umbenennen</Alert>
|
||||||
|
{:else}
|
||||||
|
<Alert class="w-full">Umbenennen erfolgreich</Alert>
|
||||||
|
{/if}
|
||||||
|
</ModalContent>
|
||||||
|
<ModalFooter><Button disabled={inProgress} on:click={closeModal}>Ok</Button></ModalFooter>
|
||||||
|
</Modal>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
ul {
|
ul {
|
||||||
min-width: 24rem;
|
min-width: 24rem;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import { Readable } from 'stream';
|
import { Readable } from 'stream';
|
||||||
import { BUCKET, client } from '$lib/minio';
|
import { BUCKET, client } from '$lib/minio';
|
||||||
import { fail } from '@sveltejs/kit';
|
import { fail, error } from '@sveltejs/kit';
|
||||||
import { v4 as uuidv4 } from 'uuid';
|
|
||||||
|
|
||||||
import { db } from '$lib/server/dbService';
|
import { getVorgangByName } from '$lib/server/vorgangService';
|
||||||
import { getVorgangByName, vorgangNameExists } from '$lib/server/vorgangService';
|
|
||||||
|
|
||||||
const isRequiredFieldValid = (value: unknown) => {
|
const isRequiredFieldValid = (value: unknown) => {
|
||||||
if (value == null) return false;
|
if (value == null) return false;
|
||||||
@@ -20,26 +18,11 @@ export const actions = {
|
|||||||
const vorgangName: string | null = data.get('vorgang') as string;
|
const vorgangName: string | null = data.get('vorgang') as string;
|
||||||
const crimeName: string | null = data.get('name') as string;
|
const crimeName: string | null = data.get('name') as string;
|
||||||
const type: string | null = data.get('type') as string;
|
const type: string | null = data.get('type') as string;
|
||||||
const vorgangPIN: string | null = data.get('vorgangPIN') as string;
|
|
||||||
const fileName: string | null = data.get('fileName') as string;
|
const fileName: string | null = data.get('fileName') as string;
|
||||||
|
|
||||||
const vorgangExists = vorgangNameExists(vorgangName);
|
|
||||||
let vorgangToken;
|
let vorgangToken;
|
||||||
|
const vorgang = getVorgangByName(vorgangName);
|
||||||
if (!vorgangExists) {
|
vorgangToken = vorgang.token;
|
||||||
vorgangToken = uuidv4();
|
|
||||||
const insertSQLStatement = `INSERT INTO cases (token, name, pin) VALUES (?, ?, ?)`;
|
|
||||||
const statement = db.prepare(insertSQLStatement);
|
|
||||||
statement.run(vorgangToken, vorgangName, vorgangPIN);
|
|
||||||
} else {
|
|
||||||
const vorgang = getVorgangByName(vorgangName);
|
|
||||||
vorgangToken = vorgang.token;
|
|
||||||
if (vorgang && vorgang.pin != vorgangPIN) {
|
|
||||||
const updateSQLStmt = `UPDATE cases SET pin = ? WHERE token = ?`;
|
|
||||||
const statement = db.prepare(updateSQLStmt);
|
|
||||||
statement.run(vorgangPIN, vorgangToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let objectName = `${vorgangToken}/${crimeName}`;
|
let objectName = `${vorgangToken}/${crimeName}`;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
@@ -60,7 +43,6 @@ export const actions = {
|
|||||||
const data = Object.fromEntries(requestData);
|
const data = Object.fromEntries(requestData);
|
||||||
const vorgang = data.vorgang;
|
const vorgang = data.vorgang;
|
||||||
const name = data.name;
|
const name = data.name;
|
||||||
const vorgangPIN = data.vorgangPIN;
|
|
||||||
let success = true;
|
let success = true;
|
||||||
const err = {};
|
const err = {};
|
||||||
if (isRequiredFieldValid(vorgang)) {
|
if (isRequiredFieldValid(vorgang)) {
|
||||||
@@ -77,13 +59,6 @@ export const actions = {
|
|||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isRequiredFieldValid(vorgangPIN)) {
|
|
||||||
err.vorgangPIN = null;
|
|
||||||
} else {
|
|
||||||
err.vorgangPIN = 'Das Feld Zugangspasswort darf nicht leer bleiben.';
|
|
||||||
success = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (success) return { success };
|
if (success) return { success };
|
||||||
|
|
||||||
return fail(400, err);
|
return fail(400, err);
|
||||||
@@ -123,3 +98,10 @@ export const actions = {
|
|||||||
return { etag, error };
|
return { etag, error };
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async (event) => {
|
||||||
|
if (!event.locals.user) {
|
||||||
|
error(404, 'Not found')
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
import shortenFileSize from '$lib/helper/shortenFileSize.js';
|
import shortenFileSize from '$lib/helper/shortenFileSize.js';
|
||||||
import Exclamation from '$lib/icons/Exclamation.svelte';
|
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||||
import FileRect from '$lib/icons/File-rect.svelte';
|
import FileRect from '$lib/icons/File-rect.svelte';
|
||||||
|
import { API_ROUTES, ROUTE_NAMES } from '../../index.js';
|
||||||
|
|
||||||
export let form;
|
export let form;
|
||||||
|
|
||||||
@@ -43,7 +44,7 @@
|
|||||||
data.append('vorgang', vorgang);
|
data.append('vorgang', vorgang);
|
||||||
data.append('name', name);
|
data.append('name', name);
|
||||||
data.append('vorgangPIN', vorgangPIN);
|
data.append('vorgangPIN', vorgangPIN);
|
||||||
const response = await fetch('?/validate', { method: 'POST', body: data });
|
const response = await fetch(ROUTE_NAMES.UPLOAD_VALIDATE, { method: 'POST', body: data });
|
||||||
/** @type {import('@sveltejs/kit').ActionResult} */
|
/** @type {import('@sveltejs/kit').ActionResult} */
|
||||||
const result = deserialize(await response.text());
|
const result = deserialize(await response.text());
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@
|
|||||||
data.append('type', files[0].type);
|
data.append('type', files[0].type);
|
||||||
data.append('fileName', files[0].name);
|
data.append('fileName', files[0].name);
|
||||||
}
|
}
|
||||||
const response = await fetch('?/url', { method: 'POST', body: data });
|
const response = await fetch(ROUTE_NAMES.UPLOAD_URL, { method: 'POST', body: data });
|
||||||
/** @type {import('@sveltejs/kit').ActionResult} */
|
/** @type {import('@sveltejs/kit').ActionResult} */
|
||||||
const result = deserialize(await response.text());
|
const result = deserialize(await response.text());
|
||||||
if (result.type === 'success') return result.data?.url;
|
if (result.type === 'success') return result.data?.url;
|
||||||
@@ -151,7 +152,6 @@
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// `/(angemeldet)/view` return true or false
|
|
||||||
async function checkVorgangExists(vorgangName: string) {
|
async function checkVorgangExists(vorgangName: string) {
|
||||||
if (vorgangName == '') {
|
if (vorgangName == '') {
|
||||||
vorgangPIN = vorgangPINOld;
|
vorgangPIN = vorgangPINOld;
|
||||||
@@ -159,7 +159,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const url = `/api/list/${vorgangName}`;
|
// `HEAD` method
|
||||||
|
const url = API_ROUTES.VORGANG_NAME_EXIST(vorgangName);
|
||||||
const response = await fetch(url, { method: 'HEAD' });
|
const response = await fetch(url, { method: 'HEAD' });
|
||||||
|
|
||||||
if (response.status === 200) {
|
if (response.status === 200) {
|
||||||
@@ -185,7 +186,7 @@
|
|||||||
async function getVorgangPIN(vorgangName: string) {
|
async function getVorgangPIN(vorgangName: string) {
|
||||||
if (vorgangName == '') return;
|
if (vorgangName == '') return;
|
||||||
|
|
||||||
let url = `/api/vorgang/${vorgangName}/vorgangPIN`;
|
let url = API_ROUTES.VORGANG_PIN(vorgangName);
|
||||||
const response = await fetch(url);
|
const response = await fetch(url);
|
||||||
|
|
||||||
if (response.status == 200) {
|
if (response.status == 200) {
|
||||||
|
|||||||
8
src/routes/(angemeldet)/user-management/+page.server.ts
Normal file
8
src/routes/(angemeldet)/user-management/+page.server.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import type { PageServerLoad } from '../../(token-based)/view/$types';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async (event) => {
|
||||||
|
if (!event.locals.user) {
|
||||||
|
error(404, 'Not Found')
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import Button from '$lib/components/Button.svelte';
|
import Button from '$lib/components/Button.svelte';
|
||||||
|
import { API_ROUTES } from '../../index.js';
|
||||||
|
|
||||||
const { data } = $props();
|
const { data } = $props();
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function getUsers() {
|
async function getUsers() {
|
||||||
const URL = '/api/users';
|
const URL = API_ROUTES.USERS;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(URL);
|
const response = await fetch(URL);
|
||||||
@@ -42,7 +43,7 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const URL = '/api/users';
|
const URL = API_ROUTES.USERS;
|
||||||
const userData = { userName: userName, userPassword: userPassword };
|
const userData = { userName: userName, userPassword: userPassword };
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -78,7 +79,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function deleteUser(userId: string) {
|
async function deleteUser(userId: string) {
|
||||||
const URL = `/api/users/${userId}`;
|
const URL = API_ROUTES.USER(userId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(URL, {
|
const response = await fetch(URL, {
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
import {
|
import { vorgangPINValidation, vorgangExists } from '$lib/server/vorgangService';
|
||||||
vorgangPINValidation,
|
|
||||||
vorgangExists
|
|
||||||
} from '$lib/server/vorgangService';
|
|
||||||
import { redirect } from '@sveltejs/kit';
|
import { redirect } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './list/[vorgang]/$types';
|
import type { LayoutServerLoad } from './$types';
|
||||||
|
import { ROUTE_NAMES } from '..';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, url, locals }) => {
|
export const load: LayoutServerLoad = async ({ params, cookies, locals }) => {
|
||||||
if (locals.user) {
|
if (locals.user) {
|
||||||
return {
|
return {
|
||||||
user: locals.user
|
user: locals.user
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const vorgangToken = params.vorgang;
|
const vorgangToken = params.vorgang ?? '';
|
||||||
const vorgangPIN = url.searchParams.get('pin');
|
const COOKIE_NAME = `token-${vorgangToken}`;
|
||||||
|
const vorgangPIN = cookies.get(COOKIE_NAME) ?? '';
|
||||||
|
|
||||||
const isVorgangValid = vorgangExists(vorgangToken);
|
const isVorgangValid = vorgangExists(vorgangToken);
|
||||||
const isVorgangPINValid = vorgangPINValidation(vorgangToken, vorgangPIN);
|
const isVorgangPINValid = vorgangPINValidation(vorgangToken, vorgangPIN);
|
||||||
|
|
||||||
if (!isVorgangValid || !isVorgangPINValid) throw redirect(303, `/anmeldung?vorgang=${vorgangToken}`);
|
if (!isVorgangValid || !isVorgangPINValid)
|
||||||
|
throw redirect(303, ROUTE_NAMES.ANMELDUNG_VORGANG_PARAM(vorgangToken));
|
||||||
};
|
};
|
||||||
|
|||||||
23
src/routes/(token-based)/list/[vorgang]/+page.server.ts
Normal file
23
src/routes/(token-based)/list/[vorgang]/+page.server.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { getCrimesListByToken, getVorgaenge } from '$lib/server/vorgangService.js';
|
||||||
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async ({ params, url }) => {
|
||||||
|
const vorgangList = getVorgaenge();
|
||||||
|
const vorgangToken = params.vorgang;
|
||||||
|
const crimesList = await getCrimesListByToken(vorgangToken);
|
||||||
|
const vorgang = vorgangList.find((v) => v.vorgangToken === vorgangToken); //vorgang sollte ein eigener Typ werden, und dann kann man es hier vernünftig typisieren
|
||||||
|
if (!vorgang || !crimesList) {
|
||||||
|
throw new Error(`Fehlgeschlagen, es wurden keine Daten zum token gefunden`);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Variabeln für NameItemEditor
|
||||||
|
const crimeNames: string[] = crimesList.map((l) => l.name);
|
||||||
|
|
||||||
|
return {
|
||||||
|
vorgang,
|
||||||
|
vorgangList,
|
||||||
|
crimesList,
|
||||||
|
url,
|
||||||
|
crimeNames
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import { fade } from 'svelte/transition';
|
||||||
import shortenFileSize from '$lib/helper/shortenFileSize';
|
import shortenFileSize from '$lib/helper/shortenFileSize';
|
||||||
import timeElapsed from '$lib/helper/timeElapsed';
|
import timeElapsed from '$lib/helper/timeElapsed';
|
||||||
|
import { deserialize } from '$app/forms';
|
||||||
|
import ExpandableForm from '$lib/components/ExpandableForm.svelte';
|
||||||
import Alert from '$lib/components/Alert.svelte';
|
import Alert from '$lib/components/Alert.svelte';
|
||||||
import Button from '$lib/components/Button.svelte';
|
import Button from '$lib/components/Button.svelte';
|
||||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
import Modal from '$lib/components/Modal/Modal.svelte';
|
||||||
@@ -12,9 +14,12 @@
|
|||||||
import { invalidateAll } from '$app/navigation';
|
import { invalidateAll } from '$app/navigation';
|
||||||
import NameItemEditor from '$lib/components/NameItemEditor.svelte';
|
import NameItemEditor from '$lib/components/NameItemEditor.svelte';
|
||||||
import EmptyList from '$lib/components/EmptyList.svelte';
|
import EmptyList from '$lib/components/EmptyList.svelte';
|
||||||
|
import FileRect from '$lib/icons/File-rect.svelte';
|
||||||
|
import Exclamation from '$lib/icons/Exclamation.svelte';
|
||||||
|
import { API_ROUTES, ROUTE_NAMES } from '../../../index.js';
|
||||||
|
|
||||||
//Seite für die Tatort-Liste
|
//Seite für die Tatort-Liste
|
||||||
let { data } = $props();
|
let { data, form } = $props();
|
||||||
|
|
||||||
interface ListItem {
|
interface ListItem {
|
||||||
//sollte Typ Vorgang sein, aber der einfachheit ist es noch ListItem, damit die Komponente NameItemEditor für Vorgang und Tatort eingesetzt werden kann
|
//sollte Typ Vorgang sein, aber der einfachheit ist es noch ListItem, damit die Komponente NameItemEditor für Vorgang und Tatort eingesetzt werden kann
|
||||||
@@ -26,53 +31,195 @@
|
|||||||
// add other properties as needed
|
// add other properties as needed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let crimesList = $state<ListItem[]>(data.crimesList);
|
||||||
let vorgangName: string = data.vorgang.vorgangName;
|
let vorgangName: string = data.vorgang.vorgangName;
|
||||||
let crimesList: ListItem[] = $state(data.crimesList);
|
|
||||||
const vorgangPIN: string = data.vorgang.vorgangPIN;
|
const vorgangPIN: string = data.vorgang.vorgangPIN;
|
||||||
let vorgangToken: string = data.vorgang.vorgangToken;
|
let vorgangToken: string = data.vorgang.vorgangToken;
|
||||||
let isEmptyList = $derived(crimesList.length === 0);
|
let isEmptyList = $derived(crimesList.length === 0);
|
||||||
|
|
||||||
|
// File Upload Variablen
|
||||||
|
let name = $state('');
|
||||||
|
let formErrors: Record<string, any> | null = $state(null);
|
||||||
|
let etag: string | null = $state(null);
|
||||||
|
let files: FileList | null = $state(null);
|
||||||
|
let fileInput = $state(null);
|
||||||
|
|
||||||
|
// Model Variablen für Upload
|
||||||
|
let openUL = $state(false);
|
||||||
|
let inProgressUL = $state(form === null);
|
||||||
|
|
||||||
|
// Variablen für Copy-Funktion
|
||||||
|
let copied = $state(false);
|
||||||
|
|
||||||
|
async function buttonClick(event: MouseEvent) {
|
||||||
|
if (!(await validateForm())) {
|
||||||
|
event.preventDefault();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const url = await getUrl();
|
||||||
|
openUL = true;
|
||||||
|
inProgressUL = true;
|
||||||
|
|
||||||
|
fetch(url, { method: 'PUT', body: files[0] })
|
||||||
|
.then((response) => {
|
||||||
|
inProgressUL = false;
|
||||||
|
etag = '123';
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
inProgressUL = false;
|
||||||
|
etag = null;
|
||||||
|
console.log('ERROR', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function validateForm() {
|
||||||
|
let data = new FormData();
|
||||||
|
data.append('vorgang', vorgangName);
|
||||||
|
data.append('name', name);
|
||||||
|
const response = await fetch(ROUTE_NAMES.UPLOAD_VALIDATE, { method: 'POST', body: data });
|
||||||
|
const result = deserialize(await response.text());
|
||||||
|
|
||||||
|
let success = true;
|
||||||
|
if (result.type === 'success') {
|
||||||
|
formErrors = null;
|
||||||
|
} else {
|
||||||
|
if (result.type === 'failure' && result.data) formErrors = result.data;
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!files?.length) {
|
||||||
|
formErrors = { file: 'Sie haben keine Datei ausgewählt.', ...formErrors };
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!(await check_valid_glb_file())) {
|
||||||
|
formErrors = { file: 'Keine gültige .GLD-Datei', ...formErrors };
|
||||||
|
success = false;
|
||||||
|
}
|
||||||
|
return success;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function uploadSuccessful() {
|
||||||
|
openUL = false;
|
||||||
|
name = '';
|
||||||
|
files = null;
|
||||||
|
fileInput.value = "";
|
||||||
|
await invalidateAll();
|
||||||
|
crimesList = data.crimesList;
|
||||||
|
}
|
||||||
|
|
||||||
|
// `val` is hex string
|
||||||
|
function swap_endian(val) {
|
||||||
|
// from https://www.geeksforgeeks.org/bit-manipulation-swap-endianness-of-a-number/
|
||||||
|
|
||||||
|
let leftmost_byte = (val & eval(0x000000ff)) >> 0;
|
||||||
|
let left_middle_byte = (val & eval(0x0000ff00)) >> 8;
|
||||||
|
let right_middle_byte = (val & eval(0x00ff0000)) >> 16;
|
||||||
|
let rightmost_byte = (val & eval(0xff000000)) >> 24;
|
||||||
|
|
||||||
|
leftmost_byte <<= 24;
|
||||||
|
left_middle_byte <<= 16;
|
||||||
|
right_middle_byte <<= 8;
|
||||||
|
rightmost_byte <<= 0;
|
||||||
|
|
||||||
|
let res = leftmost_byte | left_middle_byte | right_middle_byte | rightmost_byte;
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function check_valid_glb_file() {
|
||||||
|
// GLD Header, magic value 0x46546C67, identifies data as binary glTF, 4 bytes
|
||||||
|
// little endian!
|
||||||
|
const GLD_MAGIC = 0x46546c67;
|
||||||
|
|
||||||
|
// big endian!
|
||||||
|
let file = files[0];
|
||||||
|
const fileHeader = file.slice(0, 4);
|
||||||
|
const buffer = await fileHeader.arrayBuffer();
|
||||||
|
console.log(fileHeader);
|
||||||
|
let headerBytes = new Uint8Array(buffer);
|
||||||
|
let fileHeaderHex = '0x' + headerBytes.toHex().toString();
|
||||||
|
|
||||||
|
if (GLD_MAGIC == swap_endian(fileHeaderHex)) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getUrl() {
|
||||||
|
let data = new FormData();
|
||||||
|
data.append('vorgang', vorgangName);
|
||||||
|
data.append('name', name);
|
||||||
|
if (files?.length === 1) {
|
||||||
|
data.append('type', files[0].type);
|
||||||
|
data.append('fileName', files[0].name);
|
||||||
|
}
|
||||||
|
const response = await fetch(ROUTE_NAMES.UPLOAD_URL, { method: 'POST', body: data });
|
||||||
|
const result = deserialize(await response.text());
|
||||||
|
if (result.type === 'success') return result.data?.url;
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
//Variablen für Modal
|
//Variablen für Modal
|
||||||
let open = $state(false);
|
let open = $state(false);
|
||||||
let inProgress = $state(false);
|
let inProgress = $state(false);
|
||||||
let isError = $state(false);
|
let isError = $state(false);
|
||||||
|
|
||||||
//Variable um nur admin UI anzuzeigen
|
|
||||||
let admin = data?.user?.admin;
|
let admin = data?.user?.admin;
|
||||||
|
|
||||||
async function handleSave(newName: string, oldName: string) {
|
async function handleSave(newName: string, oldName: string) {
|
||||||
open = true;
|
open = true;
|
||||||
inProgress = true;
|
inProgress = true;
|
||||||
|
isError = false;
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api/list/${vorgangToken}/${oldName}`, {
|
const res = await fetch(API_ROUTES.CRIME(vorgangToken, oldName), {
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ vorgangToken, oldName, newName })
|
body: JSON.stringify({ vorgangToken, oldName, newName })
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
inProgress = false;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
inProgress = false;
|
|
||||||
isError = true;
|
|
||||||
console.log('ERROR', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!res.ok) {
|
if (!res.ok) {
|
||||||
const msg = await res.text();
|
throw new Error('Fehler beim Speichern');
|
||||||
console.error('❌ Fehler beim Umbenennen:', msg);
|
|
||||||
isError = true;
|
|
||||||
inProgress = false;
|
|
||||||
} else {
|
|
||||||
await invalidateAll();
|
|
||||||
crimesList = data.crimesList;
|
|
||||||
open = false;
|
|
||||||
inProgress = false;
|
|
||||||
}
|
}
|
||||||
|
await invalidateAll();
|
||||||
|
crimesList = data.crimesList;
|
||||||
|
open = false;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('⚠️ Netzwerkfehler:', err);
|
console.error('⚠️ Netzwerkfehler beim Speichern', err);
|
||||||
|
isError = true;
|
||||||
|
} finally {
|
||||||
|
inProgress = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function savePIN(newVorgangPIN: string, oldVorgangPIN: string) {
|
||||||
|
open = true;
|
||||||
|
inProgress = true;
|
||||||
|
isError = false;
|
||||||
|
try {
|
||||||
|
const res = await fetch(API_ROUTES.VORGANG(vorgangToken), {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json'
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ vorgangToken, oldVorgangPIN, newVorgangPIN,
|
||||||
|
changePIN: true})
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!res.ok) {
|
||||||
|
throw new Error('Fehler beim Speichern');
|
||||||
|
}
|
||||||
|
await invalidateAll();
|
||||||
|
crimesList = data.crimesList;
|
||||||
|
open = false;
|
||||||
|
} catch (err) {
|
||||||
|
console.error('⚠️ Netzwerkfehler beim Speichern', err);
|
||||||
|
isError = true;
|
||||||
|
} finally {
|
||||||
inProgress = false;
|
inProgress = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,45 +227,35 @@
|
|||||||
async function handleDelete(tatort: string) {
|
async function handleDelete(tatort: string) {
|
||||||
open = true;
|
open = true;
|
||||||
inProgress = true;
|
inProgress = true;
|
||||||
let url = new URL(data.url);
|
isError = false;
|
||||||
url.pathname += `/${tatort}`;
|
let path = API_ROUTES.CRIME(vorgangToken, tatort)
|
||||||
console.log('Delete tatort: ', `/api${url.pathname}`, url.pathname);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch(`/api${url.pathname}`, {
|
const res = await fetch(path, {
|
||||||
method: 'DELETE',
|
method: 'DELETE',
|
||||||
headers: {
|
headers: {
|
||||||
'Content-Type': 'application/json'
|
'Content-Type': 'application/json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ vorgangToken, tatort })
|
body: JSON.stringify({ vorgangToken, tatort })
|
||||||
})
|
});
|
||||||
.then(() => {
|
|
||||||
inProgress = false;
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
isError = true;
|
|
||||||
inProgress = false;
|
|
||||||
console.log('ERROR', err);
|
|
||||||
});
|
|
||||||
if (!res.ok) {
|
|
||||||
const msg = await res.text();
|
|
||||||
console.error('❌ Fehler beim Löschen:', msg);
|
|
||||||
} else {
|
|
||||||
console.log('🗑️ Erfolgreich gelöscht:', url.pathname);
|
|
||||||
await invalidateAll();
|
|
||||||
|
|
||||||
crimesList = data.crimesList;
|
if (!res.ok) {
|
||||||
|
throw new Error('Fehler beim Löschen');
|
||||||
}
|
}
|
||||||
|
crimesList = crimesList.filter((i) => i.name !== tatort);
|
||||||
|
await invalidateAll();
|
||||||
|
console.log('🗑️ Erfolgreich gelöscht:', path);
|
||||||
|
open = false;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
console.error('⚠️ Netzwerkfehler beim Speichern', err);
|
||||||
isError = true;
|
isError = true;
|
||||||
|
} finally {
|
||||||
inProgress = false;
|
inProgress = false;
|
||||||
console.error('⚠️ Netzwerkfehler beim Löschen:', err);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function constructMailToLink() {
|
async function copyAndOpenMail() {
|
||||||
const subject = 'Link zum Tatvorgang';
|
const subject = 'Link zum Tatvorgang';
|
||||||
|
|
||||||
const link = data.url.origin + data.url.pathname;
|
const link = data.url.origin + data.url.pathname;
|
||||||
const body = `Hallo,
|
const body = `Hallo,
|
||||||
|
|
||||||
@@ -130,27 +267,75 @@ Der Zugangs-PIN wird zur Sicherheit über einen zweiten Kommunikationskanal übe
|
|||||||
Mit freundlichen Grüßen,
|
Mit freundlichen Grüßen,
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`;
|
try {
|
||||||
|
await navigator.clipboard.writeText(body);
|
||||||
|
|
||||||
return mailtoLink;
|
copied = true;
|
||||||
}
|
|
||||||
|
// Kurz warten, dann Mail öffnen
|
||||||
|
setTimeout(() => {
|
||||||
|
const mailtoLink = `mailto:?subject=${encodeURIComponent(subject)}`;
|
||||||
|
window.location.href = mailtoLink;
|
||||||
|
}, 1000);
|
||||||
|
|
||||||
|
setTimeout(() => copied = false, 2000);
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Clipboard-Fehler:', err);
|
||||||
|
error = 'Konnte Text nicht kopieren. Bitte manuell markieren und kopieren.';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function closeModal() {
|
function closeModal() {
|
||||||
open = false;
|
open = false;
|
||||||
isError = false;
|
isError = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// drag and drop functionality
|
||||||
|
let isDragging = $state(false);
|
||||||
|
|
||||||
|
async function handleDrop(event) {
|
||||||
|
event.preventDefault();
|
||||||
|
isDragging = false;
|
||||||
|
|
||||||
|
if (event.dataTransfer?.files?.length) {
|
||||||
|
files = event.dataTransfer.files;
|
||||||
|
}
|
||||||
|
if (!(await check_valid_glb_file())) {
|
||||||
|
formErrors = { file: 'Keine gültige .GLD-Datei' }
|
||||||
|
// reset form fields etc.
|
||||||
|
files = null;
|
||||||
|
fileInput.value = '';
|
||||||
|
} else {
|
||||||
|
formErrors = { ...formErrors, file: ''}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if data.vorgang && data.crimesList}
|
<svelte:window
|
||||||
|
on:dragover|preventDefault
|
||||||
|
on:drop|preventDefault
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if data.vorgang && crimesList}
|
||||||
<div class="-z-10 bg-white">
|
<div class="-z-10 bg-white">
|
||||||
<div class="flex flex-col items-center justify-center w-full">
|
<div class="flex flex-col items-center justify-center w-full">
|
||||||
<h1 class="text-xl">Vorgang {vorgangName}</h1>
|
<h1 class="text-xl">{vorgangName}</h1>
|
||||||
|
|
||||||
{#if admin}
|
{#if admin}
|
||||||
Zugangs-PIN: {vorgangPIN}
|
<div class="flex items-center gap-2">
|
||||||
<a class="pt-2 pb-6" href={constructMailToLink()}
|
Zugangs-PIN:
|
||||||
><Button disabled={isEmptyList}>Share Link</Button></a
|
<NameItemEditor
|
||||||
>
|
list={[]}
|
||||||
|
currentName={vorgangPIN}
|
||||||
|
onSave={savePIN}
|
||||||
|
onDelete={null}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<Button variant="secondary" on:click={copyAndOpenMail} disabled={isEmptyList}>Link kopieren und Mail verfassen</Button>
|
||||||
|
{#if copied}
|
||||||
|
<p transition:fade>✔ Kopiert! Per Ctrl+V einfügen.</p>
|
||||||
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
<div class="mx-auto flex justify-center max-w-7xl h-full">
|
||||||
@@ -158,54 +343,156 @@ Mit freundlichen Grüßen,
|
|||||||
{#if isEmptyList}
|
{#if isEmptyList}
|
||||||
<EmptyList></EmptyList>
|
<EmptyList></EmptyList>
|
||||||
{:else}
|
{:else}
|
||||||
{#each data.crimesList as item, crimeListItemIndex}
|
{#each crimesList as item (item.name)}
|
||||||
<li data-testid="test-list-item">
|
<li
|
||||||
<div class=" flex gap-x-4">
|
data-testid="test-list-item"
|
||||||
<a
|
class="flex items-center justify-between gap-6 py-4 px-2 hover:bg-gray-50 rounded-lg transition"
|
||||||
href="/view/{vorgangToken}/{item.name}?pin={vorgangPIN}"
|
>
|
||||||
class=" flex justify-between gap-x-6 py-5"
|
<div class="flex items-center gap-4 flex-1">
|
||||||
aria-label="/view/{vorgangToken}/{item.name}?pin={vorgangPIN}"
|
<a
|
||||||
title={item.name}
|
data-testid="crime-link"
|
||||||
>
|
href="{ROUTE_NAMES.CRIME(vorgangToken, item.name, vorgangPIN)}"
|
||||||
<Cube />
|
class="flex items-center justify-center w-8 h-8 text-gray-600 hover:text-blue-600 transition"
|
||||||
</a>
|
aria-label="{ROUTE_NAMES.CRIME(vorgangToken, item.name, vorgangPIN)}"
|
||||||
<div class="min-w-0 flex-auto">
|
title={item.name}
|
||||||
{#if admin}
|
>
|
||||||
<NameItemEditor
|
<Cube class="w-5 h-5" />
|
||||||
list={data.crimesList}
|
</a>
|
||||||
editedName={data.crimeNames[crimeListItemIndex]}
|
|
||||||
currentName={item.name}
|
<div class="flex flex-col flex-1 min-w-0">
|
||||||
onSave={handleSave}
|
{#if admin}
|
||||||
onDelete={handleDelete}
|
<NameItemEditor
|
||||||
></NameItemEditor>
|
list={crimesList}
|
||||||
{:else}
|
currentName={item.name}
|
||||||
<span class="text-sm font-semibold leading-6 text-gray-900 inline-block min-w-1"
|
onSave={handleSave}
|
||||||
>{item.name}</span
|
onDelete={handleDelete}
|
||||||
>
|
/>
|
||||||
{/if}
|
{:else}
|
||||||
{#if item.size}
|
<p
|
||||||
<p class="mt-1 truncate text-xs leading-5 text-gray-500">
|
data-testid="test-nameItem-p"
|
||||||
{shortenFileSize(item.size)}
|
class="text-sm font-semibold leading-6 text-gray-900 truncate"
|
||||||
</p>
|
>
|
||||||
{/if}
|
{item.name}
|
||||||
</div>
|
</p>
|
||||||
</div>
|
{/if}
|
||||||
<div class="hidden sm:flex sm:flex-col sm:items-end">
|
|
||||||
<p class="text-sm leading-6 text-gray-900">3D Tatort</p>
|
<!-- size left, last modified right -->
|
||||||
{#if item.lastModified}
|
<div class="flex items-center justify-between mt-1 text-xs leading-5 text-gray-500">
|
||||||
<p class="mt-1 text-xs leading-5 text-gray-500">
|
{#if item.size}
|
||||||
Zuletzt geändert <time datetime="2023-01-23T13:23Z"
|
<span>{shortenFileSize(item.size)}</span>
|
||||||
>{timeElapsed(new Date(item.lastModified))}</time
|
{:else}
|
||||||
>
|
<span></span>
|
||||||
</p>
|
{/if}
|
||||||
{/if}
|
{#if item.lastModified}
|
||||||
</div>
|
<span>
|
||||||
</li>
|
Zuletzt geändert
|
||||||
|
<time datetime={item.lastModified}>
|
||||||
|
{timeElapsed(new Date(item.lastModified))}
|
||||||
|
</time>
|
||||||
|
</span>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
{/if}
|
{/if}
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{#if admin}
|
||||||
|
<div class="flex justify-center my-4">
|
||||||
|
<ExpandableForm>
|
||||||
|
<div class="mx-auto max-w-2xl">
|
||||||
|
<div class="flex flex-col items-center space-y-6">
|
||||||
|
<!-- Name Input -->
|
||||||
|
<div class="w-full max-w-md">
|
||||||
|
<label for="name" class="block text-sm font-medium leading-6 text-gray-900">
|
||||||
|
<span class="flex">
|
||||||
|
{#if formErrors?.name}
|
||||||
|
<span class="inline-block mr-1"><Exclamation /></span>
|
||||||
|
{/if} Modellname
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<div class="mt-2">
|
||||||
|
<div
|
||||||
|
class="flex rounded-md shadow-sm ring-1 ring-inset ring-gray-300 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-600"
|
||||||
|
>
|
||||||
|
<input
|
||||||
|
bind:value={name}
|
||||||
|
type="text"
|
||||||
|
name="name"
|
||||||
|
id="name"
|
||||||
|
autocomplete={name}
|
||||||
|
class="block flex-1 border-0 bg-transparent py-1.5 pl-1 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-sm sm:leading-6"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#if formErrors?.name}
|
||||||
|
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.name}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<!-- File Upload -->
|
||||||
|
<div class="w-full max-w-md">
|
||||||
|
<label for="file" class="block text-sm font-medium leading-6 text-gray-900">
|
||||||
|
<span class="flex">
|
||||||
|
{#if formErrors?.file}
|
||||||
|
<span class="inline-block mr-1"><Exclamation /></span>
|
||||||
|
{/if} Datei
|
||||||
|
</span>
|
||||||
|
</label>
|
||||||
|
<div
|
||||||
|
class="mt-2 flex justify-center rounded-lg border border-dashed px-6 py-10
|
||||||
|
{isDragging
|
||||||
|
? 'border-blue-500 bg-blue-50'
|
||||||
|
: 'border-gray-900/25'}"
|
||||||
|
on:dragover|preventDefault={() => (isDragging = true)}
|
||||||
|
on:dragleave={() => (isDragging = false)}
|
||||||
|
on:drop={handleDrop}
|
||||||
|
>
|
||||||
|
<div class="text-center">
|
||||||
|
<FileRect />
|
||||||
|
<div class="mt-4 flex text-sm leading-6 text-gray-600">
|
||||||
|
<label
|
||||||
|
for="file"
|
||||||
|
class="relative cursor-pointer rounded-md bg-white font-semibold text-indigo-600 focus-within:outline-none focus-within:ring-2 focus-within:ring-indigo-600 focus-within:ring-offset-2 hover:text-indigo-500"
|
||||||
|
>
|
||||||
|
<span>Wähle eine Datei aus</span>
|
||||||
|
<input id="file" bind:this={fileInput} bind:files name="file" type="file" class="sr-only" />
|
||||||
|
</label>
|
||||||
|
<p class="pl-1">oder ziehe sie ins Feld</p>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs leading-5 text-gray-600">GLB Dateien bis zu 1GB</p>
|
||||||
|
{#if files?.length}
|
||||||
|
<div class="flex justify-center text-xs mt-2">
|
||||||
|
<p class="mx-2">Datei: <span class="font-bold">{files[0].name}</span></p>
|
||||||
|
<p class="mx-2">
|
||||||
|
Größe: <span class="font-bold">{shortenFileSize(files[0].size)}</span>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{#if formErrors?.file}
|
||||||
|
<p class="block text-sm leading-6 text-red-900 mt-2">{formErrors.file}</p>
|
||||||
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="mt-6 flex items-center justify-end gap-x-6">
|
||||||
|
<Button
|
||||||
|
on:click={buttonClick}
|
||||||
|
class="rounded-md bg-indigo-600 px-3 py-2 text-sm font-semibold text-white shadow-sm hover:bg-indigo-500 focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-indigo-600"
|
||||||
|
>
|
||||||
|
Hinzufügen
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</ExpandableForm>
|
||||||
|
</div>
|
||||||
|
{/if}
|
||||||
|
|
||||||
<Modal {open}
|
<Modal {open}
|
||||||
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
|
><ModalTitle>Umbenennen</ModalTitle><ModalContent>
|
||||||
{#if inProgress}
|
{#if inProgress}
|
||||||
@@ -218,6 +505,21 @@ Mit freundlichen Grüßen,
|
|||||||
</ModalContent>
|
</ModalContent>
|
||||||
<ModalFooter><Button disabled={inProgress} on:click={closeModal}>Ok</Button></ModalFooter>
|
<ModalFooter><Button disabled={inProgress} on:click={closeModal}>Ok</Button></ModalFooter>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
|
<Modal open={openUL}
|
||||||
|
><ModalTitle>Upload</ModalTitle><ModalContent>
|
||||||
|
{#if inProgressUL}
|
||||||
|
<p class="py-2 mb-1">Upload läuft...</p>
|
||||||
|
{:else if etag}
|
||||||
|
<Alert class="w-full">Upload erfolgreich</Alert>
|
||||||
|
{:else}
|
||||||
|
<Alert class="w-full" type="error">Fehler beim Upload</Alert>
|
||||||
|
{/if}
|
||||||
|
</ModalContent>
|
||||||
|
<ModalFooter
|
||||||
|
><Button disabled={inProgressUL} on:click={uploadSuccessful}>Ok</Button></ModalFooter
|
||||||
|
>
|
||||||
|
</Modal>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
|
|
||||||
export async function load({fetch, params, url}){
|
|
||||||
const vorgangResponse = await fetch(`/api/list`);
|
|
||||||
const vorgangList = await vorgangResponse.json()
|
|
||||||
const vorgangToken = params.vorgang;
|
|
||||||
const crimesListResponse = await fetch(`/api/list/${vorgangToken}`)
|
|
||||||
const crimesList = await crimesListResponse.json();
|
|
||||||
const vorgang = vorgangList.find(v => v.vorgangToken === vorgangToken); //vorgang sollte ein eigener Typ werden, und dann kann man es hier vernünftig typisieren
|
|
||||||
if(!vorgang || !crimesList){
|
|
||||||
throw new Error(`Fehlgeschlagen, es wurden keine Daten zum token gefunden`);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Variabeln für NameItemEditor
|
|
||||||
const crimeNames: string[] = crimesList.map((l) => l.name);
|
|
||||||
|
|
||||||
|
|
||||||
return {
|
|
||||||
vorgang,
|
|
||||||
vorgangList,
|
|
||||||
crimesList,
|
|
||||||
url,
|
|
||||||
crimeNames
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,35 @@
|
|||||||
import { loginUser, logoutUser } from '$lib/server/authService';
|
import { dev } from '$app/environment';
|
||||||
import { redirect } from '@sveltejs/kit';
|
import { error, fail, redirect } from '@sveltejs/kit';
|
||||||
|
import { ROUTE_NAMES } from '../index.js';
|
||||||
|
import { vorgangPINValidation } from '$lib/server/vorgangService.js';
|
||||||
|
|
||||||
export const actions = {
|
export const actions = {
|
||||||
login: ({ request, cookies }) => loginUser({ request, cookies }),
|
default: async ({ request, cookies }) => {
|
||||||
logout: (event) => logoutUser(event),
|
|
||||||
getVorgangByToken: async ({ request }) => {
|
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
const vorgangToken = data.get('vorgang-token');
|
const vorgangToken = data.get('vorgang-token');
|
||||||
const vorgangPIN = data.get('vorgang-pin');
|
const vorgangPIN = data.get('vorgang-pin') as string;
|
||||||
|
|
||||||
if (!vorgangToken || !vorgangPIN) return;
|
if (!vorgangPIN) {
|
||||||
|
return fail(400, { message: 'Bitte einen PIN eingeben.'});
|
||||||
|
}
|
||||||
|
|
||||||
throw redirect(303, `/list/${vorgangToken}?pin=${vorgangPIN}`);
|
if (!vorgangPINValidation(vorgangToken, vorgangPIN)) {
|
||||||
|
return fail(400, { message: 'Falsche Zugangsdaten.'});
|
||||||
|
}
|
||||||
|
|
||||||
|
const COOKIE_NAME = `token-${vorgangToken}`;
|
||||||
|
cookies.set(COOKIE_NAME, vorgangPIN, {
|
||||||
|
path: '/',
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: 'strict',
|
||||||
|
secure: !dev
|
||||||
|
});
|
||||||
|
|
||||||
|
throw redirect(303, ROUTE_NAMES.VORGANG(vorgangToken));
|
||||||
}
|
}
|
||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async ({ url }) => {
|
||||||
|
const vorgang = url.searchParams.get('vorgang');
|
||||||
|
if (!vorgang) error(404, "Not Found");
|
||||||
|
};
|
||||||
@@ -1,21 +1,15 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import BaseInputField from '$lib/components/BaseInputField.svelte';
|
import BaseInputField from '$lib/components/BaseInputField.svelte';
|
||||||
import Button from '$lib/components/Button.svelte';
|
import Button from '$lib/components/Button.svelte';
|
||||||
import Modal from '$lib/components/Modal/Modal.svelte';
|
|
||||||
import ModalContent from '$lib/components/Modal/ModalContent.svelte';
|
|
||||||
import ModalFooter from '$lib/components/Modal/ModalFooter.svelte';
|
|
||||||
import ModalTitle from '$lib/components/Modal/ModalTitle.svelte';
|
|
||||||
import ArrowRight from '$lib/icons/Arrow-right.svelte';
|
import ArrowRight from '$lib/icons/Arrow-right.svelte';
|
||||||
import Login from '$lib/icons/Login.svelte';
|
|
||||||
|
|
||||||
export let form;
|
export let form;
|
||||||
|
|
||||||
export let open = false;
|
|
||||||
|
|
||||||
import { page } from '$app/state';
|
import { page } from '$app/state';
|
||||||
|
import { ROUTE_NAMES } from '../index.js';
|
||||||
const vorgangToken = page.url.searchParams.get('vorgang');
|
const vorgangToken = page.url.searchParams.get('vorgang');
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#if vorgangToken}
|
||||||
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
<div class="flex min-h-full flex-col justify-center px-6 py-12 lg:px-8">
|
||||||
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
<div class="sm:mx-auto sm:w-full sm:max-w-sm">
|
||||||
<img class="mx-auto h-10 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
<img class="mx-auto h-10 w-auto" src="/Landeswappen_NI.svg" alt="Landeswappen Niedersachsen" />
|
||||||
@@ -27,73 +21,30 @@
|
|||||||
<div class="w-full max-w-sm mx-auto">
|
<div class="w-full max-w-sm mx-auto">
|
||||||
<div class="relative mt-5 bg-gray-50 rounded-xl shadow-xl p-3 pt-1">
|
<div class="relative mt-5 bg-gray-50 rounded-xl shadow-xl p-3 pt-1">
|
||||||
<div class="mt-10">
|
<div class="mt-10">
|
||||||
<form action="?/getVorgangByToken" method="POST">
|
|
||||||
<BaseInputField
|
<form method="POST">
|
||||||
id="vorgang-token"
|
<input type="hidden" name="vorgang-token" value={vorgangToken} />
|
||||||
name="vorgang-token"
|
<div class="mt-5">
|
||||||
label="Vorgangskennung"
|
<BaseInputField
|
||||||
type="text"
|
id="vorgang-pin"
|
||||||
value={vorgangToken}
|
name="vorgang-pin"
|
||||||
/>
|
label="Zugangs-PIN"
|
||||||
<div class="mt-5">
|
type="text"
|
||||||
<BaseInputField
|
value={form?.vorgangPIN}
|
||||||
id="vorgang-pin"
|
error={form?.error?.message}
|
||||||
name="vorgang-pin"
|
/>
|
||||||
label="Zugangs-PIN"
|
</div>
|
||||||
type="text"
|
{#if form?.message}
|
||||||
value={form?.vorgangPIN}
|
<p class="block text-sm leading-6 text-red-900 mt-2">{form.message}</p>
|
||||||
error={form?.error?.message}
|
{/if}
|
||||||
/>
|
|
||||||
</div>
|
<div class="flex justify-end pt-4">
|
||||||
<div class="flex justify-end pt-4">
|
<Button type="submit"><ArrowRight /></Button>
|
||||||
<Button type="submit"><ArrowRight /></Button>
|
</div>
|
||||||
</div>
|
</form>
|
||||||
</form>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end mt-10 px-3">
|
|
||||||
<Button on:click={() => (open = true)}><Login /></Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Modal {open}>
|
{/if}
|
||||||
<ModalTitle>Anmelden</ModalTitle>
|
|
||||||
<ModalContent class="flex justify-center">
|
|
||||||
<form action="?/login" method="POST">
|
|
||||||
<div>
|
|
||||||
<label for="user" class="text-sm font-medium leading-6 text-gray-900">Kennung</label>
|
|
||||||
<div class="mt-2">
|
|
||||||
<input
|
|
||||||
id="user"
|
|
||||||
name="user"
|
|
||||||
type="text"
|
|
||||||
autocomplete="email"
|
|
||||||
required
|
|
||||||
class="rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<label for="password" class="block text-sm font-medium leading-6 text-gray-900"
|
|
||||||
>Passwort</label
|
|
||||||
>
|
|
||||||
<div class="mt-2">
|
|
||||||
<input
|
|
||||||
id="password"
|
|
||||||
name="password"
|
|
||||||
type="password"
|
|
||||||
autocomplete="current-password"
|
|
||||||
required
|
|
||||||
class="block w-full rounded-md border-0 py-1.5 text-gray-900 shadow-sm ring-1 ring-inset ring-gray-300 placeholder:text-gray-400 focus:ring-2 focus:ring-inset focus:ring-indigo-600 sm:text-sm sm:leading-6"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="flex justify-end">
|
|
||||||
<Button type="submit" class="mt-5">Anmelden</Button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</ModalContent>
|
|
||||||
<ModalFooter><Button on:click={() => (open = false)}>Ok</Button></ModalFooter>
|
|
||||||
</Modal>
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { getVorgaenge } from '$lib/server/vorgangService';
|
import { getVorgaenge } from '$lib/server/vorgangService';
|
||||||
|
|
||||||
export async function GET({ locals }) {
|
export async function GET() {
|
||||||
|
|
||||||
const vorgaenge = getVorgaenge();
|
const vorgaenge = getVorgaenge();
|
||||||
|
|
||||||
return new Response(JSON.stringify(vorgaenge), {
|
return new Response(JSON.stringify(vorgaenge), {
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import { BUCKET, client } from '$lib/minio';
|
import { BUCKET, client } from '$lib/minio';
|
||||||
|
import { json } from '@sveltejs/kit';
|
||||||
import {
|
import {
|
||||||
deleteVorgangByToken,
|
deleteVorgangByToken,
|
||||||
getCrimesListByToken,
|
getCrimesListByToken,
|
||||||
vorgangNameExists
|
vorgangNameExists,
|
||||||
|
updateVorgangAttrByToken
|
||||||
} from '$lib/server/vorgangService';
|
} from '$lib/server/vorgangService';
|
||||||
|
|
||||||
export async function DELETE({ params }) {
|
export async function DELETE({ params }) {
|
||||||
@@ -43,8 +45,7 @@ export async function HEAD({ params }) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function GET({ params, locals }) {
|
export async function GET({ params }) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const vorgangToken = params.vorgang;
|
const vorgangToken = params.vorgang;
|
||||||
const crimesList = await getCrimesListByToken(vorgangToken);
|
const crimesList = await getCrimesListByToken(vorgangToken);
|
||||||
@@ -57,3 +58,31 @@ export async function GET({ params, locals }) {
|
|||||||
return new Response(null, { status: 500 });
|
return new Response(null, { status: 500 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// change Vorgang properties
|
||||||
|
export async function PUT({ request }) {
|
||||||
|
const data = await request.json();
|
||||||
|
|
||||||
|
const vorgangToken = data['vorgangToken'];
|
||||||
|
|
||||||
|
const changePIN = data['changePIN'];
|
||||||
|
|
||||||
|
let attrChanged;
|
||||||
|
let newValue;
|
||||||
|
|
||||||
|
if (changePIN) {
|
||||||
|
attrChanged = 'pin';
|
||||||
|
newValue = data['newVorgangPIN']
|
||||||
|
} else {
|
||||||
|
attrChanged = 'name';
|
||||||
|
newValue = data['newName']
|
||||||
|
}
|
||||||
|
|
||||||
|
const res = updateVorgangAttrByToken(vorgangToken, newValue, attrChanged);
|
||||||
|
|
||||||
|
if (!res) {
|
||||||
|
return json({ msg: 'Fehler beim Umbenennen' }, { status: 400 });
|
||||||
|
}
|
||||||
|
|
||||||
|
return json({ success: 'success' }, { status: 200 });
|
||||||
|
}
|
||||||
@@ -24,7 +24,7 @@ export async function GET() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function DELETE({ request }: { request: Request }) {
|
export async function DELETE({ request }) {
|
||||||
const url_fragments = request.url.split('/');
|
const url_fragments = request.url.split('/');
|
||||||
const item = url_fragments.at(-1);
|
const item = url_fragments.at(-1);
|
||||||
const vorgang = url_fragments.at(-2);
|
const vorgang = url_fragments.at(-2);
|
||||||
|
|||||||
@@ -4,21 +4,14 @@ import bcrypt from 'bcrypt';
|
|||||||
|
|
||||||
const saltRounds = 12;
|
const saltRounds = 12;
|
||||||
|
|
||||||
export function GET({ locals }) {
|
export function GET() {
|
||||||
if (!locals.user) {
|
|
||||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const userList = getUsers();
|
const userList = getUsers();
|
||||||
|
|
||||||
return new Response(JSON.stringify(userList));
|
return new Response(JSON.stringify(userList));
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST({ request, locals }) {
|
export async function POST({ request }) {
|
||||||
if (!locals.user) {
|
|
||||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await request.json();
|
const data = await request.json();
|
||||||
const userName = data.userName;
|
const userName = data.userName;
|
||||||
const userPassword = data.userPassword;
|
const userPassword = data.userPassword;
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { deleteUser } from '$lib/server/userService';
|
import { deleteUser } from '$lib/server/userService';
|
||||||
|
|
||||||
export async function DELETE({ params, locals }) {
|
export async function DELETE({ params }) {
|
||||||
if (!locals.user) {
|
|
||||||
return json({ error: 'Unauthorized' }, { status: 401 });
|
|
||||||
}
|
|
||||||
|
|
||||||
const userId = params.user;
|
const userId = params.user;
|
||||||
const rowCount = deleteUser(userId);
|
const rowCount = deleteUser(userId);
|
||||||
|
|
||||||
|
|||||||
41
src/routes/index.ts
Normal file
41
src/routes/index.ts
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
export const ROUTE_NAMES = {
|
||||||
|
ROOT: '/',
|
||||||
|
|
||||||
|
// (angemeldet)
|
||||||
|
LIST: '/list',
|
||||||
|
UPLOAD: '/upload',
|
||||||
|
// UPLOAD actions
|
||||||
|
UPLOAD_URL: '/upload?/url',
|
||||||
|
UPLOAD_VALIDATE: '/upload?/validate',
|
||||||
|
|
||||||
|
USERMGMT: '/user-management',
|
||||||
|
|
||||||
|
// (token-based)
|
||||||
|
VORGANG: (vorgangToken: string) => `/list/${vorgangToken}`,
|
||||||
|
CRIME: (vorgangToken: string, tatort: string) => `/view/${vorgangToken}/${tatort}`,
|
||||||
|
|
||||||
|
// Anmeldung: actions
|
||||||
|
ANMELDUNG: '/anmeldung',
|
||||||
|
LOGIN: '/?/login',
|
||||||
|
LOGOUT: '/?/logout',
|
||||||
|
ANMELDUNG_GET_VORGANG_BY_TOKEN: '/anmeldung?/getVorgangByToken',
|
||||||
|
ANMELDUNG_VORGANG_PARAM: (vorgangToken: string) => `/anmeldung?vorgang=${vorgangToken}`
|
||||||
|
};
|
||||||
|
|
||||||
|
export const API_ROUTES = {
|
||||||
|
LIST: '/api/list',
|
||||||
|
VORGANG: (vorgangToken: string) => `/api/list/${vorgangToken}`,
|
||||||
|
// via `HEAD` method
|
||||||
|
VORGANG_NAME_EXIST: (vorgangName: string) => `/api/list/${vorgangName}`,
|
||||||
|
VORGANG_PIN: (vorgangName: string) => `/api/vorgang/${vorgangName}/vorgangPIN`,
|
||||||
|
|
||||||
|
// Tatort
|
||||||
|
CRIME: (vorgangToken: string, crimeName: string) => `/api/list/${vorgangToken}/${crimeName}`,
|
||||||
|
|
||||||
|
// Users
|
||||||
|
USERS: '/api/users',
|
||||||
|
USER: (userId: string) => `/api/users/${userId}`
|
||||||
|
};
|
||||||
|
|
||||||
|
const isProd = process.env.NODE_ENV == 'production';
|
||||||
|
export const DB_FULLPATH = !isProd ? './src/lib/data/tatort.db' : '/daten/tatort.db';
|
||||||
@@ -1,67 +0,0 @@
|
|||||||
import { render } from '@testing-library/svelte';
|
|
||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
import TatortListPage from '../src/routes/(token-based)/list/[vorgang]/+page.svelte';
|
|
||||||
|
|
||||||
const testUser = {
|
|
||||||
admin: true,
|
|
||||||
exp: 1757067123,
|
|
||||||
iat: 1757063523,
|
|
||||||
id: 'admin'
|
|
||||||
};
|
|
||||||
const testCrimesList = [
|
|
||||||
{
|
|
||||||
name: 'model-A',
|
|
||||||
lastModified: '2025-08-28T09:44:12.453Z',
|
|
||||||
etag: '558f35716f6af953f9bb5d75f6d77e6a',
|
|
||||||
size: 8947140,
|
|
||||||
prefix: '7596e4d5-c51f-482d-a4aa-ff76434305fc',
|
|
||||||
show_button: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'model-z',
|
|
||||||
lastModified: '2025-08-28T10:37:20.142Z',
|
|
||||||
etag: '43e3989c32c4682bee407baaf83b6fa0',
|
|
||||||
size: 35788560,
|
|
||||||
prefix: '7596e4d5-c51f-482d-a4aa-ff76434305fc',
|
|
||||||
show_button: true
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const testVorgangsList = [
|
|
||||||
{
|
|
||||||
vorgangName: 'vorgang-1',
|
|
||||||
vorgangPIN: 'pin-123',
|
|
||||||
vorgangToken: 'c322f26f-8c5e-4cb9-94b3-b5433bf5109e'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
vorgangName: 'vorgang-2',
|
|
||||||
vorgangPIN: 'pin-2',
|
|
||||||
vorgangToken: 'cb0051bc-5f38-47b8-943c-9352d4d9c984'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const baseData = {
|
|
||||||
user: testUser,
|
|
||||||
vorgang: testVorgangsList[0],
|
|
||||||
vorgangList: testVorgangsList,
|
|
||||||
crimesList: testCrimesList,
|
|
||||||
url: 'https://www.google.com',
|
|
||||||
crimeNames: [testCrimesList[0].name]
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Tatort Liste Page EmptyList-Komponente View', () => {
|
|
||||||
it('zeigt EmptyList-Komponente an, wenn Liste leer ist', () => {
|
|
||||||
const testData = { ...baseData, crimesList: [] };
|
|
||||||
const { getByTestId } = render(TatortListPage, { props: { data: testData } });
|
|
||||||
|
|
||||||
expect(getByTestId('empty-list')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('zeigt Liste(min. 1 li-Element) an, wenn Liste vorhanden ist', () => {
|
|
||||||
const testData = { ...baseData };
|
|
||||||
const { getAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
|
||||||
const items = getAllByTestId('test-list-item');
|
|
||||||
|
|
||||||
expect(items).toHaveLength(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
import { render } from '@testing-library/svelte';
|
|
||||||
import { describe, expect, it } from 'vitest';
|
|
||||||
import VorgangListPage from '../src/routes/(angemeldet)/list/+page.svelte';
|
|
||||||
const testUser = {
|
|
||||||
admin: true,
|
|
||||||
exp: 1757067123,
|
|
||||||
iat: 1757063523,
|
|
||||||
id: 'admin'
|
|
||||||
};
|
|
||||||
const testCrimesList = [
|
|
||||||
{
|
|
||||||
name: 'model-A',
|
|
||||||
lastModified: '2025-08-28T09:44:12.453Z',
|
|
||||||
etag: '558f35716f6af953f9bb5d75f6d77e6a',
|
|
||||||
size: 8947140,
|
|
||||||
prefix: '7596e4d5-c51f-482d-a4aa-ff76434305fc',
|
|
||||||
show_button: true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'model-z',
|
|
||||||
lastModified: '2025-08-28T10:37:20.142Z',
|
|
||||||
etag: '43e3989c32c4682bee407baaf83b6fa0',
|
|
||||||
size: 35788560,
|
|
||||||
prefix: '7596e4d5-c51f-482d-a4aa-ff76434305fc',
|
|
||||||
show_button: true
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const testVorgangsList = [
|
|
||||||
{
|
|
||||||
vorgangName: 'vorgang-1',
|
|
||||||
vorgangPIN: 'pin-123',
|
|
||||||
vorgangToken: 'c322f26f-8c5e-4cb9-94b3-b5433bf5109e'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
vorgangName: 'vorgang-2',
|
|
||||||
vorgangPIN: 'pin-2',
|
|
||||||
vorgangToken: 'cb0051bc-5f38-47b8-943c-9352d4d9c984'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
const baseData = {
|
|
||||||
user: testUser,
|
|
||||||
vorgang: testVorgangsList[0],
|
|
||||||
vorgangList: testVorgangsList,
|
|
||||||
crimesList: testCrimesList,
|
|
||||||
url: URL,
|
|
||||||
crimeNames: ['modell-A']
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('Vorgänge Liste Page EmptyList-Komponente View', () => {
|
|
||||||
it('zeigt EmptyList-Komponente an, wenn Liste leer ist', () => {
|
|
||||||
const testData = { ...baseData, vorgangList: [] };
|
|
||||||
const { getByTestId } = render(VorgangListPage, { props: { data: testData } });
|
|
||||||
|
|
||||||
expect(getByTestId('empty-list')).toBeInTheDocument();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('zeigt Liste(min. 1 li-Element) an, wenn Liste vorhanden ist', () => {
|
|
||||||
const testData = { ...baseData };
|
|
||||||
const { getAllByTestId } = render(VorgangListPage, { props: { data: testData } });
|
|
||||||
const items = getAllByTestId('test-list-item');
|
|
||||||
|
|
||||||
expect(items).toHaveLength(2);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
37
tests/api/API_Protection.test.ts
Normal file
37
tests/api/API_Protection.test.ts
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
|
import { handle } from '../../src/hooks.server';
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
url: new URL("http://localhost/api/list"),
|
||||||
|
cookies: { get: vi.fn(() => null) },
|
||||||
|
locals: {user: null}
|
||||||
|
};
|
||||||
|
|
||||||
|
vi.mock('$lib/auth', () => ({
|
||||||
|
decryptToken: vi.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('API-Endpoints: Zugangs-Mechanismus', () => {
|
||||||
|
test('Unautorisierter Zugriff', async () => {
|
||||||
|
const resolve = vi.fn();
|
||||||
|
|
||||||
|
const response = await handle({ event, resolve });
|
||||||
|
|
||||||
|
expect(response.status).toBe(401);
|
||||||
|
const body = await response.json();
|
||||||
|
expect(body.error).toBe('Unauthorized');
|
||||||
|
expect(resolve).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('Authentifizierter Zugriff', async () => {
|
||||||
|
event.locals = {user: { id: 'admin', admin: true }}
|
||||||
|
|
||||||
|
const resolve = vi.fn(() => new Response('ok', { status: 200 }));
|
||||||
|
|
||||||
|
const response = await handle({ event, resolve });
|
||||||
|
|
||||||
|
expect(response.status).toBe(200);
|
||||||
|
expect(await response.text()).toBe('ok');
|
||||||
|
expect(resolve).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
})
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, test, expect, vi } from 'vitest';
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
import { GET } from '../src/routes/api/list/+server';
|
import { GET } from '$root/routes/api/list/+server';
|
||||||
import { getVorgaenge } from '$lib/server/vorgangService';
|
import { getVorgaenge } from '$lib/server/vorgangService';
|
||||||
|
|
||||||
// Mocks
|
// Mocks
|
||||||
@@ -14,21 +14,6 @@ const event = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('API-Endpoints: list', () => {
|
describe('API-Endpoints: list', () => {
|
||||||
test.skip('Unerlaubter Zugriff', async () => {
|
|
||||||
const event = {
|
|
||||||
locals: {
|
|
||||||
user: null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await GET(event);
|
|
||||||
expect(response.status).toBe(401);
|
|
||||||
|
|
||||||
const json = await response.json();
|
|
||||||
const errorObj = { error: 'Unauthorized' };
|
|
||||||
expect(json).toEqual(errorObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Leere Liste wenn keine Vorgänge existieren', async () => {
|
test('Leere Liste wenn keine Vorgänge existieren', async () => {
|
||||||
vi.mocked(getVorgaenge).mockReturnValueOnce([]);
|
vi.mocked(getVorgaenge).mockReturnValueOnce([]);
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, test, expect, vi } from 'vitest';
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
import { DELETE, GET, HEAD } from '../src/routes/api/list/[vorgang]/+server';
|
import { DELETE, GET, HEAD } from '$root/routes/api/list/[vorgang]/+server';
|
||||||
import {
|
import {
|
||||||
getCrimesListByToken,
|
getCrimesListByToken,
|
||||||
vorgangNameExists,
|
vorgangNameExists,
|
||||||
@@ -31,21 +31,6 @@ const MockEvent = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
describe('API-Endpoints: list/[vorgang]', () => {
|
describe('API-Endpoints: list/[vorgang]', () => {
|
||||||
test.skip('Unerlaubter Zugriff', async () => {
|
|
||||||
const event = {
|
|
||||||
locals: {
|
|
||||||
user: null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await GET(event);
|
|
||||||
expect(response.status).toBe(401);
|
|
||||||
|
|
||||||
const json = await response.json();
|
|
||||||
const errorObj = { error: 'Unauthorized' };
|
|
||||||
expect(json).toEqual(errorObj);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('Vorgang ohne Tatorte', async () => {
|
test('Vorgang ohne Tatorte', async () => {
|
||||||
const testCrimesList = [];
|
const testCrimesList = [];
|
||||||
|
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { describe, test, expect, vi } from 'vitest';
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
import { DELETE, PUT } from '../src/routes/api/list/[vorgang]/[tatort]/+server';
|
import { DELETE, PUT } from '$root/routes/api/list/[vorgang]/[tatort]/+server';
|
||||||
import { BUCKET, client } from '$lib/minio';
|
import { BUCKET, client } from '$lib/minio';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
|
||||||
// Mock data and methods
|
// Mock data and methods
|
||||||
const fakeVorgangToken = `c399423a-ba37-4fe1-bbdf-80e5881168ff`;
|
const fakeVorgangToken = `c399423a-ba37-4fe1-bbdf-80e5881168ff`;
|
||||||
@@ -22,7 +23,8 @@ vi.mock('$lib/minio', () => ({
|
|||||||
describe('API-Endpoints: list/[vorgang]/[tatort]', () => {
|
describe('API-Endpoints: list/[vorgang]/[tatort]', () => {
|
||||||
test('Löschen von Tatorten', async () => {
|
test('Löschen von Tatorten', async () => {
|
||||||
const request = new Request(fakeCrimeAPIURL);
|
const request = new Request(fakeCrimeAPIURL);
|
||||||
const response = await DELETE({ request });
|
const locals = { user: baseData.user }
|
||||||
|
const response = await DELETE({ locals, request });
|
||||||
|
|
||||||
expect(client.removeObject).toHaveBeenCalledWith(BUCKET, fakeCrimePath);
|
expect(client.removeObject).toHaveBeenCalledWith(BUCKET, fakeCrimePath);
|
||||||
|
|
||||||
@@ -40,11 +42,12 @@ describe('API-Endpoints: list/[vorgang]/[tatort]', () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
const params = { vorgang: fakeVorgangToken };
|
const params = { vorgang: fakeVorgangToken };
|
||||||
|
const locals = { user: baseData.user }
|
||||||
|
|
||||||
// Mock Datei nicht gefunden
|
// Mock Datei nicht gefunden
|
||||||
client.statObject.mockRejectedValueOnce(new Error('NotFound'));
|
client.statObject.mockRejectedValueOnce(new Error('NotFound'));
|
||||||
|
|
||||||
const response = await PUT({ params, request });
|
const response = await PUT({ locals, params, request });
|
||||||
|
|
||||||
const fakeCrimeNewPath = `${fakeVorgangToken}/${fakeCrimeNewName}`;
|
const fakeCrimeNewPath = `${fakeVorgangToken}/${fakeCrimeNewName}`;
|
||||||
expect(client.statObject).toHaveBeenCalledWith(BUCKET, fakeCrimeNewPath);
|
expect(client.statObject).toHaveBeenCalledWith(BUCKET, fakeCrimeNewPath);
|
||||||
@@ -62,9 +65,10 @@ describe('API-Endpoints: list/[vorgang]/[tatort]', () => {
|
|||||||
newName: ''
|
newName: ''
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
const locals = { user: baseData.user }
|
||||||
const params = { vorgang: fakeVorgangToken };
|
const params = { vorgang: fakeVorgangToken };
|
||||||
|
|
||||||
const response = await PUT({ params, request });
|
const response = await PUT({ locals, params, request });
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -77,11 +81,12 @@ describe('API-Endpoints: list/[vorgang]/[tatort]', () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
const params = { vorgang: fakeVorgangToken };
|
const params = { vorgang: fakeVorgangToken };
|
||||||
|
const locals = { user: baseData.user }
|
||||||
|
|
||||||
// Datei existiert bereits
|
// Datei existiert bereits
|
||||||
client.statObject.mockResolvedValueOnce({});
|
client.statObject.mockResolvedValueOnce({});
|
||||||
|
|
||||||
const response = await PUT({ params, request });
|
const response = await PUT({ locals, params, request });
|
||||||
|
|
||||||
expect(response.status).toBe(400);
|
expect(response.status).toBe(400);
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, test, expect } from 'vitest';
|
import { describe, test, expect } from 'vitest';
|
||||||
import { GET } from '../src/routes/api/user/+server';
|
import { GET } from '$root/routes/api/user/+server';
|
||||||
|
|
||||||
const id = 'admin';
|
const id = 'admin';
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
import { describe, test, expect, vi, beforeEach } from 'vitest';
|
||||||
import { GET, POST } from '../src/routes/api/users/+server';
|
import { GET, POST } from '$root/routes/api/users/+server';
|
||||||
import bcrypt from 'bcrypt';
|
import bcrypt from 'bcrypt';
|
||||||
|
|
||||||
import { addUser, getUsers } from '$lib/server/userService';
|
import { addUser, getUsers } from '$lib/server/userService';
|
||||||
@@ -16,21 +16,6 @@ vi.mock('bcrypt', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('API-Endpoint: Users', () => {
|
describe('API-Endpoint: Users', () => {
|
||||||
test('Unerlaubter Zugriff', async () => {
|
|
||||||
const event = {
|
|
||||||
locals: {
|
|
||||||
user: null
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const response = await GET(event);
|
|
||||||
expect(response.status).toBe(401);
|
|
||||||
|
|
||||||
const errorMessage = { error: 'Unauthorized' };
|
|
||||||
const json = await response.json();
|
|
||||||
expect(json).toEqual(errorMessage);
|
|
||||||
});
|
|
||||||
|
|
||||||
// [INFO] Test auf keine User nicht notwendig, da immer min. ein User vorhanden
|
// [INFO] Test auf keine User nicht notwendig, da immer min. ein User vorhanden
|
||||||
|
|
||||||
// Mock eingelogter User bzw. stelle locals.user zur Verfügung
|
// Mock eingelogter User bzw. stelle locals.user zur Verfügung
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
import { describe, test, expect, vi } from 'vitest';
|
import { describe, test, expect, vi } from 'vitest';
|
||||||
import { GET } from '../src/routes/api/vorgang/[vorgang]/vorgangPIN/+server';
|
import { GET } from '$root/routes/api/vorgang/[vorgang]/vorgangPIN/+server';
|
||||||
import { db } from '$lib/server/dbService';
|
import { db } from '$lib/server/dbService';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
|
||||||
const mockEvent = {
|
const mockEvent = {
|
||||||
params: { vorgang: '123' }
|
params: { vorgang: '123' },
|
||||||
|
locals: { user: baseData.user }
|
||||||
};
|
};
|
||||||
|
|
||||||
vi.mock('$lib/server/dbService', () => ({
|
vi.mock('$lib/server/dbService', () => ({
|
||||||
9
tests/components/EmptyList.view.test.ts
Normal file
9
tests/components/EmptyList.view.test.ts
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
import { render, screen } from '@testing-library/svelte';
|
||||||
|
import EmptyList from '$lib/components/EmptyList.svelte'
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
describe('Komponente: EmptyList', () => {
|
||||||
|
it('zeigt Hinweistext "Keine Einträge"', () => {
|
||||||
|
render(EmptyList);
|
||||||
|
expect(screen.getByText(/keine Einträge/i)).toBeInTheDocument(); });
|
||||||
|
});
|
||||||
47
tests/components/Footer.test.ts
Normal file
47
tests/components/Footer.test.ts
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
import { render, screen } from '@testing-library/svelte';
|
||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
|
||||||
|
import Footer from '$lib/components/Footer.svelte';
|
||||||
|
|
||||||
|
describe('Footer component', () => {
|
||||||
|
test('Enthält Behörden-Name und entsprechenden Link', () => {
|
||||||
|
render(Footer);
|
||||||
|
const linkElement = screen.getByText('Innovation Hub', { exact: false });
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.LIST);
|
||||||
|
});
|
||||||
|
test('Enthält Zurück-Button und entsprechenden Link', () => {
|
||||||
|
render(Footer);
|
||||||
|
const linkElement = screen.getByText('back');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.ROOT);
|
||||||
|
});
|
||||||
|
test('Enthält Profil-Icon und entsprechenden Link: angemeldet', () => {
|
||||||
|
render(Footer, { props: { data: baseData } });
|
||||||
|
const linkElement = screen.getByText('admin');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.ROOT);
|
||||||
|
|
||||||
|
// Check for presence of `Profile` component
|
||||||
|
const svg = screen.getByTestId('profile-component');
|
||||||
|
expect(svg).toBeTruthy();
|
||||||
|
});
|
||||||
|
test('Enthält Profil-Icon und entsprechenden Link: nicht angemeldet', () => {
|
||||||
|
const { container } = render(Footer, { props: { data: null } });
|
||||||
|
|
||||||
|
const links = container.querySelectorAll('a');
|
||||||
|
const linkElement = links[2]; // Index starts at 0
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.ROOT);
|
||||||
|
|
||||||
|
// User/View does not have any ID
|
||||||
|
const ID_displayElement = screen.queryByText('admin');
|
||||||
|
expect(ID_displayElement).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
// Check for presence of `Profile` component
|
||||||
|
const svg = screen.getByTestId('profile-component');
|
||||||
|
expect(svg).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
22
tests/components/Header.test.ts
Normal file
22
tests/components/Header.test.ts
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
import { render, screen } from '@testing-library/svelte';
|
||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
|
||||||
|
import Header from '$lib/components/Header.svelte';
|
||||||
|
|
||||||
|
describe('Header component', () => {
|
||||||
|
test('Enthält Landeswappen von NDS und entsprechenden Link', () => {
|
||||||
|
render(Header, { props: { data: baseData } });
|
||||||
|
const linkElement = screen.getByText('Tatort Niedersachen').closest('a');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.ROOT);
|
||||||
|
});
|
||||||
|
test('Form enthält korrekten Link', () => {
|
||||||
|
const { container } = render(Header, { props: { data: baseData } });
|
||||||
|
const formElement = container.querySelector('form');
|
||||||
|
expect(formElement).toBeInTheDocument();
|
||||||
|
expect(formElement).toHaveAttribute('action', ROUTE_NAMES.ANMELDUNG_LOGOUT);
|
||||||
|
});
|
||||||
|
});
|
||||||
142
tests/components/NameItemEditor.test.ts
Normal file
142
tests/components/NameItemEditor.test.ts
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
import { fireEvent, render, screen } from '@testing-library/svelte';
|
||||||
|
import { describe, expect, it, test, vi } from 'vitest';
|
||||||
|
import NameItemEditor from '$lib/components/NameItemEditor.svelte';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
|
||||||
|
const testCrimesListIndex = 0;
|
||||||
|
const testItem = baseData.crimesList[testCrimesListIndex];
|
||||||
|
const testCurrentName = testItem.name;
|
||||||
|
const testLocalName = 'Fall-C';
|
||||||
|
|
||||||
|
describe('NameItemEditor - Funktionalität', () => {
|
||||||
|
const onSave = vi.fn();
|
||||||
|
const onDelete = vi.fn();
|
||||||
|
const baseProps = {
|
||||||
|
list: baseData.crimesList,
|
||||||
|
currentName: testCurrentName,
|
||||||
|
onSave,
|
||||||
|
onDelete
|
||||||
|
};
|
||||||
|
|
||||||
|
test.todo('FocusIn nach Klick auf edit');
|
||||||
|
|
||||||
|
it('zeigt initial Edit/Delete Buttons und aktuellen Namen', () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
|
||||||
|
expect(screen.getByTestId('edit-button')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('delete-button')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByTestId('commit-button')).toBeNull();
|
||||||
|
expect(screen.queryByTestId('cancel-button')).toBeNull();
|
||||||
|
expect(screen.getByText(testCurrentName)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('wechselt zu Commit/Cancel nach Klick auf Edit', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
|
||||||
|
expect(screen.getByTestId('commit-button')).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('cancel-button')).toBeInTheDocument();
|
||||||
|
expect(screen.queryByTestId('edit-button')).toBeNull();
|
||||||
|
expect(screen.queryByTestId('delete-button')).toBeNull();
|
||||||
|
expect(screen.getAllByRole('textbox')).toHaveLength(1);
|
||||||
|
expect(input).toHaveValue(testCurrentName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zeigt Fehlermeldung bei leerem Namen', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: '' } });
|
||||||
|
|
||||||
|
expect(screen.getByText('Name darf nicht leer sein.')).toBeInTheDocument();
|
||||||
|
expect(onSave).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('entfernt Fehlermeldung live beim nächsten gültigen Tastendruck', async () => {
|
||||||
|
render(NameItemEditor, {
|
||||||
|
props: {
|
||||||
|
list: baseData.crimesList,
|
||||||
|
currentName: baseData.crimesList[0].name,
|
||||||
|
onSave: vi.fn(),
|
||||||
|
onDelete: vi.fn()
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
|
||||||
|
await fireEvent.input(input, { target: { value: '' } });
|
||||||
|
expect(screen.getByText('Name darf nicht leer sein.')).toBeInTheDocument();
|
||||||
|
|
||||||
|
await fireEvent.input(input, { target: { value: 'Fall-C' } });
|
||||||
|
|
||||||
|
expect(screen.queryByText('Name darf nicht leer sein.')).toBeNull();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zeigt Fehlermeldung bei Duplikat', async () => {
|
||||||
|
const duplicateName = baseData.crimesList[1].name;
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: duplicateName } });
|
||||||
|
|
||||||
|
expect(screen.getByText('Name existiert bereits.')).toBeInTheDocument();
|
||||||
|
expect(onSave).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ruft onSave korrekt auf bei gültigem Namen: Tatort/Crime', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: testLocalName } });
|
||||||
|
await fireEvent.click(screen.getByTestId('commit-button'));
|
||||||
|
|
||||||
|
expect(onSave).toHaveBeenCalledWith(testLocalName, testCurrentName, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('ruft onDelete korrekt auf', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('delete-button'));
|
||||||
|
|
||||||
|
expect(onDelete).toHaveBeenCalledWith(testCurrentName);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('setzt Zustand zurück bei Cancel', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: 'Zwischentext' } });
|
||||||
|
await fireEvent.click(screen.getByTestId('cancel-button'));
|
||||||
|
|
||||||
|
expect(screen.getByText(testCurrentName)).toBeInTheDocument();
|
||||||
|
expect(screen.getByTestId('edit-button')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('triggert Save bei Enter-Taste: Tatort/Crime', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: 'ViaEnter' } });
|
||||||
|
await fireEvent.keyDown(input, { key: 'Enter' });
|
||||||
|
|
||||||
|
expect(onSave).toHaveBeenCalledWith('ViaEnter', testCurrentName, undefined);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('bricht ab bei Escape-Taste', async () => {
|
||||||
|
render(NameItemEditor, { props: baseProps });
|
||||||
|
await fireEvent.click(screen.getByTestId('edit-button'));
|
||||||
|
|
||||||
|
const input = screen.getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: 'Zwischentext' } });
|
||||||
|
await fireEvent.keyDown(input, { key: 'Escape' });
|
||||||
|
|
||||||
|
expect(screen.getByText(testCurrentName)).toBeInTheDocument();
|
||||||
|
expect(onSave).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
53
tests/fixtures.ts
Normal file
53
tests/fixtures.ts
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
const testUser = {
|
||||||
|
admin: true,
|
||||||
|
exp: 1757067123,
|
||||||
|
iat: 1757063523,
|
||||||
|
id: 'admin'
|
||||||
|
};
|
||||||
|
const testCrimesList = [
|
||||||
|
{
|
||||||
|
name: 'Fall-A',
|
||||||
|
lastModified: '2025-08-28T09:44:12.453Z',
|
||||||
|
etag: '558f35716f6af953f9bb5d75f6d77e6a',
|
||||||
|
size: 8947140,
|
||||||
|
prefix: '7596e4d5-c51f-482d-a4aa-ff76434305fc',
|
||||||
|
show_button: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: 'Fall-B',
|
||||||
|
lastModified: '2025-08-28T10:37:20.142Z',
|
||||||
|
etag: '43e3989c32c4682bee407baaf83b6fa0',
|
||||||
|
size: 35788560,
|
||||||
|
prefix: '7596e4d5-c51f-482d-a4aa-ff76434305fc',
|
||||||
|
show_button: true
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
const testVorgangsList = [
|
||||||
|
{
|
||||||
|
vorgangName: 'vorgang-1',
|
||||||
|
vorgangPIN: 'pin-123',
|
||||||
|
vorgangToken: 'c322f26f-8c5e-4cb9-94b3-b5433bf5109e'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
vorgangName: 'vorgang-2',
|
||||||
|
vorgangPIN: 'pin-2',
|
||||||
|
vorgangToken: 'cb0051bc-5f38-47b8-943c-9352d4d9c984'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
export const baseData = {
|
||||||
|
user: testUser,
|
||||||
|
vorgang: testVorgangsList[0],
|
||||||
|
vorgangList: testVorgangsList,
|
||||||
|
crimesList: testCrimesList,
|
||||||
|
url: `https://example.com/list/${testVorgangsList[0].vorgangToken}`,
|
||||||
|
crimeNames: ['modell-A', 'Fall-A']
|
||||||
|
};
|
||||||
|
|
||||||
|
export const mockEvent = {
|
||||||
|
locals: {
|
||||||
|
user: baseData.user
|
||||||
|
},
|
||||||
|
url: new URL(`https://example.com/anmeldung`)
|
||||||
|
};
|
||||||
143
tests/views/Anmeldung.test.ts
Normal file
143
tests/views/Anmeldung.test.ts
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest';
|
||||||
|
// import { actions } from '$root/routes/anmeldung/+page.server';
|
||||||
|
// import { load } from '$root/routes/(token-based)/+layout.server'
|
||||||
|
import { actions } from '../../src/routes/anmeldung/+page.server';
|
||||||
|
import { load } from '../../src/routes/(token-based)/+layout.server';
|
||||||
|
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
import { dev } from '$app/environment';
|
||||||
|
import { vorgangExists, vorgangPINValidation } from '$lib/server/vorgangService';
|
||||||
|
import type { Redirect } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
vi.mock('$lib/server/vorgangService', () => ({
|
||||||
|
vorgangExists: vi.fn(),
|
||||||
|
vorgangPINValidation: vi.fn()
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('Vorgang Anzeige via Token', () => {
|
||||||
|
it('Setze Cookie nach erfolgreicher Eingabe', async () => {
|
||||||
|
// Mock formData
|
||||||
|
const vorgObj = baseData.vorgang;
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.set('vorgang-token', vorgObj.vorgangToken);
|
||||||
|
formData.set('vorgang-pin', vorgObj.vorgangPIN);
|
||||||
|
|
||||||
|
const mockRequest = {
|
||||||
|
formData: vi.fn().mockResolvedValue(formData)
|
||||||
|
};
|
||||||
|
vi.mocked(vorgangPINValidation).mockReturnValueOnce(true);
|
||||||
|
|
||||||
|
const cookiesSet = vi.fn();
|
||||||
|
|
||||||
|
const event = {
|
||||||
|
request: mockRequest,
|
||||||
|
cookies: {
|
||||||
|
set: cookiesSet
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
let thrownRedirect: Redirect | undefined;
|
||||||
|
try {
|
||||||
|
await actions.default(event);
|
||||||
|
} catch (e) {
|
||||||
|
thrownRedirect = e as Redirect;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Redirect bei erfolgreicher Eingabe
|
||||||
|
expect(thrownRedirect?.status).toBe(303);
|
||||||
|
expect(thrownRedirect?.location).toBe(ROUTE_NAMES.VORGANG(vorgObj.vorgangToken));
|
||||||
|
|
||||||
|
// Cookie wurde gesetzt
|
||||||
|
const COOKIE_NAME = `token-${vorgObj.vorgangToken}`;
|
||||||
|
expect(cookiesSet).toHaveBeenCalledWith(COOKIE_NAME, vorgObj.vorgangPIN, {
|
||||||
|
path: '/',
|
||||||
|
httpOnly: true,
|
||||||
|
sameSite: 'strict',
|
||||||
|
secure: !dev
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Schlägt fehl wenn keine Daten übergeben werden', async () => {
|
||||||
|
const formData = new FormData(); // no data
|
||||||
|
const mockRequest = {
|
||||||
|
formData: vi.fn().mockResolvedValue(formData)
|
||||||
|
};
|
||||||
|
const cookiesSet = vi.fn();
|
||||||
|
const event = {
|
||||||
|
request: mockRequest,
|
||||||
|
cookies: {
|
||||||
|
set: cookiesSet
|
||||||
|
}
|
||||||
|
};
|
||||||
|
const result = await actions.default(event);
|
||||||
|
expect(result.status).toBe(400);
|
||||||
|
expect(result.data.message).toMatch(/PIN eingeben/i);
|
||||||
|
// Cookie wird nicht gesetzt
|
||||||
|
expect(cookiesSet).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
it.todo('Überprüfe was passiert, wenn Eingabe falsch, bzw. nicht im System passend gefunden');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Teste Guard', () => {
|
||||||
|
it('Lese Cookie aus', async () => {
|
||||||
|
const vorgObj = baseData.vorgang;
|
||||||
|
|
||||||
|
const COOKIE_NAME = `token-${vorgObj.vorgangToken}`;
|
||||||
|
const cookiesGet = vi.fn().mockImplementation((key: string) => {
|
||||||
|
if (key === COOKIE_NAME) return vorgObj.vorgangPIN;
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
// mocked objects
|
||||||
|
const event = {
|
||||||
|
cookies: {
|
||||||
|
get: cookiesGet
|
||||||
|
},
|
||||||
|
locals: {},
|
||||||
|
params: { vorgang: vorgObj.vorgangToken }
|
||||||
|
};
|
||||||
|
vi.mocked(vorgangExists).mockReturnValueOnce(true);
|
||||||
|
vi.mocked(vorgangPINValidation).mockReturnValueOnce(true);
|
||||||
|
|
||||||
|
await load(event);
|
||||||
|
|
||||||
|
expect(cookiesGet).toHaveBeenCalledWith(COOKIE_NAME);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Kein Cookie gesetzt', async () => {
|
||||||
|
const vorgObj = baseData.vorgang;
|
||||||
|
|
||||||
|
const COOKIE_NAME = `token-${vorgObj.vorgangToken}`;
|
||||||
|
const cookiesGet = vi.fn().mockImplementation((key: string) => {
|
||||||
|
if (key === COOKIE_NAME) return vorgObj.vorgangPIN;
|
||||||
|
return undefined;
|
||||||
|
});
|
||||||
|
|
||||||
|
// mocked objects
|
||||||
|
const event = {
|
||||||
|
cookies: {
|
||||||
|
get: cookiesGet
|
||||||
|
},
|
||||||
|
locals: {},
|
||||||
|
params: { vorgang: vorgObj.vorgangToken }
|
||||||
|
};
|
||||||
|
vi.mocked(vorgangExists).mockReturnValueOnce(true);
|
||||||
|
vi.mocked(vorgangPINValidation).mockReturnValueOnce(false);
|
||||||
|
|
||||||
|
let thrownRedirect;
|
||||||
|
try {
|
||||||
|
await load(event);
|
||||||
|
throw new Error('Function did not throw');
|
||||||
|
} catch (e) {
|
||||||
|
thrownRedirect = e;
|
||||||
|
}
|
||||||
|
expect(thrownRedirect?.status).toBe(303);
|
||||||
|
expect(thrownRedirect?.location).toBe(
|
||||||
|
ROUTE_NAMES.ANMELDUNG_VORGANG_PARAM(vorgObj.vorgangToken)
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(cookiesGet).toHaveBeenCalledWith(COOKIE_NAME);
|
||||||
|
});
|
||||||
|
});
|
||||||
23
tests/views/Home.view.test.ts
Normal file
23
tests/views/Home.view.test.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { render, screen } from '@testing-library/svelte';
|
||||||
|
import { describe, expect, it } from 'vitest';
|
||||||
|
|
||||||
|
import HomePage from '$root/routes/(angemeldet)/+page.svelte';
|
||||||
|
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
|
||||||
|
describe('Home-Page View', () => {
|
||||||
|
it('Überprüfe Links', () => {
|
||||||
|
render(HomePage, { props: { data: baseData } });
|
||||||
|
let linkElement = screen.getByText('Vorgänge');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.LIST);
|
||||||
|
|
||||||
|
linkElement = screen.queryByText('Hinzufügen');
|
||||||
|
expect(linkElement).not.toBeInTheDocument();
|
||||||
|
|
||||||
|
linkElement = screen.getByText('Benutzerverwaltung');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', ROUTE_NAMES.USERMGMT);
|
||||||
|
});
|
||||||
|
});
|
||||||
24
tests/views/Layout.test.ts
Normal file
24
tests/views/Layout.test.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import { describe, test, expect } from 'vitest';
|
||||||
|
import { load } from '$root/routes/(angemeldet)/+layout.server';
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
import { baseData, mockEvent } from '../fixtures';
|
||||||
|
|
||||||
|
describe('+layout.server load(): Teste korrekte URL', () => {
|
||||||
|
test('Werfe keinen Redirect und gebe nichts zurück', async () => {
|
||||||
|
const mockEvent = {
|
||||||
|
locals: {
|
||||||
|
user: null
|
||||||
|
},
|
||||||
|
url: new URL(`https://example.com/not-anmeldung`)
|
||||||
|
};
|
||||||
|
const res = load(mockEvent);
|
||||||
|
expect(res).toBe(undefined);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('+layout.server load(): Teste erfolgreichen Pfad', () => {
|
||||||
|
test('Werfe kein Fehler', async () => {
|
||||||
|
const result = load(mockEvent);
|
||||||
|
expect(result).toEqual({ user: baseData.user });
|
||||||
|
});
|
||||||
|
});
|
||||||
139
tests/views/TatortList.test.ts
Normal file
139
tests/views/TatortList.test.ts
Normal file
@@ -0,0 +1,139 @@
|
|||||||
|
import { render, fireEvent, screen, within } from '@testing-library/svelte';
|
||||||
|
import { describe, it, expect, vi, test } from 'vitest';
|
||||||
|
import * as nav from '$app/navigation';
|
||||||
|
import TatortListPage from '$root/routes/(token-based)/list/[vorgang]/+page.svelte';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
import { API_ROUTES } from '../../src/routes';
|
||||||
|
|
||||||
|
vi.spyOn(nav, 'invalidateAll').mockResolvedValue();
|
||||||
|
global.fetch = vi.fn().mockResolvedValue({ ok: true });
|
||||||
|
|
||||||
|
async function clickPlusButton() {
|
||||||
|
// mock animation features of the browser
|
||||||
|
|
||||||
|
window.HTMLElement.prototype.scrollIntoView = vi.fn();
|
||||||
|
window.HTMLElement.prototype.animate = vi.fn(() => ({
|
||||||
|
finished: Promise.resolve(),
|
||||||
|
cancel: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
// button is visible
|
||||||
|
const button = screen.getByRole('button', { name: /add item/i })
|
||||||
|
expect(button).toBeInTheDocument();
|
||||||
|
|
||||||
|
await fireEvent.click(button)
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('Seite: Vorgangsansicht', () => {
|
||||||
|
test.todo('Share Link disabled wenn Liste leer');
|
||||||
|
describe('Szenario: Admin + Liste gefüllt - Funktionalität', () => {
|
||||||
|
test.todo('Share Link Link generierung richtig');
|
||||||
|
|
||||||
|
it('führt PUT-Request aus und aktualisiert UI nach onSave', async () => {
|
||||||
|
const data = structuredClone(baseData);
|
||||||
|
const oldName = data.crimesList[0].name;
|
||||||
|
const newName = 'Fall-C';
|
||||||
|
|
||||||
|
render(TatortListPage, { props: { data } });
|
||||||
|
const listItem = screen.getAllByTestId('test-list-item')[0];
|
||||||
|
expect(listItem).toHaveTextContent(oldName);
|
||||||
|
|
||||||
|
await fireEvent.click(within(listItem).getByTestId('edit-button'));
|
||||||
|
const input = within(listItem).getByTestId('test-input');
|
||||||
|
await fireEvent.input(input, { target: { value: newName } });
|
||||||
|
|
||||||
|
await fireEvent.click(within(listItem).getByTestId('commit-button'));
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
expect(global.fetch).toHaveBeenCalledWith(
|
||||||
|
`/api/list/${data.vorgang.vorgangToken}/${oldName}`,
|
||||||
|
expect.objectContaining({
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
vorgangToken: data.vorgang.vorgangToken,
|
||||||
|
oldName,
|
||||||
|
newName
|
||||||
|
})
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(nav.invalidateAll).toHaveBeenCalled();
|
||||||
|
expect(within(listItem).getByText(newName)).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('führt DELETE-Request aus und entfernt Element aus UI', async () => {
|
||||||
|
const testData = structuredClone(baseData);
|
||||||
|
const oldName = testData.crimesList[0].name;
|
||||||
|
const vorgang = testData.vorgang;
|
||||||
|
|
||||||
|
render(TatortListPage, { props: { data: testData } });
|
||||||
|
const initialItems = screen.getAllByTestId('test-list-item');
|
||||||
|
expect(initialItems).toHaveLength(testData.crimesList.length);
|
||||||
|
|
||||||
|
const listItem = screen.getAllByTestId('test-list-item')[0];
|
||||||
|
expect(listItem).toHaveTextContent(oldName);
|
||||||
|
const del = within(listItem).getByTestId('delete-button');
|
||||||
|
expect(del).toBeInTheDocument()
|
||||||
|
await fireEvent.click(within(listItem).getByTestId('delete-button'));
|
||||||
|
await tick();
|
||||||
|
|
||||||
|
let expectedPath = API_ROUTES.CRIME(vorgang.vorgangToken, oldName)
|
||||||
|
expect(global.fetch).toHaveBeenCalledWith(
|
||||||
|
expectedPath,
|
||||||
|
expect.objectContaining({
|
||||||
|
method: 'DELETE',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
vorgangToken: testData.vorgang.vorgangToken,
|
||||||
|
tatort: oldName
|
||||||
|
})
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(nav.invalidateAll).toHaveBeenCalled();
|
||||||
|
const updatedItems = screen.queryAllByTestId('test-list-item');
|
||||||
|
expect(updatedItems).toHaveLength(testData.crimesList.length - 1);
|
||||||
|
expect(screen.queryByText(oldName)).toBeNull();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('Hinzufügen Button', () => {
|
||||||
|
it('Unexpandierter Button', () => {
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
const { getByTestId } = render(TatortListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
const container = getByTestId('expand-container')
|
||||||
|
expect(container).toBeInTheDocument();
|
||||||
|
|
||||||
|
// button is visible
|
||||||
|
const button = within(container).getByRole('button')
|
||||||
|
expect(button).toBeInTheDocument();
|
||||||
|
|
||||||
|
// input fields are not visible
|
||||||
|
let label = screen.queryByText('Modellname');
|
||||||
|
expect(label).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Expandierter Button nach Klick', async () => {
|
||||||
|
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
render(TatortListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
await clickPlusButton();
|
||||||
|
|
||||||
|
// input fields are visible
|
||||||
|
let label = screen.queryByText('Modellname');
|
||||||
|
expect(label).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it.todo('Check Validation: missing name', async () => {
|
||||||
|
console.log(`test: input field validation`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it.todo('Create Tatort successful', async () => {
|
||||||
|
console.log(`test: tatort upload`);
|
||||||
|
});
|
||||||
|
});
|
||||||
115
tests/views/TatortList.view.test.ts
Normal file
115
tests/views/TatortList.view.test.ts
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
import { render, screen, within } from '@testing-library/svelte';
|
||||||
|
import { describe, expect, it, test } from 'vitest';
|
||||||
|
import TatortListPage from '$root/routes/(token-based)/list/[vorgang]/+page.svelte';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
|
||||||
|
describe('Seite: Vorgangsansicht', () => {
|
||||||
|
test.todo('zeigt PIN und Share-Link, wenn Admin');
|
||||||
|
test.todo('zeigt PIN und Share-Link disabeld, wenn Liste leer');
|
||||||
|
|
||||||
|
describe('Szenario: Liste leer (unabhängig von Rolle)', () => {
|
||||||
|
it('zeigt Hinweistext bei leerer Liste', () => {
|
||||||
|
const testData = { ...baseData, crimesList: [] };
|
||||||
|
const { getByTestId } = render(TatortListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
expect(getByTestId('empty-list')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zeigt keinen Listeneintrag', () => {
|
||||||
|
const items = screen.queryAllByTestId('test-list-item');
|
||||||
|
|
||||||
|
expect(items).toHaveLength(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Szenario: Liste gefüllt (unabhängig von Rolle)', () => {
|
||||||
|
it('rendert mindestens ein Listenelement bei vorhandenen crimesList-Daten', () => {
|
||||||
|
const testData = { ...baseData };
|
||||||
|
const { queryAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
||||||
|
const items = queryAllByTestId('test-list-item');
|
||||||
|
|
||||||
|
expect(items.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zeigt für jeden Eintrag einen Link', () => {
|
||||||
|
const testData = { ...baseData };
|
||||||
|
render(TatortListPage, { props: { data: testData } });
|
||||||
|
const links = screen.queryAllByTestId('crime-link');
|
||||||
|
|
||||||
|
expect(links).toHaveLength(testData.crimesList.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('prüft href und title jedes Links', () => {
|
||||||
|
const testData = { ...baseData };
|
||||||
|
const { queryAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
||||||
|
const items = queryAllByTestId('test-list-item');
|
||||||
|
|
||||||
|
items.forEach((item, i) => {
|
||||||
|
const link = within(item).getByRole('link');
|
||||||
|
const expectedHref = ROUTE_NAMES.CRIME(testData.vorgang.vorgangToken, testData.crimesList[i].name, testData.vorgang.vorgangPIN);
|
||||||
|
|
||||||
|
expect(link).toBeInTheDocument();
|
||||||
|
expect(link).toHaveAttribute('href', expectedHref);
|
||||||
|
expect(link).toHaveAttribute('title', testData.crimesList[i].name);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.todo('testet zuletzt angezeigt, wenn item.lastModified');
|
||||||
|
test.todo('zeigt Dateigröße, wenn item.size vorhanden ist');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Szenario: Admin + Liste gefüllt', () => {
|
||||||
|
const testData = { ...baseData, user: { ...baseData.user, admin: true } };
|
||||||
|
it('zeigt Listeneinträge mit Komponente NameItemEditor', () => {
|
||||||
|
const { getAllByTestId } = render(TatortListPage, { props: { data: testData } });
|
||||||
|
const items = getAllByTestId('test-nameItemEditor');
|
||||||
|
|
||||||
|
expect(items.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.todo('Modal testen, wenn open');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Szenario: Viewer + Liste gefüllt', () => {
|
||||||
|
const testData = { ...baseData, user: { ...baseData.user, admin: false } };
|
||||||
|
it('zeigt Listeneinträge mit p', () => {
|
||||||
|
render(TatortListPage, { props: { data: testData } });
|
||||||
|
const paragraphs = screen.queryAllByTestId('test-nameItem-p');
|
||||||
|
|
||||||
|
expect(paragraphs).toHaveLength(testData.crimesList.length);
|
||||||
|
paragraphs.forEach((p, i) => {
|
||||||
|
expect(p).toHaveTextContent(testData.crimesList[i].name);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.todo('zeigt keinen Share-Link oder PIN');
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Teste Links auf Korrektheit', () => {
|
||||||
|
it('Überprüfe Links', () => {
|
||||||
|
const crimesListOneItem = baseData.crimesList.slice(0, 1);
|
||||||
|
const crimeObj = crimesListOneItem[0];
|
||||||
|
const vorgObj = baseData.vorgangList[0]
|
||||||
|
const expectedURL = ROUTE_NAMES.CRIME(vorgObj.vorgangToken, crimeObj.name, vorgObj.vorgangPIN)
|
||||||
|
|
||||||
|
render(TatortListPage, { props: { data: { ...baseData, crimesList: crimesListOneItem } } });
|
||||||
|
const listItem = screen.getByTestId("test-list-item");
|
||||||
|
const linkElement = within(listItem).getByRole('link');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', expectedURL);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('PIN Anzeige & Button', () => {
|
||||||
|
it('Teste korrekte Anzeige von PIN Komponente', () => {
|
||||||
|
const testData = { ...baseData};
|
||||||
|
render(TatortListPage, { props: { data: testData } });
|
||||||
|
const vorgObj = baseData.vorgangList[0]
|
||||||
|
|
||||||
|
// PIN is being displayed within ´NameItemEditor´
|
||||||
|
let label = screen.queryByText(vorgObj.vorgangPIN);
|
||||||
|
expect(label).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
184
tests/views/VorgangList.view.test.ts
Normal file
184
tests/views/VorgangList.view.test.ts
Normal file
@@ -0,0 +1,184 @@
|
|||||||
|
import { render, fireEvent, screen, within } from '@testing-library/svelte';
|
||||||
|
import { describe, expect, it, vi } from 'vitest';
|
||||||
|
import VorgangListPage from '$root/routes/(angemeldet)/list/+page.svelte';
|
||||||
|
import { baseData } from '../fixtures';
|
||||||
|
import { ROUTE_NAMES } from '../../src/routes';
|
||||||
|
import { actions } from '../../src/routes/(angemeldet)/list/+page.server';
|
||||||
|
import { createVorgang } from '$lib/server/vorgangService';
|
||||||
|
|
||||||
|
// mock animation features of the browser
|
||||||
|
|
||||||
|
window.HTMLElement.prototype.scrollIntoView = vi.fn();
|
||||||
|
window.HTMLElement.prototype.animate = vi.fn(() => ({
|
||||||
|
finished: Promise.resolve(),
|
||||||
|
cancel: vi.fn(),
|
||||||
|
}))
|
||||||
|
|
||||||
|
describe('Vorgänge Liste Page EmptyList-Komponente View', () => {
|
||||||
|
it('zeigt EmptyList-Komponente an, wenn Liste leer ist', () => {
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
const { getByTestId } = render(VorgangListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
expect(getByTestId('empty-list')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('zeigt Liste(mockData 2 Elemente) an, wenn Liste vorhanden ist', () => {
|
||||||
|
const testData = { ...baseData };
|
||||||
|
const { getAllByTestId } = render(VorgangListPage, { props: { data: testData } });
|
||||||
|
const items = getAllByTestId('test-list-item');
|
||||||
|
|
||||||
|
expect(items.length).toBeGreaterThan(0);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Teste Links auf Korrektheit', () => {
|
||||||
|
it('Überprüfe Links', () => {
|
||||||
|
const vorgListOneItem = baseData.vorgangList.slice(0, 1);
|
||||||
|
const vorgObj = vorgListOneItem[0];
|
||||||
|
const expectedURL = ROUTE_NAMES.VORGANG(vorgObj.vorgangToken, vorgObj.vorgangPIN)
|
||||||
|
|
||||||
|
render(VorgangListPage, { props: { data: { ...baseData, vorgangList: vorgListOneItem } } });
|
||||||
|
const listItem = screen.getByTestId("test-list-item");
|
||||||
|
const linkElement = within(listItem).getByRole('link');
|
||||||
|
expect(linkElement).toBeInTheDocument();
|
||||||
|
expect(linkElement).toHaveAttribute('href', expectedURL);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Links enthalten keinen VorgangsPIN', () => {
|
||||||
|
const vorgListOneItem = baseData.vorgangList.slice(0, 1)
|
||||||
|
|
||||||
|
render(VorgangListPage, { props: { data: { ...baseData, vorgangList: vorgListOneItem } } });
|
||||||
|
const listItem = screen.getByTestId("test-list-item");
|
||||||
|
const linkElement = within(listItem).getByRole('link');
|
||||||
|
expect(linkElement.getAttribute('href')?.toLowerCase()).not.toContain('pin');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function clickPlusButton() {
|
||||||
|
// button is visible
|
||||||
|
const button = screen.getByTestId('expand-button')
|
||||||
|
expect(button).toBeInTheDocument();
|
||||||
|
|
||||||
|
await fireEvent.click(button)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function inputVorgang() {
|
||||||
|
const input = document.getElementById("vorgang");
|
||||||
|
input.value = 'test-vorgang';
|
||||||
|
// firing the event manually for Svelte
|
||||||
|
await fireEvent.input(input)
|
||||||
|
|
||||||
|
expect(input).toHaveValue('test-vorgang');
|
||||||
|
}
|
||||||
|
|
||||||
|
async function inputVorgangPIN() {
|
||||||
|
const input = document.getElementById("pin");
|
||||||
|
input.value = 'test-pin';
|
||||||
|
// firing the event manually for Svelte
|
||||||
|
await fireEvent.input(input)
|
||||||
|
|
||||||
|
expect(input).toHaveValue('test-pin');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
describe('Hinzufügen Buton', () => {
|
||||||
|
it('Unexpandierter Button', () => {
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
const { getByTestId } = render(VorgangListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
const container = getByTestId('expand-container')
|
||||||
|
expect(container).toBeInTheDocument();
|
||||||
|
|
||||||
|
// button is visible
|
||||||
|
const button = within(container).getByRole('button')
|
||||||
|
expect(button).toBeInTheDocument();
|
||||||
|
|
||||||
|
// input fields are not visible
|
||||||
|
let label = screen.queryByText('Vorgangsname');
|
||||||
|
expect(label).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Expandierter Button nach Klick', async () => {
|
||||||
|
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
render(VorgangListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
await clickPlusButton()
|
||||||
|
|
||||||
|
// input fields are visible
|
||||||
|
let label = screen.queryByText('Vorgangsname');
|
||||||
|
expect(label).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Check Validation: missing PIN', async () => {
|
||||||
|
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
render(VorgangListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
await clickPlusButton()
|
||||||
|
|
||||||
|
// input
|
||||||
|
inputVorgang();
|
||||||
|
|
||||||
|
// submit
|
||||||
|
const button = screen.getByText('Neuen Vorgang hinzufügen')
|
||||||
|
expect(button).toBeInTheDocument()
|
||||||
|
await fireEvent.click(button);
|
||||||
|
const errorMsg = 'Bitte einen Vorgangs-PIN eingeben.';
|
||||||
|
let para = await screen.getByText(errorMsg);
|
||||||
|
expect(para).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Create Vorgang successful', async () => {
|
||||||
|
|
||||||
|
const testData = { ...baseData, vorgangList: [] };
|
||||||
|
render(VorgangListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
await clickPlusButton();
|
||||||
|
|
||||||
|
// input fields are visible
|
||||||
|
let label = screen.queryByText('Vorgangsname');
|
||||||
|
expect(label).toBeInTheDocument();
|
||||||
|
|
||||||
|
inputVorgang();
|
||||||
|
inputVorgangPIN();
|
||||||
|
|
||||||
|
// emulate button click
|
||||||
|
const button = screen.getByText('Neuen Vorgang hinzufügen');
|
||||||
|
expect(button).toBeInTheDocument();
|
||||||
|
await fireEvent.click(button);
|
||||||
|
|
||||||
|
// no error message
|
||||||
|
label = screen.queryByText('Bitte');
|
||||||
|
expect(label).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Test default action', async () => {
|
||||||
|
vi.mock('$lib/server/vorgangService', () => ({
|
||||||
|
createVorgang: vi.fn(),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const formData = new FormData(); // no data as we are mocking createVorgang
|
||||||
|
const mockRequest = {
|
||||||
|
formData: vi.fn().mockResolvedValue(formData)
|
||||||
|
};
|
||||||
|
const event = {
|
||||||
|
request: mockRequest,
|
||||||
|
};
|
||||||
|
|
||||||
|
const testVorgangToken = 'c322f26f-8c5e-4cb9-94b3-b5433bf5109e'
|
||||||
|
vi.mocked(createVorgang).mockReturnValueOnce(testVorgangToken);
|
||||||
|
const result = await actions.default(event);
|
||||||
|
expect(result).toEqual({ token: testVorgangToken });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Vorgang-Operationen', () => {
|
||||||
|
it('Teste korrekte Anzeige von Vorgang-Input Komponente', () => {
|
||||||
|
const testData = { ...baseData};
|
||||||
|
const { getAllByTestId } = render(VorgangListPage, { props: { data: testData } });
|
||||||
|
|
||||||
|
let buttons = getAllByTestId('edit-button')
|
||||||
|
expect(buttons.length).toBeGreaterThan(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -1,9 +1,16 @@
|
|||||||
import { svelteTesting } from '@testing-library/svelte/vite';
|
import { svelteTesting } from '@testing-library/svelte/vite';
|
||||||
import { sveltekit } from '@sveltejs/kit/vite';
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
|
import path from 'path';
|
||||||
import { defineConfig } from 'vite';
|
import { defineConfig } from 'vite';
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [sveltekit()],
|
plugins: [sveltekit()],
|
||||||
|
resolve: {
|
||||||
|
alias: {
|
||||||
|
$lib: path.resolve('./src/lib'),
|
||||||
|
$root: path.resolve(__dirname, './src')
|
||||||
|
}
|
||||||
|
},
|
||||||
test: {
|
test: {
|
||||||
projects: [
|
projects: [
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user