@senx/discovery-plugin-marauder
Version:
Discovery plugin - Marauder's map
2 lines • 16 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{a(n.next(t))}catch(t){s(t)}}function u(t){try{a(n["throw"](t))}catch(t){s(t)}}function a(t){t.done?e(t.value):r(t.value).then(o,u)}a((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:u(0),throw:u(1),return:u(2)},typeof Symbol==="function"&&(o[Symbol.iterator]=function(){return this}),o;function u(t){return function(i){return a([t,i])}}function a(u){if(n)throw new TypeError("Generator is already executing.");while(o&&(o=0,u[0]&&(e=0)),e)try{if(n=1,r&&(s=u[0]&2?r["return"]:u[0]?r["throw"]||((s=r["return"])&&s.call(r),0):r.next)&&!(s=s.call(r,u[1])).done)return s;if(r=0,s)u=[u[0]&2,s.value];switch(u[0]){case 0:case 1:s=u;break;case 4:e.label++;return{value:u[1],done:false};case 5:e.label++;r=u[1];u=[0];continue;case 7:u=e.ops.pop();e.trys.pop();continue;default:if(!(s=e.trys,s=s.length>0&&s[s.length-1])&&(u[0]===6||u[0]===2)){e=0;continue}if(u[0]===3&&(!s||u[1]>s[0]&&u[1]<s[3])){e.label=u[1];break}if(u[0]===6&&e.label<s[1]){e.label=s[1];s=u;break}if(s&&e.label<s[2]){e.label=s[2];e.ops.push(u);break}if(s[2])e.ops.pop();e.trys.pop();continue}u=i.call(t,e)}catch(t){u=[6,t];r=0}finally{n=s=0}if(u[0]&5)throw u[1];return{value:u[0]?u[1]:void 0,done:true}}};System.register(["./p-54266c9e.system.js","./p-bd1c239e.system.js","./p-51f5dd56.system.js"],(function(t){"use strict";var i,e,n,r,s,o,u,a,c,h;return{setters:[function(t){i=t.r;e=t.c;n=t.h;r=t.g},function(t){s=t.P;o=t.U;u=t.L;a=t.v;c=t.G},function(t){h=t.L}],execute:function(){var 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}';var f=d;var l=t("discovery_tile",function(){function t(t){i(this,t);this.statusHeaders=e(this,"statusHeaders",7);this.statusError=e(this,"statusError",7);this.execResult=e(this,"execResult",7);this.selfType=e(this,"selfType",7);this.draw=e(this,"draw",7);this.options=new s;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 s;this.firstExec=false}t.prototype.optionsUpdate=function(t,i){return __awaiter(this,void 0,void 0,(function(){var e,n,r,s,u;return __generator(this,(function(a){switch(a.label){case 0:(e=this.LOG)===null||e===void 0?void 0:e.debug(["optionsUpdate"],t,i);u=t;if(!!t&&typeof t==="string"){u=JSON.parse(t)}if(!!o.deepEqual(u,this.innerOptions))return[3,3];this.innerOptions=o.clone(u);if(!o.deepEqual((n=u.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(!!o.deepEqual(n,this.innerVars))return[3,2];this.innerVars=o.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,u,a;return __generator(this,(function(c){switch(c.label){case 0:u=o.parseEventData(t.detail,this.innerOptions.eventHandler,this.componentId);if(!u.vars)return[3,2];this.innerVars=o.clone(Object.assign(Object.assign({},(i=this.innerVars)!==null&&i!==void 0?i:{}),u.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:c.sent();c.label=2;case 2:if(!u.selected)return[3,4];a=o.clone(Object.assign(Object.assign({},(n=this.innerVars)!==null&&n!==void 0?n:{}),u.selected));if(!!o.deepEqual((r=this.innerVars)!==null&&r!==void 0?r:{},a))return[3,4];this.innerVars=o.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:c.sent();c.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=o.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 u(l,this.debug);this.componentId=a();(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 s)}this.innerVars=JSON.parse((e=this.vars)!==null&&e!==void 0?e:"{}");var n=o.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,u,a;if(((n=i.el)===null||n===void 0?void 0:n.innerHTML)!==undefined){if(!t){setTimeout((function(){return i.loaded=false}))}i.ws=h.prepare(o.unsescape(i.el.innerHTML),(r=i.innerVars)!==null&&r!==void 0?r:{},(u=(s=i.innerOptions)===null||s===void 0?void 0:s.skippedVars)!==null&&u!==void 0?u:[],i.type,i.language);if(!!window){var d=window;var f=d.DiscoveryPluginRegistry;f=f!==null&&f!==void 0?f:{};if(!!(f!==null&&f!==void 0?f:{})[i.type]&&!!f[i.type].scriptWrapper&&typeof f[i.type].scriptWrapper==="function"){i.ws=f[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=o.getUrl(i.url);if(i.url.toLowerCase().startsWith("http")){var l=Date.now();i.latestRequestTs=l;setTimeout((function(){i.hasError=false;i.errorMessage="";i.statusMessage=undefined;i.showLoader=!!i.innerOptions.showLoader}));o.httpPost(i.url,i.ws,i.innerOptions.httpHeaders).then((function(t){var n,r,s,u,a,h,d,f;if(i.latestRequestTs!==l){(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=(u=t===null||t===void 0?void 0:t.headers)!==null&&u!==void 0?u:{};i.headers.statusText="Your script execution took ".concat(c.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 v=c.getData(t.data);var w=(d=(h=v.globalParams)===null||h===void 0?void 0:h.autoRefresh)!==null&&d!==void 0?d:-1;var p=(f=v.globalParams)===null||f===void 0?void 0:f.fadeOutAfter;if(v.localvars){o.mergeDeep(i.innerVars,v.localvars)}if(w<0){w=undefined}if(i.autoRefresh!==i.innerOptions.autoRefresh||w){i.autoRefresh=w?w: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(p){if(i.timerFadeOut){window.clearInterval(i.timerFadeOut)}if(p>0){i.timerFadeOut=window.setInterval((function(){i.hiddenByWs=true;window.clearInterval(i.timerFadeOut)}),p*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 n("div",{key:"d4ad0d939e766b6f493f228ab76021b1b3803ea7"},this.loaded?n("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"},class:this.hiddenByWs?"hidden-by-ws":""},this.hasError?n("div",{class:"discovery-tile-error"},this.errorMessage):"",n("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?n("div",{class:"discovery-tile-status"},this.statusMessage):""):n("div",{class:"discovery-tile-spinner"},this.showLoader?n("discovery-spinner",{backdrop:true},"Requesting data..."):""),this.showLoader?n("div",{class:"discovery-tile-spinner"},n("discovery-spinner",{backdrop:true},"Requesting data...")):"",n("pre",{key:"891f9ed0225695209c49932fa3d57814ad86d8a9",id:"ws"},n("slot",{key:"9d22b8f2afb4a28cc557da18dcf199d0170b20fb"})))};Object.defineProperty(t.prototype,"el",{get:function(){return r(this)},enumerable:false,configurable:true});Object.defineProperty(t,"watchers",{get:function(){return{options:["optionsUpdate"],vars:["varsUpdate"]}},enumerable:false,configurable:true});return t}());l.style=f}}}));
//# sourceMappingURL=p-2da9c0ff.system.entry.js.map