diff --git a/scoreboard/public/javascripts/admin.js b/scoreboard/public/javascripts/admin.js index 94882a6..45e0008 100644 --- a/scoreboard/public/javascripts/admin.js +++ b/scoreboard/public/javascripts/admin.js @@ -30,10 +30,11 @@ function updateFrontend(values) { } async function initialUpdate() { - const response = await fetch("/admin/timerGetValues"); // Call API Endpoint /admin/timerGetValues - 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 +// 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 and parse json (which got received by backend) + console.log("Send request to refresh the monitor"); } // Timerfunctions diff --git a/scoreboard/public/javascripts/index.js b/scoreboard/public/javascripts/index.js index 8d0cd74..ceb5fc6 100644 --- a/scoreboard/public/javascripts/index.js +++ b/scoreboard/public/javascripts/index.js @@ -12,4 +12,8 @@ socket.on('timerDurationLeft', (message) => { socket.on('timerEnded', (message) => { document.getElementById("durationLeft").innerHTML = "ENDE"; // Display "STOP" in same html element as the duration +}); + +socket.on('refresh', (message) => { + document.location.reload() // Reload page on received 'refresh' messagen }); \ No newline at end of file diff --git a/scoreboard/public/javascripts/indexScore.js b/scoreboard/public/javascripts/indexScore.js new file mode 100644 index 0000000..8a9a6b1 --- /dev/null +++ b/scoreboard/public/javascripts/indexScore.js @@ -0,0 +1,41 @@ +let wss = "ws://" + window.location.hostname + ":3001" // Build socketio endpoint from window.location +const socket = io(wss); // Connect to socketio server + +socket.on('connected', (message) => { + console.log("Connected"); +}) + +socket.on('timerDurationLeft', (message) => { + console.log(message) // Log durationLeft in client console + document.getElementById("durationLeft").innerHTML = message; // Display durationLeft in corresponding html Element +}); + +socket.on('timerEnded', (message) => { + document.getElementById("durationLeft").innerHTML = "ENDE"; // Display "STOP" in same html element as the duration +}); + +socket.on('refresh', (message) => { + document.location.reload() // Reload page on received 'refresh' messagen +}); + +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 score elements from passed values +function updateScoreFrontend(values) { + document.getElementById("score").innerHTML = values.print; // Set switch status to received score enabled value +} + +async function initialUpdate() { + scoreGetValues(); +} + +// 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 +} \ No newline at end of file diff --git a/scoreboard/public/stylesheets/index.css b/scoreboard/public/stylesheets/index.css index 05bf585..0392ebc 100644 --- a/scoreboard/public/stylesheets/index.css +++ b/scoreboard/public/stylesheets/index.css @@ -1,55 +1,41 @@ html, body { - height: 100% -} - -body { - /* padding: 50px; */ - font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; - background-color: #47BAEA; -} - -a { - color: #00B7FF; -} - -.durationLeft { - font-family: 'Seven Segment', sans-serif; - font-weight: bold; - height: 100%; - font-size: 50vh; + height: 100% + } -} - -.score { - font-family: 'Seven Segment', sans-serif; - font-weight: bold; - font-size: 50vh -} - -@media ( min-width: 768px ) { - .box-time { - height:25% + body { + /* padding: 50px; */ + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; + background-color: #47BAEA; } - + + a { + color: #00B7FF; + } + .durationLeft { - font-size: 18vh + font-family: 'Seven Segment', sans-serif; + font-weight: bold; + height: 100%; + font-size: 100vh; + } - .box-etc { - height: 75% - } -} - -@media ( min-width: 992px ) { - .box-time { - height:50% - } - - .durationLeft { - font-size: 48vh - } - - .box-etc { - height: 50% - } -} \ No newline at end of file + + @media ( min-width: 768px ) { + .box-time { + height:100% + } + + .durationLeft { + font-size: 15vh + } + + @media ( min-width: 992px ) { + .box-time { + height:100% + } + + .durationLeft { + font-size: 96vh + } + } \ No newline at end of file diff --git a/scoreboard/public/stylesheets/indexScore.css b/scoreboard/public/stylesheets/indexScore.css new file mode 100644 index 0000000..05bf585 --- /dev/null +++ b/scoreboard/public/stylesheets/indexScore.css @@ -0,0 +1,55 @@ +html, body { + height: 100% +} + +body { + /* padding: 50px; */ + font: 14px "Lucida Grande", Helvetica, Arial, sans-serif; + background-color: #47BAEA; +} + +a { + color: #00B7FF; +} + +.durationLeft { + font-family: 'Seven Segment', sans-serif; + font-weight: bold; + height: 100%; + font-size: 50vh; + +} + +.score { + font-family: 'Seven Segment', sans-serif; + font-weight: bold; + font-size: 50vh +} + +@media ( min-width: 768px ) { + .box-time { + height:25% + } + + .durationLeft { + font-size: 18vh + } + + .box-etc { + height: 75% + } +} + +@media ( min-width: 992px ) { + .box-time { + height:50% + } + + .durationLeft { + font-size: 48vh + } + + .box-etc { + height: 50% + } +} \ No newline at end of file diff --git a/scoreboard/routes/admin.js b/scoreboard/routes/admin.js index 99dcb74..766ddab 100644 --- a/scoreboard/routes/admin.js +++ b/scoreboard/routes/admin.js @@ -1,7 +1,13 @@ var express = require('express'); var router = express.Router(); - -var timer = require('../controllers/timer'); +const io = require('../controllers/socketio'); +// Express router endpoint to trigger a frontend refresh on all connected sockets +router.get('/refreshMonitor', function(req, res, next) { + console.log("Monitor neu geladen"); + io.sockets.emit('refresh', ""); // Emit refresh to all connected sockets over websockets + res.status(200); // Set http status code to 200 (success) + res.send(); // send empty response +}); // Express router entpoint to start the timer router.get('/timerStart', function(req, res, next) { diff --git a/scoreboard/routes/index.js b/scoreboard/routes/index.js index f5dde8d..afbd165 100644 --- a/scoreboard/routes/index.js +++ b/scoreboard/routes/index.js @@ -1,11 +1,19 @@ var express = require('express'); var router = express.Router(); -let io = require('../controllers/socketio') -const timer = require('../controllers/timer') +let io = require('../controllers/socketio'); +const timer = require('../controllers/timer'); +const score = require('../controllers/score'); /* GET home page. */ router.get('/', function(req, res, next) { - res.render('index', { durationLeft: timer.print()}); + if (score.getEnabled()) { // If scoreboard is enabled + res.render('indexScore', { + title: "Timer and Score", + durationLeft: timer.print(), + }); + } else { // If scoreboard is not enabled + res.render('index', { title: "Timer", durationLeft: timer.print()}) + } }); io.on('connection', (socket) => { diff --git a/scoreboard/views/index.hbs b/scoreboard/views/index.hbs index 60af383..d435bc7 100644 --- a/scoreboard/views/index.hbs +++ b/scoreboard/views/index.hbs @@ -1,7 +1,7 @@
-