diff --git a/server/SHServ/Controllers/DevicesRESTAPIController.php b/server/SHServ/Controllers/DevicesRESTAPIController.php index 1116fa4..034621f 100644 --- a/server/SHServ/Controllers/DevicesRESTAPIController.php +++ b/server/SHServ/Controllers/DevicesRESTAPIController.php @@ -63,6 +63,33 @@ return $this -> utils() -> response_error($result["err_alias"]); } + public function resetup_device($device_id) { + $devices_model = new \SHServ\Models\Devices(); + + $device = $devices_model -> by_id(intval($device_id)); + + if(!$device) { + return $this -> utils() -> response_error("device_not_found"); + } + + $result = $devices_model -> resetup_device($device); + + if($result) { + $device_about = $device -> device_api() -> get_about(); + return $this -> utils() -> response_success([ + "device" => [ + "id" => $device -> id(), + "alias" => $device -> alias, + "name" => $device -> name, + "description" => $device -> description, + "device" => $device_about["data"] + ] + ]); + } + + return $this -> utils() -> response_error(); + } + public function remove_device($device_id) { $devices_model = new Devices(); $result = $devices_model -> remove_device(intval($device_id)); diff --git a/server/SHServ/Entities/Device.php b/server/SHServ/Entities/Device.php index 6143819..8a7dd80 100644 --- a/server/SHServ/Entities/Device.php +++ b/server/SHServ/Entities/Device.php @@ -93,4 +93,9 @@ $this -> device_api_instance -> set_local_token($token); return $this -> auth() -> update(); } + + public function resetup(String $token) { + $this -> auth() -> kill(); + return $this -> set_device_token($token); + } } \ No newline at end of file diff --git a/server/SHServ/Models/Devices.php b/server/SHServ/Models/Devices.php index 7eae482..74f0c7d 100644 --- a/server/SHServ/Models/Devices.php +++ b/server/SHServ/Models/Devices.php @@ -81,6 +81,11 @@ return $device; } + public function resetup_device(Device $device) { + $device_token = app() -> utils -> generate_token(16); + return $device -> resetup($device_token); + } + public function remove_device(int $device_id): Array { $device = $this -> by_id($device_id); diff --git a/server/SHServ/Routes/DevicesRESTAPI_v1.php b/server/SHServ/Routes/DevicesRESTAPI_v1.php index 5b63c2e..3d2e6d5 100644 --- a/server/SHServ/Routes/DevicesRESTAPI_v1.php +++ b/server/SHServ/Routes/DevicesRESTAPI_v1.php @@ -52,6 +52,12 @@ "{$this -> cn}\\DevicesRESTAPIController@update_alias", "/api/v1/devices/update-alias" ); + + $this -> router -> post( + [ "device_id" ], + "{$this -> cn}\\DevicesRESTAPIController@resetup_device", + "/api/v1/devices/resetup" + ); } protected function devices_restapi_get_routes() { diff --git a/webclient/dist/js/main.js b/webclient/dist/js/main.js index 635ff64..839071f 100644 --- a/webclient/dist/js/main.js +++ b/webclient/dist/js/main.js @@ -1,4 +1,4 @@ -(()=>{var Oe=Object.defineProperty,Ce=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var te=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Ne=Object.prototype.propertyIsEnumerable;var ae=(a,e,t)=>e in a?Oe(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,b=(a,e)=>{for(var t in e||(e={}))Ie.call(e,t)&&ae(a,t,e[t]);if(te)for(var t of te(e))Ne.call(e,t)&&ae(a,t,e[t]);return a},ne=(a,e)=>Ce(a,ke(e));var se=(a,e,t)=>new Promise((n,s)=>{var i=o=>{try{r(t.next(o))}catch(l){s(l)}},c=o=>{try{r(t.throw(o))}catch(l){s(l)}},r=o=>o.done?n(o.value):Promise.resolve(o.value).then(i,c);r((t=t.apply(a,e)).next())});var h,T,D;function Re(){h.dataset.navState="displayed",h.classList.remove("state-off"),h.classList.add("state-on"),T.classList.add("a-show")}function F(){h.dataset.navState="hidden",h.classList.remove("state-on"),h.classList.add("state-off"),T.classList.add("a-hide"),T.classList.remove("a-show"),setTimeout(()=>{T.classList.remove("a-hide")},300)}function ie(){console.log("HUD init"),h=document.querySelector(".hud .nav-toggle"),T=document.querySelector(".hud .navigation"),D=document.querySelector(".hud .reload-screen"),h==null||h.addEventListener("click",a=>{a.currentTarget.dataset.navState!="displayed"?Re():F()}),D==null||D.addEventListener("click",a=>{Screens.reload()})}var M=class{constructor(e,t,n){this.screens={},this.routesMap={},this.currentScreen=null,this.eventsHandlers={switch:[],reload:[],reinit:[],errorScreen:[]},this.screensContainer=document.querySelector(e),this.loader=document.querySelector(t),this.errorScreen=document.querySelector(n),console.log("Screens Init")}add(e,t){if(typeof t!="object")return console.error("Screens: screens must be object");if(typeof(t==null?void 0:t.alias)=="undefined")return console.error("Screens: undefined alias");if(typeof(t==null?void 0:t.renderer)!="function")return console.error("Screens: renderer must be function");this.screens[t.alias]=b({route:e},t),this.routesMap[e]=t.alias}switch(e){var n;if(this.runSwitchHandlers(e),this.hideErrorScreen(),this.showLoader(),(n=this.currentScreen)==null||n.DOMObject.remove(),typeof this.screens[e]=="undefined"){console.error(`Screens: "${e}" not found`);return}this.currentScreen=this.screens[e];let t=document.createElement("div");t.classList.add("screen"),t.id=e,t.dataset.alias=e,t.innerHTML=this.currentScreen.renderer(),this.currentScreen.DOMObject=t,this.screensContainer.append(this.currentScreen.DOMObject),this.currentScreen.initer(this)}reload(){this.currentScreen&&(this.runReloadHandlers(this.currentScreen.alias),this.switch(this.currentScreen.alias))}reinit(){this.currentScreen&&(this.currentScreen.initer(this),this.runReinitHandlers())}routing(){setInterval(()=>{let e=document.location.hash.split("#!")[1];if(typeof e=="undefined"||e=="")return;let t=typeof this.routesMap[e]=="undefined"?"not-found-screen":this.routesMap[e];(!this.currentScreen||this.currentScreen.alias!=t)&&this.switch(t)},50)}ready(){this.currentScreen!=null&&(this.currentScreen.DOMObject||(this.currentScreen.DOMObject=document.getElementsById(this.currentScreen.alias)),this.hideLoader(),this.currentScreen.DOMObject.classList.add("a-show"))}error(e,t){var n;(n=this.currentScreen)==null||n.DOMObject.remove(),this.errorScreen.querySelector(".error-title").innerHTML=e,this.errorScreen.querySelector(".error-text").innerHTML=t,this.showErrorScreen(),this.runErrorScreenHandlers()}hideLoader(){this.loader.classList.remove("a-show")}showLoader(){this.loader.classList.add("a-show")}showErrorScreen(){this.errorScreen.classList.add("a-show")}hideErrorScreen(){this.errorScreen.classList.remove("a-show")}getScreens(){return this.screens}getRoutesMap(){return this.routesMap}onSwitch(e){this.eventsHandlers.switch.push(e)}onReaload(e){this.eventsHandlers.reload.push(e)}onReinit(e){this.eventsHandlers.reinit.push(e)}onErrorScreen(e){this.eventsHandlers.errorScreen.push(e)}runSwitchHandlers(e){let t=Object.keys(this.routesMap).filter(n=>this.routesMap[n]==e);for(let n of this.eventsHandlers.switch)n(this,e,t.length?t[0]:void 0)}runReloadHandlers(e){for(let t of this.eventsHandlers.reload)t(this,e)}runReinitHandlers(){for(let e of this.eventsHandlers.reinit)e(this)}runErrorScreenHandlers(){for(let e of this.eventsHandlers.errorScreen)e(this)}};function xe(a,e,t,n){return` +(()=>{var Ce=Object.defineProperty,Oe=Object.defineProperties;var ke=Object.getOwnPropertyDescriptors;var te=Object.getOwnPropertySymbols;var Ie=Object.prototype.hasOwnProperty,Re=Object.prototype.propertyIsEnumerable;var ae=(a,e,t)=>e in a?Ce(a,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):a[e]=t,b=(a,e)=>{for(var t in e||(e={}))Ie.call(e,t)&&ae(a,t,e[t]);if(te)for(var t of te(e))Re.call(e,t)&&ae(a,t,e[t]);return a},ne=(a,e)=>Oe(a,ke(e));var se=(a,e,t)=>new Promise((n,s)=>{var i=o=>{try{r(t.next(o))}catch(l){s(l)}},c=o=>{try{r(t.throw(o))}catch(l){s(l)}},r=o=>o.done?n(o.value):Promise.resolve(o.value).then(i,c);r((t=t.apply(a,e)).next())});var h,T,D;function Ne(){h.dataset.navState="displayed",h.classList.remove("state-off"),h.classList.add("state-on"),T.classList.add("a-show")}function F(){h.dataset.navState="hidden",h.classList.remove("state-on"),h.classList.add("state-off"),T.classList.add("a-hide"),T.classList.remove("a-show"),setTimeout(()=>{T.classList.remove("a-hide")},300)}function ie(){console.log("HUD init"),h=document.querySelector(".hud .nav-toggle"),T=document.querySelector(".hud .navigation"),D=document.querySelector(".hud .reload-screen"),h==null||h.addEventListener("click",a=>{a.currentTarget.dataset.navState!="displayed"?Ne():F()}),D==null||D.addEventListener("click",a=>{Screens.reload()})}var M=class{constructor(e,t,n){this.screens={},this.routesMap={},this.currentScreen=null,this.eventsHandlers={switch:[],reload:[],reinit:[],errorScreen:[]},this.screensContainer=document.querySelector(e),this.loader=document.querySelector(t),this.errorScreen=document.querySelector(n),console.log("Screens Init")}add(e,t){if(typeof t!="object")return console.error("Screens: screens must be object");if(typeof(t==null?void 0:t.alias)=="undefined")return console.error("Screens: undefined alias");if(typeof(t==null?void 0:t.renderer)!="function")return console.error("Screens: renderer must be function");this.screens[t.alias]=b({route:e},t),this.routesMap[e]=t.alias}switch(e){var n;if(this.runSwitchHandlers(e),this.hideErrorScreen(),this.showLoader(),(n=this.currentScreen)==null||n.DOMObject.remove(),typeof this.screens[e]=="undefined"){console.error(`Screens: "${e}" not found`);return}this.currentScreen=this.screens[e];let t=document.createElement("div");t.classList.add("screen"),t.id=e,t.dataset.alias=e,t.innerHTML=this.currentScreen.renderer(),this.currentScreen.DOMObject=t,this.screensContainer.append(this.currentScreen.DOMObject),this.currentScreen.initer(this)}reload(){this.currentScreen&&(this.runReloadHandlers(this.currentScreen.alias),this.switch(this.currentScreen.alias))}reinit(){this.currentScreen&&(this.currentScreen.initer(this),this.runReinitHandlers())}routing(){setInterval(()=>{let e=document.location.hash.split("#!")[1];if(typeof e=="undefined"||e=="")return;let t=typeof this.routesMap[e]=="undefined"?"not-found-screen":this.routesMap[e];(!this.currentScreen||this.currentScreen.alias!=t)&&this.switch(t)},50)}ready(){this.currentScreen!=null&&(this.currentScreen.DOMObject||(this.currentScreen.DOMObject=document.getElementsById(this.currentScreen.alias)),this.hideLoader(),this.currentScreen.DOMObject.classList.add("a-show"))}error(e,t){var n;(n=this.currentScreen)==null||n.DOMObject.remove(),this.errorScreen.querySelector(".error-title").innerHTML=e,this.errorScreen.querySelector(".error-text").innerHTML=t,this.showErrorScreen(),this.runErrorScreenHandlers()}hideLoader(){this.loader.classList.remove("a-show")}showLoader(){this.loader.classList.add("a-show")}showErrorScreen(){this.errorScreen.classList.add("a-show")}hideErrorScreen(){this.errorScreen.classList.remove("a-show")}getScreens(){return this.screens}getRoutesMap(){return this.routesMap}onSwitch(e){this.eventsHandlers.switch.push(e)}onReaload(e){this.eventsHandlers.reload.push(e)}onReinit(e){this.eventsHandlers.reinit.push(e)}onErrorScreen(e){this.eventsHandlers.errorScreen.push(e)}runSwitchHandlers(e){let t=Object.keys(this.routesMap).filter(n=>this.routesMap[n]==e);for(let n of this.eventsHandlers.switch)n(this,e,t.length?t[0]:void 0)}runReloadHandlers(e){for(let t of this.eventsHandlers.reload)t(this,e)}runReinitHandlers(){for(let e of this.eventsHandlers.reinit)e(this)}runErrorScreenHandlers(){for(let e of this.eventsHandlers.errorScreen)e(this)}};function xe(a,e,t,n){return`
It's empty here yet
{{value}}",status:d=>`${d}`,connection_status:d=>`${d}`,mac:"{{value}}",alias:' {{value}}',device_id:"{{value}}",last_contact:d=>Helper.unification.timeAgo(d),create_at:d=>Helper.unification.formatDate(d),update_at:d=>Helper.unification.formatDate(d)};return l[r]?typeof l[r]=="function"?l[r](o):l[r].replaceAll("{{value}}",o):o},i="";for(let r in a){let o=(c=n[r])!=null?c:"";i+=`
+ `,console.error("deviceStateComponent",`DeviceID ${e}`);n.innerHTML=lt(t,i.data.device.alias,i.data.device.device_response),ct(n)})}},n.deviceStateComponent.create(),n}function dt(a,e,t){let n=[{payloadFieldName:"name",selector:".display-name",methName:"update_name",originalValue:e.name,isMultiString:!1},{payloadFieldName:"description",selector:".description",methName:"update_description",originalValue:e.description,isMultiString:!0},{payloadFieldName:"new_alias",selector:".alias",methName:"update_alias",originalValue:e.alias,isMultiString:!1}];for(let s of n){let i=editableString(t.querySelector(s.selector));i.editableString.onChange(c=>{let r={device_id:e.id};r[s.payloadFieldName]=c.value,a.devices[s.methName](r,(o,l,d)=>{var u,m,p;if(o||!l||!l.status)return console.error(`sh_api.devices.${s.methName}`,o),i.editableString.setValue(s.originalValue),Toasts.createError((u=o==null?void 0:o.message)!=null?u:"Error updating",(p=(m=o.raw)==null?void 0:m.msg)!=null?p:`Error of ${s.payloadFieldName} updating`).show();l.status==!0&&Screens.reinit()})})}}function N(a,e){return console.log(a),Modals.create("device-popup",{title:`Device ${a.name}`,body:t=>{var c;let n={area_id:"place-in-area-component-container",ip:"device-ip",state:"state-container",name:"display-name",description:"description",alias:"alias-view-container"},s=(r,o)=>{let l={ip:"{{value}}",status:d=>`${d}`,connection_status:d=>`${d}`,mac:"{{value}}",alias:' {{value}}',device_id:"{{value}}",last_contact:d=>Helper.unification.timeAgo(d),create_at:d=>Helper.unification.formatDate(d),update_at:d=>Helper.unification.formatDate(d)};return l[r]?typeof l[r]=="function"?l[r](o):l[r].replaceAll("{{value}}",o):o},i="";for(let r in a){let o=(c=n[r])!=null?c:"";i+=`
${a}
`,actions:n=>{let s=Helper.template.createElement("button",{class:"btn btn-primary"},"NO"),i=Helper.template.createElement("button",{class:"btn btn-warning"},"YES");return s.addEventListener("click",c=>{n.close(),t()}),i.addEventListener("click",c=>{n.close(),e()}),[s,i]}}).show()}function qe(a){let e=a.querySelector(".focus");if(!e)return;let t=a.getBoundingClientRect(),n=e.getBoundingClientRect();n.top${text}
\n\tIt's empty here yet
\n\t\t{{value}}`,\n\t\t\t\t\tstatus: 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_status: 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${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] ?? { alias: 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}", "\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\tIt's empty here yet
\n\t\t{{value}}`,\n\t\t\t\t\tstatus: 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_status: 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${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] ?? { alias: 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}", "\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 += `