@senx/discovery-plugin-marauder
Version:
Discovery plugin - Marauder's map
2 lines • 14.5 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-7d8b9e81.js";import{P as Param,U as Utils}from"./utils-2db7dc60.js";import{l as lodash,L as Logger,v as v4,G as GTSLib}from"./lodash-d98cd4b5.js";import{L as LangUtils}from"./lang-utils-ab937efb.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;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}';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.innerVars={};this.innerOptions=new Param;this.firstExec=false;this.url=undefined;this.chartTitle=undefined;this.chartDescription=undefined;this.type=undefined;this.options=new Param;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=""}t.prototype.optionsUpdate=function(t,i){var e,n;(e=this.LOG)===null||e===void 0?void 0:e.debug(["optionsUpdate"],t,i);var r=t;if(!!t&&typeof t==="string"){r=JSON.parse(t)}if(!lodash.exports.isEqual(r,this.innerOptions)){this.innerOptions=Object.assign({},r);(n=this.LOG)===null||n===void 0?void 0:n.debug(["optionsUpdate 2"],{options:this.innerOptions,newValue:t,oldValue:i})}console.log("optionsUpdate",this.type,this.innerOptions)};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(!!lodash.exports.isEqual(n,this.innerVars))return[3,2];this.innerVars=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;return __generator(this,(function(e){switch(e.label){case 0:i=Utils.parseEventData(t.detail,this.innerOptions.eventHandler,this.componentId);if(!i.vars)return[3,2];this.innerVars=Object.assign(Object.assign({},this.innerVars||{}),i.vars);if(!!(this.innerOptions.mutedVars||[]).includes(t.detail.selector))return[3,2];return[4,this.exec(true)];case 1:e.sent();e.label=2;case 2:if(!i.selected)return[3,4];this.innerVars=Object.assign(Object.assign({},this.innerVars||{}),i.selected);if(!!(this.innerOptions.mutedVars||[]).includes(t.detail.selector))return[3,4];return[4,this.exec(true)];case 3:e.sent();e.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.width=i.w-15;this.height=i.h;(t=this.LOG)===null||t===void 0?void 0:t.debug(["componentDidLoad"],"Tile - resize",this.tileResult);if(this.tileResult){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;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(this.vars||"{}");var e=Utils.getContentBounds(this.el.parentElement);this.width=e.w-15;this.height=e.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)}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;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),i.innerVars||{},((r=i.innerOptions)===null||r===void 0?void 0:r.skippedVars)||[],i.type,i.language);if(!!window){var o=window;var a=o.DiscoveryPluginRegistry;a=a||{};if(!!(a||{})[i.type]&&!!a[i.type].scriptWrapper&&typeof a[i.type].scriptWrapper==="function"){i.ws=a[i.type].scriptWrapper(i.ws)}}(s=i.LOG)===null||s===void 0?void 0:s.debug(["exec"],i.ws,i.type);i.url=Utils.getUrl(i.url);if(i.url.toLowerCase().startsWith("http")){setTimeout((function(){i.hasError=false;i.errorMessage="";i.statusMessage=undefined;if(i.innerOptions.showLoader){i.showLoader=true}}));Utils.httpPost(i.url,i.ws,i.innerOptions.httpHeaders).then((function(n){var r;var s=i.result===n.data;if((i.type||"").startsWith("input")){i.result=""}i.headers=n.headers;i.headers.statusText="Your script execution took ".concat(GTSLib.formatElapsedTime(n.status.elapsed)," serverside, fetched ").concat(n.status.fetched," datapoints and performed ").concat(n.status.ops," WarpLib operations.");(r=i.LOG)===null||r===void 0?void 0:r.debug(["exec","headers"],i.headers);i.statusHeaders.emit(i.headers);if(i.innerOptions.showStatus){i.statusMessage=i.headers.statusText}i.start=(new Date).getTime();if(i.autoRefresh!==i.innerOptions.autoRefresh){i.autoRefresh=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)}}setTimeout((function(){void function(){return __awaiter(i,void 0,void 0,(function(){var i;return __generator(this,(function(r){switch(r.label){case 0:this.loaded=true;this.showLoader=false;(i=this.LOG)===null||i===void 0?void 0:i.debug(["exec","result"],this.result);this.result=n.data;this.execResult.emit(this.result);if(!(s&&t&&!!this.tileResult))return[3,2];return[4,this.tileResult.parseEvents()];case 1:r.sent();r.label=2;case 2:e(true);return[2]}}))}))}()}))})).catch((function(t){var n;i.statusError.emit(t);setTimeout((function(){i.loaded=true;i.showLoader=false;i.hasError=i.innerOptions.showErrors;i.errorMessage=t.message||t.statusText}));(n=i.LOG)===null||n===void 0?void 0:n.error(["exec"],t);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.render=function(){var t=this;return h("div",{key:"919e5adf56b4263b461a1ff2877c7bc4b47362f2"},this.loaded?this.hasError?h("div",{class:"discovery-tile-error"},this.errorMessage):h("div",{style:{width:"100%",height:"100%",display:"flex",flexDirection:"column"}},h("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:function(i){return t.handleSelfType(i)},vars:JSON.stringify(this.innerVars),ref:function(i){return t.tileResult=i},id:this.componentId}),this.statusMessage?h("div",{class:"discovery-tile-status"},this.statusMessage):""):h("div",{class:"discovery-tile-spinner"},this.showLoader?h("discovery-spinner",null,"Requesting data..."):""),this.showLoader?h("div",{class:"discovery-tile-spinner"},h("discovery-spinner",null,"Requesting data...")):"",h("pre",{key:"b406cafb81b093bf5b2150dd55ae2be3ff1fdbb1",id:"ws"},h("slot",{key:"e07f266a931e56bbfeed86f3ec71daf8cd5074e2"})))};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