100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps
Java asset-managementbuildingdashboarddataplatformdevice-managementedge-computingenergyenergy-managementenergy-monitorfleet-managementfleet-telematicsiotiot-applicationiot-platformmodbusmqttmqtt-brokerota-updaterules-enginesmartcity
UI updates: Cleanup and bug fixes for charting
Rich Turner00c72d189ba0
diff --git a/ui/app/manager/src/pages/page-users.ts b/ui/app/manager/src/pages/page-users.tsindex f7a1ab385..0bf596ec1 100644--- a/ui/app/manager/src/pages/page-users.ts+++ b/ui/app/manager/src/pages/page-users.ts@@ -17,7 +17,7 @@ import {AppStateKeyed} from "@openremote/or-app";import { ClientRole, Role, User } from "@openremote/model";import { i18next } from "@openremote/or-translate";import { OrIcon } from "@openremote/or-icon";-import { InputType, OrInput, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";+import { InputType, OrMwcInput, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";import {showOkCancelDialog} from "@openremote/or-mwc-components/or-mwc-dialog";const tableStyle = require("@material/data-table/dist/mdc.data-table.css");@@ -268,8 +268,8 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {}private checkPassword(index) {- const repeatPasswordComponent = this.shadowRoot.getElementById("repeatPassword-"+index) as OrInput;- const passwordComponent = this.shadowRoot.getElementById("password-"+index) as OrInput;+ const repeatPasswordComponent = this.shadowRoot.getElementById("repeatPassword-"+index) as OrMwcInput;+ const passwordComponent = this.shadowRoot.getElementById("password-"+index) as OrMwcInput;if (repeatPasswordComponent.value !== passwordComponent.value) {const error = i18next.t("passwordMismatch");diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex 6f4f96b90..72c9522d5 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -18,7 +18,7 @@ import {import "@openremote/or-translate";import {style} from "./style";import manager, {AssetModelUtil, EventCallback, OREvent, subscribe, Util} from "@openremote/core";-import {InputType, OrInput} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";import Qs from "qs";import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";import "@openremote/or-mwc-components/or-mwc-menu";@@ -526,7 +526,7 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {const onAddChanged = (ev: OrAddChangedEvent) => {const nameValid = !!ev.detail.name && ev.detail.name.trim().length > 0 && ev.detail.name.trim().length < 1024;- const addBtn = dialog.shadowRoot!.getElementById("add-btn") as OrInput;+ const addBtn = dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput;addBtn.disabled = !ev.detail.descriptor || !nameValid;};diff --git a/ui/component/or-asset-tree/src/or-add-asset-dialog.ts b/ui/component/or-asset-tree/src/or-add-asset-dialog.tsindex ac57390f6..8a02f81a9 100644--- a/ui/component/or-asset-tree/src/or-add-asset-dialog.ts+++ b/ui/component/or-asset-tree/src/or-add-asset-dialog.ts@@ -11,7 +11,7 @@ import {} from "@openremote/or-mwc-components/or-mwc-list";import {i18next} from "@openremote/or-translate";import {AssetModelUtil, DefaultColor2, DefaultColor5, Util} from "@openremote/core";-import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrMwcInput, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";export type OrAddAssetDetail = {name: string | undefined;@@ -67,7 +67,7 @@ export class OrAddAssetDialog extends LitElement {public name: string = "New Asset";@query("#name-input")- protected nameInput!: OrInput;+ protected nameInput!: OrMwcInput;@query("#agent-list")protected agentList?: OrMwcList;diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex fffe85537..a729b30de 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -15,7 +15,7 @@ import "@openremote/or-mwc-components/or-mwc-dialog";import {showOkCancelDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import "@openremote/or-mwc-components/or-mwc-list";import {OrTranslate, translate} from "@openremote/or-translate";-import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrMwcInput, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";import {OrTable} from "@openremote/or-table";import {OrChartConfig, OrChartEvent} from "@openremote/or-chart";@@ -758,7 +758,7 @@ export function getPropertyTemplate(asset: Asset, property: string, hostElement:getAssetNames(ancestors).then((names) => {if (hostElement && hostElement.shadowRoot) {- const pathField = hostElement.shadowRoot.getElementById("property-parentId") as OrInput;+ const pathField = hostElement.shadowRoot.getElementById("property-parentId") as OrMwcInput;if (pathField) {pathField.value = names.reverse().join(" > ");}@@ -966,10 +966,10 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElemprotected wrapperElem!: HTMLDivElement;@query("#save-btn")- protected saveBtnElem!: OrInput;+ protected saveBtnElem!: OrMwcInput;@query("#edit-btn")- protected editBtnElem!: OrInput;+ protected editBtnElem!: OrMwcInput;constructor() {super();diff --git a/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts b/ui/component/or-asset-viewer/src/or-add-attribute-panel.tsindex 53cc7e6b2..b787040d4 100644--- a/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts+++ b/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts@@ -1,5 +1,5 @@import {customElement, html, LitElement, property, css} from "lit-element";-import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrMwcInput, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";import i18next from "i18next";import {Asset, Attribute} from "@openremote/model";import {AssetModelUtil, Util} from "@openremote/core";@@ -75,7 +75,7 @@ export class OrAddAttributePanel extends LitElement {<or-mwc-input .type="${InputType.SELECT}" .options="${attributeTypes}" .label="${i18next.t("type")}" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onTypeChanged(ev.detail.value)}"></or-mwc-input></div><div id="name-input" class="hidden">- <or-mwc-input .type="${InputType.TEXT}" .label="${i18next.t("name")}" pattern="\\w+" required @keyup="${(ev: KeyboardEvent) => this.onNameChanged((ev.target as OrInput).currentValue)}" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onNameChanged(ev.detail.value)}"></or-mwc-input>+ <or-mwc-input .type="${InputType.TEXT}" .label="${i18next.t("name")}" pattern="\\w+" required @keyup="${(ev: KeyboardEvent) => this.onNameChanged((ev.target as OrMwcInput).currentValue)}" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onNameChanged(ev.detail.value)}"></or-mwc-input></div><div id="type-input" class="hidden"><or-mwc-input .type="${InputType.SELECT}" .options="${attributeValueTypes}" .label="${i18next.t("valueType")}" @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this.onValueTypeChanged(ev.detail.value)}"></or-mwc-input>diff --git a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts b/ui/component/or-asset-viewer/src/or-edit-asset-panel.tsindex 215ab045c..ae768d3e8 100644--- a/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts+++ b/ui/component/or-asset-viewer/src/or-edit-asset-panel.ts@@ -1,5 +1,5 @@import {css, customElement, html, LitElement, property, TemplateResult, unsafeCSS} from "lit-element";-import {InputType, OrInput, OrInputChangedEvent, getValueHolderInputTemplateProvider, ValueInputProviderOptions, OrInputChangedEventDetail} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrMwcInput, OrInputChangedEvent, getValueHolderInputTemplateProvider, ValueInputProviderOptions, OrInputChangedEventDetail} from "@openremote/or-mwc-components/or-mwc-input";import i18next from "i18next";import {Asset, Attribute, NameValueHolder} from "@openremote/model";import {AssetModelUtil, DefaultColor5, DefaultColor3, Util} from "@openremote/core";@@ -324,7 +324,7 @@ export class OrEditAssetPanel extends LitElement {const onAttributeChanged = (attribute: Attribute<any>) => {const addDisabled = !(attribute.name && !asset.attributes![attribute.name] && AssetNameRegex.test(attribute.name) && attribute.type);- const addBtn = dialog!.shadowRoot!.getElementById("add-btn") as OrInput;+ const addBtn = dialog!.shadowRoot!.getElementById("add-btn") as OrMwcInput;addBtn!.disabled = addDisabled;attr = attribute;};diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex d22dcad2b..962a6e230 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -5,15 +5,18 @@ import {AssetEvent,AssetQuery,Attribute,+ AttributeEvent,+ AttributeRef,DatapointInterval,+ ReadAttributeEvent,ValueDatapoint,WellknownMetaItems} from "@openremote/model";import {AssetModelUtil, DefaultColor3, DefaultColor4, manager, Util} from "@openremote/core";-import {Chart, ChartDataset, ChartOptions, ScatterDataPoint, LineController, LineElement, PointElement, LinearScale, TimeSeriesScale, Title} from "chart.js";+import {Chart, ScatterDataPoint, LineController, LineElement, PointElement, LinearScale, TimeSeriesScale, Title} from "chart.js";import "chartjs-adapter-moment";import {OrChartConfig} from "@openremote/or-chart";-import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";import "@openremote/or-mwc-components/or-mwc-dialog";import moment from "moment";@@ -163,44 +166,23 @@ const style = css`font-weight: bold;}`;-export class OrAttributeCardAddAttributeEvent extends CustomEvent<string> {-- public static readonly NAME = "or-attribute-card-add-attribute";-- constructor(value:string) {- super(OrAttributeCardAddAttributeEvent.NAME, {- bubbles: true,- composed: true,- detail: value- });- }-}--declare global {- export interface HTMLElementEventMap {- [OrAttributeCardAddAttributeEvent.NAME]: OrAttributeCardAddAttributeEvent;- }-}@customElement("or-attribute-card")export class OrAttributeCard extends LitElement {- @property()- public assetId: string | undefined;-- @property()- public attributeName: string | undefined;-@property()public panelName?: string;protected _style!: CSSStyleDeclaration;@property({type: Object})- private assetAttributes: Attribute<any>[] = [];+ public assets: Asset[] = [];++ @property({type: Object})+ private assetAttributes: [number, Attribute<any>][] = [];@property()- private data: ValueDatapoint<any>[] = [];+ private data?: ValueDatapoint<any>[] = undefined;@property()private mainValue?: number;@@ -209,18 +191,18 @@ export class OrAttributeCard extends LitElement {@property()private mainValueSize: "xs" | "s" | "m" | "l" | "xl" = "m";@property()- private delta: {val?: number, unit?: string} = {};+ private delta?: {val?: number, unit?: string} = undefined;@property()private deltaPlus: string = "";@property()- private deltaFormat: string = "absolute";+ private deltaFormat: "absolute" | "percentage" = "absolute";+ @property()+ protected _loading: boolean = false;private error: boolean = false;- private period?: moment.unitOfTime.Base = "day";- private now: Date = new Date();- private currentPeriod?: { start: number; end: number };-+ @property()+ private period: moment.unitOfTime.Base = "day";private asset?: Asset;private formattedMainValue?: {value: number|undefined, unit: string};@@ -239,14 +221,12 @@ export class OrAttributeCard extends LitElement {constructor() {super();- this.addEventListener(OrAttributeCardAddAttributeEvent.NAME, this._setAttribute);this.addEventListener(OrAssetTreeSelectionEvent.NAME, this._onTreeSelectionChanged);}connectedCallback() {super.connectedCallback();this._style = window.getComputedStyle(this);- this.getData();}disconnectedCallback(): void {@@ -254,18 +234,29 @@ export class OrAttributeCard extends LitElement {this._cleanup();}+ firstUpdated() {+ this.loadSettings();+ }+updated(changedProperties: PropertyValues) {- if (changedProperties.has("asset") || changedProperties.has("assetAttributes")) {- if (this._dialog && this._dialog.isOpen) {- this._refreshDialog();+ // if (changedProperties.has("assetAttributes")) {+ // if (this._dialog && this._dialog.isOpen) {+ // this._refreshDialog();+ // }+ // }++ const reloadData = changedProperties.has("period") || changedProperties.has("compareTimestamp") || changedProperties.has("timestamp") || changedProperties.has("assetAttributes");++ if (reloadData) {+ this.data = undefined;+ if (this._chart) {+ this._chart.destroy();+ this._chart = undefined;}+ this.loadData();}- if (changedProperties.has("assetId") && this.assetId && changedProperties.get("assetId") !== this.assetId) {- this.getSettings();- }-- if (!this.data || !this.data.length) {+ if (!this.data || this.data.length === 0) {return;}@@ -330,12 +321,95 @@ export class OrAttributeCard extends LitElement {}if (changedProperties.has("delta")) {- this.deltaPlus = (this.delta.val && this.delta.val > 0) ? "+" : "";+ this.deltaPlus = this .delta && this.delta.val! > 0 ? "+" : "";}}- async onCompleted() {- await this.updateComplete;+ protected render() {++ if (!this.assets || !this.assetAttributes || this.assetAttributes.length === 0) {+ return html`+ <div class="panel panel-empty">+ <div class="panel-content-wrapper">+ <div class="panel-content">+ <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog()}"></or-mwc-input>+ </div>+ </div>+ </div>+ <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog>+ `;+ }++ if (this.error) {+ return html`+ <div class="panel panel-empty">+ <div class="panel-content-wrapper">+ <div class="panel-content">+ <span>${i18next.t("couldNotRetrieveAttribute")}</span>+ <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog()}"></or-mwc-input>+ </div>+ </div>+ </div>+ <or-mwc-dialog id="mdc-dialog"><or-mwc-dialog>+ `;+ }++ return html`+ <div class="panel" id="attribute-card">+ <div class="panel-content-wrapper">+ <div class="panel-title">+ <span class="panel-title-text">${this.assets[0].name + " - " + i18next.t(this.assetAttributes[0][1].name!)}</span>+ ${getContentWithMenuTemplate(html`+ <or-mwc-input icon="dots-vertical" type="button"></or-mwc-input>+ `,+ [+ {+ text: i18next.t("editAttribute"),+ value: "editAttribute"+ },+ {+ text: i18next.t("editDelta"),+ value: "editDelta"+ },+ {+ text: i18next.t("editCurrentValue"),+ value: "editCurrentValue"+ }+ ],+ undefined,+ (values: string | string[]) => this.handleMenuSelect(values as ContextMenuOptions))}+ </div>+ <div class="panel-content">+ <div class="mainvalue-wrapper">+ <span class="main-number-icon">${this.assets && this.assets.length === 1 ? getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(this.assets[0].type!)) : ""}</span>+ <span class="main-number ${this.mainValueSize}">${this.formattedMainValue ? this.formattedMainValue.value : ""}</span>+ <span class="main-number-unit ${this.mainValueSize}">${this.formattedMainValue ? this.formattedMainValue.unit : ""}</span>+ </div>+ <div class="graph-wrapper">+ <div class="chart-wrapper">+ <canvas id="chart"></canvas>+ </div>+ <div class="delta-wrapper">+ <span class="delta">${this.delta ? this.deltaPlus + (this.delta.val !== undefined && this.delta.val !== null ? this.delta.val : "") + (this.delta.unit || "") : ""}</span>+ </div>++ <div class="period-selector-wrapper">+ ${getContentWithMenuTemplate(+ html`<or-mwc-input class="period-selector" .type="${InputType.BUTTON}" .label="${i18next.t(this.period ? this.period : "-")}"></or-mwc-input>`,+ [{value: "hour", text: "hour"}, {value: "day", text: "day"}, {value: "week", text: "week"}, {value: "month", text: "month"}, {value: "year", text: "year"}]+ .map((option) => {+ option.text = i18next.t(option.value);+ return option;+ }),+ this.period,+ (value) => this._setPeriodOption(value))}+ </div>+ </div>+ </div>+ </div>+ </div>+ <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog>+ `;}protected _refreshDialog(dialogContent?: ContextMenuOptions) {@@ -361,7 +435,7 @@ export class OrAttributeCard extends LitElement {default: true,content: html`<or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("ok")}" data-mdc-dialog-action="yes"></or-mwc-input>`,action: () => {- this.delta = this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data));+ this.delta = this.data ? this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data)) : undefined;}}];@@ -392,7 +466,7 @@ export class OrAttributeCard extends LitElement {const dialog: OrMwcDialog = this._dialog as OrMwcDialog;if (dialog.shadowRoot && dialog.shadowRoot.getElementById("current-value-decimals")) {const elm = dialog.shadowRoot.getElementById("current-value-decimals") as HTMLInputElement;- const input = parseInt(elm.value);+ const input = parseInt(elm.value, 10);if (input < 0) {this.mainValueDecimals = 0;}else if (input > 10) {this.mainValueDecimals = 10;}else {this.mainValueDecimals = input;}@@ -428,8 +502,8 @@ export class OrAttributeCard extends LitElement {action: () => {const dialog: OrMwcDialog = this.shadowRoot!.getElementById("mdc-dialog") as OrMwcDialog;if (dialog.shadowRoot && dialog.shadowRoot.getElementById("attribute-picker")) {- const elm = dialog.shadowRoot.getElementById("attribute-picker") as HTMLInputElement;- this.dispatchEvent(new OrAttributeCardAddAttributeEvent(elm.value));+ const elm = dialog.shadowRoot.getElementById("attribute-picker") as OrMwcInput;+ this._setAttribute(elm.value as string);}}}@@ -444,7 +518,7 @@ export class OrAttributeCard extends LitElement {.label="${i18next.t("attribute")}".type="${InputType.LIST}".options="${this._getAttributeOptions()}"- .value="${this.attributeName}"></or-mwc-input>+ .value="${this.assetAttributes && this.assetAttributes.length > 0 ? this.assetAttributes[0][1].name : undefined}"></or-mwc-input>` : ``}`;@@ -460,7 +534,7 @@ export class OrAttributeCard extends LitElement {}}- protected _onTreeSelectionChanged(event: OrAssetTreeSelectionEvent) {+ protected async _onTreeSelectionChanged(event: OrAssetTreeSelectionEvent) {// Need to fully load the assetif (!manager.events) {return;@@ -472,51 +546,41 @@ export class OrAttributeCard extends LitElement {this.asset = undefined;} else {// fully load the asset- manager.events.sendEventWithReply({+ const assetEvent: AssetEvent = await manager.events.sendEventWithReply({event: {eventType: "read-asset",assetId: selectedNode.asset!.id}- }).then((ev) => {- this.asset = (ev as AssetEvent).asset;- this.assetAttributes = this.asset!.attributes ? Object.values(this.asset!.attributes!) : [];- }).catch(() => this.asset = undefined);+ });+ this.asset = assetEvent.asset;+ this._refreshDialog();}}protected _getAttributeOptions(): [string, string][] | undefined {- if (!this.asset || !this.assetAttributes) {+ if(!this.asset || !this.asset.attributes) {return;}- if (this.shadowRoot && this.shadowRoot.getElementById("attribute-picker")) {- const elm = this.shadowRoot.getElementById("attribute-picker") as HTMLInputElement;- elm.value = "";- }-- let attributes = this.assetAttributes;-+ const attributes = Object.values(this.asset.attributes);if (attributes && attributes.length > 0) {return attributes.filter((attribute) => attribute.meta && (attribute.meta.hasOwnProperty(WellknownMetaItems.STOREDATAPOINTS) ? attribute.meta[WellknownMetaItems.STOREDATAPOINTS] : attribute.meta.hasOwnProperty(WellknownMetaItems.AGENTLINK)))- .map((attr: Attribute<any>) => {+ .filter((attr) => (this.assetAttributes && !this.assetAttributes.some(([index, assetAttr]) => (assetAttr.name === attr.name) && this.assets[index].id === this.asset!.id)))+ .map((attr) => {const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.asset!.type, attr.name, attr);- return [attr.name!, Util.getAttributeLabel(attr, descriptors[0], this.asset!.type, false)];+ const label = Util.getAttributeLabel(attr, descriptors[0], this.asset!.type, false);+ return [attr.name!, label];});}}- private _setAttribute(event:OrAttributeCardAddAttributeEvent) {- if (this.asset && event) {- const attr = this.asset.attributes ? this.asset.attributes[event.detail] : undefined;- if (attr) {- this.assetId = this.asset.id;- this.attributeName = attr.name;-- this.getData();- this.saveSettings();- this.requestUpdate();- }+ private _setAttribute(attributeName: string) {+ if (this.asset && attributeName) {+ const attr = this.asset.attributes ? this.asset.attributes[attributeName] : undefined;+ this.assets = [this.asset];+ this.assetAttributes = attr ? [[0,attr]] : [];+ this.saveSettings();}}@@ -527,247 +591,202 @@ export class OrAttributeCard extends LitElement {}}- getSettings() {- const configStr = window.localStorage.getItem('OrChartConfig')- if (!configStr || !this.panelName) return;+ protected async loadSettings() {- const viewSelector = this.assetId ? this.assetId : window.location.hash;- const config = JSON.parse(configStr) as OrChartConfig;- const view = config.views[viewSelector][this.panelName];- if (!view) return;- if (view.assetIds && view.assetIds.length === 1 && view.assetIds[0] === this.assetId) return;+ this.assetAttributes = [];+ this.period = "day";+ this.deltaFormat = "absolute";+ this.mainValueDecimals = 0;- if (view.assetIds && view.attributes) {- const query: AssetQuery = {- ids: view.assetIds- }+ const configStr = await manager.console.retrieveData("OrChartConfig");- manager.rest.api.AssetResource.queryAssets(query).then((response) => {- const assets = response.data;- if (!view || !view.assetIds || !view.attributes || assets.length !== view.assetIds.length || assets.length !== view.attributes.length) return;-- this.assetAttributes = view.attributes.map((attr: string, index: number) => assets[index] && assets[index].attributes ? assets[index].attributes![attr] : undefined).filter(attr => !!attr) as Attribute<any>[];-- if (this.assetAttributes && this.assetAttributes.length > 0) {- this.assetId = assets[0].id;- this.period = view.period;- if(view.deltaFormat) this.deltaFormat = view.deltaFormat;- if(view.decimals) this.mainValueDecimals = view.decimals;- this.attributeName = this.assetAttributes[0].name;- this.getData();- }- });+ if (!configStr || !this.panelName) {+ return;}- }- saveSettings() {const viewSelector = window.location.hash;- const attributes = this.attributeName ? [this.attributeName] : undefined;- const assetIds = this.assetId ? [this.assetId] : undefined;- const configStr = window.localStorage.getItem('OrChartConfig')- if (!this.panelName) return;-let config: OrChartConfig;- if (configStr) {- config = JSON.parse(configStr);- } else {- config = {- views: {- [viewSelector]: {- [this.panelName] : {-- }- }- }- }- }-- config.views[viewSelector][this.panelName] = {- assetIds: assetIds,- attributes: attributes,- period: this.period,- deltaFormat: this.deltaFormat,- decimals: this.mainValueDecimals- };- const message = {- provider: "STORAGE",- action: "STORE",- key: "OrChartConfig",- value: JSON.stringify(config)+ try {+ config = JSON.parse(configStr) as OrChartConfig;+ } catch (e) {+ console.error("Failed to load chart config", e);+ manager.console.storeData("OrChartConfig", null);+ return;}- manager.console._doSendProviderMessage(message)- }- protected render() {+ const view = config && config.views ? config.views[viewSelector][this.panelName] : undefined;- if (!this.assetId || !this.attributeName) {- return html`- <div class="panel panel-empty">- <div class="panel-content-wrapper">- <div class="panel-content">- <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog()}"></or-mwc-input>- </div>- </div>- </div>- <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog>- `;+ if (!view) {+ return;}- if (this.error) {- return html`- <div class="panel panel-empty">- <div class="panel-content-wrapper">- <div class="panel-content">- <span>${i18next.t("couldNotRetrieveAttribute")}</span>- <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog()}"></or-mwc-input>- </div>- </div>- </div>- <or-mwc-dialog id="mdc-dialog"><or-mwc-dialog>- `;+ if (!view.attributeRefs) {+ // Old/invalid config format remove it+ delete config.views[viewSelector][this.panelName];+ manager.console.storeData("OrChartConfig", JSON.stringify(config));+ return;}- return html`- <div class="panel" id="attribute-card">- <div class="panel-content-wrapper">- <div class="panel-title">- <span class="panel-title-text">${this.asset ? (this.asset.name + " - " + i18next.t(this.attributeName)) : ""}</span>- ${getContentWithMenuTemplate(html`- <or-mwc-input icon="dots-vertical" type="button"></or-mwc-input>- `,- [- {- text: i18next.t("editAttribute"),- value: "editAttribute"- },- {- text: i18next.t("editDelta"),- value: "editDelta"- },- {- text: i18next.t("editCurrentValue"),- value: "editCurrentValue"- }- ],- undefined,- (values: string | string[]) => this.handleMenuSelect(values as ContextMenuOptions))}- </div>- <div class="panel-content">- <div class="mainvalue-wrapper">- <span class="main-number-icon">${getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(this.asset!.type!))}</span>- <span class="main-number ${this.mainValueSize}">${this.formattedMainValue!.value}</span>- <span class="main-number-unit ${this.mainValueSize}">${this.formattedMainValue!.unit}</span>- </div>- <div class="graph-wrapper">- <div class="chart-wrapper">- <canvas id="chart"></canvas>- </div>- <div class="delta-wrapper">- <span class="delta">${this.deltaPlus}${this.delta.val}${this.delta.unit}</span>- </div>-- <div class="period-selector-wrapper">- ${getContentWithMenuTemplate(- html`<or-mwc-input class="period-selector" .type="${InputType.BUTTON}" .label="${i18next.t(this.period ? this.period : "-")}"></or-mwc-input>`,- [{value: "hour", text: "hour"}, {value: "day", text: "day"}, {value: "week", text: "week"}, {value: "month", text: "month"}, {value: "year", text: "year"}]- .map((option) => {- option.text = i18next.t(option.value);- return option;- }),- this.period,- (value) => this._setPeriodOption(value))}- </div>- </div>- </div>- </div>- </div>- <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog>- `;- }-- protected async getAssetById(id: string): Promise<Asset> {- const response = await manager.rest.api.AssetResource.queryAssets({- ids: [id],- recursive: false- });+ const assetIds = view.attributeRefs.map((attrRef) => attrRef.id!);- if (response.status !== 200 || !response.data || !response.data.length) {- return {};+ if (assetIds.length === 0) {+ return;}- return response.data[0];- }+ this._loading = true;- protected async getDatapointsByAttribute(id: string, attributeName: string, startOfPeriod: number, endOfPeriod: number): Promise<ValueDatapoint<any>[]> {+ if (!assetIds.every(id => !!this.assets.find(asset => asset.id === id))) {+ const query = {+ select: {+ excludePath: true,+ excludeParentInfo: true+ },+ ids: assetIds+ } as AssetQuery;++ try {+ const response = await manager.rest.api.AssetResource.queryAssets(query);+ const assets = response.data || [];+ view.attributeRefs = view.attributeRefs.filter((attrRef) => !!assets.find((asset) => asset.id === attrRef.id && asset.attributes && asset.attributes.hasOwnProperty(attrRef.name!)));+ manager.console.storeData("OrChartConfig", JSON.stringify(config));+ this.assets = assets.filter((asset) => view.attributeRefs!.find((attrRef) => attrRef.id === asset.id));+ } catch (e) {+ console.error("Failed to get assets requested in settings", e);+ }- const response = await manager.rest.api.AssetDatapointResource.getDatapoints(- id,- attributeName,- {- interval: this._getInterval(),- fromTimestamp: startOfPeriod,- toTimestamp: endOfPeriod+ this._loading = false;++ if (this.assets && this.assets.length > 0) {+ this.assetAttributes = view.attributeRefs.map((attrRef) => {+ const assetIndex = this.assets.findIndex((asset) => asset.id === attrRef.id);+ const asset = assetIndex >= 0 ? this.assets[assetIndex] : undefined;+ return asset && asset.attributes ? [assetIndex!, asset.attributes[attrRef.name!]] : undefined;+ }).filter((indexAndAttr) => !!indexAndAttr) as [number, Attribute<any>][];+ this.period = view.period || "day";+ this.mainValueDecimals = view.decimals || 0;+ this.deltaFormat = view.deltaFormat || "absolute";}- );+ }+ }++ async saveSettings() {- if (response.status !== 200 || !response.data) {- return [];+ if (!this.panelName) {+ return;}- return response.data;- }+ const viewSelector = window.location.hash;+ const configStr = await manager.console.retrieveData("OrChartConfig");+ let config: OrChartConfig | undefined;- protected async getAttributeValue(assetId: string, attributeName: string): Promise<any> {+ if (configStr) {+ try {+ config = JSON.parse(configStr) as OrChartConfig;+ } catch (e) {+ console.error("Failed to load chart config", e);+ }+ }- const response = await manager.rest.api.AssetResource.queryAssets({- ids: [assetId],- recursive: false- });+ if (!config) {+ config = {+ views: {+ [viewSelector]: {+ }+ }+ }+ }- if (response.status !== 200 || !response.data) {- return [];+ if (!this.assets || !this.assetAttributes || this.assets.length === 0 || this.assetAttributes.length === 0) {+ delete config.views[viewSelector][this.panelName];+ } else {+ config.views[viewSelector][this.panelName] = {+ attributeRefs: this.assetAttributes.map(([index, attr]) => {+ const asset = this.assets[index];+ return !!asset ? {id: asset.id, name: attr.name} as AttributeRef : undefined;+ }).filter((attrRef) => !!attrRef) as AttributeRef[],+ period: this.period,+ deltaFormat: this.deltaFormat,+ decimals: this.mainValueDecimals+ };}- return response.data;+ manager.console.storeData("OrChartConfig", JSON.stringify(config));}- protected async getData() {+ protected async loadData() {- if (!this.assetId || !this.attributeName) {- this.error = true;- this.getSettings();- return false;+ if (this._loading || this.data || !this.assetAttributes || !this.assets || this.assets.length === 0 || this.assetAttributes.length === 0 || !this.period) {+ return;}- const thisMoment = moment(this.now);+ this._loading = true;- this.asset = await this.getAssetById(this.assetId);- this.currentPeriod = {- start: thisMoment.clone().subtract(1, this.period).toDate().getTime(),- end: thisMoment.clone().toDate().getTime()- };+ let interval: DatapointInterval = DatapointInterval.HOUR;+ let stepSize = 1;- this.getAttributeValue(this.assetId, this.attributeName)- .then((response) => {- this.mainValue = response[0].attributes[this.attributeName!].value;- this.formattedMainValue = this.getFormattedValue(this.mainValue!);+ switch (this.period) {+ case "hour":+ interval = DatapointInterval.MINUTE;+ stepSize = 5;+ break;+ case "day":+ interval = DatapointInterval.HOUR;+ stepSize = 1;+ break;+ case "week":+ interval = DatapointInterval.HOUR;+ stepSize = 6;+ break;+ case "month":+ interval = DatapointInterval.DAY;+ stepSize = 1;+ break;+ case "year":+ interval = DatapointInterval.MONTH;+ stepSize = 1;+ break;+ }- return this.getDatapointsByAttribute(this.assetId!, this.attributeName!, this.currentPeriod!.start, this.currentPeriod!.end);- })- .then((datapoints: ValueDatapoint<any>[]) => {- this.data = datapoints || [];- this.delta = this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data));- this.deltaPlus = (this.delta.val && this.delta.val > 0) ? "+" : "";+ const lowerCaseInterval = interval.toLowerCase();+ const startOfPeriod = moment().startOf(this.period).startOf(lowerCaseInterval as moment.unitOfTime.StartOf).add(1, lowerCaseInterval as moment.unitOfTime.Base).toDate().getTime(); moment().clone().subtract(1, this.period).toDate().getTime();+ const endOfPeriod = moment().endOf(this.period).startOf(lowerCaseInterval as moment.unitOfTime.StartOf).add(1, lowerCaseInterval as moment.unitOfTime.Base).toDate().getTime();+ this.mainValue = undefined;+ this.formattedMainValue = undefined;+ const assetId = this.assets[0].id!;+ const attributeName = this.assetAttributes[0][1].name!;++ const currentValue: AttributeEvent = await manager.events!.sendEventWithReply({+ event: {+ eventType: "read-asset-attribute",+ ref: {+ id: assetId,+ name: attributeName+ }+ } as ReadAttributeEvent+ });- this.error = false;+ this.mainValue = currentValue.attributeState!.value;+ this.formattedMainValue = this.getFormattedValue(this.mainValue!);- })- .catch((err) => {- this.error = true;- this.requestUpdate();- });+ const response = await manager.rest.api.AssetDatapointResource.getDatapoints(+ assetId,+ attributeName,+ {+ interval: interval,+ fromTimestamp: startOfPeriod,+ toTimestamp: endOfPeriod+ }+ );+ this._loading = false;++ if (response.status === 200) {+ this.data = response.data;+ this.delta = this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data));+ this.deltaPlus = this.delta && this.delta.val! > 0 ? "+" : "";+ this.error = false;+ }}protected getTotalValue(data: ValueDatapoint<any>[]): number {@@ -780,16 +799,15 @@ export class OrAttributeCard extends LitElement {return Math.max.apply(Math, data.map((e: ValueDatapoint<any>) => e.y || false ));}- protected getFormattedValue(value: number): {value: number, unit: string} | undefined {- if (!this.asset) {+ protected getFormattedValue(value: number | undefined): {value: number, unit: string} | undefined {+ if (value === undefined || !this.assets || !this.assetAttributes || this.assets.length === 0 || this.assetAttributes.length === 0) {return;}- const attr = this.asset.attributes![this.attributeName!];+ const attr = this.assetAttributes[0][1];const roundedVal = +value.toFixed(this.mainValueDecimals); // + operator prevents str return-- const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(this.attributeName!, this.asset!.type!);- const units = Util.resolveUnits(Util.getAttributeUnits(attr, attributeDescriptor, this.asset!.type));+ const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(attr.name!, this.assets[0].type!);+ const units = Util.resolveUnits(Util.getAttributeUnits(attr, attributeDescriptor, this.assets[0].type));this.setMainValueSize(roundedVal.toString());if (!units) { return {value: roundedVal, unit: "" }; }@@ -834,28 +852,6 @@ export class OrAttributeCard extends LitElement {return {val: Math.round(lastVal - firstVal), unit: ""};}- protected _getInterval() {- let interval: DatapointInterval = DatapointInterval.HOUR;- switch (this.period) {- case "hour":- interval = DatapointInterval.MINUTE;- break;- case "day":- interval = DatapointInterval.HOUR;- break;- case "week":- interval = DatapointInterval.HOUR;- break;- case "month":- interval = DatapointInterval.DAY;- break;- case "year":- interval = DatapointInterval.MONTH;- break;- }- return interval;- }-protected handleMenuSelect(value: ContextMenuOptions) {this._openDialog(value);}@@ -870,10 +866,7 @@ export class OrAttributeCard extends LitElement {protected _setPeriodOption(value: any) {this.period = value;-this.saveSettings();- this.getData();- this.requestUpdate();}}diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.tsindex 002d9547c..195a59521 100644--- a/ui/component/or-attribute-input/src/index.ts+++ b/ui/component/or-attribute-input/src/index.ts@@ -23,7 +23,7 @@ import {} from "@openremote/model";import manager, {AssetModelUtil, DefaultColor4, subscribe, Util} from "@openremote/core";import "@openremote/or-mwc-components/or-mwc-input";-import {InputType, OrInput, OrInputChangedEvent, ValueInputProviderOptions, ValueInputProviderGenerator, getValueHolderInputTemplateProvider, ValueInputProvider, OrInputChangedEventDetail} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrMwcInput, OrInputChangedEvent, ValueInputProviderOptions, ValueInputProviderGenerator, getValueHolderInputTemplateProvider, ValueInputProvider, OrInputChangedEventDetail} from "@openremote/or-mwc-components/or-mwc-input";import "@openremote/or-map";import { geoJsonPointInputTemplateProvider } from "@openremote/or-map";@@ -355,7 +355,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitEprotected _writeTimeoutHandler?: number;@query("#send-btn")- protected _sendButton!: OrInput;+ protected _sendButton!: OrMwcInput;@query("#scrim")protected _scrimElem!: HTMLDivElement;diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex 230c0b81c..60dee2656 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -11,7 +11,7 @@ import {} from "lit-element";import i18next from "i18next";import {translate} from "@openremote/or-translate";-import {Asset, Attribute, AttributeRef, DatapointInterval, WellknownMetaItems, ReadAssetEvent, AssetEvent, ValueDatapoint} from "@openremote/model";+import {Asset, Attribute, AttributeRef, DatapointInterval, WellknownMetaItems, ReadAssetEvent, AssetEvent, ValueDatapoint, AssetQuery} from "@openremote/model";import manager, {AssetModelUtil,DefaultColor2,@@ -32,7 +32,7 @@ import {Chart, ChartDataset, TimeUnit, ScatterDataPoint, ScatterController, LineTooltip,ChartConfiguration,TimeScaleOptions} from "chart.js";-import {InputType, OrInputChangedEvent} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";import moment from "moment";import {OrAssetTreeSelectionEvent} from "@openremote/or-asset-tree";import {getAssetDescriptorIconTemplate} from "@openremote/or-icon";@@ -58,15 +58,14 @@ export class OrChartEvent extends CustomEvent<OrChartEventDetail> {});}}+export interface ChartViewConfig {- assetIds?: string[];- attributes?: string[];+ attributeRefs?: AttributeRef[];timestamp?: number;- compareTimestamp?: number;+ compareOffset?: number;period?: moment.unitOfTime.Base;- deltaFormat?: string;+ deltaFormat?: "absolute" | "percentage";decimals?: number;- periodCompare?: boolean;}export interface OrChartEventDetail {@@ -85,13 +84,13 @@ export interface ChartConfig {yLabel?: string;}-export interface OrChartConfig {chart?: ChartConfig;views: {[name: string]: {[panelName: string]: ChartViewConfig}};}+// TODO: Add webpack/rollup to build so consumers aren't forced to use the same toolingconst dialogStyle = require("@material/dialog/dist/mdc.dialog.css");const tableStyle = require("@material/data-table/dist/mdc.data-table.css");@@ -333,26 +332,20 @@ export class OrChart extends translate(i18next)(LitElement) {@property({type: Object})public assets: Asset[] = [];- @property({type: String})- public activeAssetId?:string;-@property({type: Object})private activeAsset?: Asset;@property({type: Object})- public assetAttributes: Attribute<any>[] = [];-- @property({type: Object})- public attributeRef?: AttributeRef;+ public assetAttributes: [number, Attribute<any>][] = [];@property({type: Array})public colors: string[] = ["#3869B1", "#DA7E30", "#3F9852", "#CC2428", "#6B4C9A", "#922427", "#958C3D", "#535055"];@property({type: String})- public period?: moment.unitOfTime.Base = "day";+ public period: moment.unitOfTime.Base = "day";@property({type: Number})- public timestamp?: Date = moment().set('minute', 0).toDate();+ public timestamp: Date = moment().set('minute', 0).toDate();@property({type: Number})public compareTimestamp?: Date = moment().set('minute', 0).toDate();@@ -363,9 +356,6 @@ export class OrChart extends translate(i18next)(LitElement) {@property()public panelName?: string;- @property()- protected periodCompare: boolean = false;-@property()protected _loading: boolean = false;@@ -378,11 +368,10 @@ export class OrChart extends translate(i18next)(LitElement) {@query("#chart")protected _chartElem!: HTMLCanvasElement;- protected _chart?: Chart;-@query("#mdc-dialog")protected _dialogElem!: HTMLElement;+ protected _chart?: Chart;protected _dialog!: MDCDialog;protected _style!: CSSStyleDeclaration;protected _startOfPeriod?: number;@@ -390,57 +379,151 @@ export class OrChart extends translate(i18next)(LitElement) {protected _timeUnits?: TimeUnit;protected _stepSize?: number;protected _updateTimestampTimer: number | null = null;-++ constructor() {+ super();+ this.addEventListener(OrAssetTreeSelectionEvent.NAME, this._onTreeSelectionChanged);+ }++ connectedCallback() {+ super.connectedCallback();+ this._style = window.getComputedStyle(this);+ }++ disconnectedCallback(): void {+ super.disconnectedCallback();+ this._cleanup();+ }+firstUpdated() {- if (this._dialogElem) {- this._dialog = new MDCDialog(this._dialogElem);- if(!this.activeAssetId) {- this.getSettings();+ this.loadSettings();+ }++ updated(changedProperties: PropertyValues) {+ super.updated(changedProperties);++ const reloadData = changedProperties.has("period") || changedProperties.has("compareTimestamp") || changedProperties.has("timestamp") || changedProperties.has("assetAttributes");++ if (reloadData) {+ this._data = undefined;+ if (this._chart) {+ this._chart.destroy();+ this._chart = undefined;}+ this._loadData();}- }- protected _onTreeSelectionChanged(event: OrAssetTreeSelectionEvent) {- // Need to fully load the asset- if (!manager.events) {+ if (!this._data) {return;}- const selectedNode = event.detail && event.detail.newNodes.length > 0 ? event.detail.newNodes[0] : undefined;+ const now = moment().toDate().getTime();- if (!selectedNode) {- this.activeAsset = undefined;+ if (!this._chart) {+ const options = {+ type: "line",+ data: {+ datasets: this._data+ },+ options: {+ responsive: true,+ maintainAspectRatio: false,+ onResize:() => this.dispatchEvent(new OrChartEvent("resize")),+ showLines: true,+ plugins: {+ legend: {+ display: false+ },+ tooltip: {+ mode: "x",+ intersect: false,+ xPadding: 10,+ yPadding: 10,+ titleMarginBottom: 10+ },+ annotation: {+ annotations: [+ {+ type: "line",+ xMin: now,+ xMax: now,+ borderColor: "#275582",+ borderWidth: 2+ }+ ]+ },+ },+ hover: {+ mode: 'x',+ intersect: false+ },+ scales: {+ y: {+ ticks: {+ beginAtZero: true+ },+ grid: {+ color: "#cccccc"+ }+ },+ x: {+ type: "time",+ min: this._startOfPeriod,+ max: this._endOfPeriod,+ time: {+ tooltipFormat: 'MMM D, YYYY, HH:mm:ss',+ displayFormats: {+ millisecond: 'HH:mm:ss.SSS',+ second: 'HH:mm:ss',+ minute: "HH:mm",+ hour: "HH:mm",+ week: "w"+ },+ unit: this._timeUnits,+ stepSize: this._stepSize+ },+ ticks: {+ autoSkip: true,+ maxTicksLimit: 30,+ color: "#000",+ font: {+ family: "'Open Sans', Helvetica, Arial, Lucida, sans-serif",+ size: 9,+ style: "normal"+ }+ },+ gridLines: {+ color: "#cccccc"+ }+ }+ }+ }+ } as ChartConfiguration<"line", ScatterDataPoint[]>;++ this._chart = new Chart<"line", ScatterDataPoint[]>(this._chartElem.getContext("2d")!, options);} else {- // fully load the asset- manager.events.sendEventWithReply({- event: {- eventType: "read-asset",- assetId: selectedNode.asset!.id- } as ReadAssetEvent- }).then((ev) => {- this.activeAsset = (ev as AssetEvent).asset;- }).catch(() => this.activeAsset = undefined);+ if (changedProperties.has("_data")) {+ this._chart.options.scales!.x!.min = this._startOfPeriod;+ this._chart.options!.scales!.x!.max = this._endOfPeriod;+ (this._chart.options!.scales!.x! as TimeScaleOptions).time!.unit = this._timeUnits!;+ (this._chart.options!.scales!.x! as TimeScaleOptions).time!.stepSize = this._stepSize!;+ (this._chart.options!.plugins!.annotation!.annotations![0] as AnnotationOptions<"line">).xMin = now;+ (this._chart.options!.plugins!.annotation!.annotations![0] as AnnotationOptions<"line">).xMax = now;+ this._chart.data.datasets = this._data;+ this._chart.update();+ }}- }-- connectedCallback() {- super.connectedCallback();- this._style = window.getComputedStyle(this);- this.addEventListener(OrAssetTreeSelectionEvent.NAME, this._onTreeSelectionChanged);- }+ this.onCompleted().then(() => {+ this.dispatchEvent(new OrChartEvent('rendered'));+ });- disconnectedCallback(): void {- super.disconnectedCallback();- this._cleanup();- this.removeEventListener(OrAssetTreeSelectionEvent.NAME, this._onTreeSelectionChanged);}render() {const disabled = this._loading;const endDateInputType = this.getInputType();return html`- <div id="container">-+ <div id="container"><div id="chart-container"><canvas id="chart"></canvas></div>@@ -448,12 +531,12 @@ export class OrChart extends translate(i18next)(LitElement) {<div id="controls"><div class="interval-controls" style="margin-right: 6px;">${getContentWithMenuTemplate(- html`<or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("timeframe")}: ${i18next.t(this.period ? this.period : "-")}"></or-mwc-input>`,- this._getPeriodOptions(),- this.period,- (value) => this.setPeriodOption(value))}+ html`<or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("timeframe")}: ${i18next.t(this.period ? this.period : "-")}"></or-mwc-input>`,+ this._getPeriodOptions(),+ this.period,+ (value) => this.setPeriodOption(value))}- ${this.periodCompare ? html `+ ${!!this.compareTimestamp ? html `<or-mwc-input style="margin-left:auto;" .type="${InputType.BUTTON}" .label="${i18next.t("period")}" @click="${() => this.setPeriodCompare(false)}" icon="minus"></or-mwc-input>` : html`<or-mwc-input style="margin-left:auto;" .type="${InputType.BUTTON}" .label="${i18next.t("period")}" @click="${() => this.setPeriodCompare(true)}" icon="plus"></or-mwc-input>@@ -462,7 +545,7 @@ export class OrChart extends translate(i18next)(LitElement) {<div class="period-controls">- ${this.periodCompare ? html `+ ${!!this.compareTimestamp ? html `<span class="line-label solid"></span>`: ``}<or-mwc-input id="ending-date"@@ -474,7 +557,7 @@ export class OrChart extends translate(i18next)(LitElement) {<or-icon class="button-icon" icon="chevron-left" @click="${() => this._updateTimestamp(this.timestamp!, false, undefined, 0)}"></or-icon><or-icon class="button-icon" icon="chevron-right" @click="${() =>this._updateTimestamp(this.timestamp!, true, undefined, 0)}"></or-icon></div>- ${this.periodCompare ? html `+ ${!!this.compareTimestamp ? html `<div class="period-controls"><span class="line-label dashed"></span><or-mwc-input id="ending-date"@@ -489,20 +572,20 @@ export class OrChart extends translate(i18next)(LitElement) {` : html``}<div id="attribute-list">- ${this.assetAttributes && this.assetAttributes.map((attr, index) => {-- const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(attr.name!, this.assets[index]!.type!);- const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.assets[index]!.type, attr.name, attr);- const label = Util.getAttributeLabel(attr, descriptors[0], this.assets[index]!.type, true);- const bgColor = Util.getMetaValue('color', attr, undefined) ? Util.getMetaValue('color', attr, undefined) : "";+ ${this.assetAttributes && this.assetAttributes.map(([assetIndex, attr], index) => {+ const colourIndex = index % this.colors.length;+ const attributeDescriptor = AssetModelUtil.getAttributeDescriptor(attr.name!, this.assets[assetIndex]!.type!);+ const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.assets[assetIndex]!.type, attr.name, attr);+ const label = Util.getAttributeLabel(attr, descriptors[0], this.assets[assetIndex]!.type, true);+ const bgColor = this.colors[colourIndex] || "";return html`<div class="attribute-list-item" @mouseover="${()=> this.addDatasetHighlight(bgColor)}" @mouseout="${()=> this.removeDatasetHighlight(bgColor)}">- <span style="margin-right: 10px; --or-icon-width: 20px;">${getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(this.assets[index]!.type!), undefined, undefined, bgColor.split('#')[1])}</span>+ <span style="margin-right: 10px; --or-icon-width: 20px;">${getAssetDescriptorIconTemplate(AssetModelUtil.getAssetDescriptor(this.assets[assetIndex]!.type!), undefined, undefined, bgColor.split('#')[1])}</span><div class="attribute-list-item-label">- <span>${this.assets[index].name}</span>+ <span>${this.assets[assetIndex].name}</span><span style="font-size:14px; color:grey;">${label}</span></div>- <button class="button-clear" @click="${() => this._deleteAttribute(index)}"><or-icon icon="close-circle"></or-icon></button>+ <button class="button-clear" @click="${() => this._deleteAttribute(assetIndex)}"><or-icon icon="close-circle"></or-icon></button></div>`})}@@ -554,6 +637,28 @@ export class OrChart extends translate(i18next)(LitElement) {`;}+ protected async _onTreeSelectionChanged(event: OrAssetTreeSelectionEvent) {+ // Need to fully load the asset+ if (!manager.events) {+ return;+ }++ const selectedNode = event.detail && event.detail.newNodes.length > 0 ? event.detail.newNodes[0] : undefined;++ if (!selectedNode) {+ this.activeAsset = undefined;+ } else {+ // fully load the asset+ const assetEvent: AssetEvent = await manager.events.sendEventWithReply({+ event: {+ eventType: "read-asset",+ assetId: selectedNode.asset!.id+ } as ReadAssetEvent+ });+ this.activeAsset = assetEvent.asset;+ }+ }+setPeriodOption(value:any) {this.period = value;@@ -602,198 +707,125 @@ export class OrChart extends translate(i18next)(LitElement) {}}- updated(changedProperties: PropertyValues) {- super.updated(changedProperties);- if (!this._loading && changedProperties.has("activeAsset") && this.activeAsset && changedProperties.get("activeAsset") !== this.activeAsset) {- this.getSettings();- }+ async loadSettings() {- if(changedProperties.has("assetAttributes") ) {- this.assetAttributes.forEach((attr, index) => {- if(this.getAttrColor(attr)) return;- this.setAttrColor(attr)- });- }+ this.assetAttributes = [];+ this.period = "day";+ this.timestamp = moment().set('minute', 0).toDate();+ this.compareTimestamp = undefined;- const reloadData = changedProperties.has("period") || changedProperties.has("compareTimestamp") || changedProperties.has("timestamp") || changedProperties.has("assetAttributes");+ const configStr = await manager.console.retrieveData("OrChartConfig");- if (reloadData) {- this._data = undefined;- this._loadData();+ if (!configStr || !this.panelName) {+ return;}- if (!this._data) {+ const viewSelector = window.location.hash;+ let config: OrChartConfig;++ try {+ config = JSON.parse(configStr) as OrChartConfig;+ } catch (e) {+ console.error("Failed to load chart config", e);+ manager.console.storeData("OrChartConfig", null);return;}++ const view = config && config.views ? config.views[viewSelector][this.panelName] : undefined;- const now = moment().toDate().getTime();-- if (!this._chart) {- const options = {- type: "line",- data: {- datasets: this._data- },- options: {- responsive: true,- maintainAspectRatio: false,- onResize:() => this.dispatchEvent(new OrChartEvent("resize")),- showLines: true,- plugins: {- legend: {- display: false- },- tooltip: {- mode: "x",- intersect: false,- xPadding: 10,- yPadding: 10,- titleMarginBottom: 10- },- annotation: {- annotations: [- {- type: "line",- xMin: now,- xMax: now,- borderColor: "#275582",- borderWidth: 2- }- ]- },- },- hover: {- mode: 'x',- intersect: false- },- scales: {- y: {- ticks: {- beginAtZero: true- },- grid: {- color: "#cccccc"- }- },- x: {- type: "time",- min: this._startOfPeriod,- max: this._endOfPeriod,- time: {- tooltipFormat: 'MMM D, YYYY, HH:mm:ss',- displayFormats: {- millisecond: 'HH:mm:ss.SSS',- second: 'HH:mm:ss',- minute: "HH:mm",- hour: "HH:mm",- week: "w"- },- unit: this._timeUnits,- stepSize: this._stepSize- },- ticks: {- autoSkip: true,- maxTicksLimit: 30,- color: "#000",- font: {- family: "'Open Sans', Helvetica, Arial, Lucida, sans-serif",- size: 9,- style: "normal"- }- },- gridLines: {- color: "#cccccc"- }- }- }- }- } as ChartConfiguration<"line", ScatterDataPoint[]>;-- this._chart = new Chart<"line", ScatterDataPoint[]>(this._chartElem.getContext("2d")!, options);- } else {- if (changedProperties.has("_data")) {- this._chart.options.scales!.x!.min = this._startOfPeriod;- this._chart.options!.scales!.x!.max = this._endOfPeriod;- (this._chart.options!.scales!.x! as TimeScaleOptions).time!.unit = this._timeUnits!;- (this._chart.options!.scales!.x! as TimeScaleOptions).time!.stepSize = this._stepSize!;- (this._chart.options!.plugins!.annotation!.annotations![0] as AnnotationOptions<"line">).xMin = now;- (this._chart.options!.plugins!.annotation!.annotations![0] as AnnotationOptions<"line">).xMax = now;- this._chart.data.datasets = this._data;- this._chart.update();- }+ if (!view) {+ return;}- this.onCompleted().then(() => {- this.dispatchEvent(new OrChartEvent('rendered'));- });- }-- async getSettings() {- const configStr = await manager.console.retrieveData("OrChartConfig");-- if(!configStr || !this.panelName) {+ if (!view.attributeRefs) {+ // Old/invalid config format remove it+ delete config.views[viewSelector][this.panelName];+ manager.console.storeData("OrChartConfig", JSON.stringify(config));return;}- const viewSelector = this.activeAssetId ? this.activeAssetId : window.location.hash;- const config = JSON.parse(configStr) as OrChartConfig;- const view = config.views[viewSelector][this.panelName];- if (!view) {+ const assetIds = view.attributeRefs.map((attrRef) => attrRef.id!);++ if (assetIds.length === 0) {return;}- const query = {- ids: view.assetIds- }- if (view.assetIds && this.assets && view.assetIds.every(id => !!this.assets.find(asset => asset.id === id))) return;+this._loading = true;- manager.rest.api.AssetResource.queryAssets(query).then((response) => {+ if (!assetIds.every(id => !!this.assets.find(asset => asset.id === id))) {+ const query = {+ select: {+ excludePath: true,+ excludeParentInfo: true+ },+ ids: assetIds+ } as AssetQuery;++ try {+ const response = await manager.rest.api.AssetResource.queryAssets(query);+ const assets = response.data || [];+ view.attributeRefs = view.attributeRefs.filter((attrRef) => !!assets.find((asset) => asset.id === attrRef.id && asset.attributes && asset.attributes.hasOwnProperty(attrRef.name!)));+ manager.console.storeData("OrChartConfig", JSON.stringify(config));+ this.assets = assets.filter((asset) => view.attributeRefs!.find((attrRef) => attrRef.id === asset.id));+ } catch (e) {+ console.error("Failed to get assets requested in settings", e);+ }+this._loading = false;- const assets = response.data;- if (!view || !view.assetIds || !view.attributes || assets.length !== view.assetIds.length || assets.length !== view.attributes.length) return;-- this.assets = view.assetIds.map((assetId: string) => assets.find(x => x.id === assetId)!);- this.assetAttributes = view.attributes.map((attr: string, index: number) => assets[index] && assets[index].attributes ? assets[index].attributes![attr] : undefined).filter(attr => !!attr) as Attribute<any>[];- this.period = view.period;- this.timestamp = view.timestamp ? new Date(view.timestamp) : new Date();- this.compareTimestamp = view.compareTimestamp ? new Date(view.compareTimestamp) : new Date();- this.periodCompare = !!view.periodCompare;- });++ if (this.assets && this.assets.length > 0) {+ this.assetAttributes = view.attributeRefs.map((attrRef) => {+ const assetIndex = this.assets.findIndex((asset) => asset.id === attrRef.id);+ const asset = assetIndex >= 0 ? this.assets[assetIndex] : undefined;+ return asset && asset.attributes ? [assetIndex!, asset.attributes[attrRef.name!]] : undefined;+ }).filter((indexAndAttr) => !!indexAndAttr) as [number, Attribute<any>][];+ this.period = view.period || "day";+ this.timestamp = new Date();+ this.compareTimestamp = view.compareOffset ? new Date(new Date().getTime() + view.compareOffset) : undefined;+ }+ }}async saveSettings() {- if(!this.panelName) {++ if (!this.panelName) {return;}- const viewSelector = this.activeAssetId ? this.activeAssetId : window.location.hash;- const assets: Asset[] = this.assets ? this.assets.filter(asset => !!asset.id) : [];- const assetIds = assets.map(asset => asset.id!);- const attributes = this.assetAttributes ? this.assetAttributes.map(attr => attr.name!) : [];- const configStr = await manager.console.retrieveData("OrChartConfig");- let config:OrChartConfig;+ const viewSelector = window.location.hash;+ const configStr = await manager.console.retrieveData("OrChartConfig");+ let config: OrChartConfig | undefined;+if (configStr) {- config = JSON.parse(configStr);- } else {+ try {+ config = JSON.parse(configStr) as OrChartConfig;+ } catch (e) {+ console.error("Failed to load chart config", e);+ }+ }++ if (!config) {config = {views: {[viewSelector]: {- [this.panelName] : {-- }}}- }- }-- config.views[viewSelector][this.panelName] = {- assetIds: assetIds,- attributes: attributes,- period: this.period,- periodCompare: this.periodCompare,- timestamp: this.timestamp ? this.timestamp.getTime() : undefined,- compareTimestamp: this.compareTimestamp ? this.compareTimestamp.getTime() : undefined- };+ }+ }++ if (!this.assets || !this.assetAttributes || this.assets.length === 0 || this.assetAttributes.length === 0) {+ delete config.views[viewSelector][this.panelName];+ } else {+ config.views[viewSelector][this.panelName] = {+ attributeRefs: this.assetAttributes.map(([index, attr]) => {+ const asset = this.assets[index];+ return !!asset ? {id: asset.id, name: attr.name} as AttributeRef : undefined;+ }).filter((attrRef) => !!attrRef) as AttributeRef[],+ period: this.period,+ compareOffset: this.timestamp && this.compareTimestamp ? this.compareTimestamp.getTime() - this.timestamp.getTime() : undefined+ };+ }+manager.console.storeData("OrChartConfig", JSON.stringify(config));}@@ -807,33 +839,24 @@ export class OrChart extends translate(i18next)(LitElement) {}}- addAttribute(e:Event) {+ addAttribute() {if (this.shadowRoot && this.shadowRoot.getElementById('chart-attribute-picker')) {- const elm = this.shadowRoot.getElementById('chart-attribute-picker') as HTMLInputElement;+ const elm = this.shadowRoot.getElementById('chart-attribute-picker') as OrMwcInput;if (this.activeAsset) {const attr = this.activeAsset.attributes ? this.activeAsset.attributes[elm.value] : undefined;if (attr) {- this.setAttrColor(attr);- this.assetAttributes = [...this.assetAttributes, attr];+ let index = this.assets.findIndex((asset) => asset.id === this.activeAsset!.id);+ if (index < 0) {+ index = this.assets.length;+ this.assets = [...this.assets, this.activeAsset];+ }- this.assets = [...this.assets, this.activeAsset];+ this.assetAttributes = [...this.assetAttributes, [index, attr]];this.saveSettings();}}}}-- setAttrColor(attr: Attribute<any>) {- const usedColors = this.assetAttributes.map(attr => this.getAttrColor(attr));- const color = this.colors.filter(color => usedColors.indexOf(color) < 0)[0];- if (attr.meta) {- attr.meta["color"] = color;- }- }-- getAttrColor(attr: Attribute<any>) {- return Util.getMetaValue('color', attr, undefined);- }async onCompleted() {await this.updateComplete;@@ -849,10 +872,19 @@ export class OrChart extends translate(i18next)(LitElement) {}}- protected _deleteAttribute (index:number) {- this.assets = [...this.assets.slice(0, index).concat(this.assets.slice(index + 1, this.assets.length))];- this.assetAttributes = [...this.assetAttributes.slice(0, index).concat(this.assetAttributes.slice(index + 1, this.assetAttributes.length))];-+ protected _deleteAttribute (index: number) {+ const removed = this.assetAttributes.splice(index, 1)[0];+ const assetIndex = removed[0];+ this.assetAttributes = [...this.assetAttributes];+ if (!this.assetAttributes.some(([index, attrRef]) => index === assetIndex)) {+ // Asset no longer referenced+ this.assets.splice(index, 1);+ this.assetAttributes.forEach((indexRef) => {+ if (indexRef[0] >= assetIndex) {+ indexRef[0] -= 1;+ }+ });+ }this.saveSettings();}@@ -870,7 +902,7 @@ export class OrChart extends translate(i18next)(LitElement) {if (attributes && attributes.length > 0) {return attributes.filter((attribute) => attribute.meta && (attribute.meta.hasOwnProperty(WellknownMetaItems.STOREDATAPOINTS) ? attribute.meta[WellknownMetaItems.STOREDATAPOINTS] : attribute.meta.hasOwnProperty(WellknownMetaItems.AGENTLINK)))- .filter((attr) => (this.assetAttributes && !this.assetAttributes.some((assetAttr, index) => (assetAttr.name === attr.name) && this.assets[index].id === this.activeAsset!.id)))+ .filter((attr) => (this.assetAttributes && !this.assetAttributes.some(([index, assetAttr]) => (assetAttr.name === attr.name) && this.assets[index].id === this.activeAsset!.id))).map((attr) => {const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(this.activeAsset!.type, attr.name, attr);const label = Util.getAttributeLabel(attr, descriptors[0], this.activeAsset!.type, false);@@ -905,19 +937,18 @@ export class OrChart extends translate(i18next)(LitElement) {}setPeriodCompare(periodCompare:boolean) {- this.periodCompare = periodCompare;- this.saveSettings();-if (periodCompare) {- this._data = undefined;- this._loadData();+ this.compareTimestamp = this.timestamp;} else {- this._data = this._data ? this._data.map((dataset) => (dataset as any).isComparisonDataset ? undefined : dataset).filter((dataset) => !!dataset) as ChartDataset<"line", ScatterDataPoint[]>[] : undefined;+ this.compareTimestamp = undefined}++ this.saveSettings();}protected async _loadData() {- if(this._loading || this._data || !this.assetAttributes || !this.assets || this.assets.length === 0 || this.assetAttributes.length !== this.assets.length || !this.period || !this.timestamp) {++ if (this._loading || this._data || !this.assetAttributes || !this.assets || this.assets.length === 0 || this.assetAttributes.length === 0 || !this.period || !this.timestamp) {return;}@@ -958,31 +989,31 @@ export class OrChart extends translate(i18next)(LitElement) {let predictedFromTimestamp = now < this._startOfPeriod ? this._startOfPeriod : now;const data: ChartDataset<"line", ScatterDataPoint[]>[] = [];- const promises = this.assetAttributes.map(async (attribute, index) => {+ const promises = this.assetAttributes.map(async ([assetIndex, attribute], index) => {- const asset = this.assets[index];+ const asset = this.assets[assetIndex];const descriptors = AssetModelUtil.getAttributeAndValueDescriptors(asset.type, attribute.name, attribute);const label = Util.getAttributeLabel(attribute, descriptors[0], asset.type, false);-- let dataset = await this._loadAttributeData(asset, attribute, interval, this._startOfPeriod!, this._endOfPeriod!, false, asset.name + " " + label);+ const colourIndex = index % this.colors.length;+ let dataset = await this._loadAttributeData(asset, attribute, this.colors[colourIndex], interval, this._startOfPeriod!, this._endOfPeriod!, false, asset.name + " " + label);data.push(dataset);- dataset = await this._loadAttributeData(this.assets[index], attribute, interval, predictedFromTimestamp, this._endOfPeriod!, true, asset.name + " " + label + " " + i18next.t("predicted"));+ dataset = await this._loadAttributeData(this.assets[assetIndex], attribute, this.colors[colourIndex], interval, predictedFromTimestamp, this._endOfPeriod!, true, asset.name + " " + label + " " + i18next.t("predicted"));data.push(dataset);- if (this.periodCompare) {+ if (this.compareTimestamp) {const startOfPeriod = moment(this.compareTimestamp).startOf(this.period!).startOf(lowerCaseInterval as moment.unitOfTime.StartOf).add(1, lowerCaseInterval as moment.unitOfTime.Base).toDate().getTime();const endOfPeriod = moment(this.compareTimestamp).endOf(this.period!).startOf(lowerCaseInterval as moment.unitOfTime.StartOf).add(1, lowerCaseInterval as moment.unitOfTime.Base).toDate().getTime();const offset = this._startOfPeriod! - startOfPeriod;- dataset = await this._loadAttributeData(this.assets[index], attribute, interval, startOfPeriod, endOfPeriod, false, asset.name + " " + label + " " + i18next.t("compare"));+ dataset = await this._loadAttributeData(this.assets[assetIndex], attribute, this.colors[colourIndex], interval, startOfPeriod, endOfPeriod, false, asset.name + " " + label + " " + i18next.t("compare"));dataset.data.forEach((dp) => dp.x += offset);dataset.borderDash = [10, 10];(dataset as any).isComparisonDataset = true;data.push(dataset);predictedFromTimestamp = now < startOfPeriod ? startOfPeriod : now;- dataset = await this._loadAttributeData(this.assets[index], attribute, interval, startOfPeriod, endOfPeriod, true, asset.name + " " + label + " " + i18next.t("compare") + " " + i18next.t("predicted"));+ dataset = await this._loadAttributeData(this.assets[assetIndex], attribute, this.colors[colourIndex], interval, startOfPeriod, endOfPeriod, true, asset.name + " " + label + " " + i18next.t("compare") + " " + i18next.t("predicted"));dataset.data.forEach((dp) => dp.x += offset);dataset.borderDash = [6, 8];(dataset as any).isComparisonDataset = true;@@ -990,6 +1021,7 @@ export class OrChart extends translate(i18next)(LitElement) {}});+ this._loading = false;await Promise.all(promises);this._data = data;}@@ -997,7 +1029,7 @@ export class OrChart extends translate(i18next)(LitElement) {protected _timestampLabel(timestamp: Date | number | undefined) {let newMoment = moment.utc(timestamp).local();- if(this.periodCompare) {+ if(this.compareTimestamp) {const initialTimestamp = moment(this.timestamp);switch (this.period) {case "hour":@@ -1021,15 +1053,13 @@ export class OrChart extends translate(i18next)(LitElement) {return newMoment.format();}- protected async _loadAttributeData(asset: Asset, attribute: Attribute<any>, interval: DatapointInterval, from: number, to: number, predicted: boolean, label: string | undefined): Promise<ChartDataset<"line", ScatterDataPoint[]>> {-- const bgColor = this.getAttrColor(attribute);+ protected async _loadAttributeData(asset: Asset, attribute: Attribute<any>, color: string | undefined, interval: DatapointInterval, from: number, to: number, predicted: boolean, label: string | undefined): Promise<ChartDataset<"line", ScatterDataPoint[]>> {const dataset: ChartDataset<"line", ScatterDataPoint[]> = {+ borderColor: color,+ backgroundColor: color,label: label,- borderColor: bgColor,pointRadius: 2,- backgroundColor: bgColor,fill: false,data: [],borderDash: predicted ? [2, 4] : undefined@@ -1058,8 +1088,6 @@ export class OrChart extends translate(i18next)(LitElement) {);}- this._loading = false;-if (response.status === 200) {dataset.data = response.data.filter(value => value.y !== null && value.y !== undefined) as ScatterDataPoint[];}@@ -1082,10 +1110,10 @@ export class OrChart extends translate(i18next)(LitElement) {}if (compare) {this.compareTimestamp = newMoment.toDate()- this.saveSettings();} else {this.timestamp = newMoment.toDate()}+ this.saveSettings();}, timeout);}diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex ce5256257..de74f6f7b 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -6,7 +6,7 @@ import {MapWidget} from "./mapwidget";import {style} from "./style";import {OrMapMarker, OrMapMarkerChangedEvent} from "./markers/or-map-marker";import * as Util from "./util";-import { OrInput, InputType, ValueInputProviderGenerator, ValueInputTemplateFunction } from "@openremote/or-mwc-components/or-mwc-input";+import { OrMwcInput, InputType, ValueInputProviderGenerator, ValueInputTemplateFunction } from "@openremote/or-mwc-components/or-mwc-input";import {showDialog, OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {getMarkerIconAndColorFromAssetType} from "./markers/or-map-marker-asset";import { i18next } from "@openremote/or-translate";@@ -104,7 +104,7 @@ const CoordinatesRegexPattern = "^[ ]*(?:Lat: )?(-?\\d+\\.?\\d*)[, ]+(?:Lng: )?(function getCoordinatesInputKeyHandler(valueChangedHandler: (value: LngLat | undefined) => void) {return (e: KeyboardEvent) => {if (e.code === "Enter" || e.code === "NumpadEnter") {- const valStr = (e.target as OrInput).value as string;+ const valStr = (e.target as OrMwcInput).value as string;let value: LngLat | undefined;if (valStr) {@@ -125,7 +125,7 @@ export class CoordinatesControl {protected map?: MapGL;protected elem?: HTMLElement;- protected input!: OrInput;+ protected input!: OrMwcInput;protected _readonly = false;protected _value: any;protected _valueChangedHandler: (value: LngLat | undefined) => void;@@ -141,7 +141,7 @@ export class CoordinatesControl {control.classList.add("mapboxgl-ctrl");control.classList.add("mapboxgl-ctrl-group");- const input = new OrInput();+ const input = new OrMwcInput();input.type = InputType.TEXT;input.outlined = true;input.compact = true;diff --git a/ui/component/or-mwc-components/src/or-mwc-input.ts b/ui/component/or-mwc-components/src/or-mwc-input.tsindex e1a4c44b6..2d946f5ad 100644--- a/ui/component/or-mwc-components/src/or-mwc-input.ts+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts@@ -553,7 +553,7 @@ const style = css``;@customElement("or-mwc-input")-export class OrInput extends LitElement {+export class OrMwcInput extends LitElement {static get styles() {return [diff --git a/ui/component/or-rules/src/or-rule-viewer.ts b/ui/component/or-rules/src/or-rule-viewer.tsindex ce8788640..bfffbdd61 100644--- a/ui/component/or-rules/src/or-rule-viewer.ts+++ b/ui/component/or-rules/src/or-rule-viewer.ts@@ -15,7 +15,7 @@ import "./or-rule-validity";import "./flow-viewer/components/flow-editor";import "@openremote/or-mwc-components/or-mwc-input";import {translate} from "@openremote/or-translate";-import {InputType, OrInputChangedEvent, OrInput} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";import i18next from "i18next";import { GenericAxiosResponse } from "@openremote/rest";import { showErrorDialog } from "@openremote/or-mwc-components/or-mwc-dialog";@@ -122,7 +122,7 @@ export class OrRuleViewer extends translate(i18next)(LitElement) {protected wrapperElem!: HTMLDivElement;@query("#save-btn")- protected saveBtnElem!: OrInput;+ protected saveBtnElem!: OrMwcInput;protected _focusName = false;