From 6aa5893d57b4af1434b5a40894674c4158868c5a Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Thu, 10 Sep 2020 18:37:25 +0300 Subject: [PATCH] refactoring --- web/share/js/kvm/gpio.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/web/share/js/kvm/gpio.js b/web/share/js/kvm/gpio.js index a412d579..e7b3c9e1 100644 --- a/web/share/js/kvm/gpio.js +++ b/web/share/js/kvm/gpio.js @@ -75,8 +75,6 @@ export function Gpio() { $("gpio-menu-button").innerHTML = `${model.view.header.title} ↴`; } - let switches = []; - let buttons = []; let content = ""; for (let row of model.view.table) { if (row === null) { @@ -87,7 +85,7 @@ export function Gpio() { if (item.type === "output") { item.scheme = model.scheme.outputs[item.channel]; } - content += ``; + content += ``; } content += ""; } @@ -95,17 +93,21 @@ export function Gpio() { content += "
${__createItem(item, switches, buttons)}${__createItem(item)}
"; $("gpio-menu").innerHTML = content; - for (let channel of switches) { - tools.setOnClick($(`gpio-switch-${channel}`), () => __switchChannel(channel)); - } - for (let channel of buttons) { - tools.setOnClick($(`gpio-button-${channel}`), () => __pulseChannel(channel)); + for (let channel in model.scheme.outputs) { + let el = $(`gpio-switch-${channel}`); + if (el) { + tools.setOnClick(el, () => __switchChannel(channel)); + } + el = $(`gpio-button-${channel}`); + if (el) { + tools.setOnClick(el, () => __pulseChannel(channel)); + } } self.setState(__state); }; - var __createItem = function(item, switches, buttons) { + var __createItem = function(item) { if (item.type === "label") { return item.text; } else if (item.type === "input") { @@ -116,7 +118,6 @@ export function Gpio() { } else if (item.type === "output") { let controls = []; if (item.scheme["switch"]) { - switches.push(item.channel); controls.push(`
@@ -128,7 +129,6 @@ export function Gpio() { `); } if (item.scheme.pulse.delay) { - buttons.push(item.channel); controls.push(``); } return `${controls.join("")}
   
`;