diff --git a/webclient/dist/js/main.js b/webclient/dist/js/main.js index 4e34955..3837eef 100644 --- a/webclient/dist/js/main.js +++ b/webclient/dist/js/main.js @@ -330,5 +330,5 @@
${text}
\n\t{{value}}`,\n\t\t\t\t\tstate: value => {\n\t\t\t\t\t\tconst map = {\n\t\t\t\t\t\t\tactive: \"badge-success\",\n\t\t\t\t\t\t\tremoved: \"badge-error\",\n\t\t\t\t\t\t\tfreezed: \"badge-warning\" \n\t\t\t\t\t\t};\n\n\t\t\t\t\t\treturn `${value}`\n\t\t\t\t\t},\n\t\t\t\t\tconnection_state: value => {\n\t\t\t\t\t\tconst badgeClass = value == \"active\" ? \"badge-success\" : \"badge-warning\";\n\t\t\t\t\t\treturn `${value}`\n\t\t\t\t\t},\n\t\t\t\t\tmac: `{{value}}`,\n\t\t\t\t\talias: ` {{value}}`,\n\t\t\t\t\tdevice_id: `{{value}}`,\n\t\t\t\t\tlast_contact: value => Helper.unification.timeAgo(value),\n\t\t\t\t\tcreate_at: value => Helper.unification.formatDate(value),\n\t\t\t\t\tupdate_at: value => Helper.unification.formatDate(value),\n\t\t\t\t}\n\n\t\t\t\treturn map[field] \n\t\t\t\t\t? (typeof map[field] == \"function\" ? map[field](value) : map[field].replaceAll(\"{{value}}\", value))\n\t\t\t\t\t: value; \n\t\t\t}\n\n\t\t\tlet deviceProperties = \"\";\n\t\t\tfor(let field in device) {\n\t\t\t\tlet fieldValueClass = fieldClassMap[field] ?? \"\";\n\n\t\t\t\tdeviceProperties += `\n\t\t\t\t\t${device.ip}`,\n\t\t\tactions: `\n\t\t\t\t\n\n\t\t\t\t\n\t\t\t`\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Devices list\", \n\t\t{\n\t\t\tdeviceName: \"Device name\", \n\t\t\talias: \"Device alias\", \n\t\t\tstatus: \"Status\", \n\t\t\tip: \"IP\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".reboot-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tif(e.currentTarget.getAttribute(\"disabled\")) {\n\t\t\t\treturn ;\n\t\t\t}\n\n\t\t\trebootDeviceBtnHandler(sh_api, e.currentTarget);\n\t\t});\n\t});\n\n\tscr.currentScreen.DOMObject.querySelectorAll(\".details-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst device = {\n\t\t\t\tstatus: \"\",\n\t\t\t\t...JSON.parse(e.currentTarget.dataset.device)\n\t\t\t}\n\t\t\tdeviceDetailsPopup(device, sh_api).show();\n\t\t});\n\t});\n}\n\nfunction list(sh_api) {\n\treturn {\n\t\talias: \"devices\",\n\t\trenderer: () => {\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"devices\"));\n\t\t},\n\n\t\tiniter: scr => {\n\t\t\tsh_api.devices.list((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.devices.list\", err, resp, meta);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.total);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\n\t\t}\n\t};\n}\n\nexport {\n\tlist\n}", "export function deviceSetupFormPopup(device, sh_api) {\n\tdevice = Helper.unification.deviceFieldsUnification(device);\n\n\treturn Modals.create(\"device-setup\", {\n\t\ttitle: `Setup new device ${device.ip}`,\n\t\tbody: modal => {\n\n\t\t\tlet deviceProperties = \"\";\n\t\t\tfor(let field in device) {\n\t\t\t\tif(field[0] == \"_\") continue;\n\t\t\t\tdeviceProperties += `\n\t\t\t\t\t${device.ip}`,\n\t\t\tmac: `${device.mac}`,\n\t\t\twifiSignal: device.wifi_signal,\n\t\t\tactions: device.status == \"setup\" ? `\n\t\t\t\t\n\t\t\t` : \"\"\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Found devices\", \n\t\t{\n\t\t\tdeviceId: \"Device ID\",\n\t\t\tdeviceName: \"Device name\", \n\t\t\tdeviceType: \"Type\", \n\t\t\tstatus: \"Status\", \n\t\t\tip: \"IP\", \n\t\t\tmac: \"Mac\",\n\t\t\twifiSignal: \"Signal\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".setup-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst device = JSON.parse(e.currentTarget.dataset.device);\n\t\t\tdeviceSetupFormPopup(device, sh_api).show();\n\t\t});\n\t});\n}\n\nfunction scanning(sh_api) {\n\treturn {\n\t\talias: \"devices-scanning\",\n\t\trenderer: () => {\t\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"scanning\"));\n\t\t},\n\t\tiniter: scr => {\n\t\t\tsh_api.devices.scanning_all((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.devices.scanning_all\", err, resp);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.devices.length);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\n\t\t}\n\t};\n}\n\nexport {\n\tscanning\n}", "import { list } from \"./devices-list-screen.js\";\nimport { scanning } from \"./devices-scanning-screen.js\";\n\nexport default {\n\tlist,\n\tscanning\n}", "function sidebarTemplate(active) {\n\treturn Helper.template.sidebarNav([\n\t\t{\n\t\t\tcontent: ` Scopes`,\n\t\t\troute: \"/#!/scripts/scopes\",\n\t\t\tis_active: active == \"scopes\"\n\t\t},\n\t\t{\n\t\t\tcontent: ` Actions`,\n\t\t\troute: \"/#!/scripts/actions\",\n\t\t\tis_active: active == \"actions\"\n\t\t},\n\t\t{\n\t\t\tcontent: ` Regular`,\n\t\t\troute: \"/#!/scripts/regular\",\n\t\t\tis_active: active == \"regular\"\n\t\t}\n\t]);\n}\n\nfunction runActionScript(sh_api, alias, cb) {\n\tsh_api.scripts.run({\n\t\talias: alias,\n\t\tparams: {}\n\t}, (err, data, meta) => {\n\t\tif(data) {\n\t\t\tcb(true);\n\n\t\t\tsetTimeout(() => Screens.reinit(), 1000);\n\n\t\t\tsetTimeout(() => Toasts.createSuccess(\n\t\t\t\t`${alias} running`,\n\t\t\t\t`${alias} running success`\n\t\t\t).show(), 300);\n\t\t} else {\n\t\t\tcb(false);\n\n\t\t\tsetTimeout(() => Toasts.createError(\n\t\t\t\t`${alias} failed`,\n\t\t\t\t`${alias} running failed`\n\t\t\t).show(), 300);\n\t\t}\n\t});\n}\n\nfunction createActionCardHtml(action) {\n\tconst cardColor = action.state == \"enabled\" ? \"primary\" : \"warning\";\n\treturn `\n\t\t${scope.path}`,\n\t\t\tstate: Helper.template.toogleStateBadge(scope.state),\n\t\t\tactions: `\n\t\t\t\t${btnSwitch}\n\t\t\t`\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Scopes list\", \n\t\t{\n\t\t\tname: \"Scope name\", \n\t\t\tfilename: \"Filename\", \n\t\t\tstate: \"State\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".change-state-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst btn = e.currentTarget;\n\t\t\tif(btn.getAttribute(\"disabled\")) {\n\t\t\t\treturn ;\n\t\t\t}\n\n\t\t\tconst methName = btn.dataset.value == \"enable\"\n\t\t\t\t? \"scope_enable\"\n\t\t\t\t: \"scope_disable\"\n\n\t\t\tconst scope = JSON.parse(btn.dataset.scope);\n\t\t\tHelper.states.btnLoadingState(btn, true);\n\t\t\tsh_api.scripts[methName](scope.name, (err, data, meta) => {\n\t\t\t\tHelper.states.btnLoadingState(btn, false);\n\n\t\t\t\tif(data) {\n\t\t\t\t\tsetTimeout(() => Screens.reinit(), 250);\n\t\t\t\t\tToasts.createSuccess(\n\t\t\t\t\t\t`Request Success`,\n\t\t\t\t\t\t`State of ${scope.name} was changed`\n\t\t\t\t\t).show();\n\t\t\t\t} else {\n\t\t\t\t\tToasts.createError(\n\t\t\t\t\t\t\"Request failed\",\n\t\t\t\t\t\t`Scope state not changed`\n\t\t\t\t\t).show();\n\t\t\t\t}\n\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction scopes(sh_api) {\n\treturn {\n\t\ttitle: \"Scripts Scopes\",\n\t\talias: \"scripts-scopes\",\n\t\trenderer: () => {\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"scopes\"));\n\t\t},\n\t\tiniter: scr => {\n\t\t\tsh_api.scripts.scopes_list((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.scripts.scopes_list\", err, resp, meta);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.total);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\t\t\t\n\t\t}\n\t}\n}\n\nexport {\n\tscopes\n}", "import { sidebarTemplate } from \"./scripts-funcs.js\";\n\nfunction prepareData(data) {\n\tconst preparedData = [];\n\n\tfor(let script of data.scripts) {\n\t\tconst btnSwitch = script.state == \"disabled\"\n\t\t\t? ``\n\t\t\t: ``;\n\n\t\tpreparedData.push({\n\t\t\talias: `${script.alias}${script.path}`,\n\t\t\tstate: Helper.template.toogleStateBadge(script.state),\n\t\t\tactions: `\n\t\t\t\t${btnSwitch}\n\t\t\t`\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tconst provideSciptsData = {};\n\tfor(let i in data) {\n\t\tprovideSciptsData[data[i].alias] = data[i];\n\t\tdata[i][\"code\"] = \"\";\n\t}\n\tscr.currentScreen.DOMObject.provideSciptsData = provideSciptsData;\n\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Regular scripts list\", \n\t\t{\n\t\t\talias: \"Alias\", \n\t\t\tname: \"Script name\", \n\t\t\tfilename: \"Filename\", \n\t\t\tstate: \"State\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".change-state-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst btn = e.currentTarget;\n\t\t\tif(btn.getAttribute(\"disabled\")) {\n\t\t\t\treturn ;\n\t\t\t}\n\n\t\t\tconst methName = btn.dataset.value == \"enable\"\n\t\t\t\t? \"regular_enable\"\n\t\t\t\t: \"regular_disable\"\n\n\t\t\tconst script = scr.currentScreen.DOMObject.provideSciptsData[btn.dataset.alias] ?? {};\n\n\t\t\tHelper.states.btnLoadingState(btn, true);\n\t\t\tsh_api.scripts[methName](script.alias, (err, data, meta) => {\n\t\t\t\tHelper.states.btnLoadingState(btn, false);\n\n\t\t\t\tif(data) {\n\t\t\t\t\tsetTimeout(() => Screens.reinit(), 250);\n\t\t\t\t\tToasts.createSuccess(\n\t\t\t\t\t\t`Request Success`,\n\t\t\t\t\t\t`State of ${script.alias} was changed`\n\t\t\t\t\t).show();\n\t\t\t\t} else {\n\t\t\t\t\tToasts.createError(\n\t\t\t\t\t\t\"Request failed\",\n\t\t\t\t\t\t`Regular script state not changed`\n\t\t\t\t\t).show();\n\t\t\t\t}\n\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction regular(sh_api) {\n\treturn {\n\t\ttitle: \"Scripts Regular\",\n\t\talias: \"scripts-regular\",\n\t\trenderer: () => {\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"regular\"));\n\t\t},\n\t\tiniter: scr => {\n\t\t\tsh_api.scripts.regular_list((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.scripts.regular_list\", err, resp, meta);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.total);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\t\t\t\n\t\t}\n\t}\n}\n\nexport {\n\tregular\n}", "import { runActionScript } from \"./scripts-funcs.js\";\nimport { placeInArea } from \"../areas/areas-placeto-component.js\";\n\nexport function actionDetailsPopup(script, sh_api) {\n\tconsole.log(\"actionDetailsPopup\", script);\n\n\treturn Modals.create(\"action-script-popup\", {\n\t\ttitle: `${script.name}`,\n\t\tbody: modal => {\n\t\t\tconst placeInAreaContainer = (script.area_id != -1) \n\t\t\t\t? ``\n\t\t\t\t: \"\";\n\n\t\t\treturn `\n\t\t\t\t${script.alias}${script.code}\n\t\t\t\t\t\t\t${script.path}`,\n\t\t\tstate: script.state,\n\t\t\tcode: script.code,\n\t\t\tid: script.id ?? 0,\n\t\t\tarea_id: script.area_id ?? -1\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainGrid(scr, data, total) {\n\tlet grid = `${device.ip}`,\n\t\t\t\t\t\t\tactions: `\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t`\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn preparedData;\n\t\t\t\t}\n\n\t\t\t\tconst devices = prepareDevicesData(data?.data);\n\n\t\t\t\tdevicesContainer.innerHTML = Helper.template.table(\n\t\t\t\t\t\"\", \n\t\t\t\t\t{\n\t\t\t\t\t\tdeviceName: \"Device name\", \n\t\t\t\t\t\talias: \"Device alias\", \n\t\t\t\t\t\tstatus: \"Status\", \n\t\t\t\t\t\tip: \"IP\", \n\t\t\t\t\t\tactions: \"Actions\"\n\t\t\t\t\t},\n\t\t\t\t\tdevices,\n\t\t\t\t\t``\n\t\t\t\t);\n\n\t\t\t\tdevicesContainer.querySelectorAll(\".reboot-btn\").forEach(rebootBtn => {\n\t\t\t\t\trebootBtn.addEventListener(\"click\", e => {\n\t\t\t\t\t\tif(rebootBtn.getAttribute(\"disabled\")) {\n\t\t\t\t\t\t\treturn ;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\trebootDeviceBtnHandler(sh_api, e.currentTarget, modal);\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\tloader.remove();\n\n\t\t\t\tconsole.log(\"devices\", devices);\n\t\t\t});\n\t\t}\n\t});\n}", "import { \n\trunActionScript, \n\tsetActionCardEventsHandlers, \n\tcreateActionCardHtml,\n\tcreateActionCard,\n} from \"../scripts/scripts-funcs.js\";\nimport { prepareData } from \"../scripts/scripts-actions-screen.js\";\n// import { actionDetailsPopup } from \"./scripts-action-popup.js\";\n\nexport function areaActionsModal(area, sh_api) {\n\tconsole.log(\"areaActionsModal\", area);\n\n\treturn Modals.create(\"area-actions-modal\", {\n\t\ttitle: ` ${area.display_name}`,\n\t\tbody: modal => {\n\t\t\treturn `\n\t\t\t\t\n\t\t\t\t${device.ip}`,\n\t\t\t// \t\t\t\tactions: `\n\t\t\t// \t\t\t\t\t\n\t\t\t// \t\t\t\t`\n\t\t\t// \t\t\t});\n\t\t\t// \t\t}\n\n\t\t\t// \t\treturn preparedData;\n\t\t\t// \t}\n\n\t\t\t// \tconst devices = prepareDevicesData(data?.data);\n\n\t\t\t// \tdevicesContainer.innerHTML = Helper.template.table(\n\t\t\t// \t\t\"\", \n\t\t\t// \t\t{\n\t\t\t// \t\t\tdeviceName: \"Device name\", \n\t\t\t// \t\t\talias: \"Device alias\", \n\t\t\t// \t\t\tstatus: \"Status\", \n\t\t\t// \t\t\tip: \"IP\", \n\t\t\t// \t\t\tactions: \"Actions\"\n\t\t\t// \t\t},\n\t\t\t// \t\tdevices,\n\t\t\t// \t\t``\n\t\t\t// \t);\n\n\t\t\t// \tdevicesContainer.querySelectorAll(\".reboot-btn\").forEach(rebootBtn => {\n\t\t\t// \t\trebootBtn.addEventListener(\"click\", e => {\n\t\t\t// \t\t\tif(rebootBtn.getAttribute(\"disabled\")) {\n\t\t\t// \t\t\t\treturn ;\n\t\t\t// \t\t\t}\n\n\t\t\t// \t\t\trebootDeviceBtnHandler(sh_api, e.currentTarget, modal);\n\t\t\t// \t\t});\n\t\t\t// \t});\n\n\t\t\t// \tloader.remove();\n\n\t\t\t// \tconsole.log(\"devices\", devices);\n\t\t\t// });\n\t\t}\n\t});\n}", "\nexport function createNewAreaModal(sh_api) {\n\tconsole.log(\"createNewAreaModal\");\n\n\treturn Modals.create(\"create-area-modal\", {\n\t\ttitle: ` Create new Area`,\n\t\tbody: modal => {\n\t\t\treturn `\n\t\t\t\t${text}
\n\t\t\t`;\n\t\t},\n\t\tactions: modal => {\n\t\t\tconst buttonNO = Helper.template.createElement(\"button\", { class: \"btn btn-primary\" }, \"NO\");\n\t\t\tconst buttonYES = Helper.template.createElement(\"button\", { class: \"btn btn-warning\" }, \"YES\");\n\n\t\t\tbuttonNO.addEventListener(\"click\", e => {\n\t\t\t\tmodal.close();\n\t\t\t\tcanceledCb();\n\t\t\t});\n\n\t\t\tbuttonYES.addEventListener(\"click\", e => {\n\t\t\t\tmodal.close();\n\t\t\t\tconfirmedCb();\n\t\t\t});\n\n\t\t\treturn [ buttonNO, buttonYES ];\n\t\t}\n\t}).show();\n}", "function scrollToElementInFocus(container) {\n\tconst focus = container.querySelector(\".focus\");\n\tif (!focus) return;\n\n\tconst container_rect = container.getBoundingClientRect();\n\tconst focus_rect = focus.getBoundingClientRect();\n\n\tif (focus_rect.top < container_rect.top) {\n\t\tcontainer.scrollTop -= (container_rect.top - focus_rect.top);\n\t} else if (focus_rect.bottom > container_rect.bottom) {\n\t\tcontainer.scrollTop += (focus_rect.bottom - container_rect.bottom);\n\t}\n}\n\nfunction autoSetState(container) {\n\tconst totalViewed = container.advancedSelect.optionsElements.length - container.querySelectorAll(\".option.hide\").length;\n\tif(totalViewed == 0) {\n\t\tcontainer.advancedSelect.showState(\"not-found\");\n\t} else {\n\t\tcontainer.advancedSelect.showState(\"options\");\n\t}\n}\n\nexport default function advancedSelect(input, options, notFoundText) {\n\tconst container = document.createElement(\"div\");\n\tcontainer.classList.add(\"advanced-select\");\n\n\tlet optionsList = ``;\n\tfor(let optionValue in options) {\n\t\toptionsList += `${text}
\n\t{{value}}`,\n\t\t\t\t\tstate: value => {\n\t\t\t\t\t\tconst map = {\n\t\t\t\t\t\t\tactive: \"badge-success\",\n\t\t\t\t\t\t\tremoved: \"badge-error\",\n\t\t\t\t\t\t\tfreezed: \"badge-warning\" \n\t\t\t\t\t\t};\n\n\t\t\t\t\t\treturn `${value}`\n\t\t\t\t\t},\n\t\t\t\t\tconnection_state: value => {\n\t\t\t\t\t\tconst badgeClass = value == \"active\" ? \"badge-success\" : \"badge-warning\";\n\t\t\t\t\t\treturn `${value}`\n\t\t\t\t\t},\n\t\t\t\t\tmac: `{{value}}`,\n\t\t\t\t\talias: ` {{value}}`,\n\t\t\t\t\tdevice_id: `{{value}}`,\n\t\t\t\t\tlast_contact: value => Helper.unification.timeAgo(value),\n\t\t\t\t\tcreate_at: value => Helper.unification.formatDate(value),\n\t\t\t\t\tupdate_at: value => Helper.unification.formatDate(value),\n\t\t\t\t}\n\n\t\t\t\treturn map[field] \n\t\t\t\t\t? (typeof map[field] == \"function\" ? map[field](value) : map[field].replaceAll(\"{{value}}\", value))\n\t\t\t\t\t: value; \n\t\t\t}\n\n\t\t\tlet deviceProperties = \"\";\n\t\t\tfor(let field in device) {\n\t\t\t\tlet fieldValueClass = fieldClassMap[field] ?? \"\";\n\n\t\t\t\tdeviceProperties += `\n\t\t\t\t\t${device.ip}`,\n\t\t\tactions: `\n\t\t\t\t\n\n\t\t\t\t\n\t\t\t`\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Devices list\", \n\t\t{\n\t\t\tdeviceName: \"Device name\", \n\t\t\talias: \"Device alias\", \n\t\t\tstatus: \"Status\", \n\t\t\tip: \"IP\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".reboot-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tif(e.currentTarget.getAttribute(\"disabled\")) {\n\t\t\t\treturn ;\n\t\t\t}\n\n\t\t\trebootDeviceBtnHandler(sh_api, e.currentTarget);\n\t\t});\n\t});\n\n\tscr.currentScreen.DOMObject.querySelectorAll(\".details-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst device = {\n\t\t\t\tstatus: \"\",\n\t\t\t\t...JSON.parse(e.currentTarget.dataset.device)\n\t\t\t}\n\t\t\tdeviceDetailsPopup(device, sh_api).show();\n\t\t});\n\t});\n}\n\nfunction list(sh_api) {\n\treturn {\n\t\talias: \"devices\",\n\t\trenderer: () => {\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"devices\"));\n\t\t},\n\n\t\tiniter: scr => {\n\t\t\tsh_api.devices.list((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.devices.list\", err, resp, meta);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.total);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\n\t\t}\n\t};\n}\n\nexport {\n\tlist\n}", "export function deviceSetupFormPopup(device, sh_api) {\n\tdevice = Helper.unification.deviceFieldsUnification(device);\n\n\treturn Modals.create(\"device-setup\", {\n\t\ttitle: `Setup new device ${device.ip}`,\n\t\tbody: modal => {\n\n\t\t\tlet deviceProperties = \"\";\n\t\t\tfor(let field in device) {\n\t\t\t\tif(field[0] == \"_\") continue;\n\t\t\t\tdeviceProperties += `\n\t\t\t\t\t${device.ip}`,\n\t\t\tmac: `${device.mac}`,\n\t\t\twifiSignal: device.wifi_signal,\n\t\t\tactions: device.status == \"setup\" ? `\n\t\t\t\t\n\t\t\t` : \"\"\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Found devices\", \n\t\t{\n\t\t\tdeviceId: \"Device ID\",\n\t\t\tdeviceName: \"Device name\", \n\t\t\tdeviceType: \"Type\", \n\t\t\tstatus: \"Status\", \n\t\t\tip: \"IP\", \n\t\t\tmac: \"Mac\",\n\t\t\twifiSignal: \"Signal\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".setup-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst device = JSON.parse(e.currentTarget.dataset.device);\n\t\t\tdeviceSetupFormPopup(device, sh_api).show();\n\t\t});\n\t});\n}\n\nfunction scanning(sh_api) {\n\treturn {\n\t\talias: \"devices-scanning\",\n\t\trenderer: () => {\t\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"scanning\"));\n\t\t},\n\t\tiniter: scr => {\n\t\t\tsh_api.devices.scanning_all((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.devices.scanning_all\", err, resp);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.devices.length);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\n\t\t}\n\t};\n}\n\nexport {\n\tscanning\n}", "import { list } from \"./devices-list-screen.js\";\nimport { scanning } from \"./devices-scanning-screen.js\";\n\nexport default {\n\tlist,\n\tscanning\n}", "function sidebarTemplate(active) {\n\treturn Helper.template.sidebarNav([\n\t\t{\n\t\t\tcontent: ` Scopes`,\n\t\t\troute: \"/#!/scripts/scopes\",\n\t\t\tis_active: active == \"scopes\"\n\t\t},\n\t\t{\n\t\t\tcontent: ` Actions`,\n\t\t\troute: \"/#!/scripts/actions\",\n\t\t\tis_active: active == \"actions\"\n\t\t},\n\t\t{\n\t\t\tcontent: ` Regular`,\n\t\t\troute: \"/#!/scripts/regular\",\n\t\t\tis_active: active == \"regular\"\n\t\t}\n\t]);\n}\n\nfunction runActionScript(sh_api, alias, cb) {\n\tsh_api.scripts.run({\n\t\talias: alias,\n\t\tparams: {}\n\t}, (err, data, meta) => {\n\t\tif(data) {\n\t\t\tcb(true);\n\n\t\t\tsetTimeout(() => Screens.reinit(), 1000);\n\n\t\t\tsetTimeout(() => Toasts.createSuccess(\n\t\t\t\t`${alias} running`,\n\t\t\t\t`${alias} running success`\n\t\t\t).show(), 300);\n\t\t} else {\n\t\t\tcb(false);\n\n\t\t\tsetTimeout(() => Toasts.createError(\n\t\t\t\t`${alias} failed`,\n\t\t\t\t`${alias} running failed`\n\t\t\t).show(), 300);\n\t\t}\n\t});\n}\n\nfunction createActionCardHtml(action) {\n\tconst cardColor = action.state == \"enabled\" ? \"primary\" : \"warning\";\n\treturn `\n\t\t${scope.path}`,\n\t\t\tstate: Helper.template.toogleStateBadge(scope.state),\n\t\t\tactions: `\n\t\t\t\t${btnSwitch}\n\t\t\t`\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Scopes list\", \n\t\t{\n\t\t\tname: \"Scope name\", \n\t\t\tfilename: \"Filename\", \n\t\t\tstate: \"State\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".change-state-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst btn = e.currentTarget;\n\t\t\tif(btn.getAttribute(\"disabled\")) {\n\t\t\t\treturn ;\n\t\t\t}\n\n\t\t\tconst methName = btn.dataset.value == \"enable\"\n\t\t\t\t? \"scope_enable\"\n\t\t\t\t: \"scope_disable\"\n\n\t\t\tconst scope = JSON.parse(btn.dataset.scope);\n\t\t\tHelper.states.btnLoadingState(btn, true);\n\t\t\tsh_api.scripts[methName](scope.name, (err, data, meta) => {\n\t\t\t\tHelper.states.btnLoadingState(btn, false);\n\n\t\t\t\tif(data) {\n\t\t\t\t\tsetTimeout(() => Screens.reinit(), 250);\n\t\t\t\t\tToasts.createSuccess(\n\t\t\t\t\t\t`Request Success`,\n\t\t\t\t\t\t`State of ${scope.name} was changed`\n\t\t\t\t\t).show();\n\t\t\t\t} else {\n\t\t\t\t\tToasts.createError(\n\t\t\t\t\t\t\"Request failed\",\n\t\t\t\t\t\t`Scope state not changed`\n\t\t\t\t\t).show();\n\t\t\t\t}\n\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction scopes(sh_api) {\n\treturn {\n\t\ttitle: \"Scripts Scopes\",\n\t\talias: \"scripts-scopes\",\n\t\trenderer: () => {\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"scopes\"));\n\t\t},\n\t\tiniter: scr => {\n\t\t\tsh_api.scripts.scopes_list((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.scripts.scopes_list\", err, resp, meta);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.total);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\t\t\t\n\t\t}\n\t}\n}\n\nexport {\n\tscopes\n}", "import { sidebarTemplate } from \"./scripts-funcs.js\";\n\nfunction prepareData(data) {\n\tconst preparedData = [];\n\n\tfor(let script of data.scripts) {\n\t\tconst btnSwitch = script.state == \"disabled\"\n\t\t\t? ``\n\t\t\t: ``;\n\n\t\tpreparedData.push({\n\t\t\talias: `${script.alias}${script.path}`,\n\t\t\tstate: Helper.template.toogleStateBadge(script.state),\n\t\t\tactions: `\n\t\t\t\t${btnSwitch}\n\t\t\t`\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainTable(scr, data, total) {\n\tconst provideSciptsData = {};\n\tfor(let i in data) {\n\t\tprovideSciptsData[data[i].alias] = data[i];\n\t\tdata[i][\"code\"] = \"\";\n\t}\n\tscr.currentScreen.DOMObject.provideSciptsData = provideSciptsData;\n\n\tscr.currentScreen.DOMObject.querySelector(\".main-container\").innerHTML = Helper.template.table(\n\t\t\"Regular scripts list\", \n\t\t{\n\t\t\talias: \"Alias\", \n\t\t\tname: \"Script name\", \n\t\t\tfilename: \"Filename\", \n\t\t\tstate: \"State\", \n\t\t\tactions: \"Actions\"\n\t\t},\n\t\tdata,\n\t\t``\n\t);\n}\n\nfunction initMainTableInteractiveElements(scr, sh_api) {\n\tscr.currentScreen.DOMObject.querySelectorAll(\".change-state-btn\").forEach(btn => {\n\t\tbtn.addEventListener(\"click\", e => {\n\t\t\tconst btn = e.currentTarget;\n\t\t\tif(btn.getAttribute(\"disabled\")) {\n\t\t\t\treturn ;\n\t\t\t}\n\n\t\t\tconst methName = btn.dataset.value == \"enable\"\n\t\t\t\t? \"regular_enable\"\n\t\t\t\t: \"regular_disable\"\n\n\t\t\tconst script = scr.currentScreen.DOMObject.provideSciptsData[btn.dataset.alias] ?? {};\n\n\t\t\tHelper.states.btnLoadingState(btn, true);\n\t\t\tsh_api.scripts[methName](script.alias, (err, data, meta) => {\n\t\t\t\tHelper.states.btnLoadingState(btn, false);\n\n\t\t\t\tif(data) {\n\t\t\t\t\tsetTimeout(() => Screens.reinit(), 250);\n\t\t\t\t\tToasts.createSuccess(\n\t\t\t\t\t\t`Request Success`,\n\t\t\t\t\t\t`State of ${script.alias} was changed`\n\t\t\t\t\t).show();\n\t\t\t\t} else {\n\t\t\t\t\tToasts.createError(\n\t\t\t\t\t\t\"Request failed\",\n\t\t\t\t\t\t`Regular script state not changed`\n\t\t\t\t\t).show();\n\t\t\t\t}\n\n\t\t\t});\n\t\t});\n\t});\n}\n\nfunction regular(sh_api) {\n\treturn {\n\t\ttitle: \"Scripts Regular\",\n\t\talias: \"scripts-regular\",\n\t\trenderer: () => {\n\t\t\treturn Helper.template.mainTemplate(sidebarTemplate(\"regular\"));\n\t\t},\n\t\tiniter: scr => {\n\t\t\tsh_api.scripts.regular_list((err, resp, meta) => {\n\t\t\t\tconsole.log(\"sh_api.scripts.regular_list\", err, resp, meta);\n\n\t\t\t\tif(meta.status_code != 200) {\n\t\t\t\t\treturn scr.error(\"Server API ERROR\", \"\");\n\t\t\t\t}\n\n\t\t\t\trenderingMainTable(scr, prepareData(resp.data), resp.data.total);\n\t\t\t\tinitMainTableInteractiveElements(scr, sh_api);\n\n\t\t\t\tscr.ready();\n\t\t\t});\t\t\t\n\t\t}\n\t}\n}\n\nexport {\n\tregular\n}", "import { runActionScript } from \"./scripts-funcs.js\";\nimport { placeInArea } from \"../areas/areas-placeto-component.js\";\n\nexport function actionDetailsPopup(script, sh_api) {\n\tconsole.log(\"actionDetailsPopup\", script);\n\n\treturn Modals.create(\"action-script-popup\", {\n\t\ttitle: `${script.name}`,\n\t\tbody: modal => {\n\t\t\tconst placeInAreaContainer = (script.area_id != -1) \n\t\t\t\t? ``\n\t\t\t\t: \"\";\n\n\t\t\treturn `\n\t\t\t\t${script.alias}${script.code}\n\t\t\t\t\t\t\t${script.path}`,\n\t\t\tstate: script.state,\n\t\t\tcode: script.code,\n\t\t\tid: script.id ?? 0,\n\t\t\tarea_id: script.area_id ?? -1\n\t\t});\n\t}\n\n\treturn preparedData;\n}\n\nfunction renderingMainGrid(scr, data, total) {\n\tlet grid = `${device.ip}`,\n\t\t\t\t\t\t\tactions: `\n\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t`\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\treturn preparedData;\n\t\t\t\t}\n\n\t\t\t\tconst devices = prepareDevicesData(data?.data);\n\n\t\t\t\tdevicesContainer.innerHTML = Helper.template.table(\n\t\t\t\t\t\"\", \n\t\t\t\t\t{\n\t\t\t\t\t\tdeviceName: \"Device name\", \n\t\t\t\t\t\talias: \"Device alias\", \n\t\t\t\t\t\tstatus: \"Status\", \n\t\t\t\t\t\tip: \"IP\", \n\t\t\t\t\t\tactions: \"Actions\"\n\t\t\t\t\t},\n\t\t\t\t\tdevices,\n\t\t\t\t\t``\n\t\t\t\t);\n\n\t\t\t\tdevicesContainer.querySelectorAll(\".reboot-btn\").forEach(rebootBtn => {\n\t\t\t\t\trebootBtn.addEventListener(\"click\", e => {\n\t\t\t\t\t\tif(rebootBtn.getAttribute(\"disabled\")) {\n\t\t\t\t\t\t\treturn ;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\trebootDeviceBtnHandler(sh_api, e.currentTarget, modal);\n\t\t\t\t\t});\n\t\t\t\t});\n\n\t\t\t\tloader.remove();\n\n\t\t\t\tconsole.log(\"devices\", devices);\n\t\t\t});\n\t\t}\n\t});\n}", "import { \n\trunActionScript, \n\tsetActionCardEventsHandlers, \n\tcreateActionCardHtml,\n\tcreateActionCard,\n} from \"../scripts/scripts-funcs.js\";\nimport { prepareData } from \"../scripts/scripts-actions-screen.js\";\n// import { actionDetailsPopup } from \"./scripts-action-popup.js\";\n\nexport function areaActionsModal(area, sh_api) {\n\tconsole.log(\"areaActionsModal\", area);\n\n\treturn Modals.create(\"area-actions-modal\", {\n\t\ttitle: ` ${area.display_name}`,\n\t\tbody: modal => {\n\t\t\treturn `\n\t\t\t\t\n\t\t\t\t${device.ip}`,\n\t\t\t// \t\t\t\tactions: `\n\t\t\t// \t\t\t\t\t\n\t\t\t// \t\t\t\t`\n\t\t\t// \t\t\t});\n\t\t\t// \t\t}\n\n\t\t\t// \t\treturn preparedData;\n\t\t\t// \t}\n\n\t\t\t// \tconst devices = prepareDevicesData(data?.data);\n\n\t\t\t// \tdevicesContainer.innerHTML = Helper.template.table(\n\t\t\t// \t\t\"\", \n\t\t\t// \t\t{\n\t\t\t// \t\t\tdeviceName: \"Device name\", \n\t\t\t// \t\t\talias: \"Device alias\", \n\t\t\t// \t\t\tstatus: \"Status\", \n\t\t\t// \t\t\tip: \"IP\", \n\t\t\t// \t\t\tactions: \"Actions\"\n\t\t\t// \t\t},\n\t\t\t// \t\tdevices,\n\t\t\t// \t\t``\n\t\t\t// \t);\n\n\t\t\t// \tdevicesContainer.querySelectorAll(\".reboot-btn\").forEach(rebootBtn => {\n\t\t\t// \t\trebootBtn.addEventListener(\"click\", e => {\n\t\t\t// \t\t\tif(rebootBtn.getAttribute(\"disabled\")) {\n\t\t\t// \t\t\t\treturn ;\n\t\t\t// \t\t\t}\n\n\t\t\t// \t\t\trebootDeviceBtnHandler(sh_api, e.currentTarget, modal);\n\t\t\t// \t\t});\n\t\t\t// \t});\n\n\t\t\t// \tloader.remove();\n\n\t\t\t// \tconsole.log(\"devices\", devices);\n\t\t\t// });\n\t\t}\n\t});\n}", "\nexport function createNewAreaModal(sh_api) {\n\tconsole.log(\"createNewAreaModal\");\n\n\treturn Modals.create(\"create-area-modal\", {\n\t\ttitle: ` Create new Area`,\n\t\tbody: modal => {\n\t\t\treturn `\n\t\t\t\t${text}
\n\t\t\t`;\n\t\t},\n\t\tactions: modal => {\n\t\t\tconst buttonNO = Helper.template.createElement(\"button\", { class: \"btn btn-primary\" }, \"NO\");\n\t\t\tconst buttonYES = Helper.template.createElement(\"button\", { class: \"btn btn-warning\" }, \"YES\");\n\n\t\t\tbuttonNO.addEventListener(\"click\", e => {\n\t\t\t\tmodal.close();\n\t\t\t\tcanceledCb();\n\t\t\t});\n\n\t\t\tbuttonYES.addEventListener(\"click\", e => {\n\t\t\t\tmodal.close();\n\t\t\t\tconfirmedCb();\n\t\t\t});\n\n\t\t\treturn [ buttonNO, buttonYES ];\n\t\t}\n\t}).show();\n}", "function scrollToElementInFocus(container) {\n\tconst focus = container.querySelector(\".focus\");\n\tif (!focus) return;\n\n\tconst container_rect = container.getBoundingClientRect();\n\tconst focus_rect = focus.getBoundingClientRect();\n\n\tif (focus_rect.top < container_rect.top) {\n\t\tcontainer.scrollTop -= (container_rect.top - focus_rect.top);\n\t} else if (focus_rect.bottom > container_rect.bottom) {\n\t\tcontainer.scrollTop += (focus_rect.bottom - container_rect.bottom);\n\t}\n}\n\nfunction autoSetState(container) {\n\tconst totalViewed = container.advancedSelect.optionsElements.length - container.querySelectorAll(\".option.hide\").length;\n\tif(totalViewed == 0) {\n\t\tcontainer.advancedSelect.showState(\"not-found\");\n\t} else {\n\t\tcontainer.advancedSelect.showState(\"options\");\n\t}\n}\n\nexport default function advancedSelect(input, options, notFoundText) {\n\tconst container = document.createElement(\"div\");\n\tcontainer.classList.add(\"advanced-select\");\n\n\tlet optionsList = ``;\n\tfor(let optionValue in options) {\n\t\toptionsList += `