Added scoreboard functionality, seperate update admin frontend
This commit is contained in:
@@ -15,7 +15,13 @@ socket.on('timerEnded', (message) => {
|
||||
initialUpdate(); // Update admin frontend to set correct buttonstatus
|
||||
});
|
||||
|
||||
function updateFrontend(values) {
|
||||
socket.on('score', (message) => {
|
||||
console.log(message) // Log score in client console
|
||||
document.getElementById("score").innerHTML = message; // Display score in corresponding html Element
|
||||
});
|
||||
|
||||
// Update DOM timer elements from passed values
|
||||
function updateTimerFrontend(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
|
||||
@@ -29,7 +35,18 @@ function updateFrontend(values) {
|
||||
}
|
||||
}
|
||||
|
||||
// Update DOM score elements from passed values
|
||||
function updateScoreFrontend(values) {
|
||||
document.getElementById("scoreSwitchEnable").checked = values.enabled; // Set switch status to received score enabled value
|
||||
document.getElementById("score").innerHTML = values.print // Set score on admin interface
|
||||
}
|
||||
|
||||
// Initial update gets called whenever page has been loaded
|
||||
async function initialUpdate() {
|
||||
timerGetValues(); // Request new values for timer
|
||||
scoreGetValues(); // Request new values for score
|
||||
}
|
||||
|
||||
// Request monitor refresh for index frontend
|
||||
async function refreshMonitor() {
|
||||
const response = await fetch("/admin/refreshMonitor"); // Call API Endpoint /admin/timerStart
|
||||
@@ -38,12 +55,21 @@ async function refreshMonitor() {
|
||||
}
|
||||
|
||||
// Timerfunctions
|
||||
// Request important timer values
|
||||
async function timerGetValues() {
|
||||
const response = await fetch("/admin/timerGetValues"); // Call API Endpoint /admin/timerGetValues
|
||||
const data = await response.json(); // Wait for asynchronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateTimerFrontend(data); // Update admin frontend with received values for timerboard
|
||||
}
|
||||
|
||||
// Request to start the timer
|
||||
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
|
||||
const response = await fetch("/admin/timerStart"); // Call API Endpoint /admin/timerStart
|
||||
if(response.status == 200) { // If request successfull
|
||||
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
|
||||
updateTimerFrontend(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
|
||||
@@ -57,7 +83,7 @@ async function timerPause() {
|
||||
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
|
||||
updateTimerFrontend(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
|
||||
@@ -91,8 +117,49 @@ async function timerIncDec(value) {
|
||||
}
|
||||
|
||||
// Scoreboardfunctions
|
||||
// Request important values for score
|
||||
async function scoreGetValues() {
|
||||
const response = await fetch("/admin/scoreGetValues"); // Call API Endpoint /admin/scoreGetValues
|
||||
const data = await response.json(); // Wait for asynchronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateScoreFrontend(data); // Update admin frontend with received values for scoreboard
|
||||
}
|
||||
|
||||
// Toggle index page to also show scoreboard
|
||||
async function scoreToggle() {
|
||||
console.log(document.getElementById("scoreSwitchEnable").checked)
|
||||
const response = await fetch("/admin/scoreToggle"); // Call API Endpoint /admin/scoreEnable
|
||||
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
|
||||
updateScoreFrontend(data); // Update admin frontend with received values for scoreboard
|
||||
refreshMonitor(); // Send request to refresh monitor
|
||||
}
|
||||
|
||||
// Alter the score of passed team in the specified direction
|
||||
async function scoreAlterScore(team, dir) {
|
||||
const response = await fetch("/admin/scoreAlterScore", {// Call API Endpoint /admin/scoreAlterScore with the teamname to alter the score in the specified direction
|
||||
method: 'POST',
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({team: team, dir: dir})
|
||||
});
|
||||
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
|
||||
updateScoreFrontend(data); // Update admin frontend with received values
|
||||
}
|
||||
|
||||
// Switch sides
|
||||
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
|
||||
}
|
||||
updateScoreFrontend(data); // Update admin frontend with received values for scoreboard
|
||||
}
|
||||
|
||||
// Clear score
|
||||
async function scoreClearScore() {
|
||||
const response = await fetch("/admin/scoreClearScore"); // Call API Endpoint /admin/scoreResetScore
|
||||
const data = await response.json(); // Wait for asynchronous transfer to complete and parse json (which got received by backend)
|
||||
console.log(data); // Print received data
|
||||
updateScoreFrontend(data); // Update admin frontend with received values for scoreboard
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user