+
+ for(team of values.teams) {
+ // Create custom Dropdowns with different function arguments for team configuration
+ var li = document.createElement("li");
+ li.innerHTML = ` `+ team +``;
+ teamAnameDropdown.appendChild(li);
+ var li = document.createElement("li");
+ li.innerHTML = ` `+ team +``;
+ teamAname2Dropdown.appendChild(li);
+ var li = document.createElement("li");
+ li.innerHTML = ` `+ team +``;
+ teamBnameDropdown.appendChild(li);
+ var li = document.createElement("li");
+ li.innerHTML = ` `+ team +``;
+ 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);
}
\ No newline at end of file
diff --git a/scoreboard/routes/admin.js b/scoreboard/routes/admin.js
index 595bb4e..fbdea15 100644
--- a/scoreboard/routes/admin.js
+++ b/scoreboard/routes/admin.js
@@ -4,6 +4,7 @@ const io = require('../controllers/socketio');
const timer = require('../controllers/timer');
const score = require('../controllers/score');
+const db = require('../controllers/db');
// ######################################################################################################################################################
// General endpoints
@@ -123,6 +124,27 @@ router.post('/scoreConfigTeams', function(req, res, next) {
res.json(score.getValues());
});
+// ######################################################################################################################################################
+// DB endpoints
+// ######################################################################################################################################################
+
+// Express router endpoint to get important values for db contents
+router.get('/dbGetValues', function(req, res, next) {
+ res.json(db.getValues()); // Respond with important values for frontend
+});
+
+// Express router endpoint to add a team to the team database
+router.post('/dbAddTeam', function(req, res, next) {
+ db.addTeam(req.body.teamName); // Add teamname to DB
+ res.json(db.getValues()); // Respond with all important values to update the frontend
+});
+
+// Express router endpoint to delete a team from the team database
+router.post('/dbDeleteTeam', function(req, res, next) {
+ db.deleteTeam(req.body.teamName); // Add teamname to DB
+ res.json(db.getValues()); // Respond with all important values to update the frontend
+});
+
/* GET home page. */
router.get('/', function(req, res, next) {
res.render('admin');
diff --git a/scoreboard/views/admin.hbs b/scoreboard/views/admin.hbs
index 781588c..d692dce 100644
--- a/scoreboard/views/admin.hbs
+++ b/scoreboard/views/admin.hbs
@@ -93,9 +93,9 @@