Files
2026-01-18 11:52:57 +00:00

228 lines
6.2 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Status Board</title>
<style>
/* CSS for styling */
body {
background-color: #121212;
color: #fff;
margin: 0;
font-family: 'Play', sans-serif;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
}
.badge-container {
display: flex;
flex-direction: column;
align-items: center;
margin: 0 20px; /* Adjust margin as needed */
}
.title {
font-size: 30px; /* Increased font size */
margin-bottom: 10px; /* Increased margin */
}
.divider {
width: 2px;
height: 50px; /* Increased height */
background-color: #777;
margin: 0 40px; /* Adjusted margin */
}
.date {
font-size: 45px; /* Increased font size */
margin-top: 30px; /* Increased margin */
}
.badge {
display: inline-block;
position: relative;
padding: 5px 10px;
font-size: 14px;
border-radius: 5px;
margin: 5px;
}
.online {
background-color: green;
color: white;
}
.offline {
background-color: red;
color: white;
}
.error {
background-color: orange;
color: white;
}
.clock {
font-size: 50px; /* Increased font size */
margin-top: 30px; /* Increased margin */
}
.timer {
position: fixed;
bottom: 10px; /* Adjust this value to set the distance from the bottom */
right: 10px; /* Adjust this value to set the distance from the right */
font-size: 12px;
color: gray;
}
/* Ensure dark mode */
@media (prefers-color-scheme: light) {
body {
background-color: #121212;
color: #fff;
}
.badge {
background-color: #444;
}
}
</style>
</head>
<body>
<div class="date" id="date"></div>
<p>
<div class="container">
<div class="badge-container">
<div id="pi4Badge" class="badge offline">Pi 4: Offline</div>
</div>
<div class="divider"></div>
<div class="badge-container">
<div id="pi5Badge" class="badge offline">Pi 5: Offline</div>
</div>
<div class="divider"></div>
<div class="badge-container">
<div id="pi0Badge" class="badge offline">Pi 0: Offline</div>
</div>
</div>
<div class="clock" id="clock"></div>
<span id="timer" class="timer"></span>
<script>
// function to diplay the date
function displayDate() {
var currentDate = new Date();
var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
var dateString = currentDate.toLocaleDateString('en-GB', options);
document.getElementById('date').innerText = dateString;
}
// Function to update date every day
function refreshAtMidnight() {
var now = new Date();
var night = new Date(
now.getFullYear(),
now.getMonth(),
now.getDate() + 1, // the next day, midnight
0, 0, 0 // midnight
);
var timeToMidnight = night - now;
setTimeout(function () {
location.reload();
}, timeToMidnight);
}
// Initial call to update date at midnight
displayDate();
refreshAtMidnight();
// Function to update clock
function updateClock() {
var now = new Date();
var hours = now.getHours().toString().padStart(2, '0');
var minutes = now.getMinutes().toString().padStart(2, '0');
var seconds = now.getSeconds().toString().padStart(2, '0');
var timeString = hours + ":" + minutes + ":" + seconds;
document.getElementById('clock').textContent = timeString;
setTimeout(updateClock, 1000); // Update every second
}
// JavaScript for periodically updating the badges
function updateStatus() {
fetchStatus('pi4', 'pi4Badge');
fetchStatus('pi5', 'pi5Badge');
fetchStatus('pi0', 'pi0Badge');
}
function fetchStatus(server, badgeId) {
fetch('http://192.168.1.227:5000/check_status/' + server)
.then(response => response.json())
.then(data => {
const badge = document.getElementById(badgeId);
const badgeText = badge.textContent.split(':')[0].trim(); // Extract the server name from the badge text
const statusText = data.status === 'online' ? ': Online' : ': Offline';
badge.textContent = badgeText + statusText;
if (data.status === 'online') {
badge.className = 'badge online'; // Set class to 'badge' and 'online'
updateTimer(60); // Start countdown timer for next update (60 seconds)
} else {
badge.className = 'badge offline'; // Set class to 'badge' and 'offline'
}
})
.catch(error => {
console.error('Error:', error);
const badge = document.getElementById(badgeId);
badge.textContent = badge.textContent.split(':')[0].trim() + ': Server Error'; // Update badge text
badge.className = 'badge error'; // Set class to 'badge' and 'error'
});
}
// Function to update the countdown timer
function updateTimer(seconds) {
let timerElement = document.getElementById('timer');
if (!timerElement) {
const newTimerElement = document.createElement('span');
newTimerElement.id = 'timer';
newTimerElement.className = 'timer';
document.body.appendChild(newTimerElement);
timerElement = newTimerElement;
}
countdownTimer(seconds, timerElement);
}
// Function to start the countdown timer
function countdownTimer(seconds, timerElement) {
let countdown = seconds;
const timerInterval = setInterval(() => {
countdown--;
if (countdown <= 0) {
clearInterval(timerInterval);
timerElement.textContent = ''; // Clear timer text
updateStatus(); // Update status once countdown reaches 0
} else {
timerElement.textContent = 'Next update in ' + countdown + ' seconds';
}
}, 1000);
}
// Call updateTimer(seconds) with the desired time interval (in seconds)
updateTimer(60); // This example sets the timer to 60 seconds
// Call updateClock to start updating the clock
updateClock();
// Update status initially and every minute
updateStatus();
setInterval(updateStatus, 60000); // Update every minute
</script>
</body>
</html>