mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
refactoring
This commit is contained in:
parent
bae65c35ee
commit
6aa5893d57
@ -75,8 +75,6 @@ export function Gpio() {
|
|||||||
$("gpio-menu-button").innerHTML = `${model.view.header.title} ↴`;
|
$("gpio-menu-button").innerHTML = `${model.view.header.title} ↴`;
|
||||||
}
|
}
|
||||||
|
|
||||||
let switches = [];
|
|
||||||
let buttons = [];
|
|
||||||
let content = "<table class=\"kv\">";
|
let content = "<table class=\"kv\">";
|
||||||
for (let row of model.view.table) {
|
for (let row of model.view.table) {
|
||||||
if (row === null) {
|
if (row === null) {
|
||||||
@ -87,7 +85,7 @@ export function Gpio() {
|
|||||||
if (item.type === "output") {
|
if (item.type === "output") {
|
||||||
item.scheme = model.scheme.outputs[item.channel];
|
item.scheme = model.scheme.outputs[item.channel];
|
||||||
}
|
}
|
||||||
content += `<td align="center">${__createItem(item, switches, buttons)}</td>`;
|
content += `<td align="center">${__createItem(item)}</td>`;
|
||||||
}
|
}
|
||||||
content += "</tr>";
|
content += "</tr>";
|
||||||
}
|
}
|
||||||
@ -95,17 +93,21 @@ export function Gpio() {
|
|||||||
content += "</table>";
|
content += "</table>";
|
||||||
$("gpio-menu").innerHTML = content;
|
$("gpio-menu").innerHTML = content;
|
||||||
|
|
||||||
for (let channel of switches) {
|
for (let channel in model.scheme.outputs) {
|
||||||
tools.setOnClick($(`gpio-switch-${channel}`), () => __switchChannel(channel));
|
let el = $(`gpio-switch-${channel}`);
|
||||||
}
|
if (el) {
|
||||||
for (let channel of buttons) {
|
tools.setOnClick(el, () => __switchChannel(channel));
|
||||||
tools.setOnClick($(`gpio-button-${channel}`), () => __pulseChannel(channel));
|
}
|
||||||
|
el = $(`gpio-button-${channel}`);
|
||||||
|
if (el) {
|
||||||
|
tools.setOnClick(el, () => __pulseChannel(channel));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.setState(__state);
|
self.setState(__state);
|
||||||
};
|
};
|
||||||
|
|
||||||
var __createItem = function(item, switches, buttons) {
|
var __createItem = function(item) {
|
||||||
if (item.type === "label") {
|
if (item.type === "label") {
|
||||||
return item.text;
|
return item.text;
|
||||||
} else if (item.type === "input") {
|
} else if (item.type === "input") {
|
||||||
@ -116,7 +118,6 @@ export function Gpio() {
|
|||||||
} else if (item.type === "output") {
|
} else if (item.type === "output") {
|
||||||
let controls = [];
|
let controls = [];
|
||||||
if (item.scheme["switch"]) {
|
if (item.scheme["switch"]) {
|
||||||
switches.push(item.channel);
|
|
||||||
controls.push(`
|
controls.push(`
|
||||||
<td><div class="switch-box">
|
<td><div class="switch-box">
|
||||||
<input disabled type="checkbox" id="gpio-switch-${item.channel}" class="gpio-switch" />
|
<input disabled type="checkbox" id="gpio-switch-${item.channel}" class="gpio-switch" />
|
||||||
@ -128,7 +129,6 @@ export function Gpio() {
|
|||||||
`);
|
`);
|
||||||
}
|
}
|
||||||
if (item.scheme.pulse.delay) {
|
if (item.scheme.pulse.delay) {
|
||||||
buttons.push(item.channel);
|
|
||||||
controls.push(`<td><button disabled id="gpio-button-${item.channel}" class="gpio-button">${item.text}</button></td>`);
|
controls.push(`<td><button disabled id="gpio-button-${item.channel}" class="gpio-button">${item.text}</button></td>`);
|
||||||
}
|
}
|
||||||
return `<table><tr>${controls.join("<td> </td>")}</tr></table>`;
|
return `<table><tr>${controls.join("<td> </td>")}</tr></table>`;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user