From e5d96d19292224ea9513e145b02e35338eff0857 Mon Sep 17 00:00:00 2001 From: altaf-creator Date: Fri, 23 Jan 2026 09:50:33 +0800 Subject: machine override status --- frontend/admin/admin-style.css | 39 ++++++++++++++++++++- frontend/admin/admin.js | 57 +++++++++++++++++++++++++++++- frontend/admin/index.html | 3 +- frontend/admin/panel.html | 78 +++++++++++++++++++++++++++++++++++------- 4 files changed, 161 insertions(+), 16 deletions(-) (limited to 'frontend/admin') diff --git a/frontend/admin/admin-style.css b/frontend/admin/admin-style.css index 86be9f5..e04a047 100644 --- a/frontend/admin/admin-style.css +++ b/frontend/admin/admin-style.css @@ -7,5 +7,42 @@ } .admin-machine-container { - + display: flex; + flex-direction: row; + flex-wrap: wrap; + background-color: lightgrey; + gap: 16px; + padding: 16px; + width: fit-content; + max-width: 100%; + box-sizing: border-box; +} + +.admin-machine-container > div { + display: flex; + flex-direction: column; + gap: 16px; +} + +.admin-machine-container > div > img { + width: 128px; +} + +.admin-machine-container > h2 { + writing-mode: vertical-lr; + transform: rotate(180deg); + margin: 0; + height: fit-content; +} + +#passwordFeedback { + display: none; + color: red; +} + +.blocks-container { + display: flex; + flex-direction: row; + flex-wrap: wrap; + gap: 16px; } diff --git a/frontend/admin/admin.js b/frontend/admin/admin.js index bc31007..8a4a331 100644 --- a/frontend/admin/admin.js +++ b/frontend/admin/admin.js @@ -11,6 +11,9 @@ async function login() { }, body: `{"password": "${field.value}"}`, }); + + if (response.status == 202) window.location.href = "./panel.html"; + else document.getElementById("passwordFeedback").style.display = "inherit"; } async function checkLoginStatus() { @@ -18,5 +21,57 @@ async function checkLoginStatus() { method: "POST", credentials: "include" }); - console.log(response); + + return response.status == 202; +} + +async function autoLogin() { + if (await checkLoginStatus()) { + window.location.href = "./panel.html"; + } +} + +async function panelLoginCheck() { + const msg = document.getElementById("unauthorised"); + const authDiv = document.getElementById("authorised"); + + if (await checkLoginStatus()) { + msg.style.display = "none"; + authDiv.style.display = "inherit"; + } else { + msg.style.display = "inherit"; + authDiv.style.display = "none"; + } +} + +async function overrideMachineStatus(block, machine) { + const img = document.getElementById("h"+block.toString()+"m"+machine.toString()+"img"); + const dropdown = document.getElementById("h"+block.toString()+"m"+machine.toString()); + + const response = await fetch(`${API_URL}/admin_login`, { + method: "POST", + credentials: "include", + headers: { + "Content-Type": "application/json" + }, + body: `{"block": ${block}, "machine_id": ${machine}, "disabled": ${dropdown.selectedIndex == 1}`, + }); + + if (response.status != 200) { + return; + } + + if (dropdown.selectedIndex == 1) { + if (machine % 2 == 0) { + img.src = "/assets/img/washer_down.png"; + } else { + img.src = "/assets/img/dryer_down.png"; + } + } else { + if (machine % 2 == 0) { + img.src = "/assets/img/washer_off.png"; + } else { + img.src = "/assets/img/dryer_off.png"; + } + } } diff --git a/frontend/admin/index.html b/frontend/admin/index.html index 8ce5812..76df357 100644 --- a/frontend/admin/index.html +++ b/frontend/admin/index.html @@ -8,9 +8,10 @@

LaundryWeb Admin Panel Log In

+

Invalid password.

diff --git a/frontend/admin/panel.html b/frontend/admin/panel.html index b912553..1169c30 100644 --- a/frontend/admin/panel.html +++ b/frontend/admin/panel.html @@ -10,22 +10,74 @@

You are unauthorised.

-
-
- - +
+
+

Block H2

+
+ + +
+
+ + +
+
+ + +
+
+ + +
-
- - +
+

Block H1

+
+ + +
+
+ + +
+
+ + +
+
+ + +
+ + -- cgit v1.2.3