diff --git a/web/index.html b/web/index.html index 3de4aef..5840499 100644 --- a/web/index.html +++ b/web/index.html @@ -23,6 +23,18 @@ Download CSV +
+

ID mapping

+ + + + + + + + +
IDNachnameVorname
+
diff --git a/web/src/idMapping.ts b/web/src/idMapping.ts new file mode 100644 index 0000000..6af56a5 --- /dev/null +++ b/web/src/idMapping.ts @@ -0,0 +1,45 @@ +export interface IdMapping { + id_map: IDMap +} + +export interface IDMap { + [name: string]: Name +} + +export interface Name { + first: string, + last: string, +} + +export async function requestMappings(): Promise { + let req = await fetch("/api/mapping"); + + if (req.status != 200) { + console.error(await req.text()); + return { id_map: {} }; + } + + let mappings: IdMapping = await req.json(); + + return mappings; +} + +export async function addMapping(id: string, firstName: string, lastName: string) { + let req = await fetch("/api/mapping", { + method: "POST", + headers: { + "Content-type": "application/json; charset=UTF-8" + }, + body: JSON.stringify({ + id, + name: { + first: firstName, + lastName: lastName, + }, + }) + }); + + if (req.status != 200){ + console.error(await req.text()) + } +} diff --git a/web/src/main.ts b/web/src/main.ts index 7e46353..928de2a 100644 --- a/web/src/main.ts +++ b/web/src/main.ts @@ -1,2 +1,26 @@ import './style.css' +import { IDMap, Name, requestMappings } from './idMapping' + +function createTableRow(a: string, b: string, c: string): HTMLTableRowElement { + const tr = document.createElement('tr'); + [a, b, c].forEach(value => { + const td = document.createElement('td'); + td.textContent = value; + tr.appendChild(td); + }); + return tr; +} + +function orderByFirstName(obj: IDMap): { id: string, name: Name }[] { + return Object.entries(obj) + .sort(([, a], [, b]) => a.first.localeCompare(b.first)) + .map(([id, { first, last }]) => ({ id, name: { first, last } })); +} + +requestMappings().then(r => { + orderByFirstName(r.id_map).forEach(e => { + let row = createTableRow(e.id, e.name.last, e.name.first); + document.querySelector("#mappingTable")?.appendChild(row); + }) +}) diff --git a/web/src/style.css b/web/src/style.css index 3d552a6..443d9b9 100644 --- a/web/src/style.css +++ b/web/src/style.css @@ -1,2 +1,4 @@ @import "tailwindcss"; +#mappingTable{ +}