Skip to content

armgit / core

Public Imported from GitHub
0

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

Feature/data export modal (#417)

vlichtenberg22e1c37f8989
diff --git a/manager/src/web/shared/locales/en/or.json b/manager/src/web/shared/locales/en/or.json
index 073962456..61f876019 100644
--- a/manager/src/web/shared/locales/en/or.json
+++ b/manager/src/web/shared/locales/en/or.json
@@ -106,6 +106,8 @@
"ending": "Ending",
"timeframe": "Timeframe",
"addAttribute": "Add attribute",
+ "clearTable": "Clear",
+ "addAssetAttribute": "Add asset attribute",
"add": "Add",
"EQUALS_COMPARATOR": "Equals",
"GREATER_THAN": "Greater than",
@@ -130,6 +132,7 @@
"processors": "Processors",
"output": "Output",
"selectAsset": "Select asset",
+ "selectAssetOnTheLeft": "Select an asset on the left",
"noRuleStateAttributes": "No rule state attributes",
"copy": "Copy",
"paste": "Paste",
@@ -386,5 +389,12 @@
"readPermissions": "Read permissions",
"writePermissions": "Write permissions",
"valueType": "Value type",
+ "dataExport": "Data export",
+ "dataSelection": "Data selection",
+ "exportFrom": "Export from",
+ "assetName": "Asset name",
+ "attributeName": "Attribute name",
+ "oldestDatapoint": "Oldest datapoint",
+ "latestDatapoint": "Latest datapoint",
"arrayDimensions": "Array dimensions"
}
diff --git a/manager/src/web/shared/locales/nl/or.json b/manager/src/web/shared/locales/nl/or.json
index 872bc39c9..dbe3c1ca6 100644
--- a/manager/src/web/shared/locales/nl/or.json
+++ b/manager/src/web/shared/locales/nl/or.json
@@ -106,6 +106,8 @@
"ending": "Einde",
"timeframe": "Tijdvak",
"addAttribute": "Attribuut toevoegen",
+ "clearTable": "Leeg maken",
+ "addAssetAttribute": "Voeg asset attribuut toe",
"add": "toevoegen",
"EQUALS_COMPARATOR": "Gelijk aan",
"GREATER_THAN": "Groter dan",
@@ -130,6 +132,7 @@
"processors": "Processors",
"output": "Output",
"selectAsset": "Selecteer asset",
+ "selectAssetOnTheLeft": "Selecteer een asset aan de linkerkant",
"noRuleStateAttributes": "Geen rule state attributes",
"copy": "Kopiëren",
"paste": "Plakken",
@@ -375,5 +378,12 @@
"createAssetFailed": "Asset aanmaken is niet gelukt",
"readPermissions": "Leesrechten",
"writePermissions": "Schrijfrechten",
- "valueType": "Value type"
+ "valueType": "Value type",
+ "dataExport": "Data export",
+ "dataSelection": "Data selectie",
+ "exportFrom": "Exporteer vanaf",
+ "assetName": "Asset naam",
+ "attributeName": "Attribuut naam",
+ "oldestDatapoint": "Oudste datapunt",
+ "latestDatapoint": "Laatste datapunt"
}
diff --git a/ui/app/manager/src/headers.ts b/ui/app/manager/src/headers.ts
index 018aa84d4..3c0bb5fd5 100644
--- a/ui/app/manager/src/headers.ts
+++ b/ui/app/manager/src/headers.ts
@@ -115,3 +115,12 @@ export function headerItemRealms<S extends AppStateKeyed, A extends AnyAction>(o
roles: () => manager.isSuperUser()
};
}
+
+export function headerItemExport<S extends AppStateKeyed, A extends AnyAction>(orApp: OrApp<S>): HeaderItem {
+ return {
+ icon: "database-export",
+ value: "export",
+ href: "data-export",
+ text: "dataExport"
+ };
+}
\ No newline at end of file
diff --git a/ui/app/manager/src/index.ts b/ui/app/manager/src/index.ts
index 4f2f55f4c..e66a9e4a6 100644
--- a/ui/app/manager/src/index.ts
+++ b/ui/app/manager/src/index.ts
@@ -23,7 +23,8 @@ import {
headerItemUsers,
headerItemRoles,
headerItemRealms,
- headerItemInsights} from "./headers";
+ headerItemInsights,
+ headerItemExport} from "./headers";
import "./pages/page-map";
import {pageMapReducer, pageMapProvider, PageMapConfig} from "./pages/page-map";
import "./pages/page-assets";
@@ -44,6 +45,8 @@ import "./pages/page-roles";
import {pageRolesProvider} from "./pages/page-roles";
import "./pages/page-realms";
import {pageRealmsProvider} from "./pages/page-realms";
+import "./pages/page-realms";
+import {pageExportProvider} from "./pages/page-export";
import { ManagerConfig } from "@openremote/core";
const rootReducer = combineReducers({
@@ -53,7 +56,7 @@ const rootReducer = combineReducers({
type RootState = ReturnType<typeof rootReducer>;
-type HeaderName = "map" | "assets" | "rules" | "insights" | "gateway" | "logs" | "account" | "users" | "roles" | "realms" | "logout" | "language";
+type HeaderName = "map" | "assets" | "rules" | "insights" | "gateway" | "logs" | "account" | "users" | "roles" | "realms" | "logout" | "language" | "export";
export interface ManagerRealmConfig {
appTitle?: string;
@@ -93,7 +96,8 @@ export const DefaultPagesConfig: PageProvider<any>[] = [
pageAccountProvider(store),
pageRolesProvider(store),
pageUsersProvider(store),
- pageRealmsProvider(store)
+ pageRealmsProvider(store),
+ pageExportProvider(store)
];
export const DefaultHeaderMainMenu: {[name: string]: HeaderItem} = {
@@ -111,6 +115,7 @@ export const DefaultHeaderSecondaryMenu: {[name: string]: HeaderItem} = {
users: headerItemUsers(orApp),
roles: headerItemRoles(orApp),
realms: headerItemRealms(orApp),
+ export: headerItemExport(orApp),
logout: headerItemLogout(orApp)
};
diff --git a/ui/app/manager/src/pages/page-export.ts b/ui/app/manager/src/pages/page-export.ts
new file mode 100644
index 000000000..22815db4b
--- /dev/null
+++ b/ui/app/manager/src/pages/page-export.ts
@@ -0,0 +1,371 @@
+import {css, customElement, html, unsafeCSS, TemplateResult, property} from "lit-element";
+import "@openremote/or-rules";
+import {EnhancedStore} from "@reduxjs/toolkit";
+import {Page, PageProvider} from "@openremote/or-app";
+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 } from "@openremote/or-mwc-components/or-mwc-dialog";
+import { AttributeRef } from "@openremote/model";
+import moment from "moment";
+const tableStyle = require("@material/data-table/dist/mdc.data-table.css");
+
+export function pageExportProvider<S extends AppStateKeyed>(store: EnhancedStore<S>): PageProvider<S> {
+ return {
+ name: "export",
+ routes: [
+ "export"
+ ],
+ pageCreator: () => {
+ return new PageExport(store);
+ }
+ };
+}
+
+@customElement("page-export")
+class PageExport<S extends AppStateKeyed> extends Page<S> {
+
+ static get styles() {
+ // language=CSS
+ return [
+ unsafeCSS(tableStyle),
+ css`
+ #wrapper {
+ height: 100%;
+ width: 100%;
+ display: flex;
+ flex-direction: column;
+ overflow: auto;
+ }
+
+ #title {
+ padding: 0 20px;
+ font-size: 18px;
+ font-weight: bold;
+ width: calc(100% - 40px);
+ max-width: 1360px;
+ margin: 20px auto;
+ align-items: center;
+ display: flex;
+ }
+
+ #title or-icon {
+ margin-right: 10px;
+ margin-left: 14px;
+ }
+
+ .panel {
+ width: calc(100% - 90px);
+ max-width: 1310px;
+ background-color: white;
+ border: 1px solid #e5e5e5;
+ border-radius: 5px;
+ position: relative;
+ margin: 0 auto;
+ padding: 24px;
+ }
+
+ .panel-title {
+ text-transform: uppercase;
+ font-weight: bolder;
+ line-height: 1em;
+ color: var(--internal-or-asset-viewer-title-text-color);
+ margin-bottom: 20px;
+ margin-top: 0;
+ flex: 0 0 auto;
+ letter-spacing: 0.025em;
+ }
+
+ th {
+ color: ${unsafeCSS(DefaultColor3)};
+ }
+
+ .mdc-data-table__row {
+ border-top-color: #D3D3D3;
+ }
+
+ td, th {
+ width: 25%
+ }
+
+ .meta-item-container {
+ flex-direction: row;
+ overflow: hidden;
+ max-height: 0;
+ transition: max-height 0.25s ease-out;
+ padding-left: 16px;
+ }
+
+ or-mwc-input {
+ margin-bottom: 20px;
+ margin-right: 16px;
+ }
+
+ or-icon {
+ vertical-align: middle;
+ --or-icon-width: 20px;
+ --or-icon-height: 20px;
+ margin-right: 2px;
+ margin-left: -5px;
+ }
+
+ .mdc-data-table__header-cell {
+ font-weight: bold;
+ color: ${unsafeCSS(DefaultColor3)};
+ }
+
+ .button {
+ cursor: pointer;
+ display: flex;
+ flex-direction: row;
+ align-content: center;
+ padding: 16px;
+ align-items: center;
+ font-size: 14px;
+ text-transform: uppercase;
+ color: var(--or-app-color4);
+ }
+
+ .button or-icon {
+ --or-icon-fill: var(--or-app-color4);
+ margin-right: 5px;
+ }
+
+ @media screen and (max-width: 768px) {
+ #title {
+ padding: 0;
+ width: 100%;
+ }
+
+ .hide-mobile {
+ display: none;
+ }
+
+ .panel {
+ border-radius: 0;
+ border-left: 0px;
+ border-right: 0px;
+ width: calc(100% - 48px);
+ }
+
+ td, th {
+ width: 50%
+ }
+ }
+
+ .export-btn-wrapper {
+ display: flex;
+ justify-content: space-between;
+ }
+
+ .export-btn-wrapper .button {
+ padding: 0;
+ margin-right: 0;
+ margin-bottom: 0;
+ }
+ `,
+ ];
+ }
+
+ @property({type: Object, attribute: false})
+ public tableRowsHtml?: TemplateResult;
+
+ @property({type: Number})
+ private oldestTimestamp: number = moment().subtract(1, 'months').valueOf();
+ @property({type: Number})
+ private latestTimestamp: number = moment().valueOf();
+
+ private isClearExportBtnDisabled: boolean = true;
+ private isExportBtnDisabled: boolean = true;
+ private attrRefs: any[];
+
+ private tableRows: any[] = []; //todo type this so it can be put in table
+ private selectedAttributes: AttributeRef[] = [];
+
+ get name(): string {
+ return "export";
+ }
+
+ constructor(store: EnhancedStore<S>) {
+ super(store);
+ this.renderTableRows();
+ }
+
+ protected render() {
+
+ const hidden = false,
+ headers = [
+ i18next.t('assetName'),
+ i18next.t('attributeName'),
+ // i18next.t('valueType'),
+ i18next.t('oldestDatapoint'),
+ i18next.t('latestDatapoint')
+ ],
+ options = {
+ stickyFirstColumn: false
+ };
+
+ return html`
+ <div id="wrapper">
+ <div id="title">
+ <or-icon icon="database-export"></or-icon>
+ ${i18next.t("dataExport")}
+ </div>
+ <div class="panel">
+ <p class="panel-title">${i18next.t("dataSelection")}</p>
+ <div class="mdc-data-table" style="width: 100%; max-height: 500px; overflow-y: auto;margin-bottom: 2em">
+ <table class="mdc-data-table__table" aria-label="attribute list" >
+ <thead>
+ <tr class="mdc-data-table__header-row">
+ ${headers.map(header => html`
+ <th class="mdc-data-table__header-cell" role="columnheader" scope="col">${header}</th>
+ `)}
+ <th></th>
+ </tr>
+ </thead>
+ <tbody id="table-body" class="mdc-data-table__content">
+ ${this.tableRowsHtml}
+ </tbody>
+ </table>
+ </div>
+ <div>
+ <or-mwc-input .type="${InputType.DATETIME}" label="${Util.capitaliseFirstLetter(i18next.t("exportFrom"))}" .value="${moment(this.oldestTimestamp).toDate()}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => this.oldestTimestamp = evt.detail.value}"></or-mwc-input>
+ <or-mwc-input .type="${InputType.DATETIME}" label="${Util.capitaliseFirstLetter(i18next.t("to"))}" .value="${moment(this.latestTimestamp).toDate()}" @or-mwc-input-changed="${(evt: OrInputChangedEvent) => this.latestTimestamp = evt.detail.value}"></or-mwc-input>
+ </div>
+ <div class="export-btn-wrapper">
+ <or-mwc-input .disabled="${this.isClearExportBtnDisabled}" class="button" .type="${InputType.BUTTON}" label="${i18next.t("clearTable")}" @click="${() => this.cancelSelection()}"></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>
+
+ `;
+
+ }
+
+ protected renderTableRows() {
+
+ this.tableRowsHtml = html`
+ ${this.tableRows.map(attr => html`
+ <tr class="mdc-data-table__row">
+ <td class="padded-cell mdc-data-table__cell">${attr.assetName}</td>
+ <td class="padded-cell mdc-data-table__cell">${attr.attributeName}</td>
+ <td class="padded-cell mdc-data-table__cell">${moment(attr.oldestTimestamp).format('llll')}</td>
+ <td class="padded-cell mdc-data-table__cell">${moment(attr.latestTimestamp).format('llll')}</td>
+ <td>
+ <or-mwc-input type="${InputType.BUTTON}" icon="delete" @click="${() => this._deleteAttribute(attr.assetId, attr.attributeName)}" style="margin-bottom:0;margin-right:0"></or-mwc-input>
+ </td>
+ </tr>
+ `)}
+ <tr class="mdc-data-table__row">
+ <td colspan="100%">
+ <a class="button" @click="${() => this._openDialog()}"><or-icon icon="plus"></or-icon>${i18next.t("addAssetAttribute")}</a>
+ </td>
+ </tr>
+ `;
+ }
+
+ protected _deleteAttribute(assetId, attributeName) {
+ const indexTablerows = this.tableRows.findIndex(e => e.assetId === assetId && e.attributeName === attributeName);
+ const indexSelectedAttrs = this.selectedAttributes.findIndex(e => e.id === assetId && e.name === attributeName);
+
+ this.tableRows.splice(indexTablerows, 1);
+ this.selectedAttributes.splice(indexSelectedAttrs, 1);
+
+ this.renderTableRows();
+ }
+
+ protected _openDialog() {
+ const hostElement = document.body;
+
+ const dialog = new OrMwcAttributeSelector();
+ dialog.isOpen = true;
+ dialog.showOnlyDatapointAttrs = true;
+ dialog.selectedAttributes = this.selectedAttributes;
+ dialog.addEventListener(OrAddAttributeRefsEvent.NAME, async (ev: OrAddAttributeRefsEvent) => {
+ // this.selectedAttributes = ev.detail.selectedAttributes;
+
+ const dataPointInfoPromises = ev.detail.selectedAttributes.map((attrRef: AttributeRef) => {
+ return manager.rest.api.AssetDatapointResource.getDatapointPeriod({
+ assetId: attrRef.id,
+ attributeName: attrRef.name,
+ });
+ });
+
+ Promise.all(dataPointInfoPromises).then(datapointPeriod => {
+
+ const assetInfoPromises = datapointPeriod.map(result => {
+ return manager.rest.api.AssetResource.get(result.data.assetId);
+ });
+
+ Promise.all(assetInfoPromises).then(assetInfos => {
+ const allAssets = assetInfos.map(attr => attr.data),
+ allDatapoints = datapointPeriod.map(datapoints => datapoints.data);
+
+ this.tableRows = allDatapoints.map(dataInfo => {
+ const relevantAssetInfo = allAssets.find(asset => asset.id === dataInfo.assetId);
+ return {
+ assetName: relevantAssetInfo.name,
+ assetId: relevantAssetInfo.id,
+ attributeName: dataInfo.attributeName,
+ oldestTimestamp: dataInfo.oldestTimestamp,
+ latestTimestamp: dataInfo.latestTimestamp
+ };
+ });
+ this.renderTableRows();
+
+ if (allDatapoints.length > 0) {
+ this.attrRefs = allDatapoints.map(dataInfo => {
+ const relevantAssetInfo = allAssets.find(asset => asset.id === dataInfo.assetId);
+ return {
+ id: relevantAssetInfo.id,
+ name: dataInfo.attributeName
+ }
+ });
+ this.oldestTimestamp = allDatapoints[0].oldestTimestamp;
+ this.latestTimestamp = allDatapoints[0].oldestTimestamp;
+ this.isClearExportBtnDisabled = false;
+ this.isExportBtnDisabled = false;
+ } else {
+ this.isClearExportBtnDisabled = true;
+ this.isExportBtnDisabled = true;
+ }
+ })
+
+ });
+ });
+ hostElement.append(dialog);
+ return dialog;
+ }
+
+ protected export = () => {
+ manager.rest.api.AssetDatapointResource.getDatapointExport({
+ attributeRefs: JSON.stringify(this.attrRefs),
+ fromTimestamp: this.oldestTimestamp,
+ toTimestamp: this.latestTimestamp
+ }).then(response => {
+ // This is the best we can do with xhr - would need to return a link to the file for proper streamed download support
+ const url = window.URL.createObjectURL(new Blob([response.data]));
+ const link = document.createElement('a');
+ link.href = url;
+ link.setAttribute("download", "dataexport.csv");
+ document.body.appendChild(link);
+ link.click();
+ });
+ }
+
+ protected cancelSelection = () => {
+ this.selectedAttributes = [];
+ this.tableRows = [];
+ this.renderTableRows();
+ this.attrRefs = [];
+ this.isClearExportBtnDisabled = true;
+ this.isExportBtnDisabled = true;
+ }
+
+ 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 ab1335828..3e918a9a2 100644
--- a/ui/component/or-asset-tree/src/index.ts
+++ b/ui/component/or-asset-tree/src/index.ts
@@ -36,7 +36,6 @@ import {
} from "@openremote/or-mwc-components/or-mwc-dialog";
import {OrAddAssetDialog, OrAddChangedEvent} from "./or-add-asset-dialog";
import "./or-add-asset-dialog";
-import { AgentDescriptor } from "@openremote/model";
export interface AssetTreeTypeConfig {
include?: string[];
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 664943dfa..fa25c7838 100644
--- a/ui/component/or-mwc-components/src/or-mwc-dialog.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-dialog.ts
@@ -2,9 +2,12 @@ import {css, customElement, html, LitElement, property, query, TemplateResult, u
import {MDCDialog} from "@material/dialog";
import "@openremote/or-translate";
import "./or-mwc-input";
-import {InputType} from "./or-mwc-input";
+import {InputType, OrInputChangedEvent} from "./or-mwc-input";
import { i18next } from "@openremote/or-translate";
-import { Util } from "@openremote/core";
+import {DefaultColor2, DefaultColor5, Util } from "@openremote/core";
+import { Asset, AssetEvent, Attribute, AttributeDescriptor, AttributeRef } from "@openremote/model";
+import manager from "@openremote/core";
+import { AssetModelUtil } from "@openremote/core";
const dialogStyle = require("@material/dialog/dist/mdc.dialog.css");
const listStyle = require("@material/list/dist/mdc.list.css");
@@ -319,3 +322,180 @@ 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
+ });
+ }
+}
+
+@customElement("or-mwc-attribute-selector")
+export class OrMwcAttributeSelector extends OrMwcDialog {
+
+ public selectedAsset?: Asset;
+
+ private assetAttributes: Attribute<any>[] = []; // to display attributes that belong to selected asset
+
+ @property({type: Boolean})
+ public showOnlyDatapointAttrs: boolean = false;
+
+ @property({type: Array, attribute: false})
+ public selectedAttributes: AttributeRef[] = [];
+
+ constructor() {
+ super();
+
+ this.dialogTitle = 'Add attributes';
+ 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)};
+ }
+ `;
+
+ this.reRenderDialog();
+
+ }
+
+ 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 || !this.selectedAsset}"></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 {
+
+ this.dialogContent = html`
+ <div class="row" style="display: flex;height: 600px;width: 800px;">
+ <div class="col" style="width: 260px;overflow: auto;">
+ <or-asset-tree id="chart-asset-tree" readonly
+ @or-asset-tree-request-selection="${(event: CustomEvent) => this._onAssetSelectionChanged(event)}"
+ @or-asset-tree-request-delete="${() => this._onAssetSelectionDeleted()}"></or-asset-tree>
+ </div>
+ <div class="col" style="flex: 1 1 auto;width: 260px;overflow: auto;">
+ ${this.selectedAsset && this.selectedAsset.attributes ? html`
+ <div class="attributes-header">
+ <or-translate value="attribute_plural"></or-translate>
+ </div>
+ <div style="display: grid">
+ ${this.assetAttributes.map(attribute => html`
+ <or-mwc-input .type="${InputType.CHECKBOX}"
+ .label="${Util.getAttributeLabel(undefined, attribute, undefined, true)}"
+ .value="${this.selectedAttributes.some(s => s.id === this.selectedAsset!.id && s.name === attribute.name)}"
+ @or-mwc-input-changed="${(evt: OrInputChangedEvent) => this._addRemoveAttrs(evt, {id: this.selectedAsset!.id!, name: attribute.name})}"></or-mwc-input>`
+ )}
+ </div>
+ ` : html`<div style="display: flex;align-items: center;text-align: center;height: 100%;"><span style="width:100%"><or-translate value="selectAssetOnTheLeft"></or-translate></span></div>`}
+ </div>
+ `;
+ }
+
+ protected reRenderDialog(): void {
+ this.setDialogContent();
+ this.setDialogActions();
+ }
+
+ protected _addRemoveAttrs(event: OrInputChangedEvent, attrRef: AttributeRef) {
+ event.detail.value ? this.selectedAttributes.push(attrRef) : this.selectedAttributes.splice(this.selectedAttributes.findIndex(s => s.id === attrRef.id && s.name === attrRef.name), 1)
+
+ this.reRenderDialog();
+ }
+
+ protected _getAttributeOptions() {
+ if (!this.selectedAsset || !this.selectedAsset.type) {
+ this.reRenderDialog();
+ return;
+ }
+
+ manager.rest.api.AssetResource.get(this.selectedAsset.id!)
+ .then(result => {
+ this.assetAttributes = Object.values(result.data.attributes!) as Attribute<any>[];
+ if (this.showOnlyDatapointAttrs) {
+ this.assetAttributes = this.assetAttributes.filter(e => e.meta && e.meta.storeDataPoints);
+ }
+ this.reRenderDialog();
+ });
+
+ }
+
+ protected async _onAssetSelectionChanged(event: CustomEvent) {
+ if (!event.detail.detail.newNodes.length) {
+ this._onAssetSelectionDeleted();
+ } else {
+ const assetEvent: AssetEvent = await manager.events!.sendEventWithReply({
+ event: {
+ eventType: "read-asset",
+ assetId: event.detail.detail.newNodes[0].asset.id
+ }
+ });
+ this.selectedAsset = assetEvent.asset;
+ }
+
+ this._getAttributeOptions();
+ this.reRenderDialog();
+ }
+
+ protected _onAssetSelectionDeleted() {
+ this.selectedAsset = undefined;
+ this.assetAttributes = [];
+ this._getAttributeOptions();
+ this.reRenderDialog();
+ }
+
+}
diff --git a/ui/component/or-mwc-components/src/or-mwc-input.ts b/ui/component/or-mwc-components/src/or-mwc-input.ts
index 5ae39225e..b92e65e82 100644
--- a/ui/component/or-mwc-components/src/or-mwc-input.ts
+++ b/ui/component/or-mwc-components/src/or-mwc-input.ts
@@ -1040,6 +1040,7 @@ export class OrMwcInput extends LitElement {
</svg>
<div class="mdc-checkbox__mixedmark"></div>
</div>
+ <div class="mdc-checkbox__ripple"></div>
</div>
<label class="mdc-checkbox-circle" for="elem">${this.label}</label>
</div>
@@ -1331,6 +1332,7 @@ export class OrMwcInput extends LitElement {
swtch.checked = this.value;
} else if (this.type === InputType.CHECKBOX && this._mdcComponent) {
const checkbox = this._mdcComponent as MDCCheckbox;
+ checkbox.checked = !!this.value;
checkbox.disabled = this.disabled || this.readonly;
}
}