Added sideswitch functionality, cleanup, comments

This commit is contained in:
Julian Appel 2024-05-28 23:00:32 +02:00
parent 835248a9dc
commit ad6ab2ecab
5 changed files with 60 additions and 9 deletions

View File

@ -21,7 +21,7 @@ function configTeam(team, name, name2, isSpielgemeinschaft) {};
function setScore(team, score) {};
function alterScore(team, dir) {};
function clearScore() {};
function toggleSwitch() {};
function toggleSideSwitch() {};
function getEnabled() {};
function getValues() {};
@ -83,8 +83,11 @@ function clearScore() {
}
// Toggle sideswitch
function toggleSwitch() {
function toggleSideswitch() {
console.log("Seiten gewechselt");
sideswitch = !sideswitch;
io.sockets.emit('score', print());
io.sockets.emit('scoreSideswitch', '');
}
// Return enabled value
@ -92,6 +95,7 @@ function getEnabled() {
return enabled
}
// Print current score depending on sideswitch
function print() {
if(sideswitch) {
return teamB.score + ":" + teamA.score
@ -100,6 +104,7 @@ function print() {
}
}
// Return all important values
function getValues() {
return {
enabled: enabled,

View File

@ -68,7 +68,6 @@ async function initialUpdate() {
// Request monitor refresh for index frontend
async function refreshMonitor() {
const response = await fetch("/admin/refreshMonitor"); // Call API Endpoint /admin/timerStart
const data = await response.json(); // Wait for asyncronous transfer to complete
}
// ######################################################################################################################################################
@ -160,8 +159,8 @@ async function scoreAlterScore(team, dir) {
}
// Switch sides
async function scoreSwitch() {
const response = await fetch("/admin/scoreSwitch"); // Call API Endpoint /admin/scoreSwitch
async function scoreToggleSideswitch() {
const response = await fetch("/admin/scoreToggleSideswitch");// Call API Endpoint /admin/scoreSwitch
const data = await response.json(); // Wait for asyncronous transfer to complete
updateScoreFrontend(data); // Update admin frontend
}

View File

@ -27,6 +27,10 @@ socket.on('score', (message) => {
document.getElementById("score").innerHTML = message; // Display score in corresponding html Element
});
socket.on('scoreSideswitch', (message) => {
scoreGetValues(); // Update frontend when sides have been switch (switches team name sides)
});
// ######################################################################################################################################################
// General functions
// ######################################################################################################################################################

View File

@ -93,7 +93,10 @@ router.post('/scoreAlterScore', function(req, res, next) {
});
// Express router endpoint to switch the score after halftime
router.post('/scoreSwitch', function(req, res, next) {
router.get('/scoreToggleSideswitch', function(req, res, next) {
score.toggleSideswitch();
res.status(200);
res.json(score.getValues());
});
// Express router endpoint to get important score values

View File

@ -93,8 +93,8 @@
<div class="col-sm-12 col-md-12 col-lg-4">
<div class="h-100 card text-center">
<div class="card-body">
<button class="mb-2 btn btn-lg btn-danger" onclick="scoreSwitch()"><i class="fa-solid fa-rotate"></i> Seitenwechsel</button>
<button class="mb-2 btn btn-lg btn-danger" onclick="scoreClearScore()"><i class="fa-solid fa-rotate"></i> Score löschen</button>
<button class="mb-2 btn btn-lg btn-danger" data-bs-toggle="modal" data-bs-target="#scoreSwitchModal"><i class="fa-solid fa-rotate"></i> Seitenwechsel</button>
<button class="mb-2 btn btn-lg btn-danger" data-bs-toggle="modal" data-bs-target="#scoreResetModal"><i class="fa-solid fa-rotate-right"></i> Score zurücksetzen</button>
<button class="mb-2 btn btn-lg btn-danger" data-bs-toggle="modal" data-bs-target="#scoreConfigTeamsModal">Teams konfigurieren</button>
</div>
</div>
@ -188,6 +188,46 @@
</div>
<!-- Modal -->
<!-- Score switch Modal -->
<div class="modal fade" id="scoreSwitchModal" tabindex="-1" aria-labelledby="scoreSwitchModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="scoreSwitchModalLabel">Seiten wechseln?</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Möchtest du die Seiten für den Score wirklich wechseln?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="scoreToggleSideswitch()">Seitenwechsel</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Schließen</button>
</div>
</div>
</div>
</div>
<!-- Score switch Modal -->
<!-- Score reset Modal -->
<div class="modal fade" id="scoreResetModal" tabindex="-1" aria-labelledby="scoreResetModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h1 class="modal-title fs-5" id="scoreResetModalLabel">Score zurücksetzen?</h1>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>Möchtest du den Score wirklich zurücksetzen?</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-bs-dismiss="modal" onclick="scoreClearScore()">Zurücksetzen</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Schließen</button>
</div>
</div>
</div>
</div>
<!-- Score reset Modal -->
<!-- Config Team Modal -->
<div class="modal fade" id="scoreConfigTeamsModal" tabindex="-1" aria-labelledby="scoreConfigTeamsModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered">