From 6836f5b9f086158fffa582a8291c8804494d305e Mon Sep 17 00:00:00 2001 From: David Huss <dh@atoav.com> Date: Tue, 5 Nov 2024 18:10:32 +0100 Subject: [PATCH] Add uptime display --- static/modules/system.js | 20 ++++++++++++++++++++ static/style.css | 2 +- templates/index.html | 1 + 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/static/modules/system.js b/static/modules/system.js index 3ee982c..e4cb098 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 e275c60..a9ecde7 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 458c527..7c295cc 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> -- GitLab