diff --git a/webclient/dist/js/main.js b/webclient/dist/js/main.js index 12f8a89..bcb6aaa 100644 --- a/webclient/dist/js/main.js +++ b/webclient/dist/js/main.js @@ -1,4 +1,4 @@ -(()=>{var Y=Object.defineProperty;var A=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var H=(r,e,t)=>e in r?Y(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,g=(r,e)=>{for(var t in e||(e={}))W.call(e,t)&&H(r,t,e[t]);if(A)for(var t of A(e))G.call(e,t)&&H(r,t,e[t]);return r};var N=(r,e,t)=>new Promise((s,i)=>{var a=o=>{try{c(t.next(o))}catch(u){i(u)}},n=o=>{try{c(t.throw(o))}catch(u){i(u)}},c=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,n);c((t=t.apply(r,e)).next())});var v,y;function K(){v.dataset.navState="displayed",v.classList.remove("state-off"),v.classList.add("state-on"),y.classList.add("a-show")}function R(){v.dataset.navState="hidden",v.classList.remove("state-on"),v.classList.add("state-off"),y.classList.add("a-hide"),y.classList.remove("a-show"),setTimeout(()=>{y.classList.remove("a-hide")},300)}function M(){console.log("HUD init"),v=document.querySelector(".hud .nav-toggle"),y=document.querySelector(".hud .navigation"),v.addEventListener("click",r=>{r.currentTarget.dataset.navState!="displayed"?K():R()})}var w=class{constructor(e,t,s){this.screens={},this.routesMap={},this.currentScreen=null,this.eventsHandlers={switch:[]},this.screensContainer=document.querySelector(e),this.loader=document.querySelector(t),this.errorScreen=document.querySelector(s),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]=g({route:e},t),this.routesMap[e]=t.alias}switch(e){var s;if(this.runSwitchHandlers(e),this.hideErrorScreen(),this.showLoader(),(s=this.currentScreen)==null||s.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)}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 s;(s=this.currentScreen)==null||s.DOMObject.remove(),this.errorScreen.querySelector(".error-title").innerHTML=e,this.errorScreen.querySelector(".error-text").innerHTML=t,this.showErrorScreen()}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)}runSwitchHandlers(e){for(let t of this.eventsHandlers.switch)t(this,e)}};function Q(r,e,t,s){return` +(()=>{var Y=Object.defineProperty;var D=Object.getOwnPropertySymbols;var W=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var A=(r,e,t)=>e in r?Y(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,g=(r,e)=>{for(var t in e||(e={}))W.call(e,t)&&A(r,t,e[t]);if(D)for(var t of D(e))G.call(e,t)&&A(r,t,e[t]);return r};var N=(r,e,t)=>new Promise((s,i)=>{var a=o=>{try{c(t.next(o))}catch(d){i(d)}},n=o=>{try{c(t.throw(o))}catch(d){i(d)}},c=o=>o.done?s(o.value):Promise.resolve(o.value).then(a,n);c((t=t.apply(r,e)).next())});var v,S;function K(){v.dataset.navState="displayed",v.classList.remove("state-off"),v.classList.add("state-on"),S.classList.add("a-show")}function R(){v.dataset.navState="hidden",v.classList.remove("state-on"),v.classList.add("state-off"),S.classList.add("a-hide"),S.classList.remove("a-show"),setTimeout(()=>{S.classList.remove("a-hide")},300)}function M(){console.log("HUD init"),v=document.querySelector(".hud .nav-toggle"),S=document.querySelector(".hud .navigation"),v.addEventListener("click",r=>{r.currentTarget.dataset.navState!="displayed"?K():R()})}var w=class{constructor(e,t,s){this.screens={},this.routesMap={},this.currentScreen=null,this.eventsHandlers={switch:[],reload:[]},this.screensContainer=document.querySelector(e),this.loader=document.querySelector(t),this.errorScreen=document.querySelector(s),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]=g({route:e},t),this.routesMap[e]=t.alias}switch(e){var s;if(this.runSwitchHandlers(e),this.hideErrorScreen(),this.showLoader(),(s=this.currentScreen)==null||s.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(alias),this.switch(this.currentScreen.alias))}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 s;(s=this.currentScreen)==null||s.DOMObject.remove(),this.errorScreen.querySelector(".error-title").innerHTML=e,this.errorScreen.querySelector(".error-text").innerHTML=t,this.showErrorScreen()}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)}runSwitchHandlers(e){for(let t of this.eventsHandlers.switch)t(this,e)}runReloadHandlers(e){for(let t of this.eventsHandlers.reload)t(this,e)}};function Q(r,e,t,s){return` - `}function V(r){return r.close=function(){this.classList.add("a-hide"),setTimeout(()=>{this.remove()},300)},r.querySelector(".toast-close").addEventListener("click",e=>{r.close()}),r.show=function(){document.querySelector("body").append(r),setTimeout(()=>{r.classList.add("a-show")},10)},r}function S(r,e,t,s){let i=document.createElement("div");return i.innerHTML=Q(r,e,t,s),V(i.childNodes[1])}function X(r,e){return S("success",'',r,e)}function Z(r,e){return S("info",'',r,e)}function ee(r,e){return S("warning",'',r,e)}function q(r,e){return S("danger",'',r,e)}var x={create:S,createInfo:Z,createSuccess:X,createWarning:ee,createError:q,createDanger:q};function te(r){let e="";for(let t of r){let s="",i="";t.route&&(s=``,i=""),e+=` + `}function V(r){return r.close=function(){this.classList.add("a-hide"),setTimeout(()=>{this.remove()},300)},r.querySelector(".toast-close").addEventListener("click",e=>{r.close()}),r.show=function(){document.querySelector("body").append(r),setTimeout(()=>{r.classList.add("a-show")},10)},Screens.onSwitch((e,t)=>{setTimeout(()=>{r.close()},1e4)}),r}function y(r,e,t,s){let i=document.createElement("div");return i.innerHTML=Q(r,e,t,s),V(i.childNodes[1])}function X(r,e){return y("success",'',r,e)}function Z(r,e){return y("info",'',r,e)}function ee(r,e){return y("warning",'',r,e)}function q(r,e){return y("danger",'',r,e)}var C={create:y,createInfo:Z,createSuccess:X,createWarning:ee,createError:q,createDanger:q};function te(r){let e="";for(let t of r){let s="",i="";t.route&&(s=``,i=""),e+=`
  • ${s}${t.content}${i}
  • @@ -16,10 +16,10 @@ ${e} - `}function se(r,e,t,s){let i='';for(let c in e)i+=`${e[c]}`;i+="";let a="";for(let c of t){a+='';for(let o in e)a+=`${c[o]}`;a+=""}let n="";return typeof s!="undefined"&&(n=` + `}function se(r,e,t,s){let i='',a=0;for(let o in e)i+=`${e[o]}`,a++;i+="";let n="";for(let o of t){n+='';for(let d in e)n+=`${o[d]}`;n+=""}let c="";return typeof s!="undefined"&&(c=` - + ${s} @@ -28,10 +28,10 @@ ${i} - ${a} - ${n} + ${n} + ${c}
    ${r}
    - `}function C(r,e,t){let s=document.createElement(r);for(let[i,a]of Object.entries(e))i==="class"?s.className=a:i==="dataset"?Object.assign(s.dataset,a):s.setAttribute(i,a);return s.innerHTML=typeof t!="undefined"?t:"",s}function re(r,e){return["primary","success","secondary","info","warning","error","danger"].indexOf(r)<0?console.error("createAlert()","Error of type: "+r):C("div",{class:`alert alert-${r}`},e)}function ie(r){let e={device_name:"name",device_hard_id:"device_id",device_ip:"ip",device_type:"type",ip_address:"ip",mac_address:"mac",device_mac:"mac",core_version:"firmware_core_version"},t={};for(let s in r){if(typeof e[s]!="undefined"){t[e[s]]=r[s];continue}t[s]=r[s]}return t}var U={template:{sidebarNav:te,table:se,createElement:C,createAlert:re},unification:{deviceFieldsUnification:ie}};var $=class{constructor(e){this.core=e}actions_list(e){return this.core.api_get("/api/v1/scripts/actions/list",e)}scopes_list(e){return this.core.api_get("/api/v1/scripts/scopes/list",e)}regular_list(e){return this.core.api_get("/api/v1/scripts/regular/list",e)}scope_get_by_filename(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${s}`,t,{})}scope_create(e,t){return this.core.api_post("/api/v1/scripts/scopes/new",e,t)}scope_update(e,t){return this.core.api_post("/api/v1/scripts/scopes/update",e,t)}action_enable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/alias/${s}/enable`,t)}action_disable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/alias/${s}/disable`,t)}regular_enable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/regular/${s}/enable`,t)}regular_disable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/regular/${s}/disable`,t)}scope_enable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/scope/${s}/enable`,t)}scope_disable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/scope/${s}/disable`,t)}scope_remove(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${s}/remove`,t)}run(e,t){return this.core.api_post("/api/v1/scripts/actions/run",e,t)}};var E=class{constructor(e){this.core=e}list(e){return this.core.api_get("/api/v1/devices/list",e)}scanning_setup(e){return this.core.api_get("/api/v1/devices/scanning/setup",e)}scanning_all(e){return this.core.api_get("/api/v1/devices/scanning/all",e)}setup_new_device(e,t){return this.core.api_post("/api/v1/devices/setup/new-device",e,t)}info(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/info`,t)}get(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}`,t)}status(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/status`,t)}action(e,t){return this.core.api_post("/api/v1/devices/action",e,t)}remove(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/remove`,t)}reboot(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/reboot`,t)}};var T=class{constructor(e){this.core=e}list(e){return this.core.api_get("/api/v1/areas/list",e)}inner_list(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/list`,t)}new_area(e,t){return this.core.api_post("/api/v1/areas/new-area",e,t)}remove(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/remove`,t)}place_in_area(e,t){return this.core.api_post("/api/v1/areas/place-in-area",e,t)}update_display_name(e,t){return this.core.api_post("/api/v1/areas/update-display-name",e,t)}update_alias(e,t){return this.core.api_post("/api/v1/areas/update-alias",e,t)}devices(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/devices`,t)}unassign_from_area(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/unassign-from-area`,t)}types_list(e){return this.core.api_get("/api/v1/areas/types/list",e)}reboot_devices(e,t){if(e==null)return this.core.api_get("/api/v1/areas/reboot_devices",t);let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/reboot_devices`,t)}};function j(r){if(!r||typeof r!="object")return"";let e=new URLSearchParams;Object.entries(r).forEach(([s,i])=>{i!=null&&e.append(s,String(i))});let t=e.toString();return t?`?${t}`:""}function ne(r,e){let t=String(r||"").replace(/\/+$/,""),s=String(e||"").replace(/^\/+/,"");return`${t}/${s}`}function ae(r){try{return{ok:!0,data:JSON.parse(r)}}catch(e){return{ok:!1,error:e}}}var L=class{constructor(e){this.base_url=(e==null?void 0:e.base_url)||"",this.token=(e==null?void 0:e.token)||"",this.timeout_ms=Number.isFinite(e==null?void 0:e.timeout_ms)?e.timeout_ms:15e3,this.default_headers=(e==null?void 0:e.default_headers)||{},this.on_unauthorized=typeof(e==null?void 0:e.on_unauthorized)=="function"?e.on_unauthorized:null,this.proxy_path=(e==null?void 0:e.proxy_path)||"",this.scripts=new $(this),this.devices=new E(this),this.areas=new T(this)}set_base_url(e){this.base_url=e||""}set_token(e){this.token=e||""}set_proxy_path(e){this.proxy_path=e||""}_wrap_path(e,t){if(!this.proxy_path)return t?`${e}${j(t)}`:e;let s=g({path:e},t||{});return`${this.proxy_path}${j(s)}`}request(e,t,s,i,a){let n=typeof i=="function"?i:()=>{},c=ne(this.base_url,t),o=new AbortController,u=Number.isFinite(a==null?void 0:a.timeout_ms)?a.timeout_ms:this.timeout_ms,d=setTimeout(()=>o.abort(),u),m=g(g({},this.default_headers),(a==null?void 0:a.headers)||{});this.token&&(m.Authorization=`Bearer ${this.token}`);let b;s!=null&&(m["Content-Type"]="application/json",b=JSON.stringify(s)),fetch(c,{method:e,headers:m,body:b,signal:o.signal}).then(l=>N(this,null,function*(){clearTimeout(d);let h={url:c,method:e,status_code:l.status,headers:l.headers},p=yield l.text(),O=ae(p),f=O.ok?O.data:p;if(!l.ok){let _={type:"http_error",message:`HTTP ${l.status}`,status_code:l.status,raw:f};if((l.status===401||l.status===403)&&this.on_unauthorized)try{this.on_unauthorized({error:_,meta:h})}catch(D){}return n(_,null,h)}if(O.ok&&f&&typeof f=="object"){let _=f.status;if(_===!1||_==="error"){let D={type:"api_error",message:f.message||"API error",status_code:l.status,raw:f,field:f.field};return n(D,null,h)}}return n(null,f,h)})).catch(l=>{clearTimeout(d);let p=l&&(l.name==="AbortError"||String(l).includes("AbortError"))?{type:"timeout",message:`Timeout after ${u}ms`}:{type:"network_error",message:(l==null?void 0:l.message)||"Network error",details:l};return n(p,null,{url:c,method:e,status_code:0,headers:null})})}get(e,t,s){return this.request("GET",e,null,t,s)}post(e,t,s,i){return this.request("POST",e,t,s,i)}api_get(e,t,s,i){return this.get(this._wrap_path(e,s),t,i)}api_post(e,t,s,i,a){return this.post(this._wrap_path(e,i),t,s,a)}};function P(r,e){return console.log(r),Modals.create("device-popup",{title:`Device ${r.name}`,body:t=>{let s="";for(let i in r)s+=` + `}function x(r,e,t){let s=document.createElement(r);for(let[i,a]of Object.entries(e))i==="class"?s.className=a:i==="dataset"?Object.assign(s.dataset,a):s.setAttribute(i,a);return s.innerHTML=typeof t!="undefined"?t:"",s}function re(r,e){return["primary","success","secondary","info","warning","error","danger"].indexOf(r)<0?console.error("createAlert()","Error of type: "+r):x("div",{class:`alert alert-${r}`},e)}function ie(r){let e={device_name:"name",device_hard_id:"device_id",device_ip:"ip",device_type:"type",ip_address:"ip",mac_address:"mac",device_mac:"mac",core_version:"firmware_core_version"},t={};for(let s in r){if(typeof e[s]!="undefined"){t[e[s]]=r[s];continue}t[s]=r[s]}return t}var U={template:{sidebarNav:te,table:se,createElement:x,createAlert:re},unification:{deviceFieldsUnification:ie}};var $=class{constructor(e){this.core=e}actions_list(e){return this.core.api_get("/api/v1/scripts/actions/list",e)}scopes_list(e){return this.core.api_get("/api/v1/scripts/scopes/list",e)}regular_list(e){return this.core.api_get("/api/v1/scripts/regular/list",e)}scope_get_by_filename(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${s}`,t,{})}scope_create(e,t){return this.core.api_post("/api/v1/scripts/scopes/new",e,t)}scope_update(e,t){return this.core.api_post("/api/v1/scripts/scopes/update",e,t)}action_enable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/alias/${s}/enable`,t)}action_disable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/alias/${s}/disable`,t)}regular_enable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/regular/${s}/enable`,t)}regular_disable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/regular/${s}/disable`,t)}scope_enable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/scope/${s}/enable`,t)}scope_disable(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/actions/scope/${s}/disable`,t)}scope_remove(e,t){let s=encodeURIComponent(String(e||""));return this.core.api_get(`/api/v1/scripts/scopes/name/${s}/remove`,t)}run(e,t){return this.core.api_post("/api/v1/scripts/actions/run",e,t)}};var E=class{constructor(e){this.core=e}list(e){return this.core.api_get("/api/v1/devices/list",e)}scanning_setup(e){return this.core.api_get("/api/v1/devices/scanning/setup",e)}scanning_all(e){return this.core.api_get("/api/v1/devices/scanning/all",e)}setup_new_device(e,t){return this.core.api_post("/api/v1/devices/setup/new-device",e,t)}info(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/info`,t)}get(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}`,t)}status(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/status`,t)}action(e,t){return this.core.api_post("/api/v1/devices/action",e,t)}remove(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/remove`,t)}reboot(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/devices/id/${s}/reboot`,t)}};var T=class{constructor(e){this.core=e}list(e){return this.core.api_get("/api/v1/areas/list",e)}inner_list(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/list`,t)}new_area(e,t){return this.core.api_post("/api/v1/areas/new-area",e,t)}remove(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/remove`,t)}place_in_area(e,t){return this.core.api_post("/api/v1/areas/place-in-area",e,t)}update_display_name(e,t){return this.core.api_post("/api/v1/areas/update-display-name",e,t)}update_alias(e,t){return this.core.api_post("/api/v1/areas/update-alias",e,t)}devices(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/devices`,t)}unassign_from_area(e,t){let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/unassign-from-area`,t)}types_list(e){return this.core.api_get("/api/v1/areas/types/list",e)}reboot_devices(e,t){if(e==null)return this.core.api_get("/api/v1/areas/reboot_devices",t);let s=encodeURIComponent(String(e));return this.core.api_get(`/api/v1/areas/id/${s}/reboot_devices`,t)}};function j(r){if(!r||typeof r!="object")return"";let e=new URLSearchParams;Object.entries(r).forEach(([s,i])=>{i!=null&&e.append(s,String(i))});let t=e.toString();return t?`?${t}`:""}function ne(r,e){let t=String(r||"").replace(/\/+$/,""),s=String(e||"").replace(/^\/+/,"");return`${t}/${s}`}function ae(r){try{return{ok:!0,data:JSON.parse(r)}}catch(e){return{ok:!1,error:e}}}var L=class{constructor(e){this.base_url=(e==null?void 0:e.base_url)||"",this.token=(e==null?void 0:e.token)||"",this.timeout_ms=Number.isFinite(e==null?void 0:e.timeout_ms)?e.timeout_ms:15e3,this.default_headers=(e==null?void 0:e.default_headers)||{},this.on_unauthorized=typeof(e==null?void 0:e.on_unauthorized)=="function"?e.on_unauthorized:null,this.proxy_path=(e==null?void 0:e.proxy_path)||"",this.scripts=new $(this),this.devices=new E(this),this.areas=new T(this)}set_base_url(e){this.base_url=e||""}set_token(e){this.token=e||""}set_proxy_path(e){this.proxy_path=e||""}_wrap_path(e,t){if(!this.proxy_path)return t?`${e}${j(t)}`:e;let s=g({path:e},t||{});return`${this.proxy_path}${j(s)}`}request(e,t,s,i,a){let n=typeof i=="function"?i:()=>{},c=ne(this.base_url,t),o=new AbortController,d=Number.isFinite(a==null?void 0:a.timeout_ms)?a.timeout_ms:this.timeout_ms,u=setTimeout(()=>o.abort(),d),m=g(g({},this.default_headers),(a==null?void 0:a.headers)||{});this.token&&(m.Authorization=`Bearer ${this.token}`);let b;s!=null&&(m["Content-Type"]="application/json",b=JSON.stringify(s)),fetch(c,{method:e,headers:m,body:b,signal:o.signal}).then(l=>N(this,null,function*(){clearTimeout(u);let h={url:c,method:e,status_code:l.status,headers:l.headers},p=yield l.text(),O=ae(p),f=O.ok?O.data:p;if(!l.ok){let _={type:"http_error",message:`HTTP ${l.status}`,status_code:l.status,raw:f};if((l.status===401||l.status===403)&&this.on_unauthorized)try{this.on_unauthorized({error:_,meta:h})}catch(I){}return n(_,null,h)}if(O.ok&&f&&typeof f=="object"){let _=f.status;if(_===!1||_==="error"){let I={type:"api_error",message:f.message||"API error",status_code:l.status,raw:f,field:f.field};return n(I,null,h)}}return n(null,f,h)})).catch(l=>{clearTimeout(u);let p=l&&(l.name==="AbortError"||String(l).includes("AbortError"))?{type:"timeout",message:`Timeout after ${d}ms`}:{type:"network_error",message:(l==null?void 0:l.message)||"Network error",details:l};return n(p,null,{url:c,method:e,status_code:0,headers:null})})}get(e,t,s){return this.request("GET",e,null,t,s)}post(e,t,s,i){return this.request("POST",e,t,s,i)}api_get(e,t,s,i){return this.get(this._wrap_path(e,s),t,i)}api_post(e,t,s,i,a){return this.post(this._wrap_path(e,i),t,s,a)}};function P(r,e){return console.log(r),Modals.create("device-popup",{title:`Device ${r.name}`,body:t=>{let s="";for(let i in r)s+=` ${i}: ${r[i]} @@ -44,9 +44,9 @@ - `},actions:t=>{let s=Helper.template.createElement("button",{class:"btn btn-primary"},"Close"),i=Helper.template.createElement("button",{class:"btn btn-warning with-icon"},' Reboot'),a=Helper.template.createElement("button",{class:"btn btn-danger with-icon"},' Remove');return s.addEventListener("click",n=>{t.close()}),i.addEventListener("click",n=>{e.devices.reboot(r.id,(c,o,u)=>{console.log("Reboot done"),t.close(),setTimeout(()=>{o?Toasts.createSuccess("Reboot successful",`Device: ${r.name}
    + `},actions:t=>{let s=Helper.template.createElement("button",{class:"btn btn-primary"},"Close"),i=Helper.template.createElement("button",{class:"btn btn-warning with-icon"},' Reboot'),a=Helper.template.createElement("button",{class:"btn btn-danger with-icon"},' Remove');return s.addEventListener("click",n=>{t.close()}),i.addEventListener("click",n=>{e.devices.reboot(r.id,(c,o,d)=>{console.log("Reboot done"),t.close(),setTimeout(()=>{o?Toasts.createSuccess("Reboot successful",`Device: ${r.name}
    Alias: ${r.alias}`).show():Toasts.createError("Reboot failed",`Device: ${r.name}
    - Alias: ${r.alias}`).show()},300)})}),a.addEventListener("click",n=>{confirmPopup("Are you sure you want to remove this device?",()=>{e.devices.remove(r.id,(c,o,u)=>{console.log("Was removed"),t.close(),setTimeout(()=>{Toasts.createSuccess("Removed",` + Alias: ${r.alias}`).show()},300)})}),a.addEventListener("click",n=>{confirmPopup("Are you sure you want to remove this device?",()=>{e.devices.remove(r.id,(c,o,d)=>{console.log("Was removed"),t.close(),setTimeout(()=>{Toasts.createSuccess("Removed",` Device: ${r.name}
    Alias: ${r.alias}
    IP: ${r.ip} @@ -97,7 +97,7 @@
    - `},actions:t=>{let s=Helper.template.createElement("button",{class:"btn btn-primary"},"Cancel");s.addEventListener("click",a=>{t.close()});let i=Helper.template.createElement("button",{class:"btn btn-success with-icon"},' Setup');return i.addEventListener("click",a=>{if(a.currentTarget.getAttribute("disabled"))return!1;let n={device_ip:r.ip},c=document.querySelector("#device-setup .setup-form");if(c.querySelectorAll("input[type='text']").forEach(d=>{d.dispatchEvent(new Event("input",{bubbles:!0}))}),c.querySelectorAll(".label.error").length)return!1;let o=c.querySelectorAll("input"),u=c.querySelector("textarea");for(let d of o)n[d.getAttribute("name")]=d.value;n[u.getAttribute("name")]=u.value,i.setAttribute("disabled","disabled"),i.classList.add("loading"),e.devices.setup_new_device(n,(d,m,b)=>{var l,h;if(i.removeAttribute("disabled"),i.classList.remove("loading"),(d==null?void 0:d.type)=="api_error"){if(console.error("ERR! sh_api.devices.setup_new_device",d.raw),(l=d.raw)!=null&&l.failed_fields)for(let p of d.raw.failed_fields)t.querySelector(`[name="${p}"]`).parentNode.classList.add("error");if((h=d.raw)!=null&&h.msg){let p=t.querySelector(".setup-form .alert-container");p.innerHTML="",p==null||p.append(Helper.template.createAlert("error",d.raw.msg))}return!1}if(!m)return!1;o.forEach(p=>p.value=""),u.value="",t.close(),setTimeout(()=>{Toasts.createSuccess("Setup successful",`Added new device ID ${r.device_id}`).show()},300)})}),[s,i]},onready:t=>{t.querySelector(".setup-form").querySelectorAll("input").forEach(i=>{i.addEventListener("input",a=>{var n;a.currentTarget.value.length?(a.currentTarget.parentNode.classList.remove("error"),(n=a.currentTarget.parentNode.parentNode.querySelector(".input-info.error"))==null||n.remove()):(a.currentTarget.parentNode.classList.add("error"),a.currentTarget.parentNode.parentNode.querySelector(".input-info.error")||a.currentTarget.parentNode.parentNode.append(Helper.template.createElement("div",{class:"input-info error"},' Field cannot be empty')))})})}})}function z(r){return Helper.template.sidebarNav([{content:' Devices',route:"/#!/devices",is_active:r=="devices"},{content:' Scanning',route:"/#!/devices/scanning",is_active:r=="scanning"}])}function oe(r){return{alias:"devices",renderer:()=>` + `},actions:t=>{let s=Helper.template.createElement("button",{class:"btn btn-primary"},"Cancel");s.addEventListener("click",a=>{t.close()});let i=Helper.template.createElement("button",{class:"btn btn-success with-icon"},' Setup');return i.addEventListener("click",a=>{if(a.currentTarget.getAttribute("disabled"))return!1;let n={device_ip:r.ip},c=document.querySelector("#device-setup .setup-form");if(c.querySelectorAll("input[type='text']").forEach(u=>{u.dispatchEvent(new Event("input",{bubbles:!0}))}),c.querySelectorAll(".label.error").length)return!1;let o=c.querySelectorAll("input"),d=c.querySelector("textarea");for(let u of o)n[u.getAttribute("name")]=u.value;n[d.getAttribute("name")]=d.value,i.setAttribute("disabled","disabled"),i.classList.add("loading"),e.devices.setup_new_device(n,(u,m,b)=>{var l,h;if(i.removeAttribute("disabled"),i.classList.remove("loading"),(u==null?void 0:u.type)=="api_error"){if(console.error("ERR! sh_api.devices.setup_new_device",u.raw),(l=u.raw)!=null&&l.failed_fields)for(let p of u.raw.failed_fields)t.querySelector(`[name="${p}"]`).parentNode.classList.add("error");if((h=u.raw)!=null&&h.msg){let p=t.querySelector(".setup-form .alert-container");p.innerHTML="",p==null||p.append(Helper.template.createAlert("error",u.raw.msg))}return!1}if(!m)return!1;o.forEach(p=>p.value=""),d.value="",t.close(),setTimeout(()=>{Toasts.createSuccess("Setup successful",`Added new device ID ${r.device_id}`).show()},300)})}),[s,i]},onready:t=>{t.querySelector(".setup-form").querySelectorAll("input").forEach(i=>{i.addEventListener("input",a=>{var n;a.currentTarget.value.length?(a.currentTarget.parentNode.classList.remove("error"),(n=a.currentTarget.parentNode.parentNode.querySelector(".input-info.error"))==null||n.remove()):(a.currentTarget.parentNode.classList.add("error"),a.currentTarget.parentNode.parentNode.querySelector(".input-info.error")||a.currentTarget.parentNode.parentNode.append(Helper.template.createElement("div",{class:"input-info error"},' Field cannot be empty')))})})}})}function z(r){return Helper.template.sidebarNav([{content:' Devices',route:"/#!/devices",is_active:r=="devices"},{content:' Scanning',route:"/#!/devices/scanning",is_active:r=="scanning"}])}function oe(r){return{alias:"devices",renderer:()=>`