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: Migrated attribute picker to its' own component
Rich Turnerbeff4ade8644
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.jsonindex c965c6a6f..beb9b35dd 100644--- a/manager/src/web/shared/locales/en/or.json+++ b/manager/src/web/shared/locales/en/or.json@@ -107,6 +107,7 @@"ending": "Ending","timeframe": "Timeframe","addAttribute": "Add attribute",+ "selectAttributes": "Select attributes","clearTable": "Clear","addAssetAttribute": "Add asset attribute","add": "Add",diff --git a/ui/app/manager/src/pages/page-export.ts b/ui/app/manager/src/pages/page-export.tsindex 3b040fb8c..c96555d0c 100644--- a/ui/app/manager/src/pages/page-export.ts+++ b/ui/app/manager/src/pages/page-export.ts@@ -7,7 +7,7 @@ import {AppStateKeyed} from "@openremote/or-app";import {i18next} from "@openremote/or-translate";import manager, { DefaultColor3, Util } from "@openremote/core";import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";-import {OrAddAttributeRefsEvent, OrMwcAttributeSelector, OrAttributeRefsAddRequestEvent } from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrAttributePickerPickedEvent, OrAttributePicker } from "@openremote/or-attribute-picker";import { AttributeRef } from "@openremote/model";import moment from "moment";import { buttonStyle } from "@openremote/or-rules/dist/style";@@ -354,13 +354,13 @@ class PageExport<S extends AppStateKeyed> extends Page<S> {protected _openDialog() {const hostElement = document.body;- const dialog = new OrMwcAttributeSelector();+ const dialog = new OrAttributePicker();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;+ dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {+ const selectedAttributes = ev.detail;await this.renderTable(selectedAttributes);this.config = {realm: this.realm,diff --git a/ui/component/or-app/package.json b/ui/component/or-app/package.jsonindex 70cc31d59..ebcc09ed8 100644--- a/ui/component/or-app/package.json+++ b/ui/component/or-app/package.json@@ -20,6 +20,8 @@"@openremote/core": "^1.0.3","@openremote/or-mwc-components": "^1.0.3","@openremote/or-asset-tree": "^1.0.4",+ "@openremote/or-attribute-input": "^1.0.4",+ "@openremote/or-attribute-picker": "^1.0.4","@openremote/or-asset-viewer": "^1.0.4","@openremote/or-chart": "^1.0.4","@openremote/or-map": "^1.0.4",diff --git a/ui/component/or-app/tsconfig.json b/ui/component/or-app/tsconfig.jsonindex c7bd354b0..670ba3243 100644--- a/ui/component/or-app/tsconfig.json+++ b/ui/component/or-app/tsconfig.json@@ -15,6 +15,7 @@{ "path": "../../component/or-icon" },{ "path": "../../component/or-map" },{ "path": "../../component/or-attribute-input" },+ { "path": "../../component/or-attribute-picker" },{ "path": "../../component/or-asset-tree" },{ "path": "../../component/or-asset-viewer" },{ "path": "../../component/or-data-viewer" },diff --git a/ui/component/or-asset-tree/package.json b/ui/component/or-asset-tree/package.jsonindex 0a5e6c18f..aa570f62e 100644--- a/ui/component/or-asset-tree/package.json+++ b/ui/component/or-asset-tree/package.json@@ -17,6 +17,7 @@"@openremote/model": "^1.0.3","@openremote/or-icon": "^1.0.3","@openremote/or-translate": "^1.0.3",+ "@openremote/or-mwc-components": "^1.0.3","@openremote/rest": "^1.0.3","lit": "^2.0.0-rc.2","moment": "^2.24.0"diff --git a/ui/component/or-attribute-card/package.json b/ui/component/or-attribute-card/package.jsonindex af0b64f6b..b2f72032f 100644--- a/ui/component/or-attribute-card/package.json+++ b/ui/component/or-attribute-card/package.json@@ -16,6 +16,7 @@"@openremote/core": "^1.0.3","@openremote/or-chart": "^1.0.4","@openremote/or-mwc-components": "^1.0.3",+ "@openremote/or-attribute-picker": "^1.0.4","lit": "^2.0.0-rc.2","moment": "^2.24.0"},diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex f3d295b39..fb97aba76 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -20,9 +20,11 @@ import {OrChartConfig} from "@openremote/or-chart";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 "@openremote/or-attribute-picker";import moment from "moment";import {OrAssetTreeSelectionEvent} from "@openremote/or-asset-tree";-import {OrAddAttributeRefsEvent, OrMwcAttributeSelector, OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrAttributePicker, OrAttributePickerPickedEvent} from "@openremote/or-attribute-picker";import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-menu";export type ContextMenuOptions = "editAttribute" | "editDelta" | "editCurrentValue" | "delete";@@ -509,13 +511,13 @@ export class OrAttributeCard extends LitElement {protected _openAttributePicker() {const hostElement = document.body;- const dialog = new OrMwcAttributeSelector();+ const dialog = new OrAttributePicker();dialog.isOpen = true;- dialog.addEventListener(OrAddAttributeRefsEvent.NAME, async (ev: any) => {+ dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {// handle selected attrs- const attrRef = ev.detail.selectedAttributes[0];+ const attrRef = ev.detail[0];try {- const response = await manager.rest.api.AssetResource.get(attrRef.id);+ const response = await manager.rest.api.AssetResource.get(attrRef.id!);this.asset = response.data;this._setAttribute(attrRef.name as string);} catch (e) {diff --git a/ui/component/or-attribute-card/tsconfig.json b/ui/component/or-attribute-card/tsconfig.jsonindex f37e1a782..1998f8063 100644--- a/ui/component/or-attribute-card/tsconfig.json+++ b/ui/component/or-attribute-card/tsconfig.json@@ -11,6 +11,7 @@"references": [{ "path": "../core" },{ "path": "../or-chart" },- { "path": "../or-mwc-components" }+ { "path": "../or-mwc-components" },+ { "path": "../or-attribute-picker" }]}diff --git a/ui/component/or-attribute-picker/.npmignore b/ui/component/or-attribute-picker/.npmignorenew file mode 100644index 000000000..17e64b1ad--- /dev/null+++ b/ui/component/or-attribute-picker/.npmignore@@ -0,0 +1,8 @@+build/+build.gradle+test/+src/+webpack.config.js+tsconfig.json+dist/*.map+.tsbuildinfo\ No newline at end of filediff --git a/ui/component/or-attribute-picker/README.md b/ui/component/or-attribute-picker/README.mdnew file mode 100644index 000000000..1d91bc623--- /dev/null+++ b/ui/component/or-attribute-picker/README.md@@ -0,0 +1,31 @@+# @openremote/or-attribute-input \<or-attribute-input\>+[![NPM Version][npm-image]][npm-url]+[![Linux Build][travis-image]][travis-url]+[![Test Coverage][coveralls-image]][coveralls-url]++Web Component for displaying an input control.++## Install+```bash+npm i @openremote/or-attribute-input+yarn add @openremote/or-attribute-input+```++## Usage+For a full list of properties, methods and options refer to the TypeDoc generated [documentation]().+++## Supported Browsers+The last 2 versions of all modern browsers are supported, including Chrome, Safari, Opera, Firefox, Edge. In addition,+Internet Explorer 11 is also supported.+++## License+[GNU AGPL](https://www.gnu.org/licenses/agpl-3.0.en.html)++[npm-image]: https://img.shields.io/npm/v/live-xxx.svg+[npm-url]: https://npmjs.org/package/@openremote/or-attribute-input+[travis-image]: https://img.shields.io/travis/live-js/live-xxx/master.svg+[travis-url]: https://travis-ci.org/live-js/live-xxx+[coveralls-image]: https://img.shields.io/coveralls/live-js/live-xxx/master.svg+[coveralls-url]: https://coveralls.io/r/live-js/live-xxx?branch=masterdiff --git a/ui/component/or-attribute-picker/build.gradle b/ui/component/or-attribute-picker/build.gradlenew file mode 100644index 000000000..98cdcb8e2--- /dev/null+++ b/ui/component/or-attribute-picker/build.gradle@@ -0,0 +1,15 @@+buildDir = "dist"++task clean() {+ doLast {+ delete "dist"+ }+}++task prepareUi() {+ dependsOn clean, npmPrepare+}++task publishUi() {+ dependsOn clean, npmPublish+}\ No newline at end of filediff --git a/ui/component/or-attribute-picker/package.json b/ui/component/or-attribute-picker/package.jsonnew file mode 100644index 000000000..33c2e9855--- /dev/null+++ b/ui/component/or-attribute-picker/package.json@@ -0,0 +1,30 @@+{+ "name": "@openremote/or-attribute-picker",+ "version": "1.0.4",+ "description": "OpenRemote attribute picker dialog",+ "main": "dist/umd/index.bundle.js",+ "module": "dist/index.js",+ "types": "dist/index.d.ts",+ "scripts": {+ "test": "echo \"No tests\" && exit 0",+ "prepublishOnly": "npx tsc -b && npx webpack"+ },+ "author": "OpenRemote",+ "license": "AGPL-3.0-or-later",+ "dependencies": {+ "@openremote/core": "^1.0.3",+ "@openremote/or-mwc-components": "^1.0.3",+ "@openremote/or-translate": "^1.0.3",+ "@openremote/or-asset-tree": "^1.0.3",+ "lit": "^2.0.0-rc.2"+ },+ "devDependencies": {+ "tslint": ">=5.11.0",+ "typescript": ">=4.1.3",+ "webpack": "^5.16.0",+ "webpack-cli": "^4.4.0"+ },+ "publishConfig": {+ "access": "public"+ }+}diff --git a/ui/component/or-attribute-picker/src/index.ts b/ui/component/or-attribute-picker/src/index.tsnew file mode 100644index 000000000..eca767e3a--- /dev/null+++ b/ui/component/or-attribute-picker/src/index.ts@@ -0,0 +1,200 @@+import {html, unsafeCSS} from "lit";+import {customElement, property, query, state} from "lit/decorators.js";+import "@openremote/or-asset-tree";+import "@openremote/or-translate";+import "@openremote/or-mwc-components/or-mwc-input";+import "@openremote/or-mwc-components/or-mwc-list";+import {OrAssetTree, OrAssetTreeSelectionEvent} from "@openremote/or-asset-tree";+import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";+import {i18next} from "@openremote/or-translate";+import manager, {DefaultColor2, DefaultColor4, DefaultColor5, Util} from "@openremote/core";+import {Attribute, AttributeRef, WellknownMetaItems} from "@openremote/model";+import {ListItem, ListType, OrMwcListChangedEvent} from "@openremote/or-mwc-components/or-mwc-list";+import {OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";++export class OrAttributePickerPickedEvent extends CustomEvent<AttributeRef[]> {++ public static readonly NAME = "or-attribute-picker-picked";++ constructor(detail: AttributeRef[]) {+ super(OrAttributePickerPickedEvent.NAME, {+ bubbles: true,+ composed: true,+ detail: detail+ });+ }+}++declare global {+ export interface HTMLElementEventMap {+ [OrAttributePickerPickedEvent.NAME]: OrAttributePickerPickedEvent;+ }+}++type AttributeAndId = Attribute<any> & {id: string};++@customElement("or-attribute-picker")+export class OrAttributePicker extends OrMwcDialog {++ @property({type: Boolean})+ public showOnlyDatapointAttrs?: boolean = false;++ @property({type: Boolean})+ public showOnlyRuleStateAttrs?: boolean = false;++ @property({type: Boolean})+ public multiSelect?: boolean = false;++ @state()+ protected assetAttributes?: (AttributeAndId)[];++ public selectedAttributes: AttributeRef[] = [];++ @query("#add-btn")+ protected addBtn!: OrMwcInput;++ constructor() {+ super();++ this.dialogTitle = i18next.t("selectAttributes");+ this.setDialogContent();+ this.setDialogActions();+ this.dismissAction = null;++ this.styles = `+ .attributes-header {+ line-height: 48px;+ padding: 0 15px;+ background-color: ${unsafeCSS(DefaultColor2)};+ font-weight: bold;+ border-bottom: 1px solid ${unsafeCSS(DefaultColor2)};+ }+ footer.mdc-dialog__actions {+ border-top: 1px solid ${unsafeCSS(DefaultColor5)};+ }+ #header {+ background-color: ${unsafeCSS(DefaultColor4)} !important;+ }+ #dialog-content {+ padding: 0;+ }+ `;+ }++ protected setDialogActions(): void {+ this.dialogActions = [+ {+ actionName: "cancel",+ content: i18next.t("cancel")+ },+ {+ actionName: "add",+ content: html`<or-mwc-input id="add-btn" class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" ?disabled="${!this.selectedAttributes.length}"></or-mwc-input>`,+ action: () => {++ if (!this.selectedAttributes.length) {+ return;+ }++ this.dispatchEvent(new OrAttributePickerPickedEvent(this.selectedAttributes));+ }+ }+ ];+ }++ protected setDialogContent(): void {++ const getListItems: () => ListItem[] = () => {+ if (!this.assetAttributes) {+ return [];+ }++ return this.assetAttributes.map((attribute) => {+ return {+ text: Util.getAttributeLabel(undefined, attribute, undefined, true),+ value: attribute.name,+ data: attribute+ } as ListItem+ });+ };+++ this.dialogContent = () => html`+ <div class="row" style="display: flex;height: 600px;width: 800px;border-top: 1px solid ${unsafeCSS(DefaultColor5)};">+ <div class="col" style="width: 260px;overflow: auto;border-right: 1px solid ${unsafeCSS(DefaultColor5)};">+ <or-asset-tree id="chart-asset-tree" readonly+ @or-asset-tree-selection="${(ev: OrAssetTreeSelectionEvent) => this._onAssetSelectionChanged(ev)}">+ </or-asset-tree>+ </div>+ <div class="col" style="flex: 1 1 auto;width: 260px;overflow: auto;">+ ${this.assetAttributes && this.assetAttributes.length > 0 ? html`+ <div class="attributes-header">+ <or-translate value="attribute_plural"></or-translate>+ </div>+ ${this.multiSelect+ ?+ html`<div style="display: grid">+ <or-mwc-list+ id="attribute-selector" .type="${ListType.MULTI_CHECKBOX}" .listItems="${getListItems()}"+ .values="${this.selectedAttributes.map(attribute => attribute.name!)}"+ @or-mwc-list-changed="${(ev: OrMwcListChangedEvent) => this._onAttributeSelectionChanged(ev.detail.map(li => li.data as AttributeAndId))}"></or-mwc-list>+ </div>`+ :+ html`<or-mwc-input id="attribute-selector"+ style="display:flex;"+ .label="${i18next.t("attribute")}"+ .type="${InputType.LIST}"+ .options="${getListItems().map(item => ([item, item.text]))}"+ @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this._onAttributeSelectionChanged([(ev.detail.value as ListItem).data as AttributeAndId])}"+ }"></or-mwc-input>`+ }+ ` : html`<div style="display: flex;align-items: center;text-align: center;height: 100%;padding: 0 20px;"><span style="width:100%">+ <or-translate value="${+ (this.assetAttributes && this.assetAttributes.length === 0) ?+ ((this.showOnlyDatapointAttrs && this.showOnlyRuleStateAttrs) ? "noDatapointsOrRuleStateAttributes" :+ this.showOnlyDatapointAttrs ? "noDatapointsAttributes" :+ this.showOnlyRuleStateAttrs ? "noRuleStateAttributes" : "noAttributesToShow"+ ) : "selectAssetOnTheLeft"}">+ </or-translate></span></div>`}+ </div>+ `;+ }++ protected async _onAssetSelectionChanged(event: OrAssetTreeSelectionEvent) {+ this.assetAttributes = undefined;+ this.selectedAttributes = [];+ this.addBtn.disabled = true;+ const assetTree = event.target as OrAssetTree;+ assetTree.disabled = true;++ let selectedAsset = event.detail.newNodes.length === 0 ? undefined : event.detail.newNodes[0].asset;++ if (selectedAsset) {+ // Load the asset attributes+ const assetResponse = await manager.rest.api.AssetResource.get(selectedAsset.id!);+ selectedAsset = assetResponse.data;++ if (selectedAsset) {+ this.assetAttributes = Object.values(selectedAsset.attributes!).map(attr => { return {...attr, id: selectedAsset!.id!}; });++ if (this.showOnlyDatapointAttrs && this.showOnlyRuleStateAttrs) {+ this.assetAttributes = this.assetAttributes+ .filter(e => e.meta && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.RULESTATE] || e.meta[WellknownMetaItems.AGENTLINK]));+ } else if (this.showOnlyDatapointAttrs) {+ this.assetAttributes = this.assetAttributes+ .filter(e => e.meta && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.AGENTLINK]));+ } else if (this.showOnlyRuleStateAttrs) {+ this.assetAttributes = this.assetAttributes+ .filter(e => e.meta && (e.meta[WellknownMetaItems.RULESTATE] || e.meta[WellknownMetaItems.AGENTLINK]));+ }+ }+ }++ assetTree.disabled = false;+ }++ protected _onAttributeSelectionChanged(attributes: AttributeAndId[]) {+ this.selectedAttributes = attributes.map(attr => {return {id: attr.id, name: attr.name} as AttributeRef});+ this.addBtn.disabled = this.selectedAttributes.length === 0;+ }+}diff --git a/ui/component/or-attribute-picker/tsconfig.json b/ui/component/or-attribute-picker/tsconfig.jsonnew file mode 100644index 000000000..614de2aba--- /dev/null+++ b/ui/component/or-attribute-picker/tsconfig.json@@ -0,0 +1,18 @@+{+ "extends": "../../tsconfig",+ "compilerOptions": {+ "outDir": "./dist",+ "tsBuildInfoFile": "./dist/.tsbuildinfo",+ "rootDir": "src"+ },+ "include": [+ "./src",+ "../or-map/@types"+ ],+ "references": [+ { "path": "../core" },+ { "path": "../or-translate" },+ { "path": "../or-mwc-components" },+ { "path": "../or-asset-tree" }+ ]+}diff --git a/ui/component/or-attribute-picker/webpack.config.js b/ui/component/or-attribute-picker/webpack.config.jsnew file mode 100644index 000000000..a5cdec63b--- /dev/null+++ b/ui/component/or-attribute-picker/webpack.config.js@@ -0,0 +1,10 @@+const util = require("@openremote/util");++bundles = {+ "index": {+ excludeOr: true+ },+ "index.orbundle": undefined+};++module.exports = util.generateExports(__dirname);diff --git a/ui/component/or-chart/package.json b/ui/component/or-chart/package.jsonindex 6c7f14cbf..87c29292f 100644--- a/ui/component/or-chart/package.json+++ b/ui/component/or-chart/package.json@@ -19,6 +19,7 @@"@openremote/or-components": "^1.0.3","@openremote/or-icon": "^1.0.3","@openremote/or-mwc-components": "^1.0.3",+ "@openremote/or-attribute-picker": "^1.0.4","@openremote/or-translate": "^1.0.3","chart.js": "^3.1.0","chartjs-adapter-moment": "^1.0.0",diff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex 27604d284..a9ef41c63 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -37,7 +37,7 @@ import {getContentWithMenuTemplate} from "@openremote/or-mwc-components/or-mwc-mimport ChartAnnotation, { AnnotationOptions } from "chartjs-plugin-annotation";import "chartjs-adapter-moment";import {GenericAxiosResponse } from "@openremote/rest";-import {OrMwcAttributeSelector, OrAddAttributeRefsEvent} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrAttributePicker, OrAttributePickerPickedEvent} from "@openremote/or-attribute-picker";Chart.register(LineController, ScatterController, LineElement, PointElement, LinearScale, TimeScale, Title, Filler, Legend, Tooltip, ChartAnnotation);@@ -599,9 +599,6 @@ export class OrChart extends translate(i18next)(LitElement) {})}</div><or-mwc-input class="button" .type="${InputType.BUTTON}" ?disabled="${disabled}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog()}"></or-mwc-input>- <div id="mdc-dialog">- <or-mwc-attribute-selector id="attribute-selector-dialog"></or-mwc-attribute-selector>- </div></div></div>`;@@ -817,12 +814,12 @@ export class OrChart extends translate(i18next)(LitElement) {_openDialog() {const hostElement = document.body;- const dialog = new OrMwcAttributeSelector();+ const dialog = new OrAttributePicker();dialog.showOnlyDatapointAttrs = true;dialog.multiSelect = true;dialog.selectedAttributes = this._getSelectedAttributes();dialog.isOpen = true;- dialog.addEventListener(OrAddAttributeRefsEvent.NAME, (ev: any) => this._addAttribute(ev.detail.selectedAttributes));+ dialog.addEventListener(OrAttributePickerPickedEvent.NAME, (ev: any) => this._addAttribute(ev.detail));hostElement.append(dialog);return dialog;diff --git a/ui/component/or-chart/tsconfig.json b/ui/component/or-chart/tsconfig.jsonindex e12128333..0db348b2a 100644--- a/ui/component/or-chart/tsconfig.json+++ b/ui/component/or-chart/tsconfig.json@@ -15,6 +15,7 @@{ "path": "../or-icon" },{ "path": "../or-asset-tree" },{ "path": "../or-mwc-components" },+ { "path": "../or-attribute-picker" },{ "path": "../or-translate" }]}diff --git a/ui/component/or-mwc-components/package.json b/ui/component/or-mwc-components/package.jsonindex 0f39a5bd2..35300a0f2 100644--- a/ui/component/or-mwc-components/package.json+++ b/ui/component/or-mwc-components/package.json@@ -35,7 +35,6 @@"@material/textfield": "^9.0.0","@openremote/core": "^1.0.3","@openremote/or-icon": "^1.0.3",- "@openremote/or-asset-tree": "^1.0.3","@openremote/or-translate": "^1.0.3","lit": "^2.0.0-rc.2"},diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.tsindex 06bad7e0a..dd550c529 100644--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts@@ -1,15 +1,11 @@import {css, html, LitElement, PropertyValues, TemplateResult, unsafeCSS} from "lit";-import {customElement, property, query, state} from "lit/decorators.js";+import {customElement, property, query} from "lit/decorators.js";import {MDCDialog} from "@material/dialog";import "@openremote/or-translate";import "./or-mwc-input";-import {InputType, OrInputChangedEvent, OrMwcInput} from "./or-mwc-input";+import {InputType} from "./or-mwc-input";import {i18next} from "@openremote/or-translate";-import manager, {DefaultColor2, DefaultColor4, DefaultColor5, Util} from "@openremote/core";-import {Attribute, AttributeRef, WellknownMetaItems} from "@openremote/model";-import "@openremote/or-asset-tree";-import {OrAssetTree, OrAssetTreeSelectionEvent} from "@openremote/or-asset-tree";-import {ListItem, ListType, OrMwcListChangedEvent} from "./or-mwc-list";+import {Util} from "@openremote/core";const dialogStyle = require("@material/dialog/dist/mdc.dialog.css");const listStyle = require("@material/list/dist/mdc.list.css");@@ -200,7 +196,7 @@ export class OrMwcDialog extends LitElement {public dialogTitle?: string | TemplateResult;@property({type: Object, attribute: false})- public dialogContent?: TemplateResult;+ public dialogContent?: TemplateResult | (() => TemplateResult);@property({type: Array, attribute: false})public dialogActions?: DialogAction[];@@ -273,7 +269,7 @@ export class OrMwcDialog extends LitElement {: this.dialogTitle ? html`<span class="mdc-dialog__title" id="dialog-title">${this.dialogTitle}</span>` : ``}${this.dialogContent ? html`<div class="dialog-container mdc-dialog__content" id="dialog-content">- ${this.dialogContent ? this.dialogContent : html`<slot></slot>`}+ ${typeof this.dialogContent === "function" ? this.dialogContent() : this.dialogContent}</div><footer class="mdc-dialog__actions">${this.dialogActions ? this.dialogActions.map((action) => {@@ -324,210 +320,3 @@ export class OrMwcDialog extends LitElement {this.dispatchEvent(new OrMwcDialogClosedEvent(action));}}--export type AddAttrRefsEventDetail = {- selectedAttributes?: AttributeRef[];-}-export class OrAttributeRefsAddRequestEvent extends CustomEvent<Util.RequestEventDetail<AddAttrRefsEventDetail>> {-- public static readonly NAME = "or-attribute-refs-request-add";-- constructor(detail: AddAttrRefsEventDetail) {- super(OrAttributeRefsAddRequestEvent.NAME, {- bubbles: true,- composed: true,- detail: {- allow: true,- detail: detail- }- });- }-}-export class OrAddAttributeRefsEvent extends CustomEvent<AddAttrRefsEventDetail> {-- public static readonly NAME = "or-attribute-refs-add";-- constructor(detail: AddAttrRefsEventDetail) {- super(OrAddAttributeRefsEvent.NAME, {- bubbles: true,- composed: true,- detail: detail- });- }-}--declare global {- export interface HTMLElementEventMap {- [OrAddAttributeRefsEvent.NAME]: OrAddAttributeRefsEvent;- }-}--@customElement("or-mwc-attribute-selector")-export class OrMwcAttributeSelector extends OrMwcDialog {-- @property({type: Boolean})- public showOnlyDatapointAttrs?: boolean = false;-- @property({type: Boolean})- public showOnlyRuleStateAttrs?: boolean = false;-- @property({type: Boolean})- public multiSelect?: boolean = false;-- @state()- protected assetAttributes?: Attribute<any>[];- protected selectedAttributes: AttributeRef[] = [];- @query("#add-btn")- protected addBtn!: OrMwcInput;-- constructor() {- super();-- this.dialogTitle = "Add attributes";- this.setDialogContent();- this.setDialogActions();- this.dismissAction = null;-- this.styles = `- .attributes-header {- line-height: 48px;- padding: 0 15px;- background-color: ${unsafeCSS(DefaultColor2)};- font-weight: bold;- border-bottom: 1px solid ${unsafeCSS(DefaultColor2)};- }- footer.mdc-dialog__actions {- border-top: 1px solid ${unsafeCSS(DefaultColor5)};- }- #header {- background-color: ${unsafeCSS(DefaultColor4)} !important;- }- #dialog-content {- padding: 0;- }- `;- }-- protected setDialogActions(): void {- this.dialogActions = [- {- actionName: "cancel",- content: i18next.t("cancel")- },- {- actionName: "add",- content: html`<or-mwc-input id="add-btn" class="button" .type="${InputType.BUTTON}" label="${i18next.t("add")}" ?disabled="${!this.selectedAttributes.length}"></or-mwc-input>`,- action: () => {-- if (!this.selectedAttributes.length) {- return;- }-- const detail: AddAttrRefsEventDetail = {- selectedAttributes: this.selectedAttributes- };- Util.dispatchCancellableEvent(this, new OrAttributeRefsAddRequestEvent(detail))- .then((detail) => {- if (detail.allow) {- this.dispatchEvent(new OrAddAttributeRefsEvent(detail.detail));- }- });- }- }- ];- }-- protected setDialogContent(): void {-- const getListItems: () => ListItem[] = () => {- if (!this.assetAttributes) {- return [];- }-- return this.assetAttributes.map((attribute: Attribute<any>) => {- return {- text: Util.getAttributeLabel(undefined, attribute, undefined, true),- value: attribute.name,- data: attribute- } as ListItem- });- };-- this.dialogContent = html`- <div class="row" style="display: flex;height: 600px;width: 800px;border-top: 1px solid ${unsafeCSS(DefaultColor5)};">- <div class="col" style="width: 260px;overflow: auto;border-right: 1px solid ${unsafeCSS(DefaultColor5)};">- <or-asset-tree id="chart-asset-tree" readonly- @or-asset-tree-selection="${(ev: OrAssetTreeSelectionEvent) => this._onAssetSelectionChanged(ev)}">- </or-asset-tree>- </div>- <div class="col" style="flex: 1 1 auto;width: 260px;overflow: auto;">- ${this.assetAttributes && this.assetAttributes.length > 0 ? html`- <div class="attributes-header">- <or-translate value="attribute_plural"></or-translate>- </div>- ${this.multiSelect- ?- html`<div style="display: grid">- <or-mwc-list- id="attribute-selector" .type="${ListType.MULTI_CHECKBOX}" .listItems="${getListItems()}"- .values="${this.selectedAttributes.map(attribute => attribute.name!)}"- @or-mwc-list-changed="${(ev: OrMwcListChangedEvent) => this._onAttributeSelectionChanged(ev.detail.map(li => li.data as Attribute<any>))}"></or-mwc-list>- </div>`- :- html`<or-mwc-input id="attribute-selector"- style="display:flex;"- .label="${i18next.t("attribute")}"- .type="${InputType.LIST}"- .options="${getListItems().map(item => ([item, item.text]))}"- @or-mwc-input-changed="${(ev: OrInputChangedEvent) => this._onAttributeSelectionChanged([(ev.detail.value as ListItem).data as Attribute<any>])}"- }"></or-mwc-input>`- }- ` : html`<div style="display: flex;align-items: center;text-align: center;height: 100%;padding: 0 20px;"><span style="width:100%">- <or-translate value="${- (this.assetAttributes && this.assetAttributes.length === 0) ?- ((this.showOnlyDatapointAttrs && this.showOnlyRuleStateAttrs) ? "noDatapointsOrRuleStateAttributes" :- this.showOnlyDatapointAttrs ? "noDatapointsAttributes" :- this.showOnlyRuleStateAttrs ? "noRuleStateAttributes" : "noAttributesToShow"- ) : "selectAssetOnTheLeft"}">- </or-translate></span></div>`}- </div>- `;- }-- protected async _onAssetSelectionChanged(event: OrAssetTreeSelectionEvent) {- this.assetAttributes = undefined;- this.selectedAttributes = [];- const assetTree = event.target as OrAssetTree;- assetTree.disabled = true;-- let selectedAsset = event.detail.newNodes.length === 0 ? undefined : event.detail.newNodes[0].asset;-- if (selectedAsset) {- // Load the asset attributes- const assetResponse = await manager.rest.api.AssetResource.get(selectedAsset.id!);- selectedAsset = assetResponse.data;-- if (selectedAsset) {- this.assetAttributes = Object.values(selectedAsset.attributes!) as Attribute<any>[];-- if (this.showOnlyDatapointAttrs && this.showOnlyRuleStateAttrs) {- this.assetAttributes = this.assetAttributes- .filter(e => e.meta && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.RULESTATE] || e.meta[WellknownMetaItems.AGENTLINK]));- } else if (this.showOnlyDatapointAttrs) {- this.assetAttributes = this.assetAttributes- .filter(e => e.meta && (e.meta[WellknownMetaItems.STOREDATAPOINTS] || e.meta[WellknownMetaItems.AGENTLINK]));- } else if (this.showOnlyRuleStateAttrs) {- this.assetAttributes = this.assetAttributes- .filter(e => e.meta && (e.meta[WellknownMetaItems.RULESTATE] || e.meta[WellknownMetaItems.AGENTLINK]));- }- }- }-- assetTree.disabled = false;- }-- protected _onAttributeSelectionChanged(attributes: Attribute<any>[]) {- this.selectedAttributes = attributes;- this.addBtn.disabled = this.selectedAttributes.length > 0;- }-}diff --git a/ui/component/or-mwc-components/tsconfig.json b/ui/component/or-mwc-components/tsconfig.jsonindex 54481bc06..19d452147 100644--- a/ui/component/or-mwc-components/tsconfig.json+++ b/ui/component/or-mwc-components/tsconfig.json@@ -11,7 +11,6 @@"references": [{ "path": "../core" },{ "path": "../or-translate" },- { "path": "../or-asset-tree" },{ "path": "../or-icon" }]}diff --git a/ui/component/or-rules/src/flow-viewer/components/internal-picker.ts b/ui/component/or-rules/src/flow-viewer/components/internal-picker.tsindex 66f6c6100..530ef786b 100644--- a/ui/component/or-rules/src/flow-viewer/components/internal-picker.ts+++ b/ui/component/or-rules/src/flow-viewer/components/internal-picker.ts@@ -1,6 +1,6 @@import { LitElement, html, css, TemplateResult } from "lit";import {customElement, property} from "lit/decorators.js";-import { Node, PickerType, AttributeInternalValue, AssetState, WellknownMetaItems, Asset, NodeDataType, AttributeRef } from "@openremote/model";+import { Node, PickerType, AttributeInternalValue, Asset, NodeDataType, AttributeRef } from "@openremote/model";import { nodeConverter } from "../converters/node-converter";import { InputType, OrInputChangedEvent } from "@openremote/or-mwc-components/or-mwc-input";import rest from "@openremote/rest";@@ -11,8 +11,7 @@ import { NodeUtilities } from "../node-structure";import { translate, i18next } from "@openremote/or-translate";import { PickerStyle } from "../styles/picker-styles";import { AssetModelUtil, Util } from "@openremote/core";-import { OrMwcAttributeSelector } from "@openremote/or-mwc-components/or-mwc-dialog";-import { OrAddAttributeRefsEvent } from "@openremote/or-mwc-components/or-mwc-dialog";+import { OrAttributePicker, OrAttributePickerPickedEvent } from "@openremote/or-attribute-picker";@customElement("internal-picker")export class InternalPicker extends translate(i18next)(LitElement) {@@ -138,16 +137,16 @@ export class InternalPicker extends translate(i18next)(LitElement) {}const hostElement = document.body;- const dialog = new OrMwcAttributeSelector();+ const dialog = new OrAttributePicker();dialog.showOnlyRuleStateAttrs = true;dialog.showOnlyDatapointAttrs = false;dialog.multiSelect = false;dialog.selectedAttributes = _selectedAttributes;dialog.isOpen = true;- dialog.addEventListener(OrAddAttributeRefsEvent.NAME, async (ev: any) => {+ dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {const value: AttributeInternalValue = {- assetId: ev.detail.selectedAttributes[0].id,- attributeName: ev.detail.selectedAttributes[0].name+ assetId: ev.detail[0].id,+ attributeName: ev.detail[0].name};await this.setSocketTypeDynamically(value);this.setValue(value);diff --git a/ui/component/or-rules/tsconfig.json b/ui/component/or-rules/tsconfig.jsonindex 207bc0ce1..774026ae9 100644--- a/ui/component/or-rules/tsconfig.json+++ b/ui/component/or-rules/tsconfig.json@@ -15,6 +15,7 @@{ "path": "../or-components" },{ "path": "../or-mwc-components" },{ "path": "../or-attribute-input" },+ { "path": "../or-attribute-picker" },{ "path": "../or-asset-tree" }]}