mirror of
https://github.com/Djeeberjr/fw-anwesenheit.git
synced 2025-10-13 15:06:39 +00:00
fixed changed /api/mapping structure in frontend
This commit is contained in:
parent
b8bba28bda
commit
7eb18376e1
@ -1,7 +1,3 @@
|
|||||||
export interface IDMapping {
|
|
||||||
id_map: IDMap
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IDMap {
|
export interface IDMap {
|
||||||
[name: string]: Name
|
[name: string]: Name
|
||||||
}
|
}
|
||||||
@ -11,6 +7,23 @@ export interface Name {
|
|||||||
last: string,
|
last: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stupidSerdeFix(pairs: [string, Name][]): IDMap {
|
||||||
|
const map: IDMap = {};
|
||||||
|
for (const [key, value] of pairs) {
|
||||||
|
map[key] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function fetchMapping(): Promise<IDMap> {
|
||||||
|
let res = await fetch("/api/mapping");
|
||||||
|
|
||||||
|
let data = await res.json();
|
||||||
|
|
||||||
|
return stupidSerdeFix(data);
|
||||||
|
}
|
||||||
|
|
||||||
export async function addMapping(id: string, firstName: string, lastName: string) {
|
export async function addMapping(id: string, firstName: string, lastName: string) {
|
||||||
let req = await fetch("/api/mapping", {
|
let req = await fetch("/api/mapping", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
@ -1,19 +1,20 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte";
|
import { onMount } from "svelte";
|
||||||
import type { IDMapping } from "./IDMapping";
|
import { fetchMapping, type IDMap } from "./IDMapping";
|
||||||
let data: IDMapping | undefined = $state();
|
let data: IDMap | undefined = $state();
|
||||||
|
|
||||||
let { onEdit }: { onEdit?: (string,string,string) => void } = $props();
|
let {
|
||||||
|
onEdit,
|
||||||
|
}: { onEdit?: (id: string, firstName: string, lastName: string) => void } =
|
||||||
|
$props();
|
||||||
|
|
||||||
export async function reloadData() {
|
export async function reloadData() {
|
||||||
let res = await fetch("/api/mapping");
|
data = await fetchMapping();
|
||||||
|
|
||||||
data = await res.json();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let rows = $derived(
|
let rows = $derived(
|
||||||
data
|
data
|
||||||
? Object.entries(data.id_map).map(([id, value]) => ({
|
? Object.entries(data).map(([id, value]) => ({
|
||||||
id,
|
id,
|
||||||
...value,
|
...value,
|
||||||
}))
|
}))
|
||||||
@ -47,7 +48,6 @@
|
|||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
await reloadData();
|
await reloadData();
|
||||||
});
|
});
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#if data == null}
|
{#if data == null}
|
||||||
@ -84,8 +84,7 @@
|
|||||||
|
|
||||||
<span class="indicator">{indicator("first")}</span>
|
<span class="indicator">{indicator("first")}</span>
|
||||||
</th>
|
</th>
|
||||||
<th>
|
<th> </th>
|
||||||
</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -94,9 +93,14 @@
|
|||||||
<td class="whitespace-nowrap pr-5 pl-2 py-1">{row.id}</td>
|
<td class="whitespace-nowrap pr-5 pl-2 py-1">{row.id}</td>
|
||||||
<td class="whitespace-nowrap pr-5">{row.last}</td>
|
<td class="whitespace-nowrap pr-5">{row.last}</td>
|
||||||
<td class="whitespace-nowrap pr-5">{row.first}</td>
|
<td class="whitespace-nowrap pr-5">{row.first}</td>
|
||||||
<td class="pr-5" ><button onclick={()=>{
|
<td class="pr-5"
|
||||||
onEdit && onEdit(row.id,row.first,row.last);
|
><button
|
||||||
}} class="cursor-pointer">🔧</button></td>
|
onclick={() => {
|
||||||
|
onEdit && onEdit(row.id, row.first, row.last);
|
||||||
|
}}
|
||||||
|
class="cursor-pointer">🔧</button
|
||||||
|
></td
|
||||||
|
>
|
||||||
</tr>
|
</tr>
|
||||||
{/each}
|
{/each}
|
||||||
</tbody>
|
</tbody>
|
||||||
@ -106,7 +110,6 @@
|
|||||||
|
|
||||||
<style lang="css" scoped>
|
<style lang="css" scoped>
|
||||||
@reference "../app.css";
|
@reference "../app.css";
|
||||||
|
|
||||||
.indicator {
|
.indicator {
|
||||||
@apply ml-1 w-4 inline-block;
|
@apply ml-1 w-4 inline-block;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user