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: - support single-selecting attrRef in attribute selector (and explicitly put them to multi in earlier implementations) - apply attribute selector in KPI cards
Vincenta9a2b4de1b70
diff --git a/ui/app/manager/src/pages/page-export.ts b/ui/app/manager/src/pages/page-export.tsindex ebee62b38..3b040fb8c 100644--- a/ui/app/manager/src/pages/page-export.ts+++ b/ui/app/manager/src/pages/page-export.ts@@ -357,6 +357,7 @@ class PageExport<S extends AppStateKeyed> extends Page<S> {const dialog = new OrMwcAttributeSelector();dialog.isOpen = true;dialog.showOnlyDatapointAttrs = true;+ dialog.multiSelect = true;dialog.selectedAttributes = this.config.selectedAttributes;dialog.addEventListener(OrAddAttributeRefsEvent.NAME, async (ev: OrAddAttributeRefsEvent) => {const selectedAttributes = ev.detail.selectedAttributes;diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex 4481cdf9a..f3d295b39 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -17,12 +17,12 @@ import {AssetModelUtil, DefaultColor3, DefaultColor4, manager, Util} from "@openimport {Chart, ScatterDataPoint, LineController, LineElement, PointElement, LinearScale, TimeSeriesScale, Title} from "chart.js";import "chartjs-adapter-moment";import {OrChartConfig} from "@openremote/or-chart";-import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";+import {InputType, OrInputChangedEvent} 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";import {OrAssetTreeSelectionEvent} from "@openremote/or-asset-tree";-import {OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrAddAttributeRefsEvent, OrMwcAttributeSelector, OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";export type ContextMenuOptions = "editAttribute" | "editDelta" | "editCurrentValue" | "delete";@@ -337,7 +337,7 @@ export class OrAttributeCard extends LitElement {<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>+ <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openAttributePicker()}"></or-mwc-input></div></div></div>@@ -351,7 +351,7 @@ export class OrAttributeCard extends LitElement {<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>+ <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openAttributePicker()}"></or-mwc-input></div></div></div>@@ -454,6 +454,7 @@ export class OrAttributeCard extends LitElement {`;this._dialog.dismissAction = null;+ this._dialog.open();}else if (dialogContent === "editCurrentValue") {@@ -491,47 +492,10 @@ export class OrAttributeCard extends LitElement {`;this._dialog.dismissAction = null;+ this._dialog.open();}else {-- this._dialog.dialogTitle = i18next.t("addAttribute");-- this._dialog.dialogActions = [- {- actionName: "cancel",- content: html`<or-mwc-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-mwc-input>`,- action: () => {- // Nothing to do here- }- },- {- actionName: "yes",- default: true,- content: html`<or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" data-mdc-dialog-action="yes"></or-mwc-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 OrMwcInput;- this._setAttribute(elm.value as string);- }- }- }- ];-- this._dialog.dialogContent = html`- <or-asset-tree id="chart-asset-tree" readonly- .selectedIds="${this.asset ? [this.asset.id] : null}"></or-asset-tree>- ${this.asset && this.asset.attributes ? html`- <or-mwc-input id="attribute-picker"- style="display:flex;"- .label="${i18next.t("attribute")}"- .type="${InputType.LIST}"- .options="${this._getAttributeOptions()}"- .value="${this.assetAttributes && this.assetAttributes.length > 0 ? this.assetAttributes[0][1].name : undefined}"></or-mwc-input>- ` : ``}- `;-- this._dialog.dismissAction = null;+ this._openAttributePicker();}}}@@ -539,10 +503,29 @@ export class OrAttributeCard extends LitElement {protected _openDialog(dialogContent?: ContextMenuOptions) {if (this._dialog) {this._refreshDialog(dialogContent);- this._dialog.open();}}+ protected _openAttributePicker() {+ const hostElement = document.body;++ const dialog = new OrMwcAttributeSelector();+ dialog.isOpen = true;+ dialog.addEventListener(OrAddAttributeRefsEvent.NAME, async (ev: any) => {+ // handle selected attrs+ const attrRef = ev.detail.selectedAttributes[0];+ try {+ const response = await manager.rest.api.AssetResource.get(attrRef.id);+ this.asset = response.data;+ this._setAttribute(attrRef.name as string);+ } catch (e) {+ console.error("Failed to get assets requested in settings", e);+ }+ });+ hostElement.append(dialog);+ return dialog;+ }+protected async _onTreeSelectionChanged(event: OrAssetTreeSelectionEvent) {// Need to fully load the assetif (!manager.events) {diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex ad49a64ad..27604d284 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -819,6 +819,7 @@ export class OrChart extends translate(i18next)(LitElement) {const hostElement = document.body;const dialog = new OrMwcAttributeSelector();dialog.showOnlyDatapointAttrs = true;+ dialog.multiSelect = true;dialog.selectedAttributes = this._getSelectedAttributes();dialog.isOpen = true;dialog.addEventListener(OrAddAttributeRefsEvent.NAME, (ev: any) => this._addAttribute(ev.detail.selectedAttributes));diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.tsindex 0ec25a556..7529a0c46 100644--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts@@ -3,7 +3,7 @@ import {customElement, property, query} from "lit/decorators.js";import {MDCDialog} from "@material/dialog";import "@openremote/or-translate";import "./or-mwc-input";-import {InputType} from "./or-mwc-input";+import {InputType, OrInputChangedEvent} from "./or-mwc-input";import { i18next } from "@openremote/or-translate";import {DefaultColor2, DefaultColor4, DefaultColor5, Util } from "@openremote/core";import { Asset, AssetEvent, Attribute, AttributeRef, WellknownMetaItems } from "@openremote/model";@@ -367,6 +367,9 @@ export class OrMwcAttributeSelector extends OrMwcDialog {@property({type: Array, attribute: false})public selectedAttributes: AttributeRef[] = [];++ @property({type: Boolean})+ public multiSelect?: boolean = false;constructor() {super();@@ -447,12 +450,25 @@ export class OrMwcAttributeSelector extends OrMwcDialog {<div class="attributes-header"><or-translate value="attribute_plural"></or-translate></div>- <div style="display: grid">- <or-mwc-list- id="attribute-selector" .type="${ListType.MULTI_CHECKBOX}" .listItems="${listItems}"- .values="${this.selectedAttributes.map(e => e.id === this.selectedAsset!.id && e.name!)}"- @or-mwc-list-changed="${(ev: OrMwcListChangedEvent) => this._addRemoveAttrs(ev)}"></or-mwc-list>- </div>+ ${this.multiSelect+ ?+ html`<div style="display: grid">+ <or-mwc-list+ id="attribute-selector" .type="${ListType.MULTI_CHECKBOX}" .listItems="${listItems}"+ .values="${this.selectedAttributes.map(e => e.id === this.selectedAsset!.id && e.name!)}"+ @or-mwc-list-changed="${(ev: OrMwcListChangedEvent) => this._addRemoveAttrs(ev)}"></or-mwc-list>+ </div>`+ :+ html`<or-mwc-input id="attribute-selector"+ style="display:flex;"+ .label="${i18next.t("attribute")}"+ .type="${InputType.LIST}"+ .options="${listItems.map(item => ([item.value, item.text]))}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => {+ this.selectedAttributes = [{id: this.selectedAsset!.id, name: ev.detail.value}];+ this.reRenderDialog()}+ }"></or-mwc-input>`+ }` : html`<div style="display: flex;align-items: center;text-align: center;height: 100%;"><span style="width:100%"><or-translate value="selectAssetOnTheLeft"></or-translate></span></div>`}</div>`;