@senx/discovery-plugin-marauder
Version:
Discovery plugin - Marauder's map
2 lines • 11.7 kB
JavaScript
import{r as i,c as t,h as s,g as e}from"./p-e66c054b.js";import{P as h,U as n,L as o,v as a,G as r}from"./p-5b1ad25e.js";import{L as l}from"./p-8755d298.js";const d='/*!\n * Copyright 2022-2024 SenX S.A.S.\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n *//*!\n * Copyright 2022-2024 SenX S.A.S.\n *\n * Licensed under the Apache License, Version 2.0 (the "License");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an "AS IS" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */:host{width:100%;height:100%;position:relative}:host>div{width:100%;height:100%;position:relative}:host #ws{color:transparent;font-size:0;height:0;overflow:hidden}:host .discovery-tile-spinner{position:absolute;z-index:9999;top:0;left:0;width:100%;display:-ms-flexbox;display:flex;-ms-flex-align:center;align-items:center;-ms-flex-pack:center;justify-content:center;height:100%;color:#ffffff;font-weight:bold}:host .discovery-tile-error{background-color:var(--warp-view-error-bg-color, #dc3545);color:var(--warp-view-error-color, #ffffff);text-align:center;position:absolute;width:calc(100% - 40px);padding:20px;height:calc(100% - 40px);z-index:9;display:grid;-ms-flex-align:center;align-items:center}:host .discovery-tile-status{background-color:var(--warp-view-status-bg-color, #d1ecf1);color:var(--warp-view-status-color, #0c5460);text-align:center;position:relative;padding:5px 10px;width:calc(100% - 40px);margin-top:12px}:host .hidden-by-ws{opacity:0;-webkit-transition:opacity 1s ease-in-out;transition:opacity 1s ease-in-out}';const c=d;const u=class{constructor(s){i(this,s);this.statusHeaders=t(this,"statusHeaders",7);this.statusError=t(this,"statusError",7);this.execResult=t(this,"execResult",7);this.selfType=t(this,"selfType",7);this.draw=t(this,"draw",7);this.options=new h;this.language="warpscript";this.debug=false;this.unit="";this.autoRefresh=-1;this.vars="{}";this.loaded=false;this.result="[]";this.showLoader=false;this.hasError=false;this.errorMessage="";this.statusMessage="";this.hiddenByWs=false;this.innerVars={};this.innerOptions=new h;this.firstExec=false}async optionsUpdate(i,t){var s,e,h,o;(s=this.LOG)===null||s===void 0?void 0:s.debug(["optionsUpdate"],i,t);let a=i;if(!!i&&typeof i==="string"){a=JSON.parse(i)}if(!n.deepEqual(a,this.innerOptions)){this.innerOptions=n.clone(a);if(n.deepEqual((e=a.httpHeaders)!==null&&e!==void 0?e:{},(h=this.innerOptions.httpHeaders)!==null&&h!==void 0?h:{})){await this.exec(true)}(o=this.LOG)===null||o===void 0?void 0:o.debug(["optionsUpdate 2"],this.type,{options:this.innerOptions,newValue:i,oldValue:t})}}async varsUpdate(i,t){var s;let e=this.vars;if(!!this.vars&&typeof this.vars==="string"){e=JSON.parse(this.vars)}if(!n.deepEqual(e,this.innerVars)){this.innerVars=n.clone(e);await this.exec(true)}if(this.LOG){(s=this.LOG)===null||s===void 0?void 0:s.debug(["varsUpdate"],{vars:this.vars,newValue:i,oldValue:t})}}async discoveryEventHandler(i){var t,s,e,h,o;const a=n.parseEventData(i.detail,this.innerOptions.eventHandler,this.componentId);if(a.vars){this.innerVars=n.clone(Object.assign(Object.assign({},(t=this.innerVars)!==null&&t!==void 0?t:{}),a.vars));if(!((s=this.innerOptions.mutedVars)!==null&&s!==void 0?s:[]).includes(i.detail.selector)){await this.exec(true)}}if(a.selected){const t=n.clone(Object.assign(Object.assign({},(e=this.innerVars)!==null&&e!==void 0?e:{}),a.selected));if(!n.deepEqual((h=this.innerVars)!==null&&h!==void 0?h:{},t)){this.innerVars=n.clone(t);if(!((o=this.innerOptions.mutedVars)!==null&&o!==void 0?o:[]).includes(i.detail.selector)){await this.exec(true)}}}}async resize(){var i;const t=n.getContentBounds(this.el.parentElement);this.height=t.h;(i=this.LOG)===null||i===void 0?void 0:i.debug(["componentDidLoad"],"Tile - resize",this.tileResult);if(this.tileResult&&this.width!==t.w-2){this.width=t.w-2;return this.tileResult.resize()}}async show(i){if(this.tileResult){await this.tileResult.show(i)}}async showById(i){if(this.tileResult){await this.tileResult.showById(i)}}async hide(i){if(this.tileResult){await this.tileResult.hide(i)}}async hideById(i){if(this.tileResult){await this.tileResult.hideById(i)}}async setFocus(i,t,s){if(this.tileResult){await this.tileResult.setFocus(i,t,s)}}async unFocus(){if(this.tileResult){await this.tileResult.unFocus()}}componentWillLoad(){var i,t,s;this.LOG=new o(u,this.debug);this.componentId=a();(i=this.LOG)===null||i===void 0?void 0:i.debug(["componentWillLoad"],{url:this.url,type:this.type,options:this.options,language:this.language,innerVars:this.innerVars});if(!!this.options&&typeof this.options==="string"&&this.options!=="undefined"){this.innerOptions=JSON.parse(this.options)}else{this.innerOptions=Object.assign({},(t=this.options)!==null&&t!==void 0?t:new h)}this.innerVars=JSON.parse((s=this.vars)!==null&&s!==void 0?s:"{}");const e=n.getContentBounds(this.el.parentElement);this.width=e.w-2;this.height=e.h}async componentDidLoad(){if(!this.firstExec){await this.exec()}}disconnectedCallback(){var i;(i=this.LOG)===null||i===void 0?void 0:i.debug(["disconnectedCallback"],"disconnected");if(this.timer){window.clearInterval(this.timer);window.clearInterval(this.timerFadeOut)}if(!!this.socket){this.socket.close()}}async export(i="png"){if(this.tileResult){return this.tileResult.export(i)}else{return undefined}}async exec(i=false){return new Promise((t=>{var s,e,h,o,a;if(((s=this.el)===null||s===void 0?void 0:s.innerHTML)!==undefined){if(!i){setTimeout((()=>this.loaded=false))}this.ws=l.prepare(n.unsescape(this.el.innerHTML),(e=this.innerVars)!==null&&e!==void 0?e:{},(o=(h=this.innerOptions)===null||h===void 0?void 0:h.skippedVars)!==null&&o!==void 0?o:[],this.type,this.language);if(!!window){const i=window;let t=i.DiscoveryPluginRegistry;t=t!==null&&t!==void 0?t:{};if(!!(t!==null&&t!==void 0?t:{})[this.type]&&!!t[this.type].scriptWrapper&&typeof t[this.type].scriptWrapper==="function"){this.ws=t[this.type].scriptWrapper(this.ws)}}(a=this.LOG)===null||a===void 0?void 0:a.debug(["exec"],this.chartTitle,this.ws,this.type);this.url=n.getUrl(this.url);if(this.url.toLowerCase().startsWith("http")){const i=Date.now();this.latestRequestTs=i;setTimeout((()=>{this.hasError=false;this.errorMessage="";this.statusMessage=undefined;this.showLoader=!!this.innerOptions.showLoader}));n.httpPost(this.url,this.ws,this.innerOptions.httpHeaders).then((s=>{var e,h,o,a,l,d,c,u;if(this.latestRequestTs!==i){(e=this.LOG)===null||e===void 0?void 0:e.debug(["exec","liloControl"],"This request result arrived later than the latest request, discard result");t(true)}else{this.hiddenByWs=false;if(((h=this.type)!==null&&h!==void 0?h:"").startsWith("input")||((o=this.type)!==null&&o!==void 0?o:"").startsWith("svg")){this.result=""}this.headers=(a=s===null||s===void 0?void 0:s.headers)!==null&&a!==void 0?a:{};this.headers.statusText=`Your script execution took ${r.formatElapsedTime(s.status.elapsed)} serverside, fetched ${s.status.fetched} datapoints and performed ${s.status.ops} WarpLib operations.`;(l=this.LOG)===null||l===void 0?void 0:l.debug(["exec","headers"],this.headers);this.statusHeaders.emit(this.headers);if(this.innerOptions.showStatus){this.statusMessage=this.headers.statusText}this.start=window.performance.now();const i=r.getData(s.data);let e=(c=(d=i.globalParams)===null||d===void 0?void 0:d.autoRefresh)!==null&&c!==void 0?c:-1;const f=(u=i.globalParams)===null||u===void 0?void 0:u.fadeOutAfter;if(i.localvars){n.mergeDeep(this.innerVars,i.localvars)}if(e<0){e=undefined}if(this.autoRefresh!==this.innerOptions.autoRefresh||e){this.autoRefresh=e?e:this.innerOptions.autoRefresh;if(this.timer){window.clearInterval(this.timer)}if(this.autoRefresh&&this.autoRefresh>0){this.timer=window.setInterval((()=>void this.exec(true)),this.autoRefresh*1e3)}}if(f){if(this.timerFadeOut){window.clearInterval(this.timerFadeOut)}if(f>0){this.timerFadeOut=window.setInterval((()=>{this.hiddenByWs=true;window.clearInterval(this.timerFadeOut)}),f*1e3)}}requestAnimationFrame((()=>{var i;this.loaded=true;this.showLoader=false;(i=this.LOG)===null||i===void 0?void 0:i.debug(["exec","result"],this.chartTitle,this.result);this.result=s.data;this.execResult.emit(this.result);this.hasError=false;t(true)}))}})).catch((i=>{this.displayError(i);this.loaded=true;this.showLoader=false;t(true)}))}else if(this.url.toLowerCase().startsWith("ws")){if(!!this.socket){this.socket.close()}this.socket=new WebSocket(this.url);this.socket.onopen=()=>{this.socket.onmessage=i=>{var t;const s=i.data;setTimeout((()=>{this.loaded=true;this.showLoader=false}));if(s.startsWith("[\"Exception at 'EVERY")){this.hasError=this.innerOptions.showErrors;this.errorMessage=JSON.parse(s)[0]||"Error";this.statusError.emit(this.errorMessage)}else{this.result=s;this.hasError=false;this.errorMessage="";(t=this.LOG)===null||t===void 0?void 0:t.debug(["exec","result"],this.result);this.execResult.emit(this.result)}};this.socket.send(`<% ${this.ws} %> ${this.innerOptions.autoRefresh||1e3} EVERY`);t(true)}}}}))}async setZoom(i){await this.tileResult.setZoom(i)}handleSelfType(i){this.selfType.emit(i)}displayError(i){setTimeout((()=>{var t,s;this.statusError.emit(i);this.hasError=!!this.innerOptions.showErrors;this.errorMessage=(t=i.message)!==null&&t!==void 0?t:i.statusText;(s=this.LOG)===null||s===void 0?void 0:s.error(["exec"],i,this.innerOptions.showErrors,this.errorMessage)}))}render(){return s("div",{key:"d4ad0d939e766b6f493f228ab76021b1b3803ea7"},this.loaded?s("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"},class:this.hiddenByWs?"hidden-by-ws":""},this.hasError?s("div",{class:"discovery-tile-error"},this.errorMessage):"",s("discovery-tile-result",{url:this.url,start:this.start,result:this.result,type:this.type,options:JSON.stringify(this.innerOptions),unit:this.unit,debug:this.debug,height:this.height,width:this.width,language:this.language,"chart-title":this.chartTitle,"chart-description":this.chartDescription,onSelfType:i=>this.handleSelfType(i),onExecError:i=>this.displayError(i.detail),onDraw:()=>this.draw.emit(),vars:JSON.stringify(this.innerVars),ref:i=>this.tileResult=i,id:this.componentId,standalone:true}),this.statusMessage?s("div",{class:"discovery-tile-status"},this.statusMessage):""):s("div",{class:"discovery-tile-spinner"},this.showLoader?s("discovery-spinner",{backdrop:true},"Requesting data..."):""),this.showLoader?s("div",{class:"discovery-tile-spinner"},s("discovery-spinner",{backdrop:true},"Requesting data...")):"",s("pre",{key:"891f9ed0225695209c49932fa3d57814ad86d8a9",id:"ws"},s("slot",{key:"9d22b8f2afb4a28cc557da18dcf199d0170b20fb"})))}get el(){return e(this)}static get watchers(){return{options:["optionsUpdate"],vars:["varsUpdate"]}}};u.style=c;export{u as discovery_tile};
//# sourceMappingURL=p-d359deab.entry.js.map