Added db with team selection, scoreboard enabled by default, Added Debugwindow, cleanup

This commit is contained in:
2024-06-02 22:30:39 +02:00
parent 1d632252bf
commit 8f402058ad
8 changed files with 279 additions and 24 deletions
+97
View File
@@ -59,10 +59,72 @@ function updateScoreFrontend(values) {
document.getElementById("teamBisSpielgemeinschaft").checked = values.teamB.isSpielgemeinschaft;
}
// Update DOM for all db contents with the passed values
function updateDbFrontend(values) {
console.log(values);
let teamAnameDropdown = document.getElementById("teamAnameDropdown"); // Dropdown for TeamA name
let teamAname2Dropdown = document.getElementById("teamAname2Dropdown"); // Dropdown for TeamA name2
let teamBnameDropdown = document.getElementById("teamBnameDropdown"); // Dropdown for TeamB name
let teamBname2Dropdown = document.getElementById("teamBname2Dropdown"); // Dropdown for TeamB name2
// Clear innerHTML of dropdowns
teamAnameDropdown.innerHTML = "";
teamAname2Dropdown.innerHTML = "";
teamBnameDropdown.innerHTML = "";
teamBname2Dropdown.innerHTML = "";
let selectDelete = document.getElementById("dbTeamToDelete"); // Select for team deletion from db
selectDelete.innerHTML = "" // Clears all existing options from select
// <li><a class="dropdown-item" onclick="scoreInsertChosenName">Action</a></li>
for(team of values.teams) {
// Create custom Dropdowns with different function arguments for team configuration
var li = document.createElement("li");
li.innerHTML = `<a class="dropdown-item" onclick="scoreInsertChosenName('teamAname','` + team +`')"> `+ team +`</a>`;
teamAnameDropdown.appendChild(li);
var li = document.createElement("li");
li.innerHTML = `<a class="dropdown-item" onclick="scoreInsertChosenName('teamAname2','` + team +`')"> `+ team +`</a>`;
teamAname2Dropdown.appendChild(li);
var li = document.createElement("li");
li.innerHTML = `<a class="dropdown-item" onclick="scoreInsertChosenName('teamBname','` + team +`')"> `+ team +`</a>`;
teamBnameDropdown.appendChild(li);
var li = document.createElement("li");
li.innerHTML = `<a class="dropdown-item" onclick="scoreInsertChosenName('teamBname2','` + team +`')"> `+ team +`</a>`;
teamBname2Dropdown.appendChild(li);
// Create select options for deletion in debugwindow
let opt = document.createElement("option");
opt.value = team;
opt.innerHTML = team;
selectDelete.appendChild(opt);
}
}
// Inserts the passed name into the passed name text input
async function scoreInsertChosenName(field, name) {
switch(field) {
case 'teamAname':
document.getElementById("teamAname").value = name;
break;
case 'teamAname2':
document.getElementById("teamAname2").value = name;
break;
case 'teamBname':
document.getElementById("teamBname").value = name;
break;
case 'teamBname2':
document.getElementById("teamBname2").value = name;
break;
}
}
// 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
@@ -194,4 +256,39 @@ async function scoreConfigTeams() {
const data = await response.json(); // Wait for asyncronous transfer to complete
updateScoreFrontend(data); // Update admin frontend
refreshMonitor();
}
// ######################################################################################################################################################
// DB functions
// ######################################################################################################################################################
// Request important values for db contents
async function dbGetValues() {
const response = await fetch("/admin/dbGetValues"); // Call API Endpoint /admin/dbGetValues
const data = await response.json(); // Wait for asynchronous transfer to complete
updateDbFrontend(data); // Update admin frontend
}
// Add team to DB
async function dbAddTeam() {
const response = await fetch("/admin/dbAddTeam", { // 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({teamName: document.getElementById("dbTeamToAdd").value})
});
document.getElementById("dbTeamToAdd").value = ""; // Empty the text field after sending
const data = await response.json(); // Wait for asyncronous transfer to complete
updateDbFrontend(data);
}
// Delete team from DB
async function dbDeleteTeam() {
let teamName = document.getElementById("dbTeamToDelete").value;
const response = await fetch("/admin/dbDeleteTeam", { // 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({teamName: teamName})
});
const data = await response.json(); // Wait for asyncronous transfer to complete
updateDbFrontend(data);
}