diff --git a/server/SHServ/Controllers/AreasRESTAPIController.php b/server/SHServ/Controllers/AreasRESTAPIController.php index 99fb42a..a7a917c 100644 --- a/server/SHServ/Controllers/AreasRESTAPIController.php +++ b/server/SHServ/Controllers/AreasRESTAPIController.php @@ -273,9 +273,15 @@ $scripts = $area -> get_inner_scripts(true); $response_scripts = array_map(function($script) use ($scripts_base) { - return $script -> prepare_to_view($scripts_base[$script -> type][$script -> uniq_name]); + return isset($scripts_base[$script -> type][$script -> uniq_name]) + ? $script -> prepare_to_view($scripts_base[$script -> type][$script -> uniq_name]) + : false; }, $scripts); + $response_scripts = array_values(array_filter($response_scripts, function ($item) { + return $item != false; + })); + return $this -> utils() -> response_success([ "scripts" => $response_scripts, "total" => count($scripts) diff --git a/webclient/dist/js/main.js b/webclient/dist/js/main.js index 839071f..ddafeb3 100644 --- a/webclient/dist/js/main.js +++ b/webclient/dist/js/main.js @@ -1,4 +1,4 @@ -(()=>{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` +(()=>{var Ce=Object.defineProperty,Oe=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?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))Ne.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 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`
{{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 R(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+=`