Added important admin frontend functions with error handling, the corresponding api endpoints, and the timer logic
This commit is contained in:
@@ -16,26 +16,35 @@ function print() {};
|
||||
|
||||
|
||||
function start() {
|
||||
if(isPaused == true)
|
||||
{
|
||||
isPaused = false
|
||||
if(isPaused == true && durationLeft.asSeconds() != 0) { // Only allow start if timer ist currently paused and durationLeft is not 0 seconds
|
||||
console.log("Timer gestartet")
|
||||
isPaused = false // Set status of the timer
|
||||
|
||||
timerInterval = setInterval(() => { // Create Intervalfunction every 1000ms
|
||||
durationLeft.subtract(1, 'second'); // Subtract a second from from the timer
|
||||
console.log(print()); // Print durationLeft
|
||||
io.sockets.emit('timerDurationLeft', print()) // Emit durationLeft to all connected sockets
|
||||
if(durationLeft.minutes() == 0 && durationLeft.seconds() == 0) // End timer if durationLeft == 00:00
|
||||
if(durationLeft.asSeconds() == 0) // End timer if durationLeft == 00:00
|
||||
end()
|
||||
durationLeft.subtract(1, 'second'); // Subtract a second from from the timer
|
||||
}, 1000);
|
||||
}
|
||||
return true
|
||||
} else
|
||||
return false
|
||||
}
|
||||
|
||||
function pause() {
|
||||
isPaused = true; // Set status of the timer
|
||||
clearInterval(timerInterval); // End the execution
|
||||
if(!isPaused) {
|
||||
console.log("Timer pausiert");
|
||||
isPaused = true; // Set status of the timer
|
||||
clearInterval(timerInterval); // End the execution
|
||||
return true
|
||||
} else
|
||||
return false
|
||||
}
|
||||
|
||||
function reset() {
|
||||
function reset(newDuration) {
|
||||
console.log("Timer Zurückgesetzt");
|
||||
duration = moment.duration(newDuration, 'seconds').clone(); // Set initial duration to received duration in seconds
|
||||
durationLeft = duration.clone(); // Set durationLeft to the initial duration
|
||||
io.sockets.emit('timerDurationLeft', print()) // Emit durationLeft to all connected sockets
|
||||
}
|
||||
@@ -46,8 +55,7 @@ function end() {
|
||||
io.sockets.emit('timerEnded', print()) // Emit end to all connected sockets
|
||||
}
|
||||
|
||||
function print()
|
||||
{
|
||||
function print() {
|
||||
var minutes = (durationLeft.minutes() < 10) ? "0" + durationLeft.minutes() : durationLeft.minutes(); // Create leading zeros for numbers <10
|
||||
var seconds = (durationLeft.seconds() < 10) ? "0" + durationLeft.seconds() : durationLeft.seconds(); // Create leading zeros for numbers <10
|
||||
return minutes + ":" + seconds
|
||||
|
||||
Reference in New Issue
Block a user