mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 01:00:29 +08:00
refactoring
This commit is contained in:
parent
c1f408ea1a
commit
3852d0a456
@ -154,7 +154,7 @@
|
|||||||
<button class="small" data-force-hide-menu id="open-log-button">• Log</button>
|
<button class="small" data-force-hide-menu id="open-log-button">• Log</button>
|
||||||
</td>
|
</td>
|
||||||
<td class="feature-disabled" id="system-tool-wol">
|
<td class="feature-disabled" id="system-tool-wol">
|
||||||
<button class="gpio-button-__wol__ gpio-button small" data-force-hide-menu data-channel="__wol__" data-confirm="Are you sure to send Wake-on-LAN packet to the server?">• WoL</button>
|
<button class="__gpio-button-__wol__ __gpio-button small" data-force-hide-menu data-channel="__wol__" data-confirm="Are you sure to send Wake-on-LAN packet to the server?">• WoL</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -396,8 +396,8 @@
|
|||||||
<td>Connect main USB to Server:</td>
|
<td>Connect main USB to Server:</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<div class="switch-box">
|
<div class="switch-box">
|
||||||
<input class="gpio-switch-__v3_usb_breaker__ gpio-switch" disabled type="checkbox" id="gpio-switch-__v3_usb_breaker__" data-channel="__v3_usb_breaker__" data-confirm-off="Turning off this switch will disconnect the main USB<br>from the server. Are you sure you want to continue?">
|
<input class="__gpio-switch-__v3_usb_breaker__ gpio-switch" disabled type="checkbox" id="__gpio-switch-__v3_usb_breaker__" data-channel="__v3_usb_breaker__" data-confirm-off="Turning off this switch will disconnect the main USB<br>from the server. Are you sure you want to continue?">
|
||||||
<label for="gpio-switch-__v3_usb_breaker__"><span class="switch-inner"></span><span class="switch"></span></label>
|
<label for="__gpio-switch-__v3_usb_breaker__"><span class="switch-inner"></span><span class="switch"></span></label>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
@ -405,8 +405,8 @@
|
|||||||
<td>Enable locator LED:</td>
|
<td>Enable locator LED:</td>
|
||||||
<td align="right">
|
<td align="right">
|
||||||
<div class="switch-box">
|
<div class="switch-box">
|
||||||
<input class="gpio-switch-__v4_locator__ gpio-switch" disabled type="checkbox" id="gpio-switch-__v4_locator__" data-channel="__v4_locator__" data-confirm-off="">
|
<input class="__gpio-switch-__v4_locator__ gpio-switch" disabled type="checkbox" id="__gpio-switch-__v4_locator__" data-channel="__v4_locator__" data-confirm-off="">
|
||||||
<label for="gpio-switch-__v4_locator__"><span class="switch-inner"></span><span class="switch"></span></label>
|
<label for="__gpio-switch-__v4_locator__"><span class="switch-inner"></span><span class="switch"></span></label>
|
||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|||||||
@ -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-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-log") #[button(data-force-hide-menu id="open-log-button" class="small") • Log]
|
||||||
td(id="system-tool-wol" class="feature-disabled")
|
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
|
data-confirm="Are you sure to send Wake-on-LAN packet to the server?") • WoL
|
||||||
hr
|
hr
|
||||||
div(id="stream-message-no-webrtc" class="hidden")
|
div(id="stream-message-no-webrtc" class="hidden")
|
||||||
|
|||||||
@ -17,9 +17,9 @@ mixin menu_switch_notable_gpio(channel, title, confirm_off="")
|
|||||||
td !{title}:
|
td !{title}:
|
||||||
td(align="right")
|
td(align="right")
|
||||||
div(class="switch-box")
|
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)
|
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-inner")
|
||||||
span(class="switch")
|
span(class="switch")
|
||||||
|
|
||||||
|
|||||||
@ -38,26 +38,26 @@ export function Gpio(__recorder) {
|
|||||||
|
|
||||||
self.setState = function(state) {
|
self.setState = function(state) {
|
||||||
if (state) {
|
if (state) {
|
||||||
for (let channel in state.inputs) {
|
for (let ch in state.inputs) {
|
||||||
for (let el of $$(`gpio-led-${channel}`)) {
|
for (let el of $$(`__gpio-led-${ch}`)) {
|
||||||
__setLedState(el, state.inputs[channel].state);
|
__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 type of ["switch", "button"]) {
|
||||||
for (let el of $$(`gpio-${type}-${channel}`)) {
|
for (let el of $$(`__gpio-${type}-${ch}`)) {
|
||||||
tools.el.setEnabled(el, state.outputs[channel].online && !state.outputs[channel].busy);
|
tools.el.setEnabled(el, state.outputs[ch].online && !state.outputs[ch].busy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let el of $$(`gpio-switch-${channel}`)) {
|
for (let el of $$(`__gpio-switch-${ch}`)) {
|
||||||
el.checked = state.outputs[channel].state;
|
el.checked = state.outputs[ch].state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (let el of $$("gpio-led")) {
|
for (let el of $$("__gpio-led")) {
|
||||||
__setLedState(el, false);
|
__setLedState(el, false);
|
||||||
}
|
}
|
||||||
for (let selector of ["gpio-switch", "gpio-button"]) {
|
for (let selector of ["__gpio-switch", "__gpio-button"]) {
|
||||||
for (let el of $$(selector)) {
|
for (let el of $$(selector)) {
|
||||||
tools.el.setEnabled(el, false);
|
tools.el.setEnabled(el, false);
|
||||||
}
|
}
|
||||||
@ -99,12 +99,12 @@ export function Gpio(__recorder) {
|
|||||||
content += "</table>";
|
content += "</table>";
|
||||||
$("gpio-menu").innerHTML = content;
|
$("gpio-menu").innerHTML = content;
|
||||||
|
|
||||||
for (let channel in model.scheme.outputs) {
|
for (let ch in model.scheme.outputs) {
|
||||||
for (let el of $$(`gpio-switch-${channel}`)) {
|
for (let el of $$(`__gpio-switch-${ch}`)) {
|
||||||
tools.el.setOnClick(el, tools.makeClosure(__switchChannel, el));
|
tools.el.setOnClick(el, tools.partial(__switchChannel, el));
|
||||||
}
|
}
|
||||||
for (let el of $$(`gpio-button-${channel}`)) {
|
for (let el of $$(`__gpio-button-${ch}`)) {
|
||||||
tools.el.setOnClick(el, tools.makeClosure(__pulseChannel, el));
|
tools.el.setOnClick(el, tools.partial(__pulseChannel, el));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ export function Gpio(__recorder) {
|
|||||||
} else if (item.type === "input") {
|
} else if (item.type === "input") {
|
||||||
return `
|
return `
|
||||||
<img
|
<img
|
||||||
class="gpio-led gpio-led-${item.channel} inline-lamp-big led-gray"
|
class="__gpio-led __gpio-led-${item.channel} inline-lamp-big led-gray"
|
||||||
src="/share/svg/led-circle.svg"
|
src="/share/svg/led-circle.svg"
|
||||||
data-color="${item.color}"
|
data-color="${item.color}"
|
||||||
/>
|
/>
|
||||||
@ -136,12 +136,12 @@ export function Gpio(__recorder) {
|
|||||||
<input
|
<input
|
||||||
disabled
|
disabled
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
id="gpio-switch-${id}"
|
id="__gpio-switch-${id}"
|
||||||
class="gpio-switch gpio-switch-${item.channel}"
|
class="__gpio-switch __gpio-switch-${item.channel}"
|
||||||
data-channel="${item.channel}"
|
data-channel="${item.channel}"
|
||||||
data-confirm="${confirm}"
|
data-confirm="${confirm}"
|
||||||
/>
|
/>
|
||||||
<label for="gpio-switch-${id}">
|
<label for="__gpio-switch-${id}">
|
||||||
<span class="switch-inner"></span>
|
<span class="switch-inner"></span>
|
||||||
<span class="switch"></span>
|
<span class="switch"></span>
|
||||||
</label>
|
</label>
|
||||||
@ -152,7 +152,7 @@ export function Gpio(__recorder) {
|
|||||||
controls.push(`
|
controls.push(`
|
||||||
<td><button
|
<td><button
|
||||||
disabled
|
disabled
|
||||||
class="gpio-button gpio-button-${item.channel}"
|
class="__gpio-button __gpio-button-${item.channel}"
|
||||||
${item.hide ? "data-force-hide-menu" : ""}
|
${item.hide ? "data-force-hide-menu" : ""}
|
||||||
data-channel="${item.channel}"
|
data-channel="${item.channel}"
|
||||||
data-confirm="${confirm}"
|
data-confirm="${confirm}"
|
||||||
@ -179,22 +179,20 @@ export function Gpio(__recorder) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var __switchChannel = function(el) {
|
var __switchChannel = function(el) {
|
||||||
let channel = el.getAttribute("data-channel");
|
let ch = el.getAttribute("data-channel");
|
||||||
let confirm = el.getAttribute("data-confirm");
|
let confirm = el.getAttribute("data-confirm");
|
||||||
let to = (el.checked ? "1" : "0");
|
let to = (el.checked ? "1" : "0");
|
||||||
if (to === "0" && el.hasAttribute("data-confirm-off")) {
|
if (to === "0" && el.hasAttribute("data-confirm-off")) {
|
||||||
confirm = el.getAttribute("data-confirm-off");
|
confirm = el.getAttribute("data-confirm-off");
|
||||||
}
|
}
|
||||||
let act = () => {
|
let act = () => {
|
||||||
__sendPost("/api/gpio/switch", {"channel": channel, "state": to});
|
__sendPost("/api/gpio/switch", {"channel": ch, "state": to});
|
||||||
__recorder.recordGpioSwitchEvent(channel, to);
|
__recorder.recordGpioSwitchEvent(ch, to);
|
||||||
};
|
};
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
wm.confirm(tools.escape(confirm)).then(function(ok) {
|
wm.confirm(tools.escape(confirm)).then(function(ok) {
|
||||||
if (ok) {
|
if (ok) {
|
||||||
act();
|
act();
|
||||||
} else {
|
|
||||||
self.setState(__state); // Switch back
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@ -203,14 +201,18 @@ export function Gpio(__recorder) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var __pulseChannel = function(el) {
|
var __pulseChannel = function(el) {
|
||||||
let channel = el.getAttribute("data-channel");
|
let ch = el.getAttribute("data-channel");
|
||||||
let confirm = el.getAttribute("data-confirm");
|
let confirm = el.getAttribute("data-confirm");
|
||||||
let act = () => {
|
let act = () => {
|
||||||
__sendPost("/api/gpio/pulse", {"channel": channel});
|
__sendPost("/api/gpio/pulse", {"channel": ch});
|
||||||
__recorder.recordGpioPulseEvent(channel);
|
__recorder.recordGpioPulseEvent(ch);
|
||||||
};
|
};
|
||||||
if (confirm) {
|
if (confirm) {
|
||||||
wm.confirm(tools.escape(confirm)).then(function(ok) { if (ok) act(); });
|
wm.confirm(tools.escape(confirm)).then(function(ok) {
|
||||||
|
if (ok) {
|
||||||
|
act();
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
act();
|
act();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -77,7 +77,7 @@ export var tools = new function() {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
self.makeClosure = function(func, ...args) {
|
self.partial = function(func, ...args) {
|
||||||
return () => func(...args);
|
return () => func(...args);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user