Added important admin frontend functions with error handling, the corresponding api endpoints, and the timer logic
This commit is contained in:
@@ -1,11 +1,66 @@
|
||||
function updateFrontend(values) {
|
||||
values.duration = moment.duration(values.duration) // Create moment object from ISO 8601 string
|
||||
values.durationLeft = moment.duration(values.durationLeft) // Create moment object from ISO 8601 string
|
||||
document.getElementById("durationLeft").innerHTML = values.print // Display durationLeft as prettyfied string
|
||||
|
||||
function timerStart()
|
||||
{
|
||||
fetch("/admin/timerStart", {
|
||||
method: "POST",
|
||||
headers: {'Content-Type': 'text/html'},
|
||||
body: ""
|
||||
}).then(res => {
|
||||
console.log(res);
|
||||
})
|
||||
if(values.isPaused) { // Set button state depending on timer status
|
||||
document.getElementById("timerStartBtn").disabled = false
|
||||
document.getElementById("timerPauseBtn").disabled = true
|
||||
} else {
|
||||
document.getElementById("timerStartBtn").disabled = true
|
||||
document.getElementById("timerPauseBtn").disabled = false
|
||||
}
|
||||
}
|
||||
|
||||
async function initialUpdate() {
|
||||
const response = await fetch("/admin/timerGetValues"); // Call API Endpoint /admin/timerGetValues
|
||||
const data = await response.json(); // Wait for asyncronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateFrontend(data); // Update admin frontend with received values
|
||||
}
|
||||
|
||||
// Timerfunctions
|
||||
async function timerStart() {
|
||||
const response = await fetch("/admin/timerStart"); // Call API Endpoint /admin/timerStart
|
||||
if(response.status == 200) {
|
||||
const data = await response.json(); // Wait for asyncronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateFrontend(data); // Update admin frontend with received values
|
||||
} else {
|
||||
//console.log("Error, Timer bereits abgelaufen: ", response.status);
|
||||
const timerStartErrorToast = bootstrap.Toast.getOrCreateInstance(document.getElementById("timerStartErrorToast")); // Create toast instance byId timerStartErrorToast
|
||||
timerStartErrorToast.show(); // Show error toast
|
||||
}
|
||||
}
|
||||
|
||||
async function timerPause() {
|
||||
const response = await fetch("/admin/timerPause"); // Call API Endpoint /admin/timerStart
|
||||
if(response.status == 200) {
|
||||
const data = await response.json(); // Wait for asyncronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateFrontend(data); // Update admin frontend with received values
|
||||
} else {
|
||||
//console.log("Error, Timer bereits pausiert: ", response.status);
|
||||
const timerPauseErrorToast = bootstrap.Toast.getOrCreateInstance(document.getElementById("timerPauseErrorToast")); // Create toast instance byId timerStartErrorToast
|
||||
timerPauseErrorToast.show(); // Show error toast
|
||||
}
|
||||
}
|
||||
|
||||
async function timerReset() {
|
||||
let newDuration = document.getElementById("timerSelectDuration").value;
|
||||
const response = await fetch("/admin/timerReset", { // Call API Endpoint /admin/timerStart with selected new duration in seconds
|
||||
method: 'POST',
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({duration: newDuration})
|
||||
});
|
||||
const data = await response.json(); // Wait for asyncronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateFrontend(data); // Update admin frontend with received values
|
||||
}
|
||||
|
||||
// Scoreboardfunctions
|
||||
async function scoreSwitch() {
|
||||
const response = await fetch("/admin/scoreSwitch"); // Call API Endpoint /admin/timerStart
|
||||
const data = await response.json(); // Wait for asyncronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
}
|
||||
Reference in New Issue
Block a user