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 of showDialog function
Rich Turner4def89fa43d4
diff --git a/ui/app/manager/src/pages/page-export.ts b/ui/app/manager/src/pages/page-export.tsindex 2fa766910..ac655fd2f 100644--- a/ui/app/manager/src/pages/page-export.ts+++ b/ui/app/manager/src/pages/page-export.ts@@ -12,6 +12,7 @@ import { AttributeRef } from "@openremote/model";import moment from "moment";import { buttonStyle } from "@openremote/or-rules/dist/style";import {createSelector} from "reselect";+import { showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";const tableStyle = require("@material/data-table/dist/mdc.data-table.css");export function pageExportProvider<S extends AppStateKeyed>(store: EnhancedStore<S>): PageProvider<S> {@@ -265,7 +266,6 @@ class PageExport<S extends AppStateKeyed> extends Page<S> {<or-mwc-input .disabled="${this.isClearExportBtnDisabled}" class="button" .type="${InputType.BUTTON}" label="${i18next.t("clearTable")}" @click="${() => this.clearSelection()}"></or-mwc-input><or-mwc-input .disabled="${this.isExportBtnDisabled}" class="button" raised .type="${InputType.BUTTON}" label="${i18next.t("export")}" @click="${() => this.export()}"></or-mwc-input></div>- <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog></div></div>@@ -352,13 +352,13 @@ class PageExport<S extends AppStateKeyed> extends Page<S> {}protected _openDialog() {- const hostElement = document.body;- const dialog = new OrAttributePicker();- dialog.isOpen = true;- dialog.showOnlyDatapointAttrs = true;- dialog.multiSelect = true;- dialog.selectedAttributes = this.config.selectedAttributes;+ const dialog = showDialog(new OrAttributePicker()+ .setShowOnlyDatapointAttrs(true)+ .setMultiSelect(true)+ .setSelectedAttributes(this.config.selectedAttributes)+ );+dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {const selectedAttributes = ev.detail;await this.renderTable(selectedAttributes);@@ -368,8 +368,6 @@ class PageExport<S extends AppStateKeyed> extends Page<S> {}this.saveConfig();});- hostElement.append(dialog);- return dialog;}protected export = () => {diff --git a/ui/app/manager/src/pages/page-users.ts b/ui/app/manager/src/pages/page-users.tsindex 9aa10888b..39f3f5348 100644--- a/ui/app/manager/src/pages/page-users.ts+++ b/ui/app/manager/src/pages/page-users.ts@@ -9,7 +9,7 @@ import {ClientRole, Role, User, UserAssetLink, UserQuery} from "@openremote/modeimport {i18next} from "@openremote/or-translate";import {OrIcon} from "@openremote/or-icon";import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";-import {showDialog, showOkCancelDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrMwcDialog, showDialog, showOkCancelDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {showSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";import {GenericAxiosResponse} from "@openremote/rest";import {OrAssetTreeSelectionEvent} from "@openremote/or-asset-tree";@@ -592,15 +592,15 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {})};- const dialog = showDialog({- title: i18next.t("restrictAccess"),- content: html`+ const dialog = showDialog(new OrMwcDialog()+ .setHeading(i18next.t("restrictAccess"))+ .setContent(html`<or-asset-treeid="chart-asset-tree" readonly .selectedIds="${user.userAssetLinks.map(ual => ual.id.assetId)}".showSortBtn="${false}" expandNodes checkboxes@or-asset-tree-selection="${(e: OrAssetTreeSelectionEvent) => onAssetSelectionChanged(e)}"></or-asset-tree>- `,- actions: [+ `)+ .setActions([{default: true,actionName: "cancel",@@ -619,16 +619,15 @@ class PageUsers<S extends AppStateKeyed> extends Page<S> {this.requestUpdate();}}- ],- dismissAction: {+ ])+ .setDismissAction({actionName: "cancel",action: () => {user.userAssetLinks = user.previousAssetLinks;user.previousAssetLinks = undefined;openBtn.disabled = false;}- }- });+ }));}protected _onPasswordChanged(user: UserModel, suffix: string) {diff --git a/ui/component/or-app/src/index.ts b/ui/component/or-app/src/index.tsindex 660682090..37efde5d1 100644--- a/ui/component/or-app/src/index.ts+++ b/ui/component/or-app/src/index.ts@@ -16,8 +16,8 @@ import "@openremote/or-icon";import {updateMetadata} from "pwa-helpers/metadata";import i18next from "i18next";import manager, {Auth, DefaultColor2, DefaultColor3, DefaultColor4, ManagerConfig, Util, BasicLoginResult, OREvent, normaliseConfig, Manager} from "@openremote/core";-import {DEFAULT_LANGUAGES, HeaderConfig, HeaderItem, Languages} from "./or-header";-import {DialogConfig, OrMwcDialog, showErrorDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {DEFAULT_LANGUAGES, HeaderConfig, Languages} from "./or-header";+import {OrMwcDialog, showErrorDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {OrMwcSnackbar} from "@openremote/or-mwc-components/or-mwc-snackbar";import {AnyAction, EnhancedStore, Unsubscribe} from "@reduxjs/toolkit";import {ThunkMiddleware} from "redux-thunk";@@ -290,16 +290,16 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}`;- const dialog = showDialog({- styles: html`<style>${styles}</style>`,- title: html`<img id="login-logo" src="${this._config.logoMobile || this._config.logo}" /></or-icon><or-translate value="login"></or-translate>`,- content: html`+ const dialog = showDialog(new OrMwcDialog()+ .setStyles(html`<style>${styles}</style>`)+ .setHeading(html`<img id="login-logo" src="${this._config.logoMobile || this._config.logo}" /></or-icon><or-translate value="login"></or-translate>`)+ .setContent(html`<div id="login_wrapper"><or-mwc-input .label="${i18next.t("user")}" .type="${InputType.TEXT}" min="1" required .value="${username}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => u = e.detail.value}"></or-mwc-input><or-mwc-input .label="${i18next.t("password")}" .type="${InputType.PASSWORD}" min="1" required .value="${password}" @or-mwc-input-changed="${(e: OrInputChangedEvent) => p = e.detail.value}"></or-mwc-input></div>- `,- actions: [+ `)+ .setActions([{actionName: "submit",default: true,@@ -312,8 +312,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {},content: html`<or-mwc-input .type=${InputType.BUTTON} .label="${i18next.t("submit")}" raised></or-mwc-input>`}- ]- }, document.body); // Attach to document as or-app isn't visible until initialised+ ]), document.body); // Attach to document as or-app isn't visible until initialisedreturn deferred.promise;}@@ -422,7 +421,17 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}public showLanguageModal() {- showDialog(this._getLanguageModalConfig(DEFAULT_LANGUAGES));+ showDialog(new OrMwcDialog()+ .setHeading("language")+ .setDismissAction(null)+ .setActions(Object.entries(DEFAULT_LANGUAGES).map(([key, value]) => {+ return {+ content: i18next.t(value),+ actionName: key,+ action: () => {+ manager.language = key;+ }+ }})));}public stateChanged(state: S) {@@ -440,23 +449,4 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {}return realmConfig;}-- protected _getLanguageModalConfig(languages: Languages): DialogConfig {- const title = "language";- const actions = Object.entries(languages).map(([key, value]) => {- return {- content: i18next.t(value),- actionName: key,- action: () => {- manager.language = key;- }- };- });-- return {- title: title,- actions: actions,- dismissAction: null- };- }}diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.tsindex 2e702c333..5a3eef57c 100644--- a/ui/component/or-asset-tree/src/index.ts+++ b/ui/component/or-asset-tree/src/index.ts@@ -573,13 +573,12 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {addBtn.disabled = !ev.detail.descriptor || !nameValid;};- dialog = showDialog(- {- title: i18next.t("addAsset"),- content: html`+ dialog = showDialog(new OrMwcDialog()+ .setHeading(i18next.t("addAsset"))+ .setContent(html`<or-add-asset-dialog id="add-panel" .config="${this.config}" .agentTypes="${agentTypes}" .assetTypes="${assetTypes}" .parent="${parent}" @or-add-asset-changed="${onAddChanged}"></or-add-asset-dialog>- `,- actions: [+ `)+ .setActions([{actionName: "cancel",content: i18next.t("cancel")@@ -649,17 +648,16 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {});}}- ],- styles: html`+ ])+ .setStyles(html`<style>.mdc-dialog__content {padding: 0 !important;}</style>- `,- dismissAction: null- }- )+ `)+ .setDismissAction(null)+ );}protected _onDeleteClicked() {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 2f7d1dae1..1201caeb0 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@@ -416,11 +416,11 @@ export class OrEditAssetPanel extends LitElement {attr = attribute;};- const dialog = showDialog({- content: html`+ const dialog = showDialog(new OrMwcDialog()+ .setContent(html`<or-add-attribute-panel .asset="${asset}" @or-add-attribute-panel-attribute-changed="${(ev: OrAddAttributePanelAttributeChangedEvent) => onAttributeChanged(ev.detail)}"></or-add-attribute-panel>- `,- styles: html`+ `)+ .setStyles(html`<style>.mdc-dialog__surface {overflow-x: visible !important;@@ -431,9 +431,9 @@ export class OrEditAssetPanel extends LitElement {overflow: visible;}</style>- `,- title: i18next.t("addAttribute"),- actions: [+ `)+ .setHeading(i18next.t("addAttribute"))+ .setActions([{actionName: "cancel",content: i18next.t("cancel")@@ -447,9 +447,8 @@ export class OrEditAssetPanel extends LitElement {},content: html`<or-mwc-input id="add-btn" .type="${InputType.BUTTON}" disabled .label="${i18next.t("add")}"></or-mwc-input>`}- ],- dismissAction: null- });+ ])+ .setDismissAction(null));}protected _addMetaItems(attribute: Attribute<any>) {@@ -471,13 +470,13 @@ export class OrEditAssetPanel extends LitElement {};}).sort(Util.sortByString((item) => item.text));- const dialog = showDialog({- content: html`+ const dialog = showDialog(new OrMwcDialog()+ .setContent(html`<div id="meta-creator"><or-mwc-list id="meta-creator-list" .type="${ListType.MULTI_CHECKBOX}" .listItems="${metaItemList}"></or-mwc-list></div>- `,- styles: html`+ `)+ .setStyles(html`<style>#meta-creator {height: 600px;@@ -488,9 +487,9 @@ export class OrEditAssetPanel extends LitElement {height: 100%;}</style>- `,- title: i18next.t("addMetaItems"),- actions: [+ `)+ .setHeading(i18next.t("addMetaItems"))+ .setActions([{actionName: "cancel",content: i18next.t("cancel")@@ -516,9 +515,8 @@ export class OrEditAssetPanel extends LitElement {},content: i18next.t("add")}- ],- dismissAction: null- });+ ])+ .setDismissAction(null));}protected _getParentTemplate() {@@ -573,11 +571,10 @@ export class OrEditAssetPanel extends LitElement {];const openDialog = () => {- dialog = showDialog(- {- content: dialogContent,- actions: dialogActions,- styles: html`+ dialog = showDialog(new OrMwcDialog()+ .setContent(dialogContent)+ .setActions(dialogActions)+ .setStyles(html`<style>.mdc-dialog__surface {width: 400px;@@ -596,10 +593,8 @@ export class OrEditAssetPanel extends LitElement {height: 100%;}</style>- `,- dismissAction: null- }- );+ `)+ .setDismissAction(null));};return html`diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.tsindex fb97aba76..d70daf322 100644--- a/ui/component/or-attribute-card/src/index.ts+++ b/ui/component/or-attribute-card/src/index.ts@@ -23,11 +23,11 @@ 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 {OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrMwcDialog, showDialog} 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";+export type ContextMenuOption = "editAttribute" | "editDelta" | "editCurrentValue" | "delete";Chart.register(LineController, LineElement, PointElement, LinearScale, Title, TimeSeriesScale);@@ -216,9 +216,6 @@ export class OrAttributeCard extends LitElement {private _chartElem!: HTMLCanvasElement;private _chart?: Chart<"line", ScatterDataPoint[]>;- @query("#mdc-dialog")- private _dialog!: OrMwcDialog;-static get styles() {return [style@@ -227,7 +224,6 @@ export class OrAttributeCard extends LitElement {constructor() {super();- this.addEventListener(OrAssetTreeSelectionEvent.NAME, this._onTreeSelectionChanged);}connectedCallback() {@@ -339,11 +335,10 @@ 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._openAttributePicker()}"></or-mwc-input>+ <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog("editAttribute")}"></or-mwc-input></div></div></div>- <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog>`;}@@ -353,11 +348,10 @@ 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._openAttributePicker()}"></or-mwc-input>+ <or-mwc-input class="button" .type="${InputType.BUTTON}" label="${i18next.t("addAttribute")}" icon="plus" @click="${() => this._openDialog("editAttribute")}"></or-mwc-input></div></div></div>- <or-mwc-dialog id="mdc-dialog"><or-mwc-dialog>`;}@@ -369,26 +363,26 @@ export class OrAttributeCard extends LitElement {${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"- },- {- text: i18next.t("delete"),- value: "delete"- }- ],- undefined,- (values: string | string[]) => this.handleMenuSelect(values as ContextMenuOptions))}+ [+ {+ text: i18next.t("editAttribute"),+ value: "editAttribute"+ },+ {+ text: i18next.t("editDelta"),+ value: "editDelta"+ },+ {+ text: i18next.t("editCurrentValue"),+ value: "editCurrentValue"+ },+ {+ text: i18next.t("delete"),+ value: "delete"+ }+ ],+ undefined,+ (option: string | string[]) => this.handleMenuSelect(option as ContextMenuOption))}</div><div class="panel-content"><div class="mainvalue-wrapper">@@ -419,153 +413,97 @@ export class OrAttributeCard extends LitElement {</div></div></div>- <or-mwc-dialog id="mdc-dialog"></or-mwc-dialog>`;}- protected _refreshDialog(dialogContent?: ContextMenuOptions) {- if (this._dialog) {- if (dialogContent === "editDelta") {- const options = [- ["percentage", "Percentage"],- ["absolute", "Absolute"]- ];-- this._dialog.dialogTitle = i18next.t("editDelta");-- 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("ok")}" data-mdc-dialog-action="yes"></or-mwc-input>`,- action: () => {- this.delta = this.data ? this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data)) : undefined;- }- }- ];-- this._dialog.dialogContent = html`- <or-mwc-input id="delta-mode-picker" value="${this.deltaFormat}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => {this.deltaFormat = evt.detail.value;this.saveSettings();}}" .type="${InputType.LIST}" .options="${options}"></or-mwc-input>- `;-- this._dialog.dismissAction = null;- this._dialog.open();- }- else if (dialogContent === "editCurrentValue") {-- this._dialog.dialogTitle = i18next.t("editCurrentValue");-- 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("ok")}" data-mdc-dialog-action="yes"></or-mwc-input>`,- action: () => {- 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, 10);- if (input < 0) {this.mainValueDecimals = 0;}- else if (input > 10) {this.mainValueDecimals = 10;}- else {this.mainValueDecimals = input;}- this.formattedMainValue = this.getFormattedValue(this.mainValue!);- this.saveSettings();+ protected _openDialog(dialogContent?: ContextMenuOption) {++ let dialog: OrMwcDialog | undefined;++ switch (dialogContent) {+ case "editDelta":+ case "editCurrentValue":+ dialog = new OrMwcDialog()+ .setHeading(i18next.t(dialogContent))+ .setDismissAction(null)+ .setContent(+ dialogContent === "editDelta"+ ? html`+ <or-mwc-input id="delta-mode-picker" value="${this.deltaFormat}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => {this.deltaFormat = evt.detail.value;this.saveSettings();}}" .type="${InputType.LIST}" .options="${[+ ["percentage", "Percentage"],+ ["absolute", "Absolute"]+ ]}"></or-mwc-input>+ `+ : html`+ <or-mwc-input id="current-value-decimals" .label="${i18next.t("decimals")}" value="${this.mainValueDecimals}" .type="${InputType.TEXT}"></or-mwc-input>+ `+ )+ .setActions([+ {+ 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("ok")}" data-mdc-dialog-action="yes"></or-mwc-input>`,+ action: () => {+ if (dialogContent === "editDelta") {+ this.delta = this.data ? this.getFormattedDelta(this.getFirstKnownMeasurement(this.data), this.getLastKnownMeasurement(this.data)) : undefined;+ } else {+ if (dialog && dialog.shadowRoot && dialog.shadowRoot.getElementById("current-value-decimals")) {+ const elm = dialog.shadowRoot.getElementById("current-value-decimals") as HTMLInputElement;+ const input = parseInt(elm.value, 10);+ if (input < 0) {this.mainValueDecimals = 0;}+ else if (input > 10) {this.mainValueDecimals = 10;}+ else {this.mainValueDecimals = input;}+ this.formattedMainValue = this.getFormattedValue(this.mainValue!);+ this.saveSettings();+ }+ }}}+ ]);++ dialog.addEventListener(OrAssetTreeSelectionEvent.NAME, async (ev: OrAssetTreeSelectionEvent) => {+ const selectedNode = ev.detail && ev.detail.newNodes.length > 0 ? ev.detail.newNodes[0] : undefined;++ if (!selectedNode) {+ this.asset = undefined;+ } else {+ // fully load the asset+ const assetEvent: AssetEvent = await manager.events!.sendEventWithReply({+ event: {+ eventType: "read-asset",+ assetId: selectedNode.asset!.id+ }+ });+ this.asset = assetEvent.asset;}- ];-- this._dialog.dialogContent = html`- <or-mwc-input id="current-value-decimals" .label="${i18next.t("decimals")}" value="${this.mainValueDecimals}" .type="${InputType.TEXT}"></or-mwc-input>- `;-- this._dialog.dismissAction = null;- this._dialog.open();- }- else {- this._openAttributePicker();- }- }- }-- protected _openDialog(dialogContent?: ContextMenuOptions) {- if (this._dialog) {- this._refreshDialog(dialogContent);- }- }-- protected _openAttributePicker() {- const hostElement = document.body;-- const dialog = new OrAttributePicker();- dialog.isOpen = true;- dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {- // handle selected attrs- const attrRef = ev.detail[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 asset- if (!manager.events) {- return;- }-- const selectedNode = event.detail && event.detail.newNodes.length > 0 ? event.detail.newNodes[0] : undefined;-- if (!selectedNode) {- this.asset = undefined;- } else {- // fully load the asset- const assetEvent: AssetEvent = await manager.events.sendEventWithReply({- event: {- eventType: "read-asset",- assetId: selectedNode.asset!.id- }- });- this.asset = assetEvent.asset;- this._refreshDialog();- }- }-- protected _getAttributeOptions(): [string, string][] | undefined {- if(!this.asset || !this.asset.attributes) {- return;+ });+ break;+ default:+ dialog = new OrAttributePicker();++ dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {+ // handle selected attrs+ const attrRef = ev.detail[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);+ }+ });+ break;}- 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)))- .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);- const label = Util.getAttributeLabel(attr, descriptors[0], this.asset!.type, false);- return [attr.name!, label];- });+ if (dialog) {+ showDialog(dialog);}}@@ -862,7 +800,7 @@ export class OrAttributeCard extends LitElement {return {val: Math.round(lastVal - firstVal), unit: ""};}- protected handleMenuSelect(value: ContextMenuOptions) {+ protected handleMenuSelect(value: ContextMenuOption) {if (value === "delete") {this.assets = [];this.assetAttributes = [];diff --git a/ui/component/or-attribute-picker/src/index.ts b/ui/component/or-attribute-picker/src/index.tsindex dc76d5dfa..202b1dce9 100644--- a/ui/component/or-attribute-picker/src/index.ts+++ b/ui/component/or-attribute-picker/src/index.ts@@ -1,4 +1,4 @@-import {html, unsafeCSS} from "lit";+import {html, TemplateResult, unsafeCSS} from "lit";import {customElement, property, query, state} from "lit/decorators.js";import "@openremote/or-asset-tree";import "@openremote/or-translate";@@ -10,7 +10,7 @@ import {i18next} from "@openremote/or-translate";import manager, {DefaultColor2, DefaultColor4, DefaultColor5, Util} from "@openremote/core";import {Asset, 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";+import {DialogAction, DialogActionBase, OrMwcDialog} from "@openremote/or-mwc-components/or-mwc-dialog";export class OrAttributePickerPickedEvent extends CustomEvent<AttributeRef[]> {@@ -43,19 +43,19 @@ export class OrAttributePicker extends OrMwcDialog {@property({type: Boolean})public multiSelect?: boolean = false;+ public selectedAttributes: AttributeRef[] = [];+@state()protected assetAttributes?: (Attribute<any>)[];protected asset?: Asset;- public selectedAttributes: AttributeRef[] = [];-@query("#add-btn")protected addBtn!: OrMwcInput;constructor() {super();- this.dialogTitle = i18next.t("selectAttributes");+ this.heading = i18next.t("selectAttributes");this.setDialogContent();this.setDialogActions();this.dismissAction = null;@@ -80,8 +80,58 @@ export class OrAttributePicker extends OrMwcDialog {`;}+ public setShowOnlyDatapointAttrs(showOnlyDatapointAttrs: boolean | undefined): OrAttributePicker {+ this.showOnlyDatapointAttrs = showOnlyDatapointAttrs;+ return this;+ }++ public setShowOnlyRuleStateAttrs(showOnlyRuleStateAttrs: boolean | undefined): OrAttributePicker {+ this.showOnlyRuleStateAttrs = showOnlyRuleStateAttrs;+ return this;+ }++ public setMultiSelect(multiSelect: boolean | undefined): OrAttributePicker {+ this.multiSelect = multiSelect;+ return this;+ }++ public setSelectedAttributes(selectedAttributes: AttributeRef[]): OrAttributePicker {+ this.selectedAttributes = selectedAttributes;+ return this;+ }++ public setOpen(isOpen: boolean): OrAttributePicker {+ super.setOpen(isOpen);+ return this;+ }++ public setHeading(heading: TemplateResult | string | undefined): OrAttributePicker {+ super.setHeading(heading);+ return this;+ }++ public setContent(content: TemplateResult | (() => TemplateResult) | undefined): OrAttributePicker {+ throw new Error("Cannot modify attribute picker content");+ }++ public setActions(actions: DialogAction[] | undefined): OrAttributePicker {+ throw new Error("Cannot modify attribute picker actions");+ }++ public setDismissAction(action: DialogActionBase | null | undefined): OrAttributePicker {+ throw new Error("Cannot modify attribute picker dismiss action");+ }++ public setStyles(styles: string | TemplateResult | undefined): OrAttributePicker {+ throw new Error("Cannot modify attribute picker styles");+ }++ public setAvatar(avatar: boolean | undefined): OrAttributePicker {+ throw new Error("Cannot modify attribute picker avatar setting");+ }+protected setDialogActions(): void {- this.dialogActions = [+ this.actions = [{actionName: "cancel",content: i18next.t("cancel")@@ -117,7 +167,7 @@ export class OrAttributePicker extends OrMwcDialog {};- this.dialogContent = () => html`+ this.content = () => 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" readonlydiff --git a/ui/component/or-chart/src/index.ts b/ui/component/or-chart/src/index.tsindex a9ef41c63..56a86d471 100644--- a/ui/component/or-chart/src/index.ts+++ b/ui/component/or-chart/src/index.ts@@ -38,6 +38,7 @@ import ChartAnnotation, { AnnotationOptions } from "chartjs-plugin-annotation";import "chartjs-adapter-moment";import {GenericAxiosResponse } from "@openremote/rest";import {OrAttributePicker, OrAttributePickerPickedEvent} from "@openremote/or-attribute-picker";+import { showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";Chart.register(LineController, ScatterController, LineElement, PointElement, LinearScale, TimeScale, Title, Filler, Legend, Tooltip, ChartAnnotation);@@ -813,16 +814,12 @@ export class OrChart extends translate(i18next)(LitElement) {}_openDialog() {- const hostElement = document.body;- const dialog = new OrAttributePicker();- dialog.showOnlyDatapointAttrs = true;- dialog.multiSelect = true;- dialog.selectedAttributes = this._getSelectedAttributes();- dialog.isOpen = true;- dialog.addEventListener(OrAttributePickerPickedEvent.NAME, (ev: any) => this._addAttribute(ev.detail));+ const dialog = showDialog(new OrAttributePicker()+ .setShowOnlyDatapointAttrs(true)+ .setMultiSelect(true)+ .setSelectedAttributes(this._getSelectedAttributes()));- hostElement.append(dialog);- return dialog;+ dialog.addEventListener(OrAttributePickerPickedEvent.NAME, (ev: any) => this._addAttribute(ev.detail));}protected async _addAttribute(selectedAttrs?: AttributeRef[]) {diff --git a/ui/component/or-json-forms/src/controls/control-array-element.ts b/ui/component/or-json-forms/src/controls/control-array-element.tsindex b51c9f69d..5a02b6ac8 100644--- a/ui/component/or-json-forms/src/controls/control-array-element.ts+++ b/ui/component/or-json-forms/src/controls/control-array-element.ts@@ -13,7 +13,7 @@ import {customElement, property} from "lit/decorators.js";import {CombinatorInfo, controlWithoutLabel, getCombinatorInfos, getTemplateFromProps, showJsonEditor} from "../util";import {InputType, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";import {i18next} from "@openremote/or-translate";-import {showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrMwcDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import "@openremote/or-mwc-components/or-mwc-list";import {addItemOrParameterDialogStyle, baseStyle, panelStyle} from "../styles";import {ListItem, OrMwcListChangedEvent} from "@openremote/or-mwc-components/or-mwc-list";@@ -296,8 +296,8 @@ export class ControlArrayElement extends ControlBaseElement {(dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput).disabled = false;};- const dialog = showDialog({- content: html`+ const dialog = showDialog(new OrMwcDialog()+ .setContent(html`<div class="col"><form id="mdc-dialog-form-add" class="row"><div id="type-list" class="col">@@ -306,10 +306,10 @@ export class ControlArrayElement extends ControlBaseElement {<div id="parameter-desc" class="col"></div></form></div>- `,- styles: addItemOrParameterDialogStyle,- title: (this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addItem"),- actions: [+ `)+ .setStyles(addItemOrParameterDialogStyle)+ .setHeading((this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addItem"))+ .setActions([{actionName: "cancel",content: i18next.t("cancel")@@ -325,8 +325,7 @@ export class ControlArrayElement extends ControlBaseElement {},content: html`<or-mwc-input id="add-btn" .type="${InputType.BUTTON}" disabled .label="${i18next.t("add")}"></or-mwc-input>`}- ],- dismissAction: null- });+ ])+ .setDismissAction(null));}}diff --git a/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts b/ui/component/or-json-forms/src/layouts/layout-vertical-element.tsindex 04b8b6ce4..acc10f9cc 100644--- a/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts+++ b/ui/component/or-json-forms/src/layouts/layout-vertical-element.ts@@ -29,7 +29,7 @@ import {} from "../util";import {InputType, OrInputChangedEvent, OrMwcInput} from "@openremote/or-mwc-components/or-mwc-input";import {i18next} from "@openremote/or-translate";-import {showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrMwcDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import "@openremote/or-mwc-components/or-mwc-list";import "@openremote/or-components/or-collapsible-panel";import {addItemOrParameterDialogStyle, baseStyle, panelStyle} from "../styles";@@ -279,8 +279,8 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Grconst onParamChanged = (selected: StatePropsOfControl) => {selectedParameter = selected;const isOneOf = !!(selectedParameter && selectedParameter.schema && selectedParameter.schema.oneOf);- dialog.dialogContent = dialogContentProvider();(dialog.shadowRoot!.getElementById("add-btn") as OrMwcInput).disabled = isOneOf;+ dialog.requestUpdate();};// const keyValue: [any, any] = [undefined, undefined];@@ -364,11 +364,11 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr`;};- const dialog = showDialog({- content: dialogContentProvider(),- styles: addItemOrParameterDialogStyle,- title: (this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addParameter"),- actions: [+ const dialog = showDialog(new OrMwcDialog()+ .setContent(dialogContentProvider)+ .setStyles(addItemOrParameterDialogStyle)+ .setHeading((this.label ? computeLabel(this.label, this.required, false) + " - " : "") + i18next.t("addParameter"))+ .setActions([{actionName: "cancel",content: i18next.t("cancel")@@ -385,8 +385,7 @@ export class LayoutVerticalElement extends LayoutBaseElement<VerticalLayout | Gr},content: html`<or-mwc-input id="add-btn" .type="${InputType.BUTTON}" disabled .label="${i18next.t("add")}"></or-mwc-input>`}- ],- dismissAction: null- });+ ])+ .setDismissAction(null));}}diff --git a/ui/component/or-json-forms/src/util.ts b/ui/component/or-json-forms/src/util.tsindex 61cf1b855..2c5024d63 100644--- a/ui/component/or-json-forms/src/util.ts+++ b/ui/component/or-json-forms/src/util.ts@@ -32,7 +32,7 @@ import {html, TemplateResult, unsafeCSS} from "lit";import {createRef, Ref, ref} from 'lit/directives/ref.js';import {ErrorObject} from "./index";import {unknownTemplate} from "./standard-renderers";-import { showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";+import {OrMwcDialog, showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";import {AdditionalProps} from "./base-element";export function getTemplateFromProps<T extends OwnPropsOfRenderer>(state: JsonFormsSubStates | undefined, props: T | undefined): TemplateResult | undefined {@@ -340,12 +340,11 @@ export const showJsonEditor = (title: string, value: any, updateCallback: (newVaupdateBtnRef.value!.disabled = !valid;};- const dialog = showDialog(- {- content: html`+ const dialog = showDialog(new OrMwcDialog()+ .setContent(html`<or-ace-editor ${ref(editorRef)} @or-ace-editor-edit="${() => onEditorEdit()}" @or-ace-editor-changed="${(ev: OrAceEditorChangedEvent) => onEditorChanged(ev)}" .value="${value}"></or-ace-editor>- `,- actions: [+ `)+ .setActions([{actionName: "cancel",content: i18next.t("cancel")@@ -362,10 +361,10 @@ export const showJsonEditor = (title: string, value: any, updateCallback: (newVa},content: html`<or-mwc-input ${ref(updateBtnRef)} disabled .type="${InputType.BUTTON}" .label="${i18next.t("update")}"></or-mwc-input>`}- ],- title: title,- dismissAction: null,- styles: html`+ ])+ .setHeading(title)+ .setDismissAction(null)+ .setStyles(html`<style>.mdc-dialog__surface {width: 1024px;@@ -383,7 +382,5 @@ export const showJsonEditor = (title: string, value: any, updateCallback: (newVaheight: 60vh;}</style>- `- }- )+ `));};diff --git a/ui/component/or-map/src/index.ts b/ui/component/or-map/src/index.tsindex 5331f0be5..9a917400f 100644--- a/ui/component/or-map/src/index.ts+++ b/ui/component/or-map/src/index.ts@@ -1,4 +1,4 @@-import manager, {EventCallback, MapType, OREvent} from "@openremote/core";+import manager, {EventCallback, MapType} from "@openremote/core";import {FlattenedNodesObserver} from "@polymer/polymer/lib/utils/flattened-nodes-observer.js";import {CSSResult, html, LitElement, PropertyValues} from "lit";import {customElement, property, query} from "lit/decorators.js";@@ -7,10 +7,15 @@ import {MapWidget} from "./mapwidget";import {style} from "./style";import {OrMapMarker, OrMapMarkerChangedEvent} from "./markers/or-map-marker";import * as Util from "./util";-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 {+ InputType,+ OrMwcInput,+ ValueInputProviderGenerator,+ ValueInputTemplateFunction+} from "@openremote/or-mwc-components/or-mwc-input";+import {OrMwcDialog, showDialog} from "@openremote/or-mwc-components/or-mwc-dialog";import {getMarkerIconAndColorFromAssetType} from "./markers/or-map-marker-asset";-import { i18next } from "@openremote/or-translate";+import {i18next} from "@openremote/or-translate";// Re-exportsexport {Util, LngLatLike};@@ -190,9 +195,9 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (aif (!valueChangeNotifier) {return;}- if (value) {+ if (value !== undefined) {valueChangeNotifier({- value: Util.getGeoJSONPoint(value)+ value: value ? Util.getGeoJSONPoint(value) : null});} else {valueChangeNotifier(undefined);@@ -200,7 +205,7 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (a};const coordinatesControl = new CoordinatesControl(disabled, valueChangeHandler);- let pos: { lng: number, lat: number } | undefined;+ let pos: { lng: number, lat: number } | null | undefined;const templateFunction: ValueInputTemplateFunction = (value, focused, loading, sending, error, helperText) => {let center: number[] | undefined;@@ -211,7 +216,7 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (a}const centerStr = center ? center.join(", ") : undefined;- centerControl.pos = pos;+ centerControl.pos = pos || undefined;coordinatesControl.readonly = disabled || readonly || sending || loading;coordinatesControl.value = centerStr;@@ -219,12 +224,12 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (alet dialog: OrMwcDialog | undefined;- const setPos = (lngLat: LngLatLike | undefined) => {+ const setPos = (lngLat: LngLatLike | null) => {if (readonly || disabled) {return;}- pos = Util.getLngLat(lngLat);+ pos = lngLat ? Util.getLngLat(lngLat) : null;if (dialog) {// We're in compact mode modal@@ -254,24 +259,25 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (aif (compact) {const mapContent = content;+const onClick = () => {dialog = showDialog(- {- content: mapContent,- styles: html`+ new OrMwcDialog()+ .setContent(mapContent)+ .setStyles(html`<style>or-map {width: 600px !important;height: 600px !important;}</style>- `,- actions: [+ `)+ .setActions([{actionName: "none",content: i18next.t("none"),action: () => {- setPos(undefined);+ setPos(null);valueChangeHandler(pos as LngLatLike);}},@@ -287,8 +293,7 @@ export const geoJsonPointInputTemplateProvider: ValueInputProviderGenerator = (aactionName: "cancel",content: i18next.t("cancel")}- ]- });+ ]));};content = html`diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.tsindex dd550c529..c63c40d81 100644--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts@@ -10,14 +10,6 @@ import {Util} from "@openremote/core";const dialogStyle = require("@material/dialog/dist/mdc.dialog.css");const listStyle = require("@material/list/dist/mdc.list.css");-export interface DialogConfig {- title?: TemplateResult | string;- content?: TemplateResult;- actions?: DialogAction[];- avatar?: boolean;- styles?: TemplateResult | string;- dismissAction?: DialogActionBase | null;-}export interface DialogActionBase {actionName: string;action?: (dialog: OrMwcDialog) => void;@@ -64,9 +56,10 @@ declare global {export async function showErrorDialog(errorMessage: string, hostElement?: HTMLElement) {const deferred = new Util.Deferred<void>();- showDialog({- title: "error",- content: html`+ showDialog(new OrMwcDialog()+ .setHeading("error")+ .setContent(+ html`<div><p><or-translate value="errorOccurred"></or-translate>${errorMessage ? html`@@ -77,52 +70,54 @@ export async function showErrorDialog(errorMessage: string, hostElement?: HTMLEl<or-translate .value="${errorMessage}"></or-translate>` : ``}</p>- </div>`,- actions: [{- actionName: "ok",- content: i18next.t("ok"),- default: true,- action: (dialog) => deferred.resolve()- }]- }, hostElement);+ </div>`+ )+ .setActions(+ [{+ actionName: "ok",+ content: i18next.t("ok"),+ default: true,+ action: (dialog) => deferred.resolve()+ }]+ ), hostElement);await deferred.promise;}-export async function showOkCancelDialog(title: string, content: string | TemplateResult, okText?: string) {+export async function showOkCancelDialog(title: string, content: string | TemplateResult, okText?: string, hostElement?: HTMLElement) {const deferred = new Util.Deferred<boolean>();showDialog(- {- content: typeof(content) === "string" ? html`<p>${content}</p>` : content,- actions: [- {- actionName: "cancel",- content: "cancel",- default: true,- action: () => deferred.resolve(false)- },- {- actionName: "ok",- content: okText ? okText : "ok",- action: () => deferred.resolve(true)- }- ],- title: title- }- );+ new OrMwcDialog()+ .setContent(typeof(content) === "string" ? html`<p>${content}</p>` : content)+ .setActions(+ [+ {+ actionName: "cancel",+ content: "cancel",+ default: true,+ action: () => deferred.resolve(false)+ },+ {+ actionName: "ok",+ content: okText ? okText : "ok",+ action: () => deferred.resolve(true)+ }+ ]+ )+ .setHeading(title),+ hostElement);return await deferred.promise;}-export function showDialog(config: DialogConfig, hostElement?: HTMLElement): OrMwcDialog {+export function showDialog<T extends OrMwcDialog>(dialog: T, hostElement?: HTMLElement): T {if (!hostElement) {hostElement = OrMwcDialog.DialogHostElement || document.body;}- const dialog = new OrMwcDialog();- dialog.isOpen = true;+ dialog.setOpen(true);dialog.addEventListener(OrMwcDialogOpenedEvent.NAME, (ev) => {ev.stopPropagation();});@@ -134,7 +129,6 @@ export function showDialog(config: DialogConfig, hostElement?: HTMLElement): OrM}}, 0);});- dialog.config = config;hostElement.append(dialog);return dialog;}@@ -181,25 +175,14 @@ export class OrMwcDialog extends LitElement {];}- public set config(config: DialogConfig) {- if (config) {- this.dialogTitle = config.title;- this.dialogContent = config.content;- this.dialogActions = config.actions;- this.dismissAction = config.dismissAction;- this.avatar = config.avatar;- this.styles = config.styles;- }- };-@property({type: String})- public dialogTitle?: string | TemplateResult;+ public heading?: string | TemplateResult;@property({type: Object, attribute: false})- public dialogContent?: TemplateResult | (() => TemplateResult);+ public content?: TemplateResult | (() => TemplateResult);@property({type: Array, attribute: false})- public dialogActions?: DialogAction[];+ public actions?: DialogAction[];@property({type: Object, attribute: false})public dismissAction: DialogActionBase | null | undefined;@@ -222,8 +205,39 @@ export class OrMwcDialog extends LitElement {return this._mdcComponent ? this._mdcComponent.isOpen : false;}- public set isOpen(isOpen: boolean) {+ public setOpen(isOpen: boolean): OrMwcDialog {this._open = true;+ return this;+ }++ public setHeading(heading: TemplateResult | string | undefined): OrMwcDialog {+ this.heading = heading;+ return this;+ }++ public setContent(content: TemplateResult | (() => TemplateResult) | undefined): OrMwcDialog {+ this.content = content;+ return this;+ }++ public setActions(actions: DialogAction[] | undefined): OrMwcDialog {+ this.actions = actions;+ return this;+ }++ public setDismissAction(action: DialogActionBase | null | undefined): OrMwcDialog {+ this.dismissAction = action;+ return this;+ }++ public setStyles(styles: string | TemplateResult | undefined): OrMwcDialog {+ this.styles = styles;+ return this;+ }++ public setAvatar(avatar: boolean | undefined): OrMwcDialog {+ this.avatar = avatar;+ return this;}public open() {@@ -265,14 +279,14 @@ export class OrMwcDialog extends LitElement {@MDCDialog:closed="${(evt: any) => this._onDialogClosed(evt.detail.action)}"><div class="mdc-dialog__container"><div class="mdc-dialog__surface">- ${typeof(this.dialogTitle) === "string" ? html`<h2 class="mdc-dialog__title" id="dialog-title"><or-translate value="${this.dialogTitle}"></or-translate></h2>`- : this.dialogTitle ? html`<span class="mdc-dialog__title" id="dialog-title">${this.dialogTitle}</span>` : ``}- ${this.dialogContent ? html`+ ${typeof(this.heading) === "string" ? html`<h2 class="mdc-dialog__title" id="dialog-title"><or-translate value="${this.heading}"></or-translate></h2>`+ : this.heading ? html`<span class="mdc-dialog__title" id="dialog-title">${this.heading}</span>` : ``}+ ${this.content ? html`<div class="dialog-container mdc-dialog__content" id="dialog-content">- ${typeof this.dialogContent === "function" ? this.dialogContent() : this.dialogContent}+ ${typeof this.content === "function" ? this.content() : this.content}</div><footer class="mdc-dialog__actions">- ${this.dialogActions ? this.dialogActions.map((action) => {+ ${this.actions ? this.actions.map((action) => {return html`<div class="mdc-button mdc-dialog__button" ?data-mdc-dialog-button-default="${action.default}" data-mdc-dialog-action="${action.actionName}">${typeof(action.content) === "string" ? html`<or-mwc-input .type="${InputType.BUTTON}" .disabled="${action.disabled}" .label="${action.content}"></or-mwc-input>` : action.content}@@ -281,7 +295,7 @@ export class OrMwcDialog extends LitElement {</footer>` : html`<ul class="mdc-list ${this.avatar ? "mdc-list--avatar-list" : ""}">- ${!this.dialogActions ? `` : this.dialogActions!.map((action, index) => {+ ${!this.actions ? `` : this.actions!.map((action, index) => {return html`<li class="mdc-list-item" data-mdc-dialog-action="${action.actionName}"><span class="mdc-list-item__text">${action.content}</span></li>`;})}</ul>@@ -307,8 +321,8 @@ export class OrMwcDialog extends LitElement {protected _onDialogClosed(action?: string) {if (action === "close" && this.dismissAction && this.dismissAction.action) {this.dismissAction.action(this);- } else if (action && this.dialogActions) {- const matchedAction = this.dialogActions.find((dialogAction) => dialogAction.actionName === action);+ } else if (action && this.actions) {+ const matchedAction = this.actions.find((dialogAction) => dialogAction.actionName === action);if (matchedAction && matchedAction.action) {matchedAction.action(this);}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 530ef786b..379af9955 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@@ -12,6 +12,7 @@ import { translate, i18next } from "@openremote/or-translate";import { PickerStyle } from "../styles/picker-styles";import { AssetModelUtil, Util } from "@openremote/core";import { OrAttributePicker, OrAttributePickerPickedEvent } from "@openremote/or-attribute-picker";+import { showDialog } from "@openremote/or-mwc-components/or-mwc-dialog";@customElement("internal-picker")export class InternalPicker extends translate(i18next)(LitElement) {@@ -136,13 +137,12 @@ export class InternalPicker extends translate(i18next)(LitElement) {}];}- const hostElement = document.body;- const dialog = new OrAttributePicker();- dialog.showOnlyRuleStateAttrs = true;- dialog.showOnlyDatapointAttrs = false;- dialog.multiSelect = false;- dialog.selectedAttributes = _selectedAttributes;- dialog.isOpen = true;+ const dialog = showDialog(new OrAttributePicker()+ .setShowOnlyRuleStateAttrs(true)+ .setShowOnlyDatapointAttrs(false)+ .setMultiSelect(false)+ .setSelectedAttributes(_selectedAttributes));+dialog.addEventListener(OrAttributePickerPickedEvent.NAME, async (ev: OrAttributePickerPickedEvent) => {const value: AttributeInternalValue = {assetId: ev.detail[0].id,@@ -152,8 +152,6 @@ export class InternalPicker extends translate(i18next)(LitElement) {this.setValue(value);await this.setSelectedAssetFromInternalValue();});-- hostElement.append(dialog);};let selectedAttrLabel = '?';diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.tsindex d8cf5fbf7..f2de171a2 100644--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts+++ b/ui/component/or-rules/src/json-viewer/modals/or-rule-notification-modal.ts@@ -71,7 +71,7 @@ export class OrRuleNotificationModal extends translate(i18next)(LitElement) {container.appendChild(child);}});- dialog.dialogContent = html`${container}`;+ dialog.content = html`${container}`;dialog.dismissAction = null;this.requestUpdate();}@@ -128,7 +128,7 @@ export class OrRuleNotificationModal extends translate(i18next)(LitElement) {return html`<or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("message")}" @click="${notificationPickerModalOpen}"></or-mwc-input>- <or-mwc-dialog id="notification-modal" dialogTitle="${this.title}" .dialogActions="${notificationPickerModalActions}"></or-mwc-dialog>+ <or-mwc-dialog id="notification-modal" heading="${this.title}" .actions="${notificationPickerModalActions}"></or-mwc-dialog><slot class="notification-form-slot"></slot>`}diff --git a/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.ts b/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.tsindex f7da270ed..8af3f8475 100644--- a/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.ts+++ b/ui/component/or-rules/src/json-viewer/modals/or-rule-radial-modal.ts@@ -89,7 +89,7 @@ export class OrRuleRadialModal extends translate(i18next)(LitElement) {const dialog: OrMwcDialog = this.shadowRoot!.getElementById("radial-modal") as OrMwcDialog;if (dialog) {- dialog.dialogContent = html`+ dialog.content = html`<div style="display:grid"><or-map class="or-map" type="VECTOR" style="border: 1px solid #d5d5d5; height: 400px; min-width: 300px; margin-bottom: 20px;"><or-map-marker active color="#FF0000" icon="information" lat="${value.lat}" lng="${value.lng}" radius="${value.radius}"></or-map-marker>@@ -152,7 +152,7 @@ export class OrRuleRadialModal extends translate(i18next)(LitElement) {return html`<or-mwc-input .type="${InputType.BUTTON}" .label="${i18next.t("area")}" @click="${radialPickerModalOpen}"></or-mwc-input>- <or-mwc-dialog id="radial-modal" dialogTitle="area" .dialogActions="${radiusPickerModalActions}"></or-mwc-dialog>+ <or-mwc-dialog id="radial-modal" heading="area" .actions="${radiusPickerModalActions}"></or-mwc-dialog>`}}diff --git a/ui/component/or-rules/src/or-rule-validity.ts b/ui/component/or-rules/src/or-rule-validity.tsindex cd7321986..b240c7fb9 100644--- a/ui/component/or-rules/src/or-rule-validity.ts+++ b/ui/component/or-rules/src/or-rule-validity.ts@@ -144,7 +144,7 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {break;}this._validity = {...validity}- this.refreshDialogContent();+ this._dialog!.requestUpdate();}timeLabel() {@@ -200,7 +200,7 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {});break;}- this.refreshDialogContent();+ this._dialog!.requestUpdate();}getValidityType () {@@ -224,9 +224,9 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {protected showDialog() {- this._dialog = showDialog({- title: i18next.t("scheduleRuleActivity"),- styles: html`+ this._dialog = showDialog(new OrMwcDialog()+ .setHeading(i18next.t("scheduleRuleActivity"))+ .setStyles(html`<style>.mdc-dialog__surface {overflow-x: visible !important;@@ -248,9 +248,8 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {overflow: auto;}}- </style>`- ,- actions: [+ </style>`)+ .setActions([{actionName: "cancel",content: html`<or-mwc-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-mwc-input>`,@@ -277,18 +276,9 @@ export class OrRuleValidity extends translate(i18next)(LitElement) {}}},- ],- content: this.getDialogContent(),- dismissAction: null- });- }-- protected refreshDialogContent() {- if (!this._dialog) {- return;- }-- this._dialog.dialogContent = this.getDialogContent();+ ])+ .setContent(() => this.getDialogContent())+ .setDismissAction(null));}protected getDialogContent(): TemplateResult {