Skip to content

Commit

Permalink
First Iteration Space Status
Browse files Browse the repository at this point in the history
  • Loading branch information
lordiii committed Apr 30, 2024
1 parent 9dbdefd commit f0e03eb
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 51 deletions.
28 changes: 20 additions & 8 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand All @@ -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."
Expand All @@ -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]
Expand All @@ -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"
8 changes: 0 additions & 8 deletions sass/css/site.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
89 changes: 89 additions & 0 deletions static/js/status.js
Original file line number Diff line number Diff line change
@@ -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);
66 changes: 31 additions & 35 deletions templates/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,35 @@ <h5 class="border-secondary border-bottom">
</a>
</h5>

<div>
<a role="button" id="status-hackspace"
class="text-decoration-none link-dark d-flex px-2 justify-content-between bg-dark-hover"
style="margin-bottom: 1px"
href="//status.kreativitaet-trifft-technik.de">
<span>Hackspace:</span>
<span id="status-text-hackspace-open" class="d-none">Offen</span>
<span id="status-text-hackspace-closed" class="d-inline">Geschlossen</span>
</a>
<a role="button" id="status-machining"
class="text-decoration-none link-dark d-flex px-2 justify-content-between bg-dark-hover"
style="margin-bottom: 1px"
href="//status.kreativitaet-trifft-technik.de">
<span>Zerspanungstechnik:</span>
<span id="status-text-machining-open" class="d-none">Offen</span>
<span id="status-text-machining-closed" class="d-inline">Geschlossen</span>
</a>
<a role="button" id="status-3dlab"
class="text-decoration-none link-dark d-flex px-2 justify-content-between bg-dark-hover"
style="margin-bottom: 1px"
href="//status.kreativitaet-trifft-technik.de">
<span>3D Lab:</span>
<span id="status-text-3dlab-open" class="d-none">Offen</span>
<span id="status-text-3dlab-closed" class="d-inline">Geschlossen</span>
</a>
<a role="button" id="status-bike"
class="text-decoration-none link-dark d-flex px-2 justify-content-between bg-dark-hover"
style="margin-bottom: 1px"
href="//status.kreativitaet-trifft-technik.de">
<span>Radstelle:</span>
<span id="status-text-bike-open" class="d-none">Offen</span>
<span id="status-text-bike-closed" class="d-inline">Geschlossen</span>
</a>
<script>
const Rooms = {{ config.extra.rooms | json_encode | safe }};
</script>

<script src="{{ get_url(path="/js/status.js") }}"
integrity="sha384-{{ get_hash(path="/js/status.js", sha_type=384, base64=true) | safe }}"
defer="defer" async="async">
</script>

<div class="px-2" style="font-size: 0.9em">
{% for room in config.extra.rooms %}
<a role="button" id="status-{{ room.name }}"
class="px-1 d-flex flex-column text-decoration-none btn btn-danger rounded-0 text-dark"
style="margin-bottom: 1px; padding: 1px;"
href="//status.kreativitaet-trifft-technik.de">
<div class="text-start fw-bold lh-sm">
{{ room.title[lang] }}:
</div>
<div class="text-end lh-sm" id="status-text-closed-{{ room.name }}">
{{ trans(key="closed", lang=lang) }}
</div>
<div class="text-end lh-sm d-none" id="status-text-closing-{{ room.name }}">
{{ trans(key="closing", lang=lang) }}
</div>
<div class="text-end lh-sm d-none" id="status-text-open-{{ room.name }}">
{{ trans(key="open", lang=lang) }}
</div>
</a>
{% endfor %}
</div>
</div>

Expand All @@ -48,8 +44,8 @@ <h5 class="border-secondary border-bottom">
Termine
</a>
</h5>
<div>
<div class="px-2" style="font-size: 0.9em">
<!-- TODO: Calender -->
</div>
</div>
</div>
</div>

0 comments on commit f0e03eb

Please sign in to comment.