UNPKG

@senx/discovery-plugin-marauder

Version:

Discovery plugin - Marauder's map

2 lines 10 kB
import{r as i,c as t,h as s,g as e}from"./p-b07c75fa.js";import{P as h,U as n}from"./p-9fd389a9.js";import{l as o,L as a,v as r,G as d}from"./p-1117c627.js";import{L as c}from"./p-a3b5e83b.js";const l='/*!\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;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%}:host .discovery-tile-error{background-color:var(--warp-view-error-bg-color, #dc3545);color:var(--warp-view-error-color, #ffffff);text-align: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}';const f=l;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.innerVars={};this.innerOptions=new h;this.firstExec=false;this.url=undefined;this.chartTitle=undefined;this.chartDescription=undefined;this.type=undefined;this.options=new h;this.language="warpscript";this.debug=false;this.unit="";this.autoRefresh=-1;this.vars="{}";this.loaded=false;this.result="[]";this.width=undefined;this.height=undefined;this.headers=undefined;this.start=undefined;this.showLoader=false;this.hasError=false;this.errorMessage="";this.statusMessage=""}optionsUpdate(i,t){var s,e;(s=this.LOG)===null||s===void 0?void 0:s.debug(["optionsUpdate"],i,t);let h=i;if(!!i&&typeof i==="string"){h=JSON.parse(i)}if(!o.exports.isEqual(h,this.innerOptions)){this.innerOptions=Object.assign({},h);(e=this.LOG)===null||e===void 0?void 0:e.debug(["optionsUpdate 2"],{options:this.innerOptions,newValue:i,oldValue:t})}console.log("optionsUpdate",this.type,this.innerOptions)}async varsUpdate(i,t){var s;let e=this.vars;if(!!this.vars&&typeof this.vars==="string"){e=JSON.parse(this.vars)}if(!o.exports.isEqual(e,this.innerVars)){this.innerVars=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){const t=n.parseEventData(i.detail,this.innerOptions.eventHandler,this.componentId);if(t.vars){this.innerVars=Object.assign(Object.assign({},this.innerVars||{}),t.vars);if(!(this.innerOptions.mutedVars||[]).includes(i.detail.selector)){await this.exec(true)}}if(t.selected){this.innerVars=Object.assign(Object.assign({},this.innerVars||{}),t.selected);if(!(this.innerOptions.mutedVars||[]).includes(i.detail.selector)){await this.exec(true)}}}async resize(){var i;const t=n.getContentBounds(this.el.parentElement);this.width=t.w-15;this.height=t.h;(i=this.LOG)===null||i===void 0?void 0:i.debug(["componentDidLoad"],"Tile - resize",this.tileResult);if(this.tileResult){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;this.LOG=new a(u,this.debug);this.componentId=r();(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(this.vars||"{}");const s=n.getContentBounds(this.el.parentElement);this.width=s.w-15;this.height=s.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)}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;if(((s=this.el)===null||s===void 0?void 0:s.innerHTML)!==undefined){if(!i){setTimeout((()=>this.loaded=false))}this.ws=c.prepare(n.unsescape(this.el.innerHTML),this.innerVars||{},((e=this.innerOptions)===null||e===void 0?void 0:e.skippedVars)||[],this.type,this.language);if(!!window){const i=window;let t=i.DiscoveryPluginRegistry;t=t||{};if(!!(t||{})[this.type]&&!!t[this.type].scriptWrapper&&typeof t[this.type].scriptWrapper==="function"){this.ws=t[this.type].scriptWrapper(this.ws)}}(h=this.LOG)===null||h===void 0?void 0:h.debug(["exec"],this.ws,this.type);this.url=n.getUrl(this.url);if(this.url.toLowerCase().startsWith("http")){setTimeout((()=>{this.hasError=false;this.errorMessage="";this.statusMessage=undefined;if(this.innerOptions.showLoader){this.showLoader=true}}));n.httpPost(this.url,this.ws,this.innerOptions.httpHeaders).then((s=>{var e;const h=this.result===s.data;if((this.type||"").startsWith("input")){this.result=""}this.headers=s.headers;this.headers.statusText=`Your script execution took ${d.formatElapsedTime(s.status.elapsed)} serverside, fetched ${s.status.fetched} datapoints and performed ${s.status.ops} WarpLib operations.`;(e=this.LOG)===null||e===void 0?void 0:e.debug(["exec","headers"],this.headers);this.statusHeaders.emit(this.headers);if(this.innerOptions.showStatus){this.statusMessage=this.headers.statusText}this.start=(new Date).getTime();if(this.autoRefresh!==this.innerOptions.autoRefresh){this.autoRefresh=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)}}setTimeout((()=>{void(async()=>{var e;this.loaded=true;this.showLoader=false;(e=this.LOG)===null||e===void 0?void 0:e.debug(["exec","result"],this.result);this.result=s.data;this.execResult.emit(this.result);if(h&&i&&!!this.tileResult){await this.tileResult.parseEvents()}t(true)})()}))})).catch((i=>{var s;this.statusError.emit(i);setTimeout((()=>{this.loaded=true;this.showLoader=false;this.hasError=this.innerOptions.showErrors;this.errorMessage=i.message||i.statusText}));(s=this.LOG)===null||s===void 0?void 0:s.error(["exec"],i);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)}render(){return s("div",{key:"919e5adf56b4263b461a1ff2877c7bc4b47362f2"},this.loaded?this.hasError?s("div",{class:"discovery-tile-error"},this.errorMessage):s("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"}},s("discovery-tile-result",{url:this.url,start:this.start,result:this.result,type:this.type,options: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),vars:JSON.stringify(this.innerVars),ref:i=>this.tileResult=i,id:this.componentId}),this.statusMessage?s("div",{class:"discovery-tile-status"},this.statusMessage):""):s("div",{class:"discovery-tile-spinner"},this.showLoader?s("discovery-spinner",null,"Requesting data..."):""),this.showLoader?s("div",{class:"discovery-tile-spinner"},s("discovery-spinner",null,"Requesting data...")):"",s("pre",{key:"b406cafb81b093bf5b2150dd55ae2be3ff1fdbb1",id:"ws"},s("slot",{key:"e07f266a931e56bbfeed86f3ec71daf8cd5074e2"})))}get el(){return e(this)}static get watchers(){return{options:["optionsUpdate"],vars:["varsUpdate"]}}};u.style=f;export{u as discovery_tile}; //# sourceMappingURL=p-44cfd843.entry.js.map