From f0e03ebe7cc4b262c09c20aa56d33d6ebb365828 Mon Sep 17 00:00:00 2001 From: Lordiii Date: Tue, 30 Apr 2024 19:59:38 +0200 Subject: [PATCH] First Iteration Space Status --- config.toml | 28 +++++++++---- sass/css/site.scss | 8 ---- static/js/status.js | 89 ++++++++++++++++++++++++++++++++++++++++++ templates/sidebar.html | 66 +++++++++++++++---------------- 4 files changed, 140 insertions(+), 51 deletions(-) create mode 100644 static/js/status.js diff --git a/config.toml b/config.toml index 59be064..ec49a5c 100644 --- a/config.toml +++ b/config.toml @@ -14,9 +14,9 @@ generate_feed = true feed_filename = "rss.xml" taxonomies = [ - {name = "Serie", feed = true, paginate_by = 10 }, - {name = "Typ", feed = true, paginate_by = 10 }, - {name = "Gruppe", feed = true, paginate_by = 10 } + { name = "Serie", feed = true, paginate_by = 10 }, + { name = "Typ", feed = true, paginate_by = 10 }, + { name = "Gruppe", feed = true, paginate_by = 10 } ] [link_checker] @@ -50,6 +50,10 @@ all = "Alle" images = "Bilder" arrival = "Anreise" +closed = "Geschlossen" +closing = "Schließt bald" +open = "Geöffnet" + [extra] ifs_base_path = "https://www.mainframe.io/media/ifs-images" resource_base = "https://ktt-ol.github.io" @@ -63,6 +67,13 @@ bs_color_map = [ "light" ] +rooms = [ + { name = "space", title = { de = "Hackspace", en = "Hackspace" } }, + { name = "machining", title = { de = "Zerspanungstechnik", en = "Machining" } }, + { name = "lab3d", title = { de = "3D Lab", en = "3D Lab" } }, + { name = "radstelle", title = { de = "Radstelle", en = "Cycling" } }, +] + [languages.en] title = "Kreativität trifft Technik e.V." description = "Website of Kreativität trifft Technik e.V." @@ -75,9 +86,9 @@ generate_feed = true feed_filename = "rss.xml" taxonomies = [ - {name = "Series", feed = true, paginate_by = 10 }, - {name = "Type", feed = true, paginate_by = 10 }, - {name = "Group", feed = true, paginate_by = 10 } + { name = "Series", feed = true, paginate_by = 10 }, + { name = "Type", feed = true, paginate_by = 10 }, + { name = "Group", feed = true, paginate_by = 10 } ] [languages.en.translations] @@ -90,5 +101,6 @@ all = "All" images = "Images" arrival = "Arrival" -status_finished = "Finished" -status_in_progress = "In Progress" +closed = "Closed" +closing = "Closing soon" +open = "Open" \ No newline at end of file diff --git a/sass/css/site.scss b/sass/css/site.scss index 397c000..1dd2533 100644 --- a/sass/css/site.scss +++ b/sass/css/site.scss @@ -8,14 +8,6 @@ body { margin: 0; } -.bg-dark-hover:hover { - background-color: rgba(var(--bs-danger-rgb), 0.9) !important; -} - -.bg-dark-hover { - background-color: rgba(var(--bs-danger-rgb), 1) !important; -} - @for $i from 1 through 6 { h#{$i} { color: var(--bs-primary); diff --git a/static/js/status.js b/static/js/status.js new file mode 100644 index 0000000..45e281b --- /dev/null +++ b/static/js/status.js @@ -0,0 +1,89 @@ +const ApiUrl = "https://status.kreativitaet-trifft-technik.de/api/openState"; + +const StateClosed = { + name: "closed", + color: "btn-danger" +}; + +const StateClosing = { + name: "closing", + color: "btn-warning" +}; + +const StateOpen = { + name: "open", + color: "btn-success" +}; + +const States = { + text_id_prefix: "status-text-", + button_id_prefix: "status-", + all_states: [ + StateClosed, + StateClosing, + StateOpen + ], + state_map: { + "none": StateClosed, + "closing": StateClosing, + "open": StateOpen, + "open+": StateOpen, + }, +}; + +/** + * @param {string} room_name + * @param {string} color + */ +function set_button_color(room_name, color) { + let id = States.button_id_prefix + room_name; + for (let state of States.all_states) { + document.getElementById(id).classList.remove(state.color); + } + document.getElementById(id).classList.add(color); +} + +/** + * @param {string} room_name + * @param {string} state_name + */ +function set_room_status(room_name, state_name) { + let state = States.state_map[state_name]; + if (state) { + let room = Rooms.find(r => r.name === room_name); + + if (room) { + for (let status of States.all_states) { + document.getElementById(`${States.text_id_prefix + status.name}-${room.name}`).classList.add("d-none"); + } + document.getElementById(`${States.text_id_prefix + state.name}-${room.name}`).classList.remove("d-none"); + set_button_color(room_name, state.color) + } else { + throw new Error(`Unknown room supplied: ${room_name}`) + } + } else { + throw new Error(`Unknown status option supplied: ${state_name}`) + } +} + +async function fetch_current_status() { + let currentStatus = await (await fetch(ApiUrl)).json(); + console.info("Processing current status information", currentStatus); + + for (let room_name in currentStatus) { + set_room_status(room_name, currentStatus[room_name].state); + } +} + +function set_all_rooms(state_name = "closed") { + if (!States.state_map[status]) { + throw new Error(`Unknown status option supplied: ${state_name}`) + } + + for (let room of Rooms) { + set_room_status(room.name, state_name); + } +} + +fetch_current_status(); +setInterval(fetch_current_status, 5000); \ No newline at end of file diff --git a/templates/sidebar.html b/templates/sidebar.html index 35ffdcc..b01d021 100644 --- a/templates/sidebar.html +++ b/templates/sidebar.html @@ -6,39 +6,35 @@
-
- - Hackspace: - Offen - Geschlossen - - - Zerspanungstechnik: - Offen - Geschlossen - - - 3D Lab: - Offen - Geschlossen - - - Radstelle: - Offen - Geschlossen - + + + + +
@@ -48,8 +44,8 @@
Termine
-
+
- \ No newline at end of file +