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
LocalStorage for insights page, update language
Robin Dekkersbcd2ca539521
diff --git a/deployment/manager/shared/locales/de/or.json b/deployment/manager/shared/locales/de/or.jsonindex be5e87f19..429282651 100644--- a/deployment/manager/shared/locales/de/or.json+++ b/deployment/manager/shared/locales/de/or.json@@ -186,7 +186,7 @@"CURRENCY": "%.1f","SPEED": "%.1f","CHARGE": "%.1f",- "ENERGY": "%.1f",+ "ENERGY": "%.3f","CO2": "%.1f","HUMIDITY": "%.1f"}diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.jsonindex 62a24d001..05084da6a 100644--- a/deployment/manager/shared/locales/en/or.json+++ b/deployment/manager/shared/locales/en/or.json@@ -201,7 +201,7 @@"CURRENCY": "%.1f","SPEED": "%.1f","CHARGE": "%.1f",- "ENERGY": "%.1f",+ "ENERGY": "%.3f","CO2": "%.1f","HUMIDITY": "%.1f"},diff --git a/deployment/manager/shared/locales/es/or.json b/deployment/manager/shared/locales/es/or.jsonindex f4b067caa..731ae2025 100644--- a/deployment/manager/shared/locales/es/or.json+++ b/deployment/manager/shared/locales/es/or.json@@ -187,7 +187,7 @@"CURRENCY": "%.1f","SPEED": "%.1f","CHARGE": "%.1f",- "ENERGY": "%.1f",+ "ENERGY": "%.3f","CO2": "%.1f","HUMIDITY": "%.1f"}diff --git a/deployment/manager/shared/locales/fr/or.json b/deployment/manager/shared/locales/fr/or.jsonindex 44efbc0da..2945654a0 100644--- a/deployment/manager/shared/locales/fr/or.json+++ b/deployment/manager/shared/locales/fr/or.json@@ -120,7 +120,7 @@"CURRENCY": "%.1f","SPEED": "%.1f","CHARGE": "%.1f",- "ENERGY": "%.1f",+ "ENERGY": "%.3f","CO2": "%.1f","HUMIDITY": "%.1f"}diff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.jsonindex 56eb8f94b..03010f2b9 100644--- a/deployment/manager/shared/locales/nl/or.json+++ b/deployment/manager/shared/locales/nl/or.json@@ -201,7 +201,7 @@"CURRENCY": "%.1f","SPEED": "%.1f","CHARGE": "%.1f",- "ENERGY": "%.1f",+ "ENERGY": "%.3f","CO2": "%.1f","HUMIDITY": "%.1f"},diff --git a/ui/app/or-app/src/index.ts b/ui/app/or-app/src/index.tsindex 488e36ea4..fae4b6e55 100644--- a/ui/app/or-app/src/index.ts+++ b/ui/app/or-app/src/index.ts@@ -375,7 +375,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}return html`${unsafeHTML(this._config.styles ? this._config.styles.strings : ``)}- <or-header .logo="${this._config.logo}" .logoMobile="${this._config.logoMobile}" .config="${this._config.header}"></or-header>+ <or-header logo="${this._config.logo}" .logoMobile="${this._config.logoMobile}" .config="${this._config.header}"></or-header><!-- Main content --><main role="main" class="main-content d-none"></main>diff --git a/ui/app/or-app/src/or-header.ts b/ui/app/or-app/src/or-header.tsindex bb9dc4e8d..4954b161c 100644--- a/ui/app/or-app/src/or-header.ts+++ b/ui/app/or-app/src/or-header.ts@@ -1,5 +1,6 @@import {customElement, html, LitElement, property, query, TemplateResult, css, unsafeCSS} from "lit-element";import {until} from "lit-html/directives/until";+import { ifDefined } from 'lit-html/directives/if-defined.js';import i18next from "i18next";import {DefaultColor1, DefaultColor2, DefaultColor3, DefaultColor4, DefaultBoxShadowBottom, DefaultHeaderHeight} from "@openremote/core";import manager from "@openremote/core";@@ -359,7 +360,7 @@ class OrHeader extends LitElement {<div id="mobile-bottom">${secondaryItems.filter(option => !option.hideMobile && (!option.roles || option.roles.some(r => manager.hasRole(r)))).map(headerItem => {return html`- <a class="menu-item" href="${headerItem.href}" @click="${(e: MouseEvent) => this._onHeaderItemSelect(headerItem)}" ?selected="${this.activeMenu === headerItem.href}"><or-icon icon="${headerItem.icon}"></or-icon><or-translate value="${headerItem.text}"></or-translate></a>+ <a class="menu-item" href="${ifDefined(headerItem.href)}" @click="${(e: MouseEvent) => this._onHeaderItemSelect(headerItem)}" ?selected="${this.activeMenu === headerItem.href}"><or-icon icon="${headerItem.icon}"></or-icon><or-translate value="${headerItem.text}"></or-translate></a>`})}</div>` : ``}diff --git a/ui/component/core/src/console.ts b/ui/component/core/src/console.tsindex 9862127ad..cd1b5a16f 100644--- a/ui/component/core/src/console.ts+++ b/ui/component/core/src/console.ts@@ -354,7 +354,7 @@ export class Console {}}- protected _doSendProviderMessage(msg: any) {+ public _doSendProviderMessage(msg: any) {if (this.isMobile) {this._postNativeShellMessage({type: "provider", data: msg});} else {diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex 993594c12..3a981c0d7 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -454,28 +454,31 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem`;}- } else if (panelConfig && panelConfig.type === "chart") {+ }+ // DEPRECATED+ // else if (panelConfig && panelConfig.type === "chart") {- let storeDataPointAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))+ // let storeDataPointAttrs = attrs.filter((attr) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))- let assetAttributes;- // let defaultAttrs = storeDataPointAttrs.filter((attr) => (defaultAttributes && defaultAttributes.indexOf(attr.name!) >= 0));- // if(defaultAttrs.length > 0){- // assetAttributes = defaultAttrs;- // } else- if(storeDataPointAttrs.length > 0) {- assetAttributes = storeDataPointAttrs;- assetAttributes.length = 1;- }- const assetList:Asset[] = [];- if(assetAttributes) {- assetAttributes.forEach(attr => assetList.push(asset));- }- content = html`- <or-chart id="chart" .config="${viewerConfig.chartConfig}" .activeAsset="${asset}" activeAssetId="${asset.id}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>- `;+ // let assetAttributes;+ // // let defaultAttrs = storeDataPointAttrs.filter((attr) => (defaultAttributes && defaultAttributes.indexOf(attr.name!) >= 0));+ // // if(defaultAttrs.length > 0){+ // // assetAttributes = defaultAttrs;+ // // } else+ // if(storeDataPointAttrs.length > 0) {+ // assetAttributes = storeDataPointAttrs;+ // assetAttributes.length = 1;+ // }+ // const assetList:Asset[] = [];+ // if(assetAttributes) {+ // assetAttributes.forEach(attr => assetList.push(asset));+ // }+ // content = html`+ // <or-chart id="chart" panelName="${panelName}" .config="${viewerConfig.chartConfig}" .activeAsset="${asset}" activeAssetId="${asset.id}" .assets="${assetList ? assetList : [asset]}" .assetAttributes="${assetAttributes}"></or-chart>+ // `;- } else if (panelConfig && panelConfig.type === "location") {+ // }+ else if (panelConfig && panelConfig.type === "location") {const attribute = attrs.find((attr) => attr.name === AttributeType.LOCATION.attributeName);if (attribute) {diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex ee112e979..9ca44fea4 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -151,6 +151,24 @@ const style = css`color: #4D9D2A;}`;+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 {@@ -161,6 +179,9 @@ export class OrAttributeCard extends LitElement {@property()public attributeName: string | undefined;+ @property()+ public panelName?: string;+@property({type: Object})private assetAttributes: AssetAttribute[] = [];@@ -202,15 +223,54 @@ export class OrAttributeCard extends LitElement {];}+ constructor(){+ super();+ this.addEventListener(OrAttributeCardAddAttributeEvent.NAME, this._setAttribute)+ }+connectedCallback() {super.connectedCallback();this.getData();}++ renderDialogHTML() {+ const dialog: OrMwcDialog = this.shadowRoot!.getElementById("mdc-dialog") as OrMwcDialog;+ if(!this.shadowRoot) return++ if (dialog) {+ dialog.dialogContent =html`+ <or-asset-tree id="chart-asset-tree"+ .selectedIds="${this.asset ? [this.asset.id] : null}]"+ @or-asset-tree-request-select="${(e: OrAssetTreeRequestSelectEvent) => {+ this.asset = {...e.detail.detail.node.asset!}+ this._getAttributeOptions();+ let attributes = [...Util.getAssetAttributes(this.asset)];+ this.assetAttributes = [...attributes];+ }}">+ </or-asset-tree>+ ${this.asset && this.asset.attributes ? html`+ <or-input id="attribute-picker"+ style="display:flex;"+ .label="${i18next.t("attribute")}"+ .type="${InputType.LIST}"+ .options="${this._getAttributeOptions()}"+ .value="${this.attributeName}"></or-input>+ ` : ``}+ `;+ this.requestUpdate();+ }+ }updated(changedProperties: PropertyValues) {+ if (changedProperties.has("assetAttributes")) {+ this.renderDialogHTML();+ }++ if (changedProperties.has("assetId") && this.assetId && changedProperties.get("assetId") !== this.assetId) {+ this.getSettings();+ }- super.updated(changedProperties);if (!this.data || !this.data.length) {return;@@ -279,7 +339,7 @@ export class OrAttributeCard extends LitElement {if (changedProperties.has("mainValue")) {this.formattedMainValue = this.getFormattedValue(this.mainValue!);}-+}async onCompleted() {@@ -299,9 +359,10 @@ export class OrAttributeCard extends LitElement {<or-asset-tree id="chart-asset-tree".selectedIds="${this.asset ? [this.asset.id] : null}]"@or-asset-tree-request-select="${(e: OrAssetTreeRequestSelectEvent) => {- this.asset = e.detail.detail.node.asset!;+ this.asset = {...e.detail.detail.node.asset!};+ let attributes = [...Util.getAssetAttributes(this.asset)];+ this.assetAttributes = [...attributes];this._getAttributeOptions();- this.requestUpdate();}}"></or-asset-tree>${this.asset && this.asset.attributes ? html`@@ -330,25 +391,22 @@ export class OrAttributeCard extends LitElement {let attributes = [...Util.getAssetAttributes(this.asset)];if (attributes && attributes.length > 0) {attributes = attributes- .filter((attr: AssetAttribute) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!))- .filter((attr: AssetAttribute) => (this.assetAttributes && !this.assetAttributes.some((assetAttr: AssetAttribute) => (assetAttr.name === attr.name) && (assetAttr.assetId === attr.assetId))));+ .filter((attr: AssetAttribute) => Util.getFirstMetaItem(attr, MetaItemType.STORE_DATA_POINTS.urn!));const options = attributes.map((attr: AssetAttribute) => [attr.name, Util.getAttributeLabel(attr, undefined)]);return options;}}- private _setAttribute(e: Event) {- if (this.shadowRoot && this.shadowRoot.getElementById("attribute-picker")) {- const elm = this.shadowRoot.getElementById("attribute-picker") as HTMLInputElement;- if (this.asset) {- const attr = Util.getAssetAttribute(this.asset, elm.value);- if (attr) {- this.assetId = this.asset.id;- this.attributeName = attr.name;+ private _setAttribute(event:OrAttributeCardAddAttributeEvent) {+ if (this.asset && event) {+ const attr = Util.getAssetAttribute(this.asset , event.detail);+ if (attr) {+ this.assetId = this.asset.id;+ this.attributeName = attr.name;- this.getData();- this.requestUpdate();- }+ this.getData();+ this.saveSettings();+ this.requestUpdate();}}}@@ -360,15 +418,73 @@ export class OrAttributeCard extends LitElement {}}+ getSettings() {+ const configStr = window.localStorage.getItem('OrChartConfig')+ if(!configStr || !this.panelName) return++ const viewSelector = this.assetId ? this.assetId : window.location.hash;+ const config = JSON.parse(configStr);+ const view = config.views[viewSelector][this.panelName];+ if(!view) return+ const query = {+ ids: view.assetIds+ }+ if(view.assetIds === this.assetAttributes.map(attr => attr.assetId)) return++ manager.rest.api.AssetResource.queryAssets(query).then((response) => {+ const assets = response.data;+ if(assets.length > 0) {+ this.assetAttributes = view.attributes.map((attr: string, index: number) => Util.getAssetAttribute(assets[index], attr));+ if(this.assetAttributes && this.assetAttributes.length > 0) {+ this.assetId = assets[0].id;+ this.attributeName = this.assetAttributes[0].name;+ this.getData();+ }+ }+ });++ }++ saveSettings() {+ const viewSelector = window.location.hash;+ const attributes = [this.attributeName];+ const assetIds = [this.assetId];+ 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+ };+ const message = {+ provider: "STORAGE",+ action: "STORE",+ key: "OrChartConfig",+ value: JSON.stringify(config)++ }+ manager.console._doSendProviderMessage(message)+ }+protected render() {const dialogActions: DialogAction[] = [- {- actionName: "set",- default: true,- content: html`<or-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" data-mdc-dialog-action="yes"></or-input>`,- action: () => this._setAttribute- },{actionName: "cancel",content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,@@ -376,6 +492,18 @@ export class OrAttributeCard extends LitElement {// Nothing to do here}},+ {+ actionName: "yes",+ default: true,+ content: html`<or-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" data-mdc-dialog-action="yes"></or-input>`,+ 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));+ }+ }+ }];if (!this.assetId || !this.attributeName) {@@ -485,13 +613,14 @@ export class OrAttributeCard extends LitElement {if (!this.assetId || !this.attributeName) {this.error = true;+ this.getSettings();return false;}const thisMoment = moment(this.now);this.asset = await this.getAssetById(this.assetId);-+ console.log(this.asset);this.currentPeriod = {start: thisMoment.startOf(this.period).toDate().getTime(),end: thisMoment.endOf(this.period).toDate().getTime()diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex 7c4698354..7f40db18f 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -74,7 +74,9 @@ export interface ChartConfig {export interface OrChartConfig {chart?: ChartConfig;- views: {[name: string]: ChartViewConfig};+ views: {[name: string]: {+ [panelName: string]: ChartViewConfig+ }};}// TODO: Add webpack/rollup to build so consumers aren't forced to use the same toolingconst dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css");@@ -367,6 +369,9 @@ export class OrChart extends translate(i18next)(LitElement) {@property({type: Object})public config?: OrChartConfig;+ @property()+ public panelName?: string;+@property()protected periodCompare: boolean = false;@@ -705,12 +710,11 @@ export class OrChart extends translate(i18next)(LitElement) {getSettings() {const configStr = window.localStorage.getItem('OrChartConfig')- if(!configStr) return+ if(!configStr || !this.panelName) returnconst viewSelector = this.activeAssetId ? this.activeAssetId : window.location.hash;const config = JSON.parse(configStr);- const view = config.views[viewSelector]-+ const view = config.views[viewSelector][this.panelName];if(!view) returnconst query = {ids: view.assetIds@@ -720,10 +724,13 @@ export class OrChart extends translate(i18next)(LitElement) {manager.rest.api.AssetResource.queryAssets(query).then((response) => {const assets = response.data;- this.assets = view.assetIds.map((assetId: string) => assets.find(x => x.id === assetId));- this.assetAttributes = view.attributes.map((attr: string, index: number) => Util.getAssetAttribute(this.assets[index], attr));- this.period = view.period;- this._loading = false;+ if(assets.length > 0) {+ this.assets = view.assetIds.map((assetId: string) => assets.find(x => x.id === assetId));+ this.assetAttributes = view.attributes.map((attr: string, index: number) => Util.getAssetAttribute(this.assets[index], attr));+ console.log(this.assets, this.assetAttributes);+ this.period = view.period;+ this._loading = false;+ }});}@@ -734,23 +741,36 @@ export class OrChart extends translate(i18next)(LitElement) {const assetIds = assets.map(asset => asset.id);const attributes = this.assetAttributes.map(attr => attr.name);const configStr = window.localStorage.getItem('OrChartConfig')+ if(!this.panelName) return+let config:OrChartConfig;if(configStr) {config = JSON.parse(configStr);} else {config = {views: {- [viewSelector]: {}+ [viewSelector]: {+ [name] : {++ }+ }}}}- config.views[viewSelector] = {+ config.views[viewSelector][this.panelName] = {assetIds: assetIds,attributes: attributes,period: this.period};- window.localStorage.setItem('OrChartConfig', JSON.stringify(config))+ const message = {+ provider: "STORAGE",+ action: "STORE",+ key: "OrChartConfig",+ value: JSON.stringify(config)++ }+ manager.console._doSendProviderMessage(message)}_openDialog() {diff --git a/ui/component/or-data-viewer/src/index.ts b/ui/component/or-data-viewer/src/index.tsindex cfd2544c5..0e850b9c5 100644--- a/ui/component/or-data-viewer/src/index.ts+++ b/ui/component/or-data-viewer/src/index.ts@@ -204,13 +204,13 @@ export class OrDataViewer extends subscribe(manager)(translate(i18next)(LitElemeif (panelConfig && panelConfig.type === "chart") {content = html`- <or-chart id="chart" .config="${this.config.chartConfig}"></or-chart>+ <or-chart id="chart" panelName="${panelName}" .config="${this.config.chartConfig}"></or-chart>`;}if (panelConfig && panelConfig.type === "kpi") {content = html`- <or-attribute-card .config="${this.config.chartConfig}"></or-attribute-card>+ <or-attribute-card panelName="${panelName}" .config="${this.config.chartConfig}"></or-attribute-card>`;}return content;diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.tsindex be618d90d..df0e34823 100644--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts@@ -82,6 +82,10 @@ const style = css`.dialog-container > * {flex: 1 1 0;}++ .mdc-list {+ padding: 0 24px+ }`;@@ -190,7 +194,6 @@ export class OrMwcDialog extends LitElement {protected _onDialogClosed(action?: string) {this.dispatchEvent(new OrMwcDialogClosedEvent(action));-if (action && this.dialogActions) {const matchedAction = this.dialogActions.find((dialogAction) => dialogAction.actionName === action);if (matchedAction && matchedAction.action) {diff --git a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.tsindex 11ed36921..938273a70 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-action-notification.ts@@ -77,6 +77,7 @@ export class OrRuleActionNotification extends LitElement {});}}+if(this.type === NotificationTargetType.ASSET) {idOptions.push(["*", i18next.t("matched")]);if(this._listItems) this._listItems.forEach((asset: Asset) => idOptions.push([asset.id!, asset.name!] as [string, string]));@@ -91,7 +92,7 @@ export class OrRuleActionNotification extends LitElement {}- if(this.type){+ if(targetTypes.length > 0){targetTypeTemplate = html`<or-input type="${InputType.SELECT}".options="${targetTypes}"value="${this.type ? this.type : targetTypes[0]}"@@ -156,7 +157,7 @@ export class OrRuleActionNotification extends LitElement {}getNotificationTargetType() {- if(!this.action.target) return NotificationTargetType.CUSTOM;+ if(!this.action.target) return;if(this.action.target.assets || this.action.target.matchedAssets) return NotificationTargetType.ASSET;if(this.action.target.users) return NotificationTargetType.USER;diff --git a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.tsindex 63d3f98c2..bac575b40 100644--- a/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts+++ b/ui/component/or-rules/src/json-viewer/or-rule-then-otherwise.ts@@ -57,7 +57,7 @@ function getActionTypesMenu(config?: RulesConfig, assetDescriptors?: AssetDescriif (addNotification) {menu.push({- text: i18next.t("notification"),+ text: i18next.t("email"),icon: "email",value: ActionType.NOTIFICATION,styleMap: {"--or-icon-fill": "#" + NOTIFICATION_COLOR}@@ -450,7 +450,9 @@ class OrRuleThenOtherwise extends translate(i18next)(LitElement) {action.action = "notification";action.notification = {message: {- type: "push"+ type: "push",+ title: "%RULESET_NAME%",+ body: "%TRIGGER_ASSETS%"}};} else {