From 3852d0a4568c3726d0182f3b00a9a3e8bb7e8af9 Mon Sep 17 00:00:00 2001 From: Maxim Devaev Date: Fri, 18 Oct 2024 08:28:30 +0300 Subject: [PATCH] refactoring --- web/kvm/index.html | 10 +++---- web/kvm/navbar-system.pug | 2 +- web/kvm/navbar.pug | 4 +-- web/share/js/kvm/gpio.js | 60 ++++++++++++++++++++------------------- web/share/js/tools.js | 2 +- 5 files changed, 40 insertions(+), 38 deletions(-) diff --git a/web/kvm/index.html b/web/kvm/index.html index c0a9a6dd..3bac7104 100644 --- a/web/kvm/index.html +++ b/web/kvm/index.html @@ -154,7 +154,7 @@ - + @@ -396,8 +396,8 @@ Connect main USB to Server:
- - + +
@@ -405,8 +405,8 @@ Enable locator LED:
- - + +
diff --git a/web/kvm/navbar-system.pug b/web/kvm/navbar-system.pug index d6cb31d5..d10dbee0 100644 --- a/web/kvm/navbar-system.pug +++ b/web/kvm/navbar-system.pug @@ -13,7 +13,7 @@ li(id="system-dropdown" class="right") td(id="system-tool-about") #[button(data-force-hide-menu data-show-window="about-window" class="small") • About] td(id="system-tool-log") #[button(data-force-hide-menu id="open-log-button" class="small") • Log] td(id="system-tool-wol" class="feature-disabled") - button(data-force-hide-menu class="gpio-button-__wol__ gpio-button small" data-channel="__wol__" + button(data-force-hide-menu class="__gpio-button-__wol__ __gpio-button small" data-channel="__wol__" data-confirm="Are you sure to send Wake-on-LAN packet to the server?") • WoL hr div(id="stream-message-no-webrtc" class="hidden") diff --git a/web/kvm/navbar.pug b/web/kvm/navbar.pug index 381fc067..b1c6b5eb 100644 --- a/web/kvm/navbar.pug +++ b/web/kvm/navbar.pug @@ -17,9 +17,9 @@ mixin menu_switch_notable_gpio(channel, title, confirm_off="") td !{title}: td(align="right") div(class="switch-box") - input(disabled type="checkbox" id=`gpio-switch-${channel}` class=`gpio-switch-${channel} gpio-switch` + input(disabled type="checkbox" id=`__gpio-switch-${channel}` class=`__gpio-switch-${channel} gpio-switch` data-channel=channel data-confirm-off=confirm_off) - label(for=`gpio-switch-${channel}`) + label(for=`__gpio-switch-${channel}`) span(class="switch-inner") span(class="switch") diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js index 293561b3..fea1af32 100644 --- a/web/share/js/kvm/gpio.js +++ b/web/share/js/kvm/gpio.js @@ -38,26 +38,26 @@ export function Gpio(__recorder) { self.setState = function(state) { if (state) { - for (let channel in state.inputs) { - for (let el of $$(`gpio-led-${channel}`)) { - __setLedState(el, state.inputs[channel].state); + for (let ch in state.inputs) { + for (let el of $$(`__gpio-led-${ch}`)) { + __setLedState(el, state.inputs[ch].state); } } - for (let channel in state.outputs) { + for (let ch in state.outputs) { for (let type of ["switch", "button"]) { - for (let el of $$(`gpio-${type}-${channel}`)) { - tools.el.setEnabled(el, state.outputs[channel].online && !state.outputs[channel].busy); + 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-${channel}`)) { - el.checked = state.outputs[channel].state; + for (let el of $$(`__gpio-switch-${ch}`)) { + el.checked = state.outputs[ch].state; } } } else { - for (let el of $$("gpio-led")) { + for (let el of $$("__gpio-led")) { __setLedState(el, false); } - for (let selector of ["gpio-switch", "gpio-button"]) { + for (let selector of ["__gpio-switch", "__gpio-button"]) { for (let el of $$(selector)) { tools.el.setEnabled(el, false); } @@ -99,12 +99,12 @@ export function Gpio(__recorder) { content += ""; $("gpio-menu").innerHTML = content; - for (let channel in model.scheme.outputs) { - for (let el of $$(`gpio-switch-${channel}`)) { - tools.el.setOnClick(el, tools.makeClosure(__switchChannel, el)); + for (let ch in model.scheme.outputs) { + for (let el of $$(`__gpio-switch-${ch}`)) { + tools.el.setOnClick(el, tools.partial(__switchChannel, el)); } - for (let el of $$(`gpio-button-${channel}`)) { - tools.el.setOnClick(el, tools.makeClosure(__pulseChannel, el)); + for (let el of $$(`__gpio-button-${ch}`)) { + tools.el.setOnClick(el, tools.partial(__pulseChannel, el)); } } @@ -121,7 +121,7 @@ export function Gpio(__recorder) { } else if (item.type === "input") { return ` @@ -136,12 +136,12 @@ export function Gpio(__recorder) { -