Skip to content

armgit / core

Public Imported from GitHub
0

100% open-source IoT Platform - Integrate your devices, add intelligence, build custom apps

UI updates: various improvements including or-asset-tree recursive delete support

Rich Turner973a28bd1fb7
diff --git a/deployment/manager/shared/locales/de/or.json b/deployment/manager/shared/locales/de/or.json
index 573f5e8af..7e524503b 100644
--- a/deployment/manager/shared/locales/de/or.json
+++ b/deployment/manager/shared/locales/de/or.json
@@ -78,8 +78,7 @@
"lang": "Sprache",
"status": "Status",
"name": "Name",
- "deleteAssetsNoChildrenAllowed": "Asset kann nicht gelöscht werden da es Kindelemente enthält. Bitte löschen Sie zuerst alle Kindelemente.",
- "confirmDeleteAssets": "Asset löschen?",
+ "deleteAssetsConfirm": "Remove asset(s) and all descendant assets?",
"ok": "OK",
"cancel": "Abbrechen",
"createdOn": "Erstellt am:",
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index 318cc932d..2f76341a1 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -78,8 +78,8 @@
"lang": "Language",
"status": "Status",
"name": "Name",
- "deleteAssetsNoChildrenAllowed": "Only assets that have no descendants can be deleted, please remove descendents first.",
- "confirmDeleteAssets": "Remove assets?",
+ "deleteAssetsConfirm": "Remove asset(s) and all descendant assets?",
+ "deleteFailed": "Failed to delete requested asset(s)",
"ok": "OK",
"cancel": "Cancel",
"createdOn": "Created on",
diff --git a/deployment/manager/shared/locales/es/or.json b/deployment/manager/shared/locales/es/or.json
index 666faaea3..c0ba08eaa 100644
--- a/deployment/manager/shared/locales/es/or.json
+++ b/deployment/manager/shared/locales/es/or.json
@@ -78,8 +78,7 @@
"lang":"Idioma",
"status": "Estado",
"name": "Nombre",
- "deleteAssetsNoChildrenAllowed": "Solo se pueden eliminar los activos que no tienen descendientes, elimine primero los descendientes.",
- "confirmDeleteAssets": "¿Eliminar activos?",
+ "deleteAssetsConfirm": "Remove asset(s) and all descendant assets?",
"ok": "OK",
"cancel": "Cancelar",
"createdOn": "Creado en",
diff --git a/deployment/manager/shared/locales/fr/or.json b/deployment/manager/shared/locales/fr/or.json
index e3ced4e8e..978241f5a 100644
--- a/deployment/manager/shared/locales/fr/or.json
+++ b/deployment/manager/shared/locales/fr/or.json
@@ -75,8 +75,7 @@
"creationDate": "Date de création",
"status": "Statut",
"name": "Nom",
- "deleteAssetsNoChildrenAllowed": "Seules les ressources qui n'ont pas de descendants peuvent être supprimées, veuillez enlever les descendants d'abord.",
- "confirmDeleteAssets": "Effacer les ressources?",
+ "deleteAssetsConfirm": "Remove asset(s) and all descendant assets?",
"ok": "OK",
"cancel": "Annuler",
"createdOn": "Créé le",
diff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.json
index eb7396fd3..a7d472a05 100644
--- a/deployment/manager/shared/locales/nl/or.json
+++ b/deployment/manager/shared/locales/nl/or.json
@@ -78,8 +78,7 @@
"lang": "Taal",
"status": "Status",
"name": "Naam",
- "deleteAssetsNoChildrenAllowed": "Kan deze asset niet verwijderen. Verwijder de onderliggende assets eerst.",
- "confirmDeleteAssets": "Asset verwijderen?",
+ "deleteAssetsConfirm": "Remove asset(s) and all descendant assets?",
"ok": "OK",
"cancel": "Annuleren",
"createdOn": "Aangemaakt op",
diff --git a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
index 988600b85..592824c01 100644
--- a/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
+++ b/manager/src/main/java/org/openremote/manager/asset/AssetStorageService.java
@@ -701,12 +701,14 @@ public class AssetStorageService extends RouteBuilder implements ContainerServic
// Update all empty attribute timestamps with server-time (a caller which doesn't have a
// reliable time source such as a browser should clear the timestamp when setting an attribute
// value).
+ // Ensure attribute names are not stored in the value object
asset.getAttributesStream().forEach(attribute -> {
Optional<Long> timestamp = attribute.getValueTimestamp();
if (!timestamp.isPresent() || timestamp.get() <= 0) {
attribute.setValueTimestamp(timerService.getCurrentTimeMillis());
}
+ attribute.getObjectValue().remove("name");
});
// If username present
diff --git a/model/src/main/java/org/openremote/model/asset/AssetResource.java b/model/src/main/java/org/openremote/model/asset/AssetResource.java
index 177469b53..38582ae34 100644
--- a/model/src/main/java/org/openremote/model/asset/AssetResource.java
+++ b/model/src/main/java/org/openremote/model/asset/AssetResource.java
@@ -235,8 +235,7 @@ public interface AssetResource {
/**
* Deletes an asset. Regular users can only delete assets in their authenticated realm, the superuser can delete
* assets in other (all) realms. A 403 status is returned if a regular user tries to delete an asset in a realm
- * different than its authenticated realm, or if the user is restricted. A 400 status code is returned if the asset
- * has children and therefore can't be deleted.
+ * different than its authenticated realm, or if the user is restricted.
*/
@DELETE
@Produces(APPLICATION_JSON)
diff --git a/ui/app/or-app/src/index.ts b/ui/app/or-app/src/index.ts
index ccfcfdf6a..1c88f9fb3 100644
--- a/ui/app/or-app/src/index.ts
+++ b/ui/app/or-app/src/index.ts
@@ -19,7 +19,7 @@ import {updateMetadata} from "pwa-helpers/metadata";
import i18next from "i18next";
import manager, {Auth, DefaultColor2, DefaultColor3, ManagerConfig, Util, BasicLoginResult} from "@openremote/core";
import {DEFAULT_LANGUAGES, HeaderConfig, HeaderItem, Languages} from "./or-header";
-import {DialogConfig, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import {DialogConfig, OrMwcDialog, showErrorDialog, showDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
import {AnyAction, EnhancedStore, Unsubscribe} from "@reduxjs/toolkit";
import {ThunkMiddleware} from "redux-thunk";
import {AppStateKeyed, updatePage} from "./app";
@@ -160,9 +160,6 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
@property()
protected _page?: string;
- @query("#app-modal")
- protected _appModal!: OrMwcDialog;
-
protected _config!: DefaultAppConfig;
protected _store: EnhancedStore<S, AnyAction, ReadonlyArray<ThunkMiddleware<S>>>;
@@ -219,6 +216,9 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
constructor(store: EnhancedStore<S, AnyAction, ReadonlyArray<ThunkMiddleware<S>>>) {
super();
this._store = store;
+
+ // Set this element as the host for dialogs
+ OrMwcDialog.DialogHostElement = this;
}
connectedCallback() {
@@ -295,7 +295,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
router.resolve();
} else {
- this.showErrorModal(manager.isError ? "managerError." + manager.error : "");
+ showErrorDialog(manager.isError ? "managerError." + manager.error : "");
}
});
}
@@ -319,7 +319,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
}
`;
- this.showModal({
+ 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`
@@ -337,7 +337,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
cancel: false,
username: u,
password: p,
- closeCallback: () => { this.closeModal(); }
+ closeCallback: () => { dialog.close(); }
});
},
content: html`<or-input .type=${InputType.BUTTON} .label="${i18next.t("submit")}" raised></or-input>`
@@ -390,8 +390,8 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
<!-- Main content -->
<main role="main" class="main-content d-none"></main>
-
- <or-mwc-dialog id="app-modal"></or-mwc-dialog>
+
+ <slot></slot>
`;
}
@@ -404,43 +404,7 @@ export class OrApp<S extends AppStateKeyed> extends LitElement {
}
public showLanguageModal() {
- this.showModal(this._getLanguageModalConfig(DEFAULT_LANGUAGES));
- }
-
- public showErrorModal(errorMessage: string) {
- this.showModal({
- title: "error",
- content: html`
- <div>
- <p><or-translate value="errorOccurred"></or-translate>
- ${errorMessage ? html`
- :</p>
- <p>
- <or-translate value="error"></or-translate>
- <span> = </span>
- <or-translate .value="${errorMessage}"></or-translate>
- ` : ``}
- </p>
- </div>`,
- actions: [{
- actionName: "ok",
- content: i18next.t("ok"),
- default: true
- }]
- });
- }
-
- public showModal(config: DialogConfig) {
- if (this._appModal) {
- this._appModal.config = config;
- this._appModal.open();
- }
- }
-
- public closeModal() {
- if (this._appModal) {
- this._appModal.close();
- }
+ showDialog(this._getLanguageModalConfig(DEFAULT_LANGUAGES));
}
public stateChanged(state: S) {
diff --git a/ui/component/or-asset-tree/src/index.ts b/ui/component/or-asset-tree/src/index.ts
index ef73a784e..f27722b1a 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -15,7 +15,7 @@ import "@openremote/or-mwc-components/dist/or-mwc-list";
import {ListItem, OrMwcListChangedEvent} from "@openremote/or-mwc-components/dist/or-mwc-list";
import {i18next, OrTranslate} from "@openremote/or-translate";
import "@openremote/or-mwc-components/dist/or-mwc-dialog";
-import {showDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import {showDialog, showErrorDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
export interface AssetTreeTypeConfig {
include?: string[];
@@ -235,6 +235,9 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
@property({type: Boolean})
public disabled: boolean = false;
+ @property({type: Boolean})
+ public disableSubscribe: boolean = false;
+
@property({type: Boolean})
public multiSelect?: boolean = true;
@@ -367,6 +370,12 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
this._updateSort(this._nodes!, this._getSortFunction());
}
+ if (_changedProperties.has("disabledSubscribe")) {
+ if (this.disableSubscribe) {
+ this._removeEventSubscriptions();
+ }
+ }
+
return result;
}
@@ -597,42 +606,54 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
protected _doDelete() {
- if (!this._selectedNodes) {
+ if (!this._selectedNodes || this._selectedNodes.length === 0) {
return;
}
- // Check each selected node has no children
- if (this._selectedNodes.find((node) => node.children && node.children.length > 0)) {
- window.alert(i18next.t("deleteAssetsNoChildrenAllowed"));
- return;
- }
+ const doDelete = () => {
+ this.disabled = true;
- if (!this._okToDelete()) {
- return;
- }
+ // Get all descendant IDs of selected nodes
+ const assetIds: string[] = [];
+ OrAssetTree._forEachNodeRecursive(this._selectedNodes, (node) => {
+ assetIds.push(node.asset!.id!);
+ });
- this.disabled = true;
- manager.rest.api.AssetResource.delete({
- assetId: this._selectedNodes.map((node) => node.asset!.id!)
- }, {
- paramsSerializer: params => Qs.stringify(params, {arrayFormat: 'repeat'})
- }).then((response) => {
- if (response.status !== 200) {
- // TODO: Error announcement
- }
+ manager.rest.api.AssetResource.delete({
+ assetId: assetIds
+ }, {
+ paramsSerializer: params => Qs.stringify(params, {arrayFormat: 'repeat'})
+ }).then((response) => {
+ // Clear nodes to re-fetch them
+ this._nodes = undefined;
+ this.disabled = false;
- // Clear nodes to refetch them
- this._nodes = undefined;
- }).catch((reason) => {
- // TODO: Error announcement
- // Clear nodes to re-fetch them
- this._nodes = undefined;
- });
- this.disabled = true;
- }
+ if (response.status !== 204) {
+ showErrorDialog(i18next.t("deleteFailed"));
+ }
+ }).catch((reason) => {
+ // Clear nodes to re-fetch them
+ this._nodes = undefined;
+ this.disabled = false;
+ showErrorDialog(i18next.t("deleteFailed"));
+ });
+ };
- protected _okToDelete() {
- return window.confirm(i18next.t("confirmDeleteAssets"));
+ // Confirm deletion request
+ showDialog({
+ content: html`<or-translate value="deleteAssetsConfirm"></or-translate>`,
+ actions: [
+ {
+ content: i18next.t("ok"),
+ actionName: "ok",
+ action: () => doDelete()
+ },
+ {
+ content: i18next.t("cancel"),
+ actionName: "cancel"
+ }
+ ]
+ });
}
protected async _doAdd(asset: Asset) {
@@ -696,8 +717,10 @@ export class OrAssetTree extends subscribe(manager)(LitElement) {
/* Subscribe mixin overrides */
public async _addEventSubscriptions(): Promise<void> {
- // Subscribe to asset events for all assets in the realm
- this._subscriptionIds = [await manager.getEventProvider()!.subscribeAssetEvents(null, false, (event) => this._onEvent(event))];
+ if (!this.disableSubscribe) {
+ // Subscribe to asset events for all assets in the realm
+ this._subscriptionIds = [await manager.getEventProvider()!.subscribeAssetEvents(null, false, (event) => this._onEvent(event))];
+ }
}
public onEventsConnect() {
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index c0a3bb1dd..062a40540 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -836,18 +836,23 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
if (editMode) {
content = html`
- <or-edit-asset-panel .asset="${this.asset}" .attrs="${this._attributes}"></or-edit-asset-panel>
+ <div id="edit-container">
+ <or-edit-asset-panel .asset="${this.asset}"></or-edit-asset-panel>
+ </div>
`;
} else {
if (this._viewerConfig.panels) {
- content = html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
-
- if (panelConfig.hide) {
- return ``;
- }
-
- return getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this, this._viewerConfig!, panelConfig)) || ``;
- })}`;
+ content = html`
+ <div id="view-container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">
+ ${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {
+
+ if (panelConfig.hide) {
+ return ``;
+ }
+
+ return getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this, this._viewerConfig!, panelConfig)) || ``;
+ })}
+ </div>`;
}
}
@@ -864,9 +869,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
<div id="created-time" class="mobileHidden"><or-translate value="createdOnWithDate" .options="${{ date: new Date(this.asset!.createdOn!) } as i18next.TOptions<i18next.InitOptions>}"></or-translate></div>
${editMode ? html`<or-input id="save-btn" .disabled="${!this.isModified()}" raised .type="${InputType.BUTTON}" .label="${i18next.t("save")}" @or-input-changed="${() => this._saveAsset()}"></or-input>` : ``}
</div>
- <div id="container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">
- ${content}
- </div>
+ ${content}
</div>
`;
}
@@ -938,7 +941,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
public static generateGrid(shadowRoot: ShadowRoot | null) {
if (shadowRoot) {
- const grid = shadowRoot.querySelector('#container');
+ const grid = shadowRoot.querySelector('#view-container');
if (grid) {
const rowHeight = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-auto-rows'), 10);
const rowGap = parseInt(window.getComputedStyle(grid).getPropertyValue('grid-row-gap'), 10);
diff --git a/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts b/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts
index fbe58bc06..a37f90d1f 100644
--- a/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts
+++ b/ui/component/or-asset-viewer/src/or-add-attribute-panel.ts
@@ -100,7 +100,7 @@ export class OrAddAttributePanel extends LitElement {
this.attribute.value = descriptor.initialValue;
this.attribute.type = descriptor.valueDescriptor!.name as AttributeValueDescriptor; // TODO: Fix once asset model works properly
if (descriptor.metaItemDescriptors) {
- this.attribute.meta = descriptor.metaItemDescriptors.map((descriptor) => {
+ this.attribute.meta = descriptor.metaItemDescriptors.filter((descriptor) => descriptor.required || (descriptor.hasOwnProperty("initialValue") && descriptor.initialValue !== null)).map((descriptor) => {
return {
name: descriptor.urn,
value: descriptor.initialValue
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.ts
index 579b6a722..f8b6ae43b 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
@@ -9,9 +9,12 @@ import {showDialog, OrMwcDialog, DialogAction} from "@openremote/or-mwc-componen
import {ListItem, ListType, OrMwcList} from "@openremote/or-mwc-components/dist/or-mwc-list";
import "./or-add-attribute-panel";
import {getField, getPanel, getPropertyTemplate} from "./index";
-import {OrAddAttributePanelAttributeChangedEvent} from "./or-add-attribute-panel";
+import {
+ OrAddAttributePanelAttributeChangedEvent,
+} from "./or-add-attribute-panel";
import {panelStyles} from "./style";
import { OrAssetTree, UiAssetTreeNode } from "@openremote/or-asset-tree";
+import { OrAttributeInputChangedEvent } from "@openremote/or-attribute-input";
// TODO: Add webpack/rollup to build so consumers aren't forced to use the same tooling
const tableStyle = require("!!raw-loader!@material/data-table/dist/mdc.data-table.css");
@@ -132,9 +135,6 @@ export class OrEditAssetPanel extends LitElement {
@property({attribute: false})
protected asset!: Asset;
- @property({attribute: false})
- protected attrs!: Attribute[];
-
public static get styles() {
return [
unsafeCSS(tableStyle),
@@ -189,7 +189,7 @@ export class OrEditAssetPanel extends LitElement {
</tr>
</thead>
<tbody class="mdc-data-table__content">
- ${this.attrs!.sort(Util.sortByString((attr: Attribute) => attr.name!.toUpperCase())).map((attr) => this._getEditAttributeTemplate(this.asset.type!, attr))}
+ ${Object.entries(this.asset.attributes!).sort(Util.sortByString(([name, attribute]) => name.toUpperCase())).map(([name, attribute]) => {attribute.name = name; return this._getEditAttributeTemplate(this.asset.type!, attribute as Attribute);})}
<tr>
<td colspan="4">
<div class="item-add">
@@ -213,7 +213,7 @@ export class OrEditAssetPanel extends LitElement {
protected _getEditAttributeTemplate(assetType: string, attribute: Attribute): TemplateResult {
const deleteAttribute = () => {
- this.attrs!.splice(this.attrs!.indexOf(attribute), 1);
+ delete this.asset.attributes![attribute.name!];
this._onModified();
};
@@ -222,7 +222,7 @@ export class OrEditAssetPanel extends LitElement {
<td class="padded-cell mdc-data-table__cell expander-cell"><or-icon icon="chevron-right"></or-icon><span>${attribute.name}</span></td>
<td class="padded-cell mdc-data-table__cell">${attribute.type}</td>
<td class="padded-cell overflow-visible mdc-data-table__cell">
- <or-attribute-input compact .assetType="${assetType}" .label=${null} .readonly="${false}" .attribute="${attribute}" disableWrite disableSubscribe disableButton></or-attribute-input>
+ <or-attribute-input compact .assetType="${assetType}" .label=${null} .readonly="${false}" .attribute="${attribute}" disableWrite disableSubscribe disableButton @or-attribute-input-changed="${(e: OrAttributeInputChangedEvent) => this._onAttributeModified(attribute, e.detail.value)}"></or-attribute-input>
</td>
<td class="padded-cell mdc-data-table__cell actions-cell"><or-input type="${InputType.BUTTON}" icon="delete" @click="${deleteAttribute}"></td>
</tr>
@@ -246,6 +246,12 @@ export class OrEditAssetPanel extends LitElement {
this.requestUpdate();
}
+ protected _onAttributeModified(attribute: Attribute, newValue: any) {
+ attribute.value = newValue;
+ attribute.valueTimestamp = undefined; // Clear timestamp so server will set this
+ this._onModified();
+ }
+
protected _onMetaItemModified(metaItem: MetaItem, value: any) {
metaItem.value = value;
this._onModified();
@@ -344,7 +350,7 @@ export class OrEditAssetPanel extends LitElement {
default: true,
actionName: "add",
action: () => {
- this.attrs!.push(attr);
+ this.asset.attributes![attr.name!] = attr;
this._onModified();
},
content: html`<or-input id="add-btn" .type="${InputType.BUTTON}" disabled .label="${i18next.t("add")}"></or-input>`
@@ -433,14 +439,10 @@ export class OrEditAssetPanel extends LitElement {
}
protected _getParentTemplate() {
- const showDialog = () => {
- const dialog = this.shadowRoot!.getElementById("asset-picker-modal") as OrMwcDialog;
- dialog.open();
- };
const viewer = this;
+ let dialog: OrMwcDialog;
const setParent = () => {
- const dialog = this.shadowRoot!.getElementById("asset-picker-modal") as OrMwcDialog;
const assetTree = dialog.shadowRoot!.getElementById("parent-asset-tree") as OrAssetTree;
this.asset.parentId = assetTree.selectedIds!.length === 1 ? assetTree.selectedIds![0] : undefined;
// Need to update the assets path as well
@@ -467,7 +469,7 @@ export class OrEditAssetPanel extends LitElement {
const parentSelector = (node: UiAssetTreeNode) => node.asset!.id !== this.asset.id;
// Prevent change event from bubbling up as it will affect any ancestor listeners that are interested in a different asset tree
- const dialogContent = html`<or-asset-tree id="parent-asset-tree" .selectedIds="${this.asset!.parentId ? [this.asset.parentId] : []}" @or-asset-tree-request-select="${blockEvent}" @or-asset-tree-selection-changed="${blockEvent}" .selector="${parentSelector}"></or-asset-tree>`;
+ const dialogContent = html`<or-asset-tree id="parent-asset-tree" disableSubscribe readonly .selectedIds="${this.asset!.parentId ? [this.asset.parentId] : []}" @or-asset-tree-request-select="${blockEvent}" @or-asset-tree-selection-changed="${blockEvent}" .selector="${parentSelector}"></or-asset-tree>`;
const dialogActions: DialogAction[] = [
{
@@ -487,12 +489,40 @@ export class OrEditAssetPanel extends LitElement {
}
];
+ const openDialog = () => {
+ dialog = showDialog(
+ {
+ content: dialogContent,
+ actions: dialogActions,
+ styles: html`
+ <style>
+ .mdc-dialog__surface {
+ width: 400px;
+ height: 800px;
+ display: flex;
+ overflow: visible;
+ overflow-x: visible !important;
+ overflow-y: visible !important;
+ }
+ #dialog-content {
+ flex: 1;
+ overflow: visible;
+ min-height: 0;
+ }
+ or-asset-tree {
+ height: 100%;
+ }
+ </style>
+ `
+ }
+ );
+ };
+
return html`
<div id="parent-edit-wrapper">
${getPropertyTemplate(this.asset, "parentId", this, undefined, undefined, {readonly: false, label: i18next.t("parent")})}
- <or-input id="change-parent-btn" type="${InputType.BUTTON}" raised .label="${i18next.t("edit")}" @or-input-changed="${showDialog}"></or-input>
+ <or-input id="change-parent-btn" type="${InputType.BUTTON}" raised .label="${i18next.t("edit")}" @or-input-changed="${openDialog}"></or-input>
</div>
- <or-mwc-dialog id="asset-picker-modal" .dialogContent="${dialogContent}" .dialogActions="${dialogActions}" .multiSelect="${false}"></or-mwc-dialog>
`;
}
}
diff --git a/ui/component/or-asset-viewer/src/style.ts b/ui/component/or-asset-viewer/src/style.ts
index a811556f9..2d1613a63 100644
--- a/ui/component/or-asset-viewer/src/style.ts
+++ b/ui/component/or-asset-viewer/src/style.ts
@@ -77,7 +77,6 @@ export const style = css`
width: 100%;
display: flex;
flex-direction: column;
- overflow: auto;
}
#wrapper.saving {
@@ -85,7 +84,8 @@ export const style = css`
pointer-events: none;
}
- #container {
+ #view-container {
+ flex: 1 0 auto;
box-sizing: border-box;
display: grid;
padding: 20px 20px;
@@ -100,6 +100,12 @@ export const style = css`
animation: fadein 0.3s;
}
+ #edit-container {
+ flex: 0 1 auto;
+ margin-top: 10px;
+ overflow: auto;
+ }
+
#name-input {
width: 300px;
}
@@ -144,6 +150,7 @@ export const style = css`
#asset-header {
padding: 20px 30px 0 30px;
display: flex;
+ flex: 0 0 auto;
align-items: center;
justify-content: space-between;
}
@@ -188,7 +195,7 @@ export const style = css`
cursor: pointer;
}
- or-edit-asset-panel {
+ #edit-container {
grid-column-start: 1;
grid-column-end: 3;
}
@@ -235,7 +242,7 @@ export const style = css`
grid-row-start: 4;
}
- #container {
+ #view-container {
grid-auto-rows: auto;
grid-template-columns: 100% !important;
padding: 20px 0;
diff --git a/ui/component/or-attribute-input/src/index.ts b/ui/component/or-attribute-input/src/index.ts
index b374947f2..6a17142cb 100644
--- a/ui/component/or-attribute-input/src/index.ts
+++ b/ui/component/or-attribute-input/src/index.ts
@@ -637,7 +637,7 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
}
if (_changedProperties.has("attribute")) {
- const oldAttr = _changedProperties.get("attribute") as AssetAttribute;
+ const oldAttr = {..._changedProperties.get("attribute") as AssetAttribute};
const attr = this.attribute;
if (oldAttr && attr) {
@@ -979,11 +979,6 @@ export class OrAttributeInput extends subscribe(manager)(translate(i18next)(LitE
this._writeTimeoutHandler = window.setTimeout(() => this._onWriteTimeout(), this.writeTimeout);
} else {
- if (this.attribute) {
- this.attribute.value = newValue;
- this.attribute.valueTimestamp = undefined; // Clear timestamp so server will set this
- }
-
this.value = newValue;
this.dispatchEvent(new OrAttributeInputChangedEvent(newValue, oldValue));
}
diff --git a/ui/component/or-mwc-components/src/or-mwc-dialog.ts b/ui/component/or-mwc-components/src/or-mwc-dialog.ts
index eb1c69369..27288706b 100644
--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts
@@ -3,6 +3,7 @@ import {MDCDialog} from "@material/dialog";
import "@openremote/or-translate";
import "@openremote/or-input";
import {InputType} from "@openremote/or-input";
+import { i18next } from "@openremote/or-translate";
const dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css");
const listStyle = require("!!raw-loader!@material/list/dist/mdc.list.css");
@@ -58,9 +59,32 @@ declare global {
}
}
-export function showDialog(config: DialogConfig, hostElement: HTMLElement = document.body): OrMwcDialog {
+export function showErrorDialog(errorMessage: string) {
+ showDialog({
+ title: "error",
+ content: html`
+ <div>
+ <p><or-translate value="errorOccurred"></or-translate>
+ ${errorMessage ? html`
+ :</p>
+ <p>
+ <or-translate value="error"></or-translate>
+ <span> = </span>
+ <or-translate .value="${errorMessage}"></or-translate>
+ ` : ``}
+ </p>
+ </div>`,
+ actions: [{
+ actionName: "ok",
+ content: i18next.t("ok"),
+ default: true
+ }]
+ });
+}
+
+export function showDialog(config: DialogConfig, hostElement?: HTMLElement): OrMwcDialog {
if (!hostElement) {
- hostElement = document.body;
+ hostElement = OrMwcDialog.DialogHostElement || document.body;
}
const dialog = new OrMwcDialog();
@@ -110,6 +134,11 @@ const style = css`
@customElement("or-mwc-dialog")
export class OrMwcDialog extends LitElement {
+ /**
+ * Can be set by apps to control where in the DOM dialogs are added
+ */
+ public static DialogHostElement: HTMLElement;
+
static get styles() {
return [
css`${unsafeCSS(dialogStyle)}`,
@@ -203,7 +232,7 @@ export class OrMwcDialog extends LitElement {
<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>`
- : html`<span class="mdc-dialog__title" id="dialog-title">${this.dialogTitle}</span>`}
+ : 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>`}
diff --git a/ui/tsconfig.json b/ui/tsconfig.json
index 8fdfaf765..f33e0f911 100644
--- a/ui/tsconfig.json
+++ b/ui/tsconfig.json
@@ -6,7 +6,8 @@
"moduleResolution": "node",
"lib": [
"dom",
- "es2017"
+ "es2017",
+ "es2019"
],
"noEmitOnError": true,
"strict": true,