Added refernce mirrored to mirror team position when sitting behind the main monitor

This commit is contained in:
2024-06-06 21:56:54 +02:00
parent c0ffac18e4
commit a27c38eeb3
4 changed files with 107 additions and 30 deletions
+51 -11
View File
@@ -20,12 +20,22 @@ socket.on('timerEnded', (message) => {
socket.on('score', (message) => {
console.log(message); // Log score in client console
document.getElementById("score").innerHTML = message; // Display score in corresponding html Element
scoreGetValues();
// document.getElementById("score").innerHTML = message; // Display score in corresponding html Element
});
// ######################################################################################################################################################
// General functions
// ######################################################################################################################################################
// Initial update gets called whenever page has been loaded
async function initialUpdate() {
etcGetValues(); // Request new values for etc stuff
timerGetValues(); // Request new values for timer
scoreGetValues(); // Request new values for score
dbGetValues(); // Request new values for db contents
}
// Update DOM timer elements from passed values
function updateEtcFrontend(values) {
console.log(values);
@@ -48,13 +58,22 @@ function updateTimerFrontend(values) {
}
}
// Build colname to show Teams on Adminpanel based on isSpielgemeinschaft
function buildColFromIsSpielgemeinschaft(team) {
if(team.isSpielgemeinschaft) {
return team.name + "<br>" + team.name2;
} else {
return team.name + "<br>&nbsp;";
}
}
// Update DOM score elements from passed values
function updateScoreFrontend(values) {
console.log(values); // Print received data
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
document.getElementById("scoreSwitchReferenceMirrored").checked = values.referenceMirrored; // Set switch status to received score enabled value
// Input current Team values into form inputs
// Config Teams - Input current teams into text fields
document.getElementById("teamAname").value = values.teamA.name;
document.getElementById("teamAname2").value = values.teamA.name2;
document.getElementById("teamAisSpielgemeinschaft").checked = values.teamA.isSpielgemeinschaft;
@@ -62,6 +81,27 @@ function updateScoreFrontend(values) {
document.getElementById("teamBname").value = values.teamB.name;
document.getElementById("teamBname2").value = values.teamB.name2;
document.getElementById("teamBisSpielgemeinschaft").checked = values.teamB.isSpielgemeinschaft;
// Show current Teams on admin panel
if(!values.referenceMirrored && !values.sideswitch || values.referenceMirrored && values.sideswitch) { // If not mirrored on adminpanel, show like main frontend while considering sideswitch state
document.getElementById("score").innerHTML = values.teamA.score + ':' + values.teamB.score;
document.getElementById("teamAcolName").innerHTML = buildColFromIsSpielgemeinschaft(values.teamA);
document.getElementById("teamBcolName").innerHTML = buildColFromIsSpielgemeinschaft(values.teamB);
document.getElementById("teamAinc").setAttribute("onclick", "scoreAlterScore('teamA', 'inc')");
document.getElementById("teamAdec").setAttribute("onclick", "scoreAlterScore('teamA', 'dec')");
document.getElementById("teamBinc").setAttribute("onclick", "scoreAlterScore('teamB', 'inc')");
document.getElementById("teamBdec").setAttribute("onclick", "scoreAlterScore('teamB', 'dec')");
} else if(!values.referenceMirrored && values.sideswitch || values.referenceMirrored && !values.sideswitch) { // Else, swap posistions
document.getElementById("score").innerHTML = values.teamB.score + ':' + values.teamA.score;
document.getElementById("teamAcolName").innerHTML = buildColFromIsSpielgemeinschaft(values.teamB);
document.getElementById("teamBcolName").innerHTML = buildColFromIsSpielgemeinschaft(values.teamA);
document.getElementById("teamAinc").setAttribute("onclick", "scoreAlterScore('teamB', 'inc')");
document.getElementById("teamAdec").setAttribute("onclick", "scoreAlterScore('teamB', 'dec')");
document.getElementById("teamBinc").setAttribute("onclick", "scoreAlterScore('teamA', 'inc')");
document.getElementById("teamBdec").setAttribute("onclick", "scoreAlterScore('teamA', 'dec')");
}
}
// Update DOM for all db contents with the passed values
@@ -125,20 +165,13 @@ async function scoreInsertChosenName(field, name) {
}
}
// Initial update gets called whenever page has been loaded
async function initialUpdate() {
timerGetValues(); // Request new values for timer
scoreGetValues(); // Request new values for score
dbGetValues(); // Request new values for db contents
}
// Request monitor refresh for index frontend
async function refreshMonitor() {
const response = await fetch("/admin/refreshMonitor"); // Call API Endpoint /admin/timerStart
}
async function openBrowser() {
const response = await fetch("/admin/openBrowser"); // Call API Endpoint /admin/openBrowser
const response = await fetch("/admin/openBrowser"); // Call API Endpoint /admin/openBrowser
}
async function killBrowser() {
@@ -259,6 +292,13 @@ async function scoreToggleSideswitch() {
updateScoreFrontend(data); // Update admin frontend
}
// Switch sides to mirror admin panel when sitting behind main monitor
async function scoreToggleReferenceMirrored() {
const response = await fetch("/admin/scoreToggleReferenceMirrored");// Call API Endpoint /admin/scoreSwitch
const data = await response.json(); // Wait for asyncronous transfer to complete
updateScoreFrontend(data); // Update admin frontend
}
// Clear score
async function scoreClearScore() {
const response = await fetch("/admin/scoreClearScore"); // Call API Endpoint /admin/scoreClearScore