Skip to content

armgit / core

Public Imported from GitHub
0

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

or-asset-viewer updated group panel functionality

Rich Turner03165a137062
diff --git a/deployment/manager/shared/locales/de/or.json b/deployment/manager/shared/locales/de/or.json
index 7785ebb79..046e16398 100644
--- a/deployment/manager/shared/locales/de/or.json
+++ b/deployment/manager/shared/locales/de/or.json
@@ -108,6 +108,6 @@
"attributes": "Attribute",
"info": "Info",
"logs":"Logs",
- "choose_lang":"Choose language",
- "add_remove_attributes":"Add/remove attributes"
+ "chooseLanguage":"Choose language",
+ "addRemoveAttributes":"Add/remove attributes"
}
diff --git a/deployment/manager/shared/locales/en/or.json b/deployment/manager/shared/locales/en/or.json
index 17934f049..5f31d3f66 100644
--- a/deployment/manager/shared/locales/en/or.json
+++ b/deployment/manager/shared/locales/en/or.json
@@ -170,6 +170,6 @@
"reset": "Reset",
"noLongerMatches": "No longer matches",
"logs":"Logs",
- "choose_lang":"Choose language",
- "add_remove_attributes":"Add/remove attributes"
+ "chooseLang":"Choose language",
+ "addRemoveAttributes":"Add/remove attributes"
}
diff --git a/deployment/manager/shared/locales/es/or.json b/deployment/manager/shared/locales/es/or.json
index bc932d960..a81aa0edd 100644
--- a/deployment/manager/shared/locales/es/or.json
+++ b/deployment/manager/shared/locales/es/or.json
@@ -108,6 +108,6 @@
"attributes": "Atributos",
"info": "Informacion",
"logs":"Logs",
- "choose_lang":"Choose language",
- "add_remove_attributes":"Add/remove attributes"
+ "chooseLanguage":"Choose language",
+ "addRemoveAttributes":"Add/remove attributes"
}
diff --git a/deployment/manager/shared/locales/fr/or.json b/deployment/manager/shared/locales/fr/or.json
index 260ef7009..a65fdef8f 100644
--- a/deployment/manager/shared/locales/fr/or.json
+++ b/deployment/manager/shared/locales/fr/or.json
@@ -108,6 +108,6 @@
"attributes": "Attributs",
"info": "Info",
"logs":"Logs",
- "choose_lang":"Choose language",
- "add_remove_attributes":"Add/remove attributes"
+ "chooseLanguage":"Choose language",
+ "addRemoveAttributes":"Add/remove attributes"
}
diff --git a/deployment/manager/shared/locales/nl/or.json b/deployment/manager/shared/locales/nl/or.json
index e088ee638..21daee345 100644
--- a/deployment/manager/shared/locales/nl/or.json
+++ b/deployment/manager/shared/locales/nl/or.json
@@ -170,6 +170,6 @@
"reset": "Reset",
"noLongerMatches": "Niet meer geldig",
"logs":"Logs",
- "choose_lang":"Kies een taal",
- "add_remove_attributes":"Attributen toevoegen/verwijderen"
+ "chooseLanguage":"Kies een taal",
+ "addRemoveAttributes":"Attributen toevoegen/verwijderen"
}
diff --git a/ui/component/or-asset-viewer/package.json b/ui/component/or-asset-viewer/package.json
index ef357c742..9460a5d87 100644
--- a/ui/component/or-asset-viewer/package.json
+++ b/ui/component/or-asset-viewer/package.json
@@ -23,6 +23,7 @@
"@openremote/or-map": "^1.1.0",
"@openremote/or-chart": "^1.1.0",
"@openremote/rest": "^1.1.0",
+ "@openremote/or-mwc-components": "^1.1.0",
"lit-element": "^2.2.1"
},
"devDependencies": {
diff --git a/ui/component/or-asset-viewer/src/components/or-attributes-modal.ts b/ui/component/or-asset-viewer/src/components/or-attributes-modal.ts
deleted file mode 100644
index 62c0831ec..000000000
--- a/ui/component/or-asset-viewer/src/components/or-attributes-modal.ts
+++ /dev/null
@@ -1,108 +0,0 @@
-import {customElement, html, css, LitElement, property, query, unsafeCSS} from "lit-element";
-import "@openremote/or-icon";
-import i18next from "i18next";
-import {InputType, OrInputChangedEvent} from "@openremote/or-input";
-import {MDCDialog} from "@material/dialog";
-const dialogStyle = require("!!raw-loader!@material/dialog/dist/mdc.dialog.css");
-
-export interface AttributesConfig {
- name: string;
- value: boolean;
-}
-
-// language=CSS
-const style = css`
- :host {
- position: relative;
- }
-
- #language-dialog-content {
- display: flex;
- }
-
- #language-picker {
- flex: 1 1 0;
- }
-
-`;
-
-@customElement("or-attributes-modal")
-export class OrAttributesModal extends LitElement {
-
- @property()
- public selectedAttributes!: AttributesConfig[];
-
- @query("#mdc-dialog-add-remove-attributes")
- protected _dialogElem!: HTMLElement;
-
- protected _dialog!: MDCDialog;
-
- static get styles() {
- return [
- css`${unsafeCSS(dialogStyle)}`,
- style
- ];
- }
-
- firstUpdated() {
- this._dialog = new MDCDialog(this._dialogElem);
- }
-
- private checkboxChanged = (attributeName: string, newValue: boolean) => {
- const index = this.selectedAttributes.findIndex((attr: AttributesConfig) => attr.name === attributeName);
- this.selectedAttributes[index] = {name: attributeName, value: newValue};
- }
-
- private sendSelectedAttributes = () => {
- this.dispatchEvent(
- new CustomEvent("UpdateSelectedAttributes", {
- bubbles: true,
- composed: true,
- detail: this.selectedAttributes
- })
- );
- }
-
- protected render() {
- return html`
- <div id="mdc-dialog-add-remove-attributes"
- class="mdc-dialog"
- role="alertdialog"
- aria-modal="true"
- aria-labelledby="my-dialog-title"
- aria-describedby="my-dialog-content">
- <div class="mdc-dialog__container">
- <div class="mdc-dialog__surface">
- <h2 class="mdc-dialog__title" id="my-dialog-title">${i18next.t("add_remove_attributes")}</h2>
- <div class="dialog-container mdc-dialog__content" id="language-dialog-content" style="display:grid">
- ${this.selectedAttributes.map((attribute: AttributesConfig) => {
- return html`<div style="grid-column: 1 / -1;">
- <or-input .type="${InputType.CHECKBOX}" .label="${attribute.name}" .value="${attribute.value}"
- @or-input-changed="${(evt: OrInputChangedEvent) => this.checkboxChanged(attribute.name, evt.detail.value)}"></or-input>
- </div>`;
- })}
- </div>
- <footer class="mdc-dialog__actions">
- <or-input class="button"
- slot="secondaryAction"
- .type="${InputType.BUTTON}"
- label="${i18next.t("Cancel")}"
- class="mdc-button mdc-dialog__button"
- data-mdc-dialog-action="no"></or-input>
-
- <or-input class="button"
- slot="primaryAction"
- .type="${InputType.BUTTON}"
- label="${i18next.t("ok")}"
- class="mdc-button mdc-dialog__button"
- @click="${() => this.sendSelectedAttributes()}"
- data-mdc-dialog-action="yes"></or-input>
-
- </footer>
- </div>
- </div>
- <div class="mdc-dialog__scrim"></div>
- </div>
- `;
- }
-}
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.ts
index e9cefec29..9e3c459df 100644
--- a/ui/component/or-asset-viewer/src/index.ts
+++ b/ui/component/or-asset-viewer/src/index.ts
@@ -1,24 +1,19 @@
import {customElement, html, LitElement, property, PropertyValues, TemplateResult} from "lit-element";
-import {until} from "lit-html/directives/until";
import "@openremote/or-icon";
import "@openremote/or-input";
import "@openremote/or-attribute-input";
import "@openremote/or-attribute-history";
import "@openremote/or-chart";
-import "@openremote/or-translate";
-import {translate} from "@openremote/or-translate";
-import {InputType, OrInput, OrInputChangedEvent} from "@openremote/or-input";
+import "@openremote/or-table";
import "@openremote/or-map";
-import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";
import "@openremote/or-panel";
-import "@openremote/or-table";
+import "@openremote/or-mwc-components/dist/or-mwc-dialog";
+import {OrTranslate, translate} from "@openremote/or-translate";
+import {InputType, OrInputChangedEvent} from "@openremote/or-input";
+import manager, {AssetModelUtil, subscribe, Util} from "@openremote/core";
+import {OrTable} from "@openremote/or-table";
import {OrChartConfig, OrChartEvent} from "@openremote/or-chart";
-import {
- AssetTableConfig,
- HistoryConfig,
- OrAttributeHistory,
- OrAttributeHistoryEvent
-} from "@openremote/or-attribute-history";
+import {HistoryConfig, OrAttributeHistory, OrAttributeHistoryEvent} from "@openremote/or-attribute-history";
import {Type as MapType, Util as MapUtil} from "@openremote/or-map";
import {
Asset,
@@ -28,16 +23,14 @@ import {
Attribute,
AttributeEvent,
AttributeType,
- MetaItemType,
- MetaItem
+ MetaItem,
+ MetaItemType
} from "@openremote/model";
import {style} from "./style";
import i18next from "i18next";
import {styleMap} from "lit-html/directives/style-map";
import {classMap} from "lit-html/directives/class-map";
-import "./components/or-attributes-modal";
-import {MDCDialog} from "@material/dialog";
-import {AttributesConfig} from "./components/or-attributes-modal";
+import {DialogAction, OrMwcDialog} from "@openremote/or-mwc-components/dist/or-mwc-dialog";
export type PanelType = "property" | "location" | "attribute" | "history" | "chart" | "group";
@@ -53,6 +46,13 @@ export interface PanelConfig {
fieldStyles?: { [field: string]: { [style: string]: string } };
}
+export interface GroupPanelConfig extends PanelConfig {
+ childAssetTypes?: { [assetType: string]: {
+ availableAttributes?: string[];
+ selectedAttributes?: string[];
+ }}
+}
+
export interface AssetViewerConfig {
panels: {[name: string]: PanelConfig};
viewerStyles?: { [style: string]: string };
@@ -62,7 +62,6 @@ export interface AssetViewerConfig {
mapType?: MapType;
historyConfig?: HistoryConfig;
chartConfig?: OrChartConfig;
- groupConfig?: OrGroupConfig;
}
export interface ViewerConfig {
@@ -75,10 +74,6 @@ export interface ViewerConfig {
historyConfig?: HistoryConfig;
}
-export interface OrGroupConfig {
- columnFilters?: string[];
-}
-
class EventHandler {
_callbacks: Function[];
@@ -117,7 +112,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
type: "group",
include: ["userNotes", "childAssetType"],
panelStyles: {}
- },
+ } as GroupPanelConfig,
info: {
type: "attribute",
hideOnMobile: true,
@@ -163,9 +158,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
gridRowStart: "1"
}
}
- },
- groupConfig: {
- columnFilters: ["a", "b", "c"]
}
};
@@ -176,15 +168,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
"path",
"accessPublicRead"
];
- public static selectedHeaders: AttributesConfig[] = [
- {name: "nO2", value: true},
- {name: "ozon", value: true},
- {name: "relHumidity", value: false},
- {name: "temperature", value: true},
- {name: "particlesPM1", value: false},
- {name: "particlesPM10", value: false},
- {name: "particlesPM2_5", value: true}
- ];
static get styles() {
return [
@@ -213,9 +196,6 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
this.addEventListener(OrChartEvent.NAME, () => OrAssetViewer.generateGrid(this.shadowRoot));
this.addEventListener(OrAttributeHistoryEvent.NAME, () => OrAssetViewer.generateGrid(this.shadowRoot));
- this.addEventListener("UpdateSelectedAttributes", (event: any) => {
- OrAssetViewer.selectedHeaders = event.detail;
- });
}
shouldUpdate(changedProperties: PropertyValues): boolean {
@@ -478,7 +458,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
} else if (panelConfig && panelConfig.type === "chart") {
content = html`
- <or-chart id="chart" .config="${viewerConfig.chartConfig}" activeAssetId="${asset.id}" .activeAsset="${asset}" ></or-chart>
+ <or-chart id="chart" .config="${viewerConfig.chartConfig}" activeAssetId="${asset.id}" .activeAsset="${asset}"></or-chart>
`;
} else if (panelConfig && panelConfig.type === "location") {
@@ -546,49 +526,117 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
return;
}
- const openModal = () => {
- const modal = shadowRoot!.getElementById("modal-attributes");
- if (modal && modal.shadowRoot) {
- const component = modal.shadowRoot.getElementById("mdc-dialog-add-remove-attributes");
- if (component) {
- const dialog = new MDCDialog(component);
- if (dialog) {
- dialog.open();
- }
+ // Get child asset type attribute value
+ const childAssetTypeAttribute = Util.getAssetAttribute(asset, "childAssetType");
+ const groupConfig = panelConfig as GroupPanelConfig;
+
+ if (!childAssetTypeAttribute || typeof childAssetTypeAttribute.value !== "string") {
+ return;
+ }
+ let childAssetType = childAssetTypeAttribute.value as string;
+ let childAssets: Asset[] = [];
+
+ // Determine available and selected attributes for the child asset type
+ let availableAttributes: string[] = [];
+ let selectedAttributes: string[] = [];
+ let newlySelectedAttributes: string[] = []; // Updated when the dialog is open
+
+ if (groupConfig.childAssetTypes && groupConfig.childAssetTypes[childAssetType]) {
+ availableAttributes = groupConfig.childAssetTypes[childAssetType].availableAttributes ? groupConfig.childAssetTypes[childAssetType].availableAttributes! : [];
+ selectedAttributes = groupConfig.childAssetTypes[childAssetType].selectedAttributes ? groupConfig.childAssetTypes[childAssetType].selectedAttributes! : [];
+ }
+
+ // Get available and selected attributes from asset descriptor if not defined in config
+ if (availableAttributes.length === 0) {
+ const descriptor = AssetModelUtil.getAssetDescriptor(childAssetType);
+ if (descriptor && descriptor.attributeDescriptors) {
+ availableAttributes = descriptor.attributeDescriptors.map((descriptor) => descriptor.attributeName!);
+ }
+ }
+ if ((!selectedAttributes || selectedAttributes.length === 0) && availableAttributes) {
+ selectedAttributes = [...availableAttributes];
+ }
+
+ const attributePickerModalActions: DialogAction[] = [
+ {
+ actionName: "ok",
+ default: true,
+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("ok")}"></or-input>`,
+ action: () => {
+ selectedAttributes.length = 0;
+ selectedAttributes.push(...newlySelectedAttributes);
+ updateTable();
}
+ },
+ {
+ actionName: "cancel",
+ content: html`<or-input class="button" .type="${InputType.BUTTON}" .label="${i18next.t("cancel")}"></or-input>`,
+ action: () => {
+ // Nothing to do here
+ }
+ },
+ ];
+
+ const attributePickerModalOpen = () => {
+ const dialog: OrMwcDialog = shadowRoot!.getElementById(panelName + "-attribute-modal") as OrMwcDialog;
+
+ if (dialog) {
+ newlySelectedAttributes.length = 0;
+ newlySelectedAttributes.push(...selectedAttributes);
+ // Update content which will cause a re-render
+ dialog.dialogContent = html`
+ <div style="display:grid">
+ ${availableAttributes.sort().map((attribute) =>
+ html`<div style="grid-column: 1 / -1;">
+ <or-input .type="${InputType.CHECKBOX}" .label="${i18next.t(attribute)}" .value="${!!newlySelectedAttributes.find((selected) => selected === attribute)}"
+ @or-input-changed="${(evt: OrInputChangedEvent) => evt.detail.value ? newlySelectedAttributes.push(attribute) : newlySelectedAttributes.splice(newlySelectedAttributes.findIndex((s) => s == attribute), 1)}"></or-input>
+ </div>`)}
+ </div>
+ `;
+ dialog.open();
}
};
- let headers = ["a", "b", "c"];
- let rows = [["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"],
- ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"]];
- let columnFilter = viewerConfig.groupConfig!.columnFilters || ["a"];
-
- const renderTable = this.getAssetChildren(asset.id!, asset.attributes!.childAssetType.value)
- .then((assetChildren: Asset[]) => {
- if (assetChildren && assetChildren.length > 0) {
-
- // deduct the column headers from the first asset
- headers = Object.getOwnPropertyNames(assetChildren[0].attributes);
-
- // turn children into a format of data that or-table wants
- rows = assetChildren.map((row: Asset) => {
- return headers.map((header: string) => {
- return row.attributes![header].value;
- });
- });
-
- return html`
- <or-table
- .headers='${headers}'
- .rows='${rows}'
- .columnFilter='${columnFilter}'></or-table>
- `;
- } else {
- return html`<span>No data found</span>`;
- }
+ // let headers = ["a", "b", "c"];
+ // let rows = [["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"],
+ // ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"], ["0", "1", "2"]];
+ // let columnFilter = viewerConfig.groupConfig!.columnFilters || ["a"];
+
+ // Function to update the table and message when assets or config changes
+ let updateTable = () => {
+
+ const loadingMsg: OrTranslate = shadowRoot!.getElementById(panelName + "-attribute-table-msg") as OrTranslate;
+ const attributeTable: OrTable = shadowRoot!.getElementById(panelName + "-attribute-table") as OrTable;
+
+ if (!loadingMsg || !attributeTable) {
+ return;
+ }
+
+ if (selectedAttributes.length === 0 || !childAssets || childAssets.length === 0) {
+ loadingMsg.value = "noData";
+ loadingMsg.hidden = false;
+ attributeTable.hidden = true;
+ return;
+ }
+
+ // Update table properties which will cause a re-render
+ loadingMsg.hidden = true;
+ attributeTable.hidden = false;
+ attributeTable.headers = [...selectedAttributes].sort();
+ attributeTable.rows = childAssets.map((asset) => {
+ return attributeTable.headers.map((attributeName) => {
+ return asset.attributes![attributeName] ? asset.attributes![attributeName].value! as string : "";
+ });
});
+ };
+
+ // Load child assets async then update the table
+ this.getAssetChildren(asset.id!, asset.attributes!.childAssetType.value).then((assetChildren) => {
+ childAssets = assetChildren;
+ updateTable();
+ });
+ // Define the DOM content for this panel
content = html`
<style>
#asset-group-add-remove-columns {
@@ -597,17 +645,13 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
right: var(--internal-or-asset-viewer-panel-padding);
}
</style>
- <or-icon id="asset-group-add-remove-columns" icon="plus-minus" @click="${() => openModal()}"></or-icon>
- <button @click="${() => columnFilter = ["a", "b"]}">hit</button>
- <pre>${columnFilter}</pre>
- ${until(renderTable, `<span>Loading...</span>`)}
- <or-attributes-modal
- id="modal-attributes"
- .selectedAttributes="${this.selectedHeaders}"></or-attributes-modal>
+ <or-icon id="asset-group-add-remove-columns" icon="plus-minus" @click="${() => attributePickerModalOpen()}"></or-icon>
+ <or-table hidden .id="${panelName}-attribute-table"></or-table>
+ <span><or-translate id="${panelName}-attribute-table-msg" value="loading"></or-translate></span>
+ <or-mwc-dialog id="${panelName}-attribute-modal" dialogTitle="addRemoveAttributes" .dialogActions="${attributePickerModalActions}"></or-mwc-dialog>
`;
} else if (panelConfig && panelConfig.type === "attribute") {
-
if (asset.type !== "urn:openremote:asset:group") {
return;
}
@@ -752,26 +796,17 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem
return config;
}
- public static async getAssetNames(ids: string[]): Promise<string[]> {
+ public static async getAssetChildren(id: string, childAssetType: string): Promise<Asset[]> {
const response = await manager.rest.api.AssetResource.queryAssets({
select: {
excludePath: true,
excludeParentInfo: true
},
- ids: ids
- });
-
- if (response.status !== 200 || !response.data || response.data.length !== ids.length) {
- return ids;
- }
-
- return ids.map((id) => response.data.find((asset) => asset.id === id)!.name!);
- }
-
- public static async getAssetChildren(id: string, childAssetType: string): Promise<any[]> {
- const response = await manager.rest.api.AssetResource.queryAssets({
- ids: [id],
- recursive: true
+ parents: [
+ {
+ id: id
+ }
+ ]
});
if (response.status !== 200 || !response.data) {
diff --git a/ui/component/or-asset-viewer/tsconfig.json b/ui/component/or-asset-viewer/tsconfig.json
index ffe7e24d4..0b30f0d4f 100644
--- a/ui/component/or-asset-viewer/tsconfig.json
+++ b/ui/component/or-asset-viewer/tsconfig.json
@@ -19,6 +19,7 @@
{ "path": "../or-icon" },
{ "path": "../or-map" },
{ "path": "../or-attribute-input" },
- { "path": "../or-attribute-history" }
+ { "path": "../or-attribute-history" },
+ { "path": "../or-mwc-components" }
]
}
\ No newline at end of file
diff --git a/ui/component/or-header/src/or-language-modal.ts b/ui/component/or-header/src/or-language-modal.ts
index a75989bc1..27783aadc 100644
--- a/ui/component/or-header/src/or-language-modal.ts
+++ b/ui/component/or-header/src/or-language-modal.ts
@@ -76,7 +76,7 @@ export class OrLanguageModal extends LitElement {
aria-describedby="my-dialog-content">
<div class="mdc-dialog__container">
<div class="mdc-dialog__surface">
- <h2 class="mdc-dialog__title" id="my-dialog-title">Choice language</h2>
+ <h2 class="mdc-dialog__title" id="my-dialog-title">${i18next.t("chooseLanguage")}</h2>
<div class="dialog-container mdc-dialog__content" id="language-dialog-content">
<or-input id="language-picker"
.label="${i18next.t("language")}"
diff --git a/ui/component/or-table/src/index.ts b/ui/component/or-table/src/index.ts
index 9fbd53e7e..e5607cc94 100644
--- a/ui/component/or-table/src/index.ts
+++ b/ui/component/or-table/src/index.ts
@@ -36,7 +36,7 @@ export class OrTable extends LitElement {
public headers!: string[];
@property({type: Array})
- public rows!: [string[]];
+ public rows!: string[][];
@property({type: Array})
public columnFilter?: string[];