-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
edit(turnout/opening-status): change styling of turnout and opening-s…
…tatus pages.
- Loading branch information
1 parent
0b813a8
commit e389a30
Showing
5 changed files
with
252 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,63 @@ | ||
const registerForm = document.getElementById('registerForm'); | ||
const nameInput = document.getElementById('nameInput'); | ||
const occupantsList = document.getElementById('occupantsList'); | ||
|
||
function updateOccupantsList() { | ||
fetch('https://d1s96qvov1.execute-api.eu-north-1.amazonaws.com/dev/people/status') | ||
.then(response => response.json()) | ||
.then(data => { | ||
occupantsList.innerHTML = ''; // Clear the list first | ||
data.occupants.forEach(name => { | ||
const listItem = document.createElement('li'); | ||
listItem.textContent = name; | ||
|
||
const unregisterButton = document.createElement('button'); | ||
unregisterButton.textContent = 'Unregister'; | ||
unregisterButton.classList.add('unregister-button'); | ||
unregisterButton.onclick = () => unregister(name); | ||
|
||
listItem.appendChild(unregisterButton); | ||
occupantsList.appendChild(listItem); | ||
}); | ||
}); | ||
} | ||
|
||
registerForm.onsubmit = function(event) { | ||
event.preventDefault(); | ||
const name = nameInput.value; | ||
|
||
fetch('https://d1s96qvov1.execute-api.eu-north-1.amazonaws.com/dev/people/register', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ name: name }), | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.status === "registered") { | ||
nameInput.value = ''; // Clear the input field | ||
updateOccupantsList(); // Refresh the occupants list | ||
document.addEventListener("DOMContentLoaded", function () { | ||
const apiUrl = "https://d1s96qvov1.execute-api.eu-north-1.amazonaws.com/dev/people"; | ||
const registerForm = document.getElementById("registerForm"); | ||
const nameInput = document.getElementById("nameInput"); | ||
const occupantsList = document.getElementById("occupantsList"); | ||
|
||
// Fetch and display the current occupants | ||
function fetchOccupants() { | ||
fetch(`${apiUrl}/status`) | ||
.then(response => response.json()) | ||
.then(data => { | ||
occupantsList.innerHTML = ""; // Clear the list | ||
if (data.occupants && data.occupants.length > 0) { | ||
data.occupants.forEach(person => { | ||
const listItem = document.createElement("li"); | ||
listItem.textContent = person; | ||
const unregisterButton = document.createElement("button"); | ||
unregisterButton.textContent = "Rimuovi"; | ||
unregisterButton.className = "unregister-button"; | ||
unregisterButton.addEventListener("click", () => unregisterPerson(person)); | ||
listItem.appendChild(unregisterButton); | ||
occupantsList.appendChild(listItem); | ||
}); | ||
} else { | ||
occupantsList.innerHTML = "<li>Nessuno è in aula in questo momento.</li>"; | ||
} | ||
}); | ||
}; | ||
}) | ||
.catch(error => console.error("Error fetching occupants:", error)); | ||
} | ||
|
||
function unregister(name) { | ||
fetch('https://d1s96qvov1.execute-api.eu-north-1.amazonaws.com/dev/people/unregister', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ name: name }), | ||
// Register a new person | ||
registerForm.addEventListener("submit", function (event) { | ||
event.preventDefault(); | ||
const name = nameInput.value.trim(); | ||
if (name) { | ||
fetch(`${apiUrl}/register`, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ name }) | ||
}) | ||
.then(() => { | ||
nameInput.value = ""; | ||
fetchOccupants(); | ||
}) | ||
.catch(error => console.error("Error registering person:", error)); | ||
} | ||
}); | ||
|
||
// Unregister a person | ||
function unregisterPerson(name) { | ||
fetch(`${apiUrl}/unregister`, { | ||
method: "POST", | ||
headers: { "Content-Type": "application/json" }, | ||
body: JSON.stringify({ name }) | ||
}) | ||
.then(response => response.json()) | ||
.then(data => { | ||
if (data.status === "unregistered") { | ||
updateOccupantsList(); // Refresh the occupants list | ||
} | ||
}); | ||
} | ||
|
||
updateOccupantsList(); | ||
setInterval(updateOccupantsList, 20000); // Update every 20 seconds | ||
|
||
.then(() => fetchOccupants()) | ||
.catch(error => console.error("Error unregistering person:", error)); | ||
} | ||
|
||
// Fetch occupants initially and at intervals | ||
fetchOccupants(); | ||
setInterval(fetchOccupants, 30000); // Refresh every 30 seconds | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.