diff --git a/static/modules/system.js b/static/modules/system.js index 3ee982ce8d78fc9fff110818e289e9260b29aaab..e4cb098583869ee9cdbcf624d3fbb8af27431d79 100644 --- a/static/modules/system.js +++ b/static/modules/system.js @@ -65,6 +65,8 @@ class System { if (this.power == "off") { this.onPowerOff(this); updateStatus(this.status_display, "off", "off"); + let uptime_display = document.getElementById("uptime-display"); + uptime_display.classList.add("hidden"); } if (this.power == "unknown") { this.onPowerUnknown(this); @@ -87,6 +89,24 @@ class System { updateStatus(this.status_display, "stopping...", "stopping..."); } } + + // Update the Uptime if the system is on + if (this.power == "on" && 'power-time' in system_status) { + let uptime_display = document.getElementById("uptime-display"); + uptime_display.classList.remove("hidden"); + let power_up = Date.parse(system_status['power-time']); + let now = new Date(); + let t = now - power_up; + console.log(t); + let minutes = Math.round(t/1000/60, 0); + if (minutes < 240) { + uptime_display.innerHTML = `on for ${minutes} min`; + } else { + let hours = Math.round(minutes/60, 1); + uptime_display.innerHTML = `on for ${hours} h`; + } + + } }; // Health Changes diff --git a/static/style.css b/static/style.css index e275c60c9ef9121e5c8b13cb72c7936186954742..a9ecde7c9248298d346de7943a5cfe47e32f3330 100644 --- a/static/style.css +++ b/static/style.css @@ -49,7 +49,7 @@ header { text-transform: uppercase; font-size: 1.2em; } - .time-display { + .time-display, #uptime-display { margin: 0; padding: 0; } diff --git a/templates/index.html b/templates/index.html index 458c527aed03ae84103d892b54aaca217c5ed015..7c295cc0dd49538ed80fc75440ac7a598073d5af 100644 --- a/templates/index.html +++ b/templates/index.html @@ -31,6 +31,7 @@ <div class="title"> <h1>Extended Library</h1> <p class="time-display"></p> + <p id="uptime-display"></p> </div> <button id="power-off-button" class="rectangle-button danger">POWER OFF</button>