@senx/discovery-widgets
Version:
Discovery Widgets Elements
912 lines (911 loc) • 41.7 kB
JavaScript
/*
* Copyright 2022-2025 SenX S.A.S.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { h, Host } from "@stencil/core";
import { Utils } from "../../utils/utils";
import { Param } from "../../model/param";
import { Logger } from "../../utils/logger";
import { GTSLib } from "../../utils/gts.lib";
import { Dashboard } from "../../model/types";
import { JsonLib } from "../../utils/jsonLib";
import { v4 } from "uuid";
import { PdfLib } from "../../utils/pdfLib";
import { LangUtils } from "../../utils/lang-utils";
import _ from "lodash";
export class DiscoveryDashboardComponent {
constructor() {
this.options = new Param();
this.debug = false;
this.autoRefresh = -1;
this.cellHeight = 220;
this.cols = 12;
this.type = 'dashboard';
this.vars = '{}';
this.inTile = false;
this.loaded = false;
this.types = {};
this.hasError = false;
this.done = {};
this.innerVars = {};
this.eventState = {};
this.firstLoad = false;
this.errorMessage = '';
}
optionsUpdate(newValue, oldValue) {
var _a, _b;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['optionsUpdate'], newValue, oldValue);
let opts = newValue;
if (!!newValue && typeof newValue === 'string') {
opts = JSON.parse(newValue);
}
if (!Utils.deepEqual(opts, this.innerOptions)) {
this.innerOptions = Utils.clone(opts);
(_b = this.LOG) === null || _b === void 0 ? void 0 : _b.debug(['optionsUpdate'], { options: this.innerOptions, newValue, oldValue });
}
}
dataUpdate(newValue, oldValue) {
var _a;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['dataUpdate'], { newValue, oldValue });
this.parseResult();
}
varsUpdate(newValue, oldValue) {
var _a;
let vars = this.vars;
if (!!this.vars && typeof this.vars === 'string') {
vars = JSON.parse(this.vars);
}
if (!Utils.deepEqual(vars, this.innerVars)) {
this.innerVars = Utils.clone(vars);
this.exec();
}
if (this.LOG) {
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['varsUpdate'], { vars: this.vars, newValue, oldValue });
}
}
warpscriptUpdate(newValue, oldValue) {
var _a;
if (this.warpscript !== undefined && this.warpscript !== '' && this.warpscript !== 'undefined') {
this.exec();
}
if (this.LOG) {
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['warpscriptUpdate'], {
ws: this.ws,
newValue, oldValue,
});
}
}
async discoveryEventHandler(event) {
var _a, _b, _c, _d;
this.eventState = Object.assign(Object.assign({}, this.eventState), { vars: Object.assign(Object.assign({}, (_a = this.eventState.vars) !== null && _a !== void 0 ? _a : {}), Utils.clone(Utils.parseEventData(event.detail, 'tag=.*,type=.*', this.componentId).vars)) });
const res = Utils.parseEventData(event.detail, (_b = this.innerOptions) === null || _b === void 0 ? void 0 : _b.eventHandler, this.componentId);
if (res.vars) {
this.innerVars = Utils.clone(Object.assign(Object.assign({}, ((_c = this.innerVars) !== null && _c !== void 0 ? _c : {})), res.vars));
if (!((_d = this.innerOptions.mutedVars) !== null && _d !== void 0 ? _d : []).includes(event.detail.selector)) {
this.exec();
}
}
if (res.popup && this.modal) {
this.modalContent = res.popup;
await this.modal.open();
}
if (res.style) {
this.innerStyle = Utils.clone(Object.assign(Object.assign({}, this.innerStyle), res.style));
}
if (res.audio) {
this.audioFile = res.audio;
}
if (res.title) {
this.title = res.title;
}
if (res.description) {
this.description = res.description;
}
if (res.link) {
if (res.link.target === '_blank') {
window.open(res.link.link, '_blank').focus();
}
else {
window.location.href = res.link.link;
}
}
}
// noinspection JSUnusedGlobalSymbols
componentWillLoad() {
var _a, _b;
this.LOG = new Logger(DiscoveryDashboardComponent, this.debug);
this.componentId = v4();
if (!!this.options && typeof this.options === 'string' && this.options !== 'undefined') {
this.innerOptions = JSON.parse((_a = this.options) !== null && _a !== void 0 ? _a : '{}');
}
else if (this.options === 'undefined') {
this.innerOptions = new Param();
}
else {
this.innerOptions = Utils.clone(this.options);
}
(_b = this.LOG) === null || _b === void 0 ? void 0 : _b.debug(['componentWillLoad'], { url: this.url, options: this.innerOptions });
this.firstLoad = true;
}
// noinspection JSUnusedGlobalSymbols
componentDidLoad() {
const dims = Utils.getContentBounds(this.el.parentElement);
this.width = dims.w - 15;
this.height = dims.h;
this.exec();
}
// noinspection JSUnusedGlobalSymbols
disconnectedCallback() {
var _a;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['disconnectedCallback'], 'disconnected');
if (this.timer) {
window.clearInterval(this.timer);
}
}
async getPDF(save = true, output = 'blob', a4 = false) {
var _a, _b;
try {
const win = Utils.getContentBounds(this.dash);
const struct = await this.getDashboardStructure();
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['getPDF'], struct);
return await PdfLib.generatePDF(this.dash, win.w, win.h, struct, save, output, a4, this.LOG);
}
catch (e) {
(_b = this.LOG) === null || _b === void 0 ? void 0 : _b.error(['getPDF'], e);
}
}
async getVars() {
var _a, _b;
return Promise.resolve(Utils.clone((_b = (_a = this.eventState) === null || _a === void 0 ? void 0 : _a.vars) !== null && _b !== void 0 ? _b : {}));
}
async getDashboardStructure() {
var _a, _b, _c, _d, _e, _f;
const result = Utils.clone(this.result);
const tiles = Utils.clone(this.tiles);
const res = await Promise.all(tiles.map(((t) => { var _a; return (_a = t.elem) === null || _a === void 0 ? void 0 : _a.export('png'); })));
for (let i = 0; i < tiles.length; i++) {
tiles[i].png = (_a = res[i]) === null || _a === void 0 ? void 0 : _a.dataUrl;
tiles[i].bgColor = Utils.getCSSColor(this.el, '--warp-view-tile-background', (_b = res[i]) === null || _b === void 0 ? void 0 : _b.bgColor);
tiles[i].uid = v4();
delete tiles[i].macro;
delete tiles[i].data;
delete tiles[i].endpoint;
}
result.tiles = tiles.filter((t) => t.type !== 'hidden');
result.cellHeight = (_d = (_c = result.cellHeight) !== null && _c !== void 0 ? _c : this.cellHeight) !== null && _d !== void 0 ? _d : 220;
result.cols = (_f = (_e = result.cols) !== null && _e !== void 0 ? _e : this.cols) !== null && _f !== void 0 ? _f : 12;
result.bgColor = Utils.getCSSColor(this.el, '--warp-view-dashboard-background', '#fff');
result.fontColor = Utils.getCSSColor(this.el, '--warp-view-font-color', '#000');
return Object.assign(Object.assign({}, new Dashboard()), result);
}
exec() {
var _a;
this.ws = (_a = this.warpscript) !== null && _a !== void 0 ? _a : Utils.unsescape(this.el.innerHTML);
this.hasError = false;
this.errorMessage = '';
if (this.ws !== undefined && this.ws !== '' && this.ws !== 'undefined' && this.firstLoad) {
this.loaded = false;
this.done = {};
Utils.httpPost(Utils.getUrl(this.url), this.ws + ' DUP TYPEOF \'MACRO\' == <% EVAL %> IFT', this.innerOptions.httpHeaders)
.then((res) => {
var _a, _b, _c, _d, _e, _f, _g, _h;
const result = new JsonLib().parse(res.data);
const tmpResult = result.length > 0 ? (_a = result[0]) !== null && _a !== void 0 ? _a : new Dashboard() : new Dashboard();
this.innerOptions = Utils.clone(Object.assign(Object.assign({}, this.innerOptions), ((_b = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.options) !== null && _b !== void 0 ? _b : {})));
this.headers = res.headers;
this.headers.statusText = `Your script execution took ${GTSLib.formatElapsedTime(res.status.elapsed)} serverside, fetched ${res.status.fetched} datapoints and performed ${res.status.ops} WarpLib operations.`;
this.statusHeaders.emit(this.headers);
this.loaded = true;
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(() => this.exec(), this.autoRefresh * 1000);
}
}
this.innerType = (_d = (_c = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.type) !== null && _c !== void 0 ? _c : this.type) !== null && _d !== void 0 ? _d : 'dashboard';
if (typeof (tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles) === 'string') {
(_e = this.LOG) === null || _e === void 0 ? void 0 : _e.debug(['exec', 'macroTiles'], tmpResult.tiles);
const ws = LangUtils.prepare(Utils.unsescape(tmpResult.tiles + ' EVAL'), this.innerVars || {}, (_g = (_f = this.innerOptions) === null || _f === void 0 ? void 0 : _f.skippedVars) !== null && _g !== void 0 ? _g : [], 'dashboard', 'warpscript');
Utils.httpPost(this.url, ws, this.innerOptions.httpHeaders).then((t) => {
var _a, _b;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['exec', 'macroTiles', 'res'], t);
this.renderedTiles = (_b = new JsonLib().parse(t.data)[0]) !== null && _b !== void 0 ? _b : [];
this.sanitizeTiles();
this.processResult(tmpResult);
}).catch(e => {
var _a;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.error(['exec'], e);
tmpResult.tiles = [];
this.processResult(tmpResult);
});
}
else {
this.renderedTiles = (_h = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles) !== null && _h !== void 0 ? _h : [];
this.sanitizeTiles();
this.processResult(tmpResult);
}
}).catch(e => {
var _a, _b;
this.loaded = true;
this.statusError.emit(e);
if (!this.inTile) {
this.hasError = !!this.innerOptions.showErrors;
this.errorMessage = (_a = e.message) !== null && _a !== void 0 ? _a : e.statusText;
}
(_b = this.LOG) === null || _b === void 0 ? void 0 : _b.error(['exec'], e);
});
}
else if (this.inTile) {
// TODO: dashboard within a dashboard: this hacky delay ensure to have the right innerOptions to avoid the first requests that will end in 403.
setTimeout(() => this.parseResult(), 1000);
}
else {
this.parseResult();
}
}
sanitizeTiles() {
this.renderedTiles.forEach(t => t.data = DiscoveryDashboardComponent.sanitize(t.data));
}
parseResult() {
var _a, _b, _c, _d, _e;
let tmpResult;
if (!!this.data && typeof this.data === 'string') {
const res = JSON.parse(this.data);
tmpResult = GTSLib.isArray(res) ? res[0] : res;
}
else {
tmpResult = GTSLib.isArray(this.data) ? this.data[0] : this.data;
}
this.innerOptions = Utils.clone(Object.assign(Object.assign({}, this.innerOptions), (_a = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.options) !== null && _a !== void 0 ? _a : {}));
this.innerType = (_c = (_b = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.type) !== null && _b !== void 0 ? _b : this.type) !== null && _c !== void 0 ? _c : 'dashboard';
this.loaded = true;
if (typeof (tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles) === 'string') {
(_d = this.LOG) === null || _d === void 0 ? void 0 : _d.debug(['exec', 'macroTiles'], tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles);
this.processMacroTiles(tmpResult);
}
else {
this.renderedTiles = (_e = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles) !== null && _e !== void 0 ? _e : [];
this.sanitizeTiles();
}
this.processResult(tmpResult);
}
processMacroTiles(tmpResult) {
if (this.refreshTimer) {
clearInterval(this.refreshTimer);
}
if (typeof tmpResult.tiles === 'string') {
Utils.httpPost(this.url, tmpResult.tiles + ' EVAL', this.innerOptions.httpHeaders).then((t) => {
var _a, _b;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.debug(['exec', 'macroTiles', 'res'], t);
this.renderedTiles = new JsonLib().parse(t.data)[0] || [];
this.sanitizeTiles();
this.processResult(tmpResult);
if (((_b = this.innerOptions.autoRefresh) !== null && _b !== void 0 ? _b : 0) > 0 && !!this.data) {
this.refreshTimer = setTimeout(() => this.processMacroTiles(tmpResult), this.innerOptions.autoRefresh * 1000);
}
}).catch(e => {
var _a;
(_a = this.LOG) === null || _a === void 0 ? void 0 : _a.error(['exec'], e);
tmpResult.tiles = [];
});
}
}
processResult(tmpResult) {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
tmpResult = tmpResult !== null && tmpResult !== void 0 ? tmpResult : new Dashboard();
if (!!this.vars && typeof this.vars === 'string') {
this.innerVars = JSON.parse(this.vars);
}
else {
this.innerVars = (_a = this.vars) !== null && _a !== void 0 ? _a : {};
}
if (this.innerType === 'scada') {
const tiles = tmpResult.tiles; // items array
if (tiles.length > 0) {
let y = 0;
let height = 0;
tiles.forEach(item => {
if (item.y >= y) {
y = item.y;
height = Math.max(y + item.h, height);
}
});
this.scadaHeight = height + 20;
}
}
if (!GTSLib.isArray(tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles)) {
tmpResult.tiles = [...(_b = tmpResult === null || tmpResult === void 0 ? void 0 : tmpResult.tiles) !== null && _b !== void 0 ? _b : []];
}
else {
tmpResult.tiles = (_c = tmpResult.tiles) !== null && _c !== void 0 ? _c : [];
}
(_d = this.LOG) === null || _d === void 0 ? void 0 : _d.debug(['processResult', 'tmpResult'], tmpResult);
tmpResult.vars = Utils.clone(Object.assign(Object.assign({}, (_e = tmpResult.vars) !== null && _e !== void 0 ? _e : {}), this.innerVars));
tmpResult.cols = (_g = (_f = tmpResult.cols) !== null && _f !== void 0 ? _f : this.cols) !== null && _g !== void 0 ? _g : 12;
this.result = Utils.clone(tmpResult);
this.title = (_h = this.dashboardTitle) !== null && _h !== void 0 ? _h : this.result.title;
this.description = this.result.description;
this.tiles = [];
for (let i = 0; i < ((_k = (_j = this.result) === null || _j === void 0 ? void 0 : _j.tiles) !== null && _k !== void 0 ? _k : []).length; i++) {
this.done[i] = 0;
}
}
static merge(options, tileOptions) {
var _a;
if (typeof options === 'string') {
options = JSON.parse(options);
}
const opts = Utils.clone(options);
const params = _.merge(new Param(), opts, { eventHandler: undefined }, tileOptions !== null && tileOptions !== void 0 ? tileOptions : {});
params.httpHeaders = (_a = opts.httpHeaders) !== null && _a !== void 0 ? _a : {};
return params;
}
static mergeVars(vars) {
let myVars = {};
vars.map((v) => typeof v === 'string' ? JSON.parse(v) : v).forEach(v => myVars = Object.assign(Object.assign({}, myVars), v));
return myVars;
}
static sanitize(data) {
if (typeof data === 'string' && !data.startsWith('[') && !data.startsWith('{'))
return '["' + data + '"]';
else if (typeof data === 'string')
return data;
else
return GTSLib.isArray(data) ? data : [data];
}
getType(id, type) {
var _a, _b, _c, _d;
return ((_b = (_a = this.types[id]) !== null && _a !== void 0 ? _a : type) !== null && _b !== void 0 ? _b : '').replace(/:/gi, '-') + (((_d = (_c = this.renderedTiles[id]) === null || _c === void 0 ? void 0 : _c.options) === null || _d === void 0 ? void 0 : _d.responsive) ? ' auto-height' : '');
}
getRowSpan(id, span) {
var _a, _b;
return ((_b = (_a = this.renderedTiles[id]) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.responsive) ? `span ${span - 1}` : `${span}`;
}
setActualType(id, type) {
type.stopPropagation();
this.types[id] = type.detail;
this.types = Utils.clone(this.types);
}
getRendering() {
var _a, _b, _c, _d, _e;
this.tiles = [];
switch (this.innerType) {
case 'scada':
return this.result ? h("div", { class: "discovery-scada-main" }, this.title && this.title !== '' ? h("h1", null, this.title) : '', this.description && this.description !== '' ? h("p", null, this.description) : '', h("div", { class: "discovery-scada-wrapper", style: { height: `${this.scadaHeight}px` } }, ((_a = this.renderedTiles) !== null && _a !== void 0 ? _a : []).map((t, i) => {
var _a, _b, _c;
return h("div", { class: 'discovery-scada-tile ' + this.getType(i, t.type), style: {
left: `${t.x}px`,
width: `${t.w}px`,
height: `${t.h}px`,
top: `${t.y}px`,
zIndex: `${((_a = t.z) !== null && _a !== void 0 ? _a : 0)}`,
} }, h("div", null, t.macro
? h("discovery-tile", { url: (_b = t.endpoint) !== null && _b !== void 0 ? _b : this.url, type: t.type, "chart-title": t.title, unit: t.unit, onSelfType: type => this.setActualType(i, type), debug: this.debug, id: `chart-${i}`, script: t.macro + ' EVAL', ref: (el) => this.addTile(el, t, i), vars: JSON.stringify(DiscoveryDashboardComponent.mergeVars([this.result.vars, t.vars])), options: JSON.stringify(DiscoveryDashboardComponent.merge(this.innerOptions, t.options)) })
: h("discovery-tile-result", { url: (_c = t.endpoint) !== null && _c !== void 0 ? _c : this.url, result: t.data, type: t.type, onSelfType: type => this.setActualType(i, type), ref: (el) => this.addTile(el, t, i), id: `chart-${i}}`, unit: t.unit, options: DiscoveryDashboardComponent.merge(this.innerOptions, t.options), debug: this.debug, "chart-title": t.title })));
}))) : '';
case 'dashboard':
return this.result ?
h("div", { class: "discovery-dashboard-main" }, this.title && this.title !== '' ? h("h1", null, this.title) : '', this.description && this.description !== '' ? h("p", null, this.description) : '', h("div", { class: "discovery-dashboard-wrapper", style: {
width: '100%',
gridAutoRows: `minmax(${((_c = (_b = this.result) === null || _b === void 0 ? void 0 : _b.cellHeight) !== null && _c !== void 0 ? _c : this.cellHeight)}px, auto)`,
gridTemplateColumns: `repeat(${this.result.cols}, 1fr)`,
} }, ((_d = this.renderedTiles) !== null && _d !== void 0 ? _d : []).map((t, i) => {
var _a, _b;
return h("div", { class: 'discovery-dashboard-tile ' + this.getType(i, t.type), style: {
gridColumn: `${(t.x + 1)} / ${(t.x + t.w + 1)}`,
gridRow: `${(t.y + 1)} / ${(t.y + t.h + 1)}`,
height: `${((this.result.cellHeight || this.cellHeight) * t.h + 10 * (t.h - 1) + 5)}px`,
minHeight: '100%',
gridRowEnd: this.getRowSpan(i, t.y + t.h + 1),
} }, h("div", null, t.macro
? h("discovery-tile", { url: (_a = t.endpoint) !== null && _a !== void 0 ? _a : this.url, type: t.type, "chart-title": t.title, debug: this.debug, unit: t.unit, id: `chart-${i}`, script: t.macro + ' EVAL', ref: (el) => this.addTile(el, t, i), onSelfType: type => this.setActualType(i, type), vars: JSON.stringify(DiscoveryDashboardComponent.mergeVars([this.innerVars, this.result.vars, t.vars])), options: JSON.stringify(DiscoveryDashboardComponent.merge(this.innerOptions, t.options)) })
: h("discovery-tile-result", { url: (_b = t.endpoint) !== null && _b !== void 0 ? _b : this.url, result: t.data, type: t.type, ref: (el) => this.addTile(el, t, i), unit: t.unit, id: `chart-${i}}`, onSelfType: type => this.setActualType(i, type), options: DiscoveryDashboardComponent.merge(this.innerOptions, t.options), debug: this.debug, "chart-title": t.title })));
}))) : '';
case 'flex':
return this.result ?
h("div", { class: "discovery-flex-main" }, this.title && this.title !== '' ? h("h1", null, this.title) : '', this.description && this.description !== '' ? h("p", null, this.description) : '', h("div", { class: "discovery-flex-wrapper" }, ((_e = this.renderedTiles) !== null && _e !== void 0 ? _e : []).map((t, i) => {
var _a, _b;
return h("div", { class: 'discovery-dashboard-tile ' + this.getType(i, t.type), style: {
height: this.getHeight(t),
minHeight: '100%',
maxWidth: `calc(100% / ${this.result.cols} * ${t.w} - var(--warp-view-dashboard-gap, 10px) * 2)`,
}, id: t.id }, h("div", null, t.macro
? h("discovery-tile", { url: (_a = t.endpoint) !== null && _a !== void 0 ? _a : this.url, type: t.type, "chart-title": t.title, debug: this.debug, unit: t.unit, script: t.macro + ' EVAL', id: `chart-${i}`, onSelfType: type => this.setActualType(i, type), ref: (el) => this.addTile(el, t, i), vars: JSON.stringify(DiscoveryDashboardComponent.mergeVars([this.result.vars, t.vars])), options: JSON.stringify(DiscoveryDashboardComponent.merge(this.innerOptions, t.options)) })
: h("discovery-tile-result", { url: (_b = t.endpoint) !== null && _b !== void 0 ? _b : this.url, result: t.data, type: t.type, ref: (el) => this.addTile(el, t, i), unit: t.unit, onSelfType: type => this.setActualType(i, type), id: `chart-${i}}`, options: JSON.stringify(DiscoveryDashboardComponent.merge(this.innerOptions, t.options)), debug: this.debug, "chart-title": t.title })));
}))) : '';
default:
return '';
}
}
render() {
return h(Host, { key: '2b5ef5b83a0d8fe0e94b404f78b811520e6314ff' }, h("discovery-modal", { key: '5df223f8c096a5a6acdd829095e76f0824790340', ref: (el) => this.modal = el, data: this.modalContent, options: this.innerOptions, url: this.url, parentId: this.componentId, debug: this.debug }), this.loaded
? [
h("style", null, this.generateStyle(this.innerStyle)),
this.hasError ? h("div", { class: "discovery-tile-error" }, this.errorMessage) : '',
h("div", { ref: el => this.dash = el }, this.getRendering()),
this.audioFile ? h("audio", { src: this.audioFile, autoPlay: true, id: "song" }) : '',
]
: h("discovery-spinner", null, "Requesting data..."), h("pre", { key: 'f8739a9a7e3d448b12a241dd54d0b69d99055817', id: "ws" }, h("slot", { key: '0d9b99a23a88400e058ecddb58fafa83073c2590' })));
}
generateStyle(styles) {
var _a;
this.innerStyles = Utils.clone(Object.assign(Object.assign(Object.assign({}, this.innerStyles), styles), (_a = this.innerOptions.customStyles) !== null && _a !== void 0 ? _a : {}));
return Object.keys(this.innerStyles || {}).map(k => `${k} { ${this.innerStyles[k]} }`).join('\n');
}
addTile(el, t, i) {
if (el) {
t.elem = el;
this.tiles.push(t);
el.addEventListener('draw', () => {
var _a;
this.done[i] = (this.done[i] || 0) + 1;
const res = Object.keys(this.done).map(s => {
var _a;
switch ((_a = this.tiles[i]) === null || _a === void 0 ? void 0 : _a.type) {
case 'line':
case 'area':
case 'scatter':
case 'spline-area':
case 'step-area':
case 'spline':
case 'step':
case 'step-after':
case 'step-before':
return this.done[s] === !!this.tiles[i].macro ? 2 : 1;
default:
return this.done[s] === 1;
}
});
if (((_a = this.renderedTiles) !== null && _a !== void 0 ? _a : []).length === Object.keys(this.done).length && res.every(r => !!r)) {
this.rendered.emit();
}
});
}
}
getHeight(t) {
var _a;
return `${(((_a = this.result.cellHeight) !== null && _a !== void 0 ? _a : this.cellHeight) * t.h + 10 * (t.h - 1) + 5)}px`;
}
static get is() { return "discovery-dashboard"; }
static get encapsulation() { return "shadow"; }
static get originalStyleUrls() {
return {
"$": ["discovery-dashboard.scss"]
};
}
static get styleUrls() {
return {
"$": ["discovery-dashboard.css"]
};
}
static get properties() {
return {
"url": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "url",
"reflect": false
},
"dashboardTitle": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "dashboard-title",
"reflect": false
},
"data": {
"type": "string",
"mutable": true,
"complexType": {
"original": "Dashboard | string",
"resolved": "Dashboard | string",
"references": {
"Dashboard": {
"location": "import",
"path": "../../model/types",
"id": "src/model/types.ts::Dashboard"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "data",
"reflect": false
},
"warpscript": {
"type": "string",
"mutable": false,
"complexType": {
"original": "string",
"resolved": "string",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "warpscript",
"reflect": false
},
"options": {
"type": "string",
"mutable": true,
"complexType": {
"original": "Param | string",
"resolved": "Param | string",
"references": {
"Param": {
"location": "import",
"path": "../../model/param",
"id": "src/model/param.ts::Param"
}
}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "options",
"reflect": false,
"defaultValue": "new Param()"
},
"debug": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "debug",
"reflect": false,
"defaultValue": "false"
},
"autoRefresh": {
"type": "number",
"mutable": true,
"complexType": {
"original": "number",
"resolved": "number",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "auto-refresh",
"reflect": false,
"defaultValue": "-1"
},
"cellHeight": {
"type": "number",
"mutable": false,
"complexType": {
"original": "number",
"resolved": "number",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "cell-height",
"reflect": false,
"defaultValue": "220"
},
"cols": {
"type": "number",
"mutable": false,
"complexType": {
"original": "number",
"resolved": "number",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "cols",
"reflect": false,
"defaultValue": "12"
},
"type": {
"type": "string",
"mutable": false,
"complexType": {
"original": "'scada' | 'dashboard' | 'flex'",
"resolved": "\"dashboard\" | \"flex\" | \"scada\"",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "type",
"reflect": false,
"defaultValue": "'dashboard'"
},
"vars": {
"type": "any",
"mutable": false,
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "vars",
"reflect": false,
"defaultValue": "'{}'"
},
"inTile": {
"type": "boolean",
"mutable": false,
"complexType": {
"original": "boolean",
"resolved": "boolean",
"references": {}
},
"required": false,
"optional": false,
"docs": {
"tags": [],
"text": ""
},
"getter": false,
"setter": false,
"attribute": "in-tile",
"reflect": false,
"defaultValue": "false"
}
};
}
static get states() {
return {
"width": {},
"height": {},
"result": {},
"modalContent": {},
"headers": {},
"loaded": {},
"start": {},
"innerStyle": {},
"audioFile": {},
"title": {},
"description": {},
"types": {},
"hasError": {}
};
}
static get events() {
return [{
"method": "statusHeaders",
"name": "statusHeaders",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "string[]",
"resolved": "string[]",
"references": {}
}
}, {
"method": "statusError",
"name": "statusError",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "any",
"resolved": "any",
"references": {}
}
}, {
"method": "rendered",
"name": "rendered",
"bubbles": true,
"cancelable": true,
"composed": true,
"docs": {
"tags": [],
"text": ""
},
"complexType": {
"original": "void",
"resolved": "void",
"references": {}
}
}];
}
static get methods() {
return {
"getPDF": {
"complexType": {
"signature": "(save?: boolean, output?: string, a4?: boolean) => Promise<any>",
"parameters": [{
"name": "save",
"type": "boolean",
"docs": ""
}, {
"name": "output",
"type": "string",
"docs": ""
}, {
"name": "a4",
"type": "boolean",
"docs": ""
}],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<any>"
},
"docs": {
"text": "",
"tags": []
}
},
"getVars": {
"complexType": {
"signature": "() => Promise<any>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
}
},
"return": "Promise<any>"
},
"docs": {
"text": "",
"tags": []
}
},
"getDashboardStructure": {
"complexType": {
"signature": "() => Promise<Dashboard>",
"parameters": [],
"references": {
"Promise": {
"location": "global",
"id": "global::Promise"
},
"Dashboard": {
"location": "import",
"path": "../../model/types",
"id": "src/model/types.ts::Dashboard"
}
},
"return": "Promise<Dashboard>"
},
"docs": {
"text": "",
"tags": []
}
}
};
}
static get elementRef() { return "el"; }
static get watchers() {
return [{
"propName": "options",
"methodName": "optionsUpdate"
}, {
"propName": "data",
"methodName": "dataUpdate"
}, {
"propName": "vars",
"methodName": "varsUpdate"
}, {
"propName": "warpscript",
"methodName": "warpscriptUpdate"
}];
}
static get listeners() {
return [{
"name": "discoveryEvent",
"method": "discoveryEventHandler",
"target": "window",
"capture": false,
"passive": false
}];
}
}
//# sourceMappingURL=discovery-dashboard.js.map