From 05c82f079e4c3eb064012c69db9294c479990035 Mon Sep 17 00:00:00 2001 From: jaguililla Date: Wed, 18 Sep 2024 08:00:49 +0200 Subject: [PATCH] Add basic front-end :wip --- src/main/resources/static/index.html | 58 +++++++++----------------- src/main/resources/static/main.js | 62 ++++++++++++++++++++++++++++ src/main/resources/static/simple.css | 6 ++- 3 files changed, 87 insertions(+), 39 deletions(-) create mode 100644 src/main/resources/static/main.js diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index ac75567..68a7498 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -15,9 +15,17 @@ -

Appointments

+
+

Appointments

+

Example task application

-

Open

+ +
+ +

Open

@@ -26,16 +34,10 @@

Open

- - - - - - - +
Order
ab0
-

New

+

New

@@ -44,32 +46,12 @@

New

- + diff --git a/src/main/resources/static/main.js b/src/main/resources/static/main.js new file mode 100644 index 0000000..acc73f6 --- /dev/null +++ b/src/main/resources/static/main.js @@ -0,0 +1,62 @@ + +const http = new XMLHttpRequest(); + +const tbody = document.querySelector("tbody#appointments"); +const template = document.querySelector("#appointmentRow"); +const titleInput = document.querySelector("#title"); +const orderInput = document.querySelector("#order"); + +function httpSend(method, url, body, callback) { + http.open(method, url); + http.setRequestHeader('Content-type', 'application/json'); + http.send(JSON.stringify(body)); + http.onload = callback; +} + +function httpGet(url, body, callback) { + httpSend('GET', url, body, callback); +} + +function httpPost(url, body, callback) { + httpSend('POST', url, body, callback); +} + +function addTask(task) { + const clone = template.content.cloneNode(true); + const td = clone.querySelectorAll("td"); + const input = clone.querySelectorAll("input"); + td[0].textContent = task.title; + td[1].textContent = task.order; + input.checked = task.completed; + tbody.appendChild(clone); +} + +function add() { + const body = { + title: titleInput.value, + order: orderInput.valueAsNumber + }; + + httpPost('/appointments', body, () => { + titleInput.value = ""; + orderInput.value = 0; + + addTask(JSON.parse(http.responseText)); + }); +} + +function main() { + + httpGet('/appointments', null, () => { + for (const tr of tbody.children) + tr.remove(); + + const response = JSON.parse(http.responseText); + for (const task of response) + addTask(task); + + console.log(http.responseText); + }); +} + +document.body.onload = main; diff --git a/src/main/resources/static/simple.css b/src/main/resources/static/simple.css index 3971637..2ec0254 100644 --- a/src/main/resources/static/simple.css +++ b/src/main/resources/static/simple.css @@ -9,8 +9,12 @@ --body-font-size: 1.15rem; --footer-font-size: 0.9rem; --nav-font-size: 1rem; + --aside-font-size: 1rem; + --figcaption-font-size: 0.9rem; + --cite-font-size: 0.9rem; --body-line-height: 1.5; + --h3-line-height: 1.1; --standard-border-radius: 5px; @@ -326,7 +330,7 @@ aside, details, pre, progress { } aside { - font-size: 1rem; + font-size: var(--aside-font-size); width: 30%; padding: 0 15px; margin-inline-start: 15px;