@senx/discovery-plugin-marauder
Version:
Discovery plugin - Marauder's map
2 lines • 16.3 kB
JavaScript
var __awaiter=this&&this.__awaiter||function(t,i,e,n){function r(t){return t instanceof e?t:new e((function(i){i(t)}))}return new(e||(e=Promise))((function(e,s){function o(t){try{u(n.next(t))}catch(t){s(t)}}function a(t){try{u(n["throw"](t))}catch(t){s(t)}}function u(t){t.done?e(t.value):r(t.value).then(o,a)}u((n=n.apply(t,i||[])).next())}))};var __generator=this&&this.__generator||function(t,i){var e={label:0,sent:function(){if(s[0]&1)throw s[1];return s[1]},trys:[],ops:[]},n,r,s,o;return o={next:a(0),throw:a(1),return:a(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function a(t){return function(i){return u([t,i])}}function u(a){if(n)throw new TypeError("Generator is already executing.");while(o&&(o=0,a[0]&&(e=0)),e)try{if(n=1,r&&(s=a[0]&2?r["return"]:a[0]?r["throw"]||((s=r["return"])&&s.call(r),0):r.next)&&!(s=s.call(r,a[1])).done)return s;if(r=0,s)a=[a[0]&2,s.value];switch(a[0]){case 0:case 1:s=a;break;case 4:e.label++;return{value:a[1],done:false};case 5:e.label++;r=a[1];a=[0];continue;case 7:a=e.ops.pop();e.trys.pop();continue;default:if(!(s=e.trys,s=s.length>0&&s[s.length-1])&&(a[0]===6||a[0]===2)){e=0;continue}if(a[0]===3&&(!s||a[1]>s[0]&&a[1]<s[3])){e.label=a[1];break}if(a[0]===6&&e.label<s[1]){e.label=s[1];s=a;break}if(s&&e.label<s[2]){e.label=s[2];e.ops.push(a);break}if(s[2])e.ops.pop();e.trys.pop();continue}a=i.call(t,e)}catch(t){a=[6,t];r=0}finally{n=s=0}if(a[0]&5)throw a[1];return{value:a[0]?a[1]:void 0,done:true}}};import{r as registerInstance,c as createEvent,h,g as getElement}from"./index-324c6d3b.js";import{P as Param,U as Utils,L as Logger,v as v4,G as GTSLib}from"./utils-7a8be8c0.js";import{L as LangUtils}from"./lang-utils-700756ea.js";var discoveryTileCss='/*!\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}';var DiscoveryTileStyle0=discoveryTileCss;var DiscoveryTileComponent=function(){function t(t){registerInstance(this,t);this.statusHeaders=createEvent(this,"statusHeaders",7);this.statusError=createEvent(this,"statusError",7);this.execResult=createEvent(this,"execResult",7);this.selfType=createEvent(this,"selfType",7);this.draw=createEvent(this,"draw",7);this.options=new Param;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 Param;this.firstExec=false}t.prototype.optionsUpdate=function(t,i){return __awaiter(this,void 0,void 0,(function(){var e,n,r,s,o;return __generator(this,(function(a){switch(a.label){case 0:(e=this.LOG)===null||e===void 0?void 0:e.debug(["optionsUpdate"],t,i);o=t;if(!!t&&typeof t==="string"){o=JSON.parse(t)}if(!!Utils.deepEqual(o,this.innerOptions))return[3,3];this.innerOptions=Utils.clone(o);if(!Utils.deepEqual((n=o.httpHeaders)!==null&&n!==void 0?n:{},(r=this.innerOptions.httpHeaders)!==null&&r!==void 0?r:{}))return[3,2];return[4,this.exec(true)];case 1:a.sent();a.label=2;case 2:(s=this.LOG)===null||s===void 0?void 0:s.debug(["optionsUpdate 2"],this.type,{options:this.innerOptions,newValue:t,oldValue:i});a.label=3;case 3:return[2]}}))}))};t.prototype.varsUpdate=function(t,i){return __awaiter(this,void 0,void 0,(function(){var e,n;return __generator(this,(function(r){switch(r.label){case 0:n=this.vars;if(!!this.vars&&typeof this.vars==="string"){n=JSON.parse(this.vars)}if(!!Utils.deepEqual(n,this.innerVars))return[3,2];this.innerVars=Utils.clone(n);return[4,this.exec(true)];case 1:r.sent();r.label=2;case 2:if(this.LOG){(e=this.LOG)===null||e===void 0?void 0:e.debug(["varsUpdate"],{vars:this.vars,newValue:t,oldValue:i})}return[2]}}))}))};t.prototype.discoveryEventHandler=function(t){return __awaiter(this,void 0,void 0,(function(){var i,e,n,r,s,o,a;return __generator(this,(function(u){switch(u.label){case 0:o=Utils.parseEventData(t.detail,this.innerOptions.eventHandler,this.componentId);if(!o.vars)return[3,2];this.innerVars=Utils.clone(Object.assign(Object.assign({},(i=this.innerVars)!==null&&i!==void 0?i:{}),o.vars));if(!!((e=this.innerOptions.mutedVars)!==null&&e!==void 0?e:[]).includes(t.detail.selector))return[3,2];return[4,this.exec(true)];case 1:u.sent();u.label=2;case 2:if(!o.selected)return[3,4];a=Utils.clone(Object.assign(Object.assign({},(n=this.innerVars)!==null&&n!==void 0?n:{}),o.selected));if(!!Utils.deepEqual((r=this.innerVars)!==null&&r!==void 0?r:{},a))return[3,4];this.innerVars=Utils.clone(a);if(!!((s=this.innerOptions.mutedVars)!==null&&s!==void 0?s:[]).includes(t.detail.selector))return[3,4];return[4,this.exec(true)];case 3:u.sent();u.label=4;case 4:return[2]}}))}))};t.prototype.resize=function(){return __awaiter(this,void 0,void 0,(function(){var t,i;return __generator(this,(function(e){i=Utils.getContentBounds(this.el.parentElement);this.height=i.h;(t=this.LOG)===null||t===void 0?void 0:t.debug(["componentDidLoad"],"Tile - resize",this.tileResult);if(this.tileResult&&this.width!==i.w-2){this.width=i.w-2;return[2,this.tileResult.resize()]}return[2]}))}))};t.prototype.show=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){switch(i.label){case 0:if(!this.tileResult)return[3,2];return[4,this.tileResult.show(t)];case 1:i.sent();i.label=2;case 2:return[2]}}))}))};t.prototype.showById=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){switch(i.label){case 0:if(!this.tileResult)return[3,2];return[4,this.tileResult.showById(t)];case 1:i.sent();i.label=2;case 2:return[2]}}))}))};t.prototype.hide=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){switch(i.label){case 0:if(!this.tileResult)return[3,2];return[4,this.tileResult.hide(t)];case 1:i.sent();i.label=2;case 2:return[2]}}))}))};t.prototype.hideById=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){switch(i.label){case 0:if(!this.tileResult)return[3,2];return[4,this.tileResult.hideById(t)];case 1:i.sent();i.label=2;case 2:return[2]}}))}))};t.prototype.setFocus=function(t,i,e){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(n){switch(n.label){case 0:if(!this.tileResult)return[3,2];return[4,this.tileResult.setFocus(t,i,e)];case 1:n.sent();n.label=2;case 2:return[2]}}))}))};t.prototype.unFocus=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!this.tileResult)return[3,2];return[4,this.tileResult.unFocus()];case 1:t.sent();t.label=2;case 2:return[2]}}))}))};t.prototype.componentWillLoad=function(){var t,i,e;this.LOG=new Logger(DiscoveryTileComponent,this.debug);this.componentId=v4();(t=this.LOG)===null||t===void 0?void 0:t.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({},(i=this.options)!==null&&i!==void 0?i:new Param)}this.innerVars=JSON.parse((e=this.vars)!==null&&e!==void 0?e:"{}");var n=Utils.getContentBounds(this.el.parentElement);this.width=n.w-2;this.height=n.h};t.prototype.componentDidLoad=function(){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(t){switch(t.label){case 0:if(!!this.firstExec)return[3,2];return[4,this.exec()];case 1:t.sent();t.label=2;case 2:return[2]}}))}))};t.prototype.disconnectedCallback=function(){var t;(t=this.LOG)===null||t===void 0?void 0:t.debug(["disconnectedCallback"],"disconnected");if(this.timer){window.clearInterval(this.timer);window.clearInterval(this.timerFadeOut)}if(!!this.socket){this.socket.close()}};t.prototype.export=function(){return __awaiter(this,arguments,void 0,(function(t){if(t===void 0){t="png"}return __generator(this,(function(i){if(this.tileResult){return[2,this.tileResult.export(t)]}else{return[2,undefined]}return[2]}))}))};t.prototype.exec=function(){return __awaiter(this,arguments,void 0,(function(t){var i=this;if(t===void 0){t=false}return __generator(this,(function(e){return[2,new Promise((function(e){var n,r,s,o,a;if(((n=i.el)===null||n===void 0?void 0:n.innerHTML)!==undefined){if(!t){setTimeout((function(){return i.loaded=false}))}i.ws=LangUtils.prepare(Utils.unsescape(i.el.innerHTML),(r=i.innerVars)!==null&&r!==void 0?r:{},(o=(s=i.innerOptions)===null||s===void 0?void 0:s.skippedVars)!==null&&o!==void 0?o:[],i.type,i.language);if(!!window){var u=window;var c=u.DiscoveryPluginRegistry;c=c!==null&&c!==void 0?c:{};if(!!(c!==null&&c!==void 0?c:{})[i.type]&&!!c[i.type].scriptWrapper&&typeof c[i.type].scriptWrapper==="function"){i.ws=c[i.type].scriptWrapper(i.ws)}}(a=i.LOG)===null||a===void 0?void 0:a.debug(["exec"],i.chartTitle,i.ws,i.type);i.url=Utils.getUrl(i.url);if(i.url.toLowerCase().startsWith("http")){var h=Date.now();i.latestRequestTs=h;setTimeout((function(){i.hasError=false;i.errorMessage="";i.statusMessage=undefined;i.showLoader=!!i.innerOptions.showLoader}));Utils.httpPost(i.url,i.ws,i.innerOptions.httpHeaders).then((function(t){var n,r,s,o,a,u,c,l;if(i.latestRequestTs!==h){(n=i.LOG)===null||n===void 0?void 0:n.debug(["exec","liloControl"],"This request result arrived later than the latest request, discard result");e(true)}else{i.hiddenByWs=false;if(((r=i.type)!==null&&r!==void 0?r:"").startsWith("input")||((s=i.type)!==null&&s!==void 0?s:"").startsWith("svg")){i.result=""}i.headers=(o=t===null||t===void 0?void 0:t.headers)!==null&&o!==void 0?o:{};i.headers.statusText="Your script execution took ".concat(GTSLib.formatElapsedTime(t.status.elapsed)," serverside, fetched ").concat(t.status.fetched," datapoints and performed ").concat(t.status.ops," WarpLib operations.");(a=i.LOG)===null||a===void 0?void 0:a.debug(["exec","headers"],i.headers);i.statusHeaders.emit(i.headers);if(i.innerOptions.showStatus){i.statusMessage=i.headers.statusText}i.start=window.performance.now();var d=GTSLib.getData(t.data);var f=(c=(u=d.globalParams)===null||u===void 0?void 0:u.autoRefresh)!==null&&c!==void 0?c:-1;var v=(l=d.globalParams)===null||l===void 0?void 0:l.fadeOutAfter;if(d.localvars){Utils.mergeDeep(i.innerVars,d.localvars)}if(f<0){f=undefined}if(i.autoRefresh!==i.innerOptions.autoRefresh||f){i.autoRefresh=f?f:i.innerOptions.autoRefresh;if(i.timer){window.clearInterval(i.timer)}if(i.autoRefresh&&i.autoRefresh>0){i.timer=window.setInterval((function(){return void i.exec(true)}),i.autoRefresh*1e3)}}if(v){if(i.timerFadeOut){window.clearInterval(i.timerFadeOut)}if(v>0){i.timerFadeOut=window.setInterval((function(){i.hiddenByWs=true;window.clearInterval(i.timerFadeOut)}),v*1e3)}}requestAnimationFrame((function(){var n;i.loaded=true;i.showLoader=false;(n=i.LOG)===null||n===void 0?void 0:n.debug(["exec","result"],i.chartTitle,i.result);i.result=t.data;i.execResult.emit(i.result);i.hasError=false;e(true)}))}})).catch((function(t){i.displayError(t);i.loaded=true;i.showLoader=false;e(true)}))}else if(i.url.toLowerCase().startsWith("ws")){if(!!i.socket){i.socket.close()}i.socket=new WebSocket(i.url);i.socket.onopen=function(){i.socket.onmessage=function(t){var e;var n=t.data;setTimeout((function(){i.loaded=true;i.showLoader=false}));if(n.startsWith("[\"Exception at 'EVERY")){i.hasError=i.innerOptions.showErrors;i.errorMessage=JSON.parse(n)[0]||"Error";i.statusError.emit(i.errorMessage)}else{i.result=n;i.hasError=false;i.errorMessage="";(e=i.LOG)===null||e===void 0?void 0:e.debug(["exec","result"],i.result);i.execResult.emit(i.result)}};i.socket.send("<% ".concat(i.ws," %> ").concat(i.innerOptions.autoRefresh||1e3," EVERY"));e(true)}}}}))]}))}))};t.prototype.setZoom=function(t){return __awaiter(this,void 0,void 0,(function(){return __generator(this,(function(i){switch(i.label){case 0:return[4,this.tileResult.setZoom(t)];case 1:i.sent();return[2]}}))}))};t.prototype.handleSelfType=function(t){this.selfType.emit(t)};t.prototype.displayError=function(t){var i=this;setTimeout((function(){var e,n;i.statusError.emit(t);i.hasError=!!i.innerOptions.showErrors;i.errorMessage=(e=t.message)!==null&&e!==void 0?e:t.statusText;(n=i.LOG)===null||n===void 0?void 0:n.error(["exec"],t,i.innerOptions.showErrors,i.errorMessage)}))};t.prototype.render=function(){var t=this;return h("div",{key:"d4ad0d939e766b6f493f228ab76021b1b3803ea7"},this.loaded?h("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"},class:this.hiddenByWs?"hidden-by-ws":""},this.hasError?h("div",{class:"discovery-tile-error"},this.errorMessage):"",h("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:function(i){return t.handleSelfType(i)},onExecError:function(i){return t.displayError(i.detail)},onDraw:function(){return t.draw.emit()},vars:JSON.stringify(this.innerVars),ref:function(i){return t.tileResult=i},id:this.componentId,standalone:true}),this.statusMessage?h("div",{class:"discovery-tile-status"},this.statusMessage):""):h("div",{class:"discovery-tile-spinner"},this.showLoader?h("discovery-spinner",{backdrop:true},"Requesting data..."):""),this.showLoader?h("div",{class:"discovery-tile-spinner"},h("discovery-spinner",{backdrop:true},"Requesting data...")):"",h("pre",{key:"891f9ed0225695209c49932fa3d57814ad86d8a9",id:"ws"},h("slot",{key:"9d22b8f2afb4a28cc557da18dcf199d0170b20fb"})))};Object.defineProperty(t.prototype,"el",{get:function(){return getElement(this)},enumerable:false,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{options:["optionsUpdate"],vars:["varsUpdate"]}},enumerable:false,configurable:true});return t}();DiscoveryTileComponent.style=DiscoveryTileStyle0;export{DiscoveryTileComponent as discovery_tile};
//# sourceMappingURL=discovery-tile.entry.js.map