summaryrefslogtreecommitdiff
path: root/web/share
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2024-11-04 18:06:16 +0200
committerMaxim Devaev <[email protected]>2024-11-04 18:06:16 +0200
commit7ef2e16b51eab24897cc6447c826a5a1c2b8efed (patch)
tree1dafb2521cfa1e91a213f823b98873fc47000e74 /web/share
parentd93639ba8dcd003f82221f4ed99159755f2213c3 (diff)
minor partial state fixes
Diffstat (limited to 'web/share')
-rw-r--r--web/share/js/kvm/atx.js15
-rw-r--r--web/share/js/kvm/gpio.js46
-rw-r--r--web/share/js/kvm/msd.js57
-rw-r--r--web/share/js/kvm/ocr.js24
-rw-r--r--web/share/js/kvm/stream.js8
5 files changed, 80 insertions, 70 deletions
diff --git a/web/share/js/kvm/atx.js b/web/share/js/kvm/atx.js
index 4d9764ea..796a4eeb 100644
--- a/web/share/js/kvm/atx.js
+++ b/web/share/js/kvm/atx.js
@@ -53,30 +53,33 @@ export function Atx(__recorder) {
__state = {"leds": {}};
}
if (state.enabled !== undefined) {
- tools.feature.setEnabled($("atx-dropdown"), state.enabled);
__state.enabled = state.enabled;
+ tools.feature.setEnabled($("atx-dropdown"), __state.enabled);
}
if (__state.enabled !== undefined) {
if (state.busy !== undefined) {
- __updateButtons(!state.busy);
__state.busy = state.busy;
+ __updateButtons(!__state.busy);
}
if (state.leds !== undefined) {
__state.leds = state.leds;
}
if (state.busy !== undefined || state.leds !== undefined) {
- let busy = __state.busy;
- let leds = __state.leds;
- $("atx-power-led").className = (busy ? "led-yellow" : (leds.power ? "led-green" : "led-gray"));
- $("atx-hdd-led").className = (leds.hdd ? "led-red" : "led-gray");
+ __updateLeds(__state.leds.power, __state.leds.hdd, __state.busy);
}
}
} else {
__state = null;
+ __updateLeds(false, false, false);
__updateButtons(false);
}
};
+ var __updateLeds = function(power, hdd, busy) {
+ $("atx-power-led").className = (busy ? "led-yellow" : (power ? "led-green" : "led-gray"));
+ $("atx-hdd-led").className = (hdd ? "led-red" : "led-gray");
+ };
+
var __updateButtons = function(enabled) {
for (let id of ["atx-power-button", "atx-power-button-long", "atx-reset-button"]) {
tools.el.setEnabled($(id), enabled);
diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js
index 9e237a54..41d5ee92 100644
--- a/web/share/js/kvm/gpio.js
+++ b/web/share/js/kvm/gpio.js
@@ -38,14 +38,20 @@ export function Gpio(__recorder) {
self.setState = function(state) {
if (state) {
- if (state.model) {
- __applyModel(state.model);
+ if (state.model !== undefined) {
__has_model = true;
+ __updateModel(state.model);
}
- if (__has_model && state.state) {
- __applyState(state.state);
+ if (__has_model && state.state !== undefined) {
+ if (state.state.inputs !== undefined) {
+ __updateInputs(state.state.inputs);
+ }
+ if (state.state.outputs !== undefined) {
+ __updateOutputs(state.state.outputs);
+ }
}
} else {
+ __has_model = false;
for (let el of $$("__gpio-led")) {
__setLedState(el, false);
}
@@ -54,33 +60,31 @@ export function Gpio(__recorder) {
tools.el.setEnabled(el, false);
}
}
- __has_model = false;
}
};
- var __applyState = function(state) {
- if (state.inputs) {
- for (let ch in state.inputs) {
- for (let el of $$(`__gpio-led-${ch}`)) {
- __setLedState(el, state.inputs[ch].state);
- }
+ var __updateInputs = function(inputs) {
+ for (let ch in inputs) {
+ for (let el of $$(`__gpio-led-${ch}`)) {
+ __setLedState(el, inputs[ch].state);
}
}
- if (state.outputs) {
- for (let ch in state.outputs) {
- for (let type of ["switch", "button"]) {
- for (let el of $$(`__gpio-${type}-${ch}`)) {
- tools.el.setEnabled(el, state.outputs[ch].online && !state.outputs[ch].busy);
- }
- }
- for (let el of $$(`__gpio-switch-${ch}`)) {
- el.checked = state.outputs[ch].state;
+ };
+
+ var __updateOutputs = function(outputs) {
+ for (let ch in outputs) {
+ for (let type of ["switch", "button"]) {
+ for (let el of $$(`__gpio-${type}-${ch}`)) {
+ tools.el.setEnabled(el, (outputs[ch].online && !outputs[ch].busy));
}
}
+ for (let el of $$(`__gpio-switch-${ch}`)) {
+ el.checked = outputs[ch].state;
+ }
}
};
- var __applyModel = function(model) {
+ var __updateModel = function(model) {
tools.feature.setEnabled($("gpio-dropdown"), model.view.table.length);
if (model.view.table.length) {
let title = [];
diff --git a/web/share/js/kvm/msd.js b/web/share/js/kvm/msd.js
index 3a558b00..c20bd70a 100644
--- a/web/share/js/kvm/msd.js
+++ b/web/share/js/kvm/msd.js
@@ -66,12 +66,11 @@ export function Msd() {
self.setState = function(state) {
if (state) {
if (!__state) {
- __state = {};
- __state.storage = {};
+ __state = {"storage": {}};
}
if (state.enabled !== undefined) {
- tools.feature.setEnabled($("msd-dropdown"), state.enabled);
__state.enabled = state.enabled;
+ tools.feature.setEnabled($("msd-dropdown"), __state.enabled);
}
if (__state.enabled !== undefined) {
if (state.online !== undefined) {
@@ -80,31 +79,27 @@ export function Msd() {
if (state.busy !== undefined) {
__state.busy = state.busy;
}
- if (state.drive !== undefined || (state.storage && state.storage.images !== undefined)) {
- let drive = (state.drive !== undefined ? state.drive : __state.drive);
- let images = (
- state.storage && state.storage.images !== undefined
- ? state.storage.images
- : __state.storage && __state.storage.images !== undefined
- ? __state.storage.images
- : null
- );
- if (drive && images) {
- __updateImageSelector(drive, images);
- }
- __state.drive = drive;
- __state.storage.images = images;
- }
- if (state.storage && state.storage.parts !== undefined) {
- __updateParts(state.storage.parts);
- __state.storage.parts = state.storage.parts;
+ if (state.drive) { // Null on offline, ignore
+ __state.drive = state.drive;
}
- if (state.storage && state.storage.uploading !== undefined) {
- __updateUploading(state.storage.uploading);
- __state.storage.uploading = state.storage.uploading;
+ if (state.storage) { // Null on offline, ignore
+ if (state.storage.parts !== undefined) {
+ __state.storage.parts = state.storage.parts;
+ __updateParts(__state.storage.parts);
+ }
+ if (state.storage.uploading !== undefined) {
+ __state.storage.uploading = state.storage.uploading;
+ __updateUploading(__state.storage.uploading);
+ }
+ if (state.storage.downloading !== undefined) {
+ __state.storage.downloading = state.storage.downloading;
+ }
+ if (state.storage.images !== undefined) {
+ __state.storage.images = state.storage.images;
+ }
}
- if (state.storage && state.storage.downloading !== undefined) {
- __state.storage.downloading = state.storage.downloading;
+ if (state.drive || (state.storage && state.storage.images !== undefined)) {
+ __updateImageSelector(__state.drive, __state.storage.images);
}
}
} else {
@@ -403,10 +398,12 @@ export function Msd() {
let file = tools.input.getFile(el);
if (file) {
$("msd-new-url").value = "";
- let part = __state.storage.parts[$("msd-new-part-selector").value];
- if (file.size > part.size) {
- wm.error(`The new image is too big for the Mass Storage partition.<br>Maximum: ${tools.formatSize(part.size)}`);
- el.value = "";
+ if (__state && __state.storage && __state.storage.parts) {
+ let part = __state.storage.parts[$("msd-new-part-selector").value];
+ if (part && (file.size > part.size)) {
+ wm.error(`The new image is too big for the Mass Storage partition.<br>Maximum: ${tools.formatSize(part.size)}`);
+ el.value = "";
+ }
}
}
__refreshControls();
diff --git a/web/share/js/kvm/ocr.js b/web/share/js/kvm/ocr.js
index 8dab2741..87ef58d8 100644
--- a/web/share/js/kvm/ocr.js
+++ b/web/share/js/kvm/ocr.js
@@ -76,20 +76,26 @@ export function Ocr(__getGeometry) {
if (state) {
if (state.enabled !== undefined) {
__enabled = (state.enabled && !tools.browser.is_mobile);
+ tools.feature.setEnabled($("stream-ocr"), __enabled);
+ $("stream-ocr-led").className = (__enabled ? "led-gray" : "hidden");
+ }
+ if (__enabled && state.langs !== undefined) {
+ __updateLangs(state.langs);
}
} else {
__enabled = false;
+ tools.feature.setEnabled($("stream-ocr"), false);
+ $("stream-ocr-led").className = "hidden";
}
- if (__enabled) {
- let el = $("stream-ocr-lang-selector");
- el.options.length = 0;
- for (let lang of state.langs.available) {
- tools.selector.addOption(el, lang, lang);
- }
- el.value = tools.storage.get("stream.ocr.lang", state.langs["default"]);
+ };
+
+ var __updateLangs = function(langs) {
+ let el = $("stream-ocr-lang-selector");
+ el.options.length = 0;
+ for (let lang of langs.available) {
+ tools.selector.addOption(el, lang, lang);
}
- tools.feature.setEnabled($("stream-ocr"), __enabled);
- $("stream-ocr-led").className = (__enabled ? "led-gray" : "hidden");
+ el.value = tools.storage.get("stream.ocr.lang", langs["default"]);
};
var __startSelection = function(event) {
diff --git a/web/share/js/kvm/stream.js b/web/share/js/kvm/stream.js
index 504c7086..b436c093 100644
--- a/web/share/js/kvm/stream.js
+++ b/web/share/js/kvm/stream.js
@@ -138,17 +138,17 @@ export function Streamer() {
if (!__state) {
__state = {};
}
- if (state.features) {
+ if (state.features !== undefined) {
__state.features = state.features;
__state.limits = state.limits; // Following together with features
}
- if (__state.features && state.streamer !== undefined) {
- __setControlsEnabled(!!state.streamer);
+ if (__state.features !== undefined && state.streamer !== undefined) {
__state.streamer = state.streamer;
+ __setControlsEnabled(!!state.streamer);
}
} else {
- __setControlsEnabled(false);
__state = null;
+ __setControlsEnabled(false);
}
let visible = wm.isWindowVisible($("stream-window"));
__applyState((visible && __state && __state.features) ? state : null);