From dc5b8c2522aaefe11a5d7ce1f27cadcd5d193d75 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Thu, 9 Jul 2020 11:06:03 +0300 Subject: [PATCH] hw tab in web ui --- kvmd/apps/kvmd/info/hw.py | 2 +- web/kvm/index.html | 15 +++++-- web/share/css/kvm/about.css | 5 ++- web/share/js/kvm/session.js | 80 +++++++++++++++++++++++++++---------- web/share/js/tools.js | 4 ++ 5 files changed, 79 insertions(+), 27 deletions(-) diff --git a/kvmd/apps/kvmd/info/hw.py b/kvmd/apps/kvmd/info/hw.py index 04c28b29..b9b7c94e 100644 --- a/kvmd/apps/kvmd/info/hw.py +++ b/kvmd/apps/kvmd/info/hw.py @@ -69,7 +69,7 @@ class HwInfoSubmanager(BaseInfoSubmanager): "type": "rpi", "base": model, }, - "state": { + "health": { "temp": { "cpu": cpu_temp, "gpu": gpu_temp, diff --git a/web/kvm/index.html b/web/kvm/index.html index 8c576db5..c244756b 100644 --- a/web/kvm/index.html +++ b/web/kvm/index.html @@ -693,8 +693,11 @@
- - + + + + + @@ -702,12 +705,18 @@ -
+
No data
+
+
+ No data +
+
+
No data diff --git a/web/share/css/kvm/about.css b/web/share/css/kvm/about.css index d7cc3af1..1b586bb6 100644 --- a/web/share/css/kvm/about.css +++ b/web/share/css/kvm/about.css @@ -41,11 +41,12 @@ div#about td.copyright { font-size: 0.8em; } -div#about div#about-meta, div#about-version, div#about-thanks { +div#about div#about-meta, div#about-hw, div#about-version, div#about-thanks { height: 250px; } -#about-tab-info-button:checked~#about-tab-info-content, +#about-tab-meta-button:checked~#about-tab-meta-content, +#about-tab-hw-button:checked~#about-tab-hw-content, #about-tab-version-button:checked~#about-tab-version-content, #about-tab-thanks-button:checked~#about-tab-thanks-content { display: block; diff --git a/web/share/js/kvm/session.js b/web/share/js/kvm/session.js index e450a962..6c14fbdf 100644 --- a/web/share/js/kvm/session.js +++ b/web/share/js/kvm/session.js @@ -55,18 +55,6 @@ export function Session() { /************************************************************************/ - var __setAboutInfoSystem = function(state) { - $("about-version").innerHTML = ` - KVMD: ${state.kvmd.version}
-
- Streamer: ${state.streamer.version} (${state.streamer.app}) - ${__formatStreamerFeatures(state.streamer.features)} -
- ${state.kernel.system} kernel: - ${__formatUname(state.kernel)} - `; - }; - var __setAboutInfoMeta = function(state) { if (state != null) { let text = JSON.stringify(state, undefined, 4).replace(/ /g, " ").replace(/\n/g, "
"); @@ -88,13 +76,65 @@ export function Session() { } }; + var __setAboutInfoHw = function(state) { + $("about-hw").innerHTML = ` + Platform base: ${state.platform.base}
+
+ Temperature: + ${__formatTemp(state.health.temp)} +
+ Throttling: + ${__formatThrottling(state.health.throttling)} + `; + }; + + var __formatTemp = function(temp) { + let pairs = []; + for (let field of Object.keys(temp).sort()) { + pairs.push([field.toUpperCase(), `${temp[field]}°C`]); + } + return __formatUl(pairs); + }; + + var __formatThrottling = function(throttling) { + if (throttling !== null) { + let pairs = []; + for (let field of Object.keys(throttling.parsed_flags).sort()) { + pairs.push([ + tools.upperFirst(field).replace("_", " "), + __formatThrottleError(throttling.parsed_flags[field]), + ]); + } + return __formatUl(pairs); + } else { + return "NO DATA"; + } + }; + + var __formatThrottleError = function(flags) { + let colored = ((color, text) => `${text}`); + return ` + ${flags["now"] ? colored("red", "RIGHT NOW") : colored("green", "No")}; + ${flags["past"] ? colored("red", "In the past") : colored("green", "Never")} + `; + }; + + var __setAboutInfoSystem = function(state) { + $("about-version").innerHTML = ` + KVMD: ${state.kvmd.version}
+
+ Streamer: ${state.streamer.version} (${state.streamer.app}) + ${__formatStreamerFeatures(state.streamer.features)} +
+ ${state.kernel.system} kernel: + ${__formatUname(state.kernel)} + `; + }; + var __formatStreamerFeatures = function(features) { let pairs = []; for (let field of Object.keys(features).sort()) { - pairs.push([ - field, - (features[field] ? "Yes" : "No"), - ]); + pairs.push([field, (features[field] ? "Yes" : "No")]); } return __formatUl(pairs); }; @@ -103,10 +143,7 @@ export function Session() { let pairs = []; for (let field of Object.keys(kernel).sort()) { if (field != "system") { - pairs.push([ - field[0].toUpperCase() + field.slice(1), - kernel[field], - ]); + pairs.push([tools.upperFirst(field), kernel[field]]); } } return __formatUl(pairs); @@ -158,8 +195,9 @@ export function Session() { let data = JSON.parse(event.data); switch (data.event_type) { case "pong": __missed_heartbeats = 0; break; - case "info_system_state": __setAboutInfoSystem(data.event); break; case "info_meta_state": __setAboutInfoMeta(data.event); break; + case "info_hw_state": __setAboutInfoHw(data.event); break; + case "info_system_state": __setAboutInfoSystem(data.event); break; case "wol_state": __wol.setState(data.event); break; case "hid_state": __hid.setState(data.event); break; case "atx_state": __atx.setState(data.event); break; diff --git a/web/share/js/tools.js b/web/share/js/tools.js index e3fa3892..63524a6a 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -46,6 +46,10 @@ export var tools = new function() { /************************************************************************/ + this.upperFirst = function(text) { + return text[0].toUpperCase() + text.slice(1); + }; + this.makeId = function() { let chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let id = "";