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: or-asset-viewer config provider interface updates
Rich Turner1396b04aa93b
diff --git a/ui/component/or-asset-viewer/src/index.ts b/ui/component/or-asset-viewer/src/index.tsindex e1f974a02..3c38d34fd 100644--- a/ui/component/or-asset-viewer/src/index.ts+++ b/ui/component/or-asset-viewer/src/index.ts@@ -57,9 +57,9 @@ export interface GroupPanelConfig extends PanelConfig {export interface AssetViewerConfig {panels?: {[name: string]: PanelConfig};viewerStyles?: { [style: string]: string };- propertyViewProvider?: (asset: Asset, property: string, value: any, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;- attributeViewProvider?: (asset: Asset, attribute: Attribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;- panelViewProvider?: (asset: Asset, attributes: Attribute[], panelName: string, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;+ propertyViewProvider?: (asset: Asset, property: string, value: any, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;+ attributeViewProvider?: (asset: Asset, attribute: Attribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;+ panelViewProvider?: (asset: Asset, attributes: Attribute[], panelName: string, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) => TemplateResult | undefined;mapType?: MapType;historyConfig?: HistoryConfig;chartConfig?: OrChartConfig;@@ -115,13 +115,13 @@ function getPanel(name: string, panelConfig: PanelConfig, content: TemplateResul`;}-export function getPanelContent(panelName: string, asset: Asset, attributes: AssetAttribute[], viewerConfig: AssetViewerConfig, panelConfig: PanelConfig, shadowRoot: ShadowRoot | null): TemplateResult | undefined {+export function getPanelContent(panelName: string, asset: Asset, attributes: AssetAttribute[], hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig): TemplateResult | undefined {if (panelConfig.hide || attributes.length === 0) {return;}if (viewerConfig.panelViewProvider) {- const template = viewerConfig.panelViewProvider(asset, attributes, panelName, viewerConfig, panelConfig);+ const template = viewerConfig.panelViewProvider(asset, attributes, panelName, hostElement, viewerConfig, panelConfig);if (template) {return template;}@@ -158,8 +158,8 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assif (historyAttrs.length > 0) {const attributeChanged = (attributeName: string) => {- if (shadowRoot) {- const attributeHistory = shadowRoot.getElementById("attribute-history") as OrAttributeHistory;+ if (hostElement.shadowRoot) {+ const attributeHistory = hostElement.shadowRoot.getElementById("attribute-history") as OrAttributeHistory;if (attributeHistory) {@@ -174,7 +174,6 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass}};-const options = historyAttrs.map((attr) => {const attributeDescriptor = AssetModelUtil.getAttributeDescriptorFromAsset(attr.name!);let label = Util.getAttributeLabel(attr, attributeDescriptor);@@ -261,7 +260,7 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assconst center = lngLat ? lngLat.toArray() : undefined;const showOnMapMeta = Util.getFirstMetaItem(attribute, MetaItemType.SHOW_ON_DASHBOARD.urn!);const attributeMetaChanged = async (value: string) => {- if (shadowRoot) {+ if (hostElement.shadowRoot) {if (attribute) {@@ -368,7 +367,7 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass];const attributePickerModalOpen = () => {- const dialog: OrMwcDialog = shadowRoot!.getElementById(panelName + "-attribute-modal") as OrMwcDialog;+ const dialog: OrMwcDialog = hostElement.shadowRoot!.getElementById(panelName + "-attribute-modal") as OrMwcDialog;if (dialog) {newlySelectedAttributes.length = 0;@@ -390,8 +389,8 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Ass// Function to update the table and message when assets or config changeslet updateTable = () => {- const loadingMsg: OrTranslate = shadowRoot!.getElementById(panelName + "-attribute-table-msg") as OrTranslate;- const attributeTable: OrTable = shadowRoot!.getElementById(panelName + "-attribute-table") as OrTable;+ const loadingMsg: OrTranslate = hostElement.shadowRoot!.getElementById(panelName + "-attribute-table-msg") as OrTranslate;+ const attributeTable: OrTable = hostElement.shadowRoot!.getElementById(panelName + "-attribute-table") as OrTable;if (!loadingMsg || !attributeTable) {return;@@ -419,6 +418,7 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assarr.unshift(asset.name!);return arr;});+ window.setTimeout(() => OrAssetViewer.generateGrid(hostElement.shadowRoot), 0);};// Load child assets async then update the table@@ -434,9 +434,10 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assposition: absolute;top: 20px;right: var(--internal-or-asset-viewer-panel-padding);+ cursor: pointer;}</style>- <or-icon id="asset-group-add-remove-columns" icon="plus-minus" @click="${() => attributePickerModalOpen()}"></or-icon>+ <or-icon id="asset-group-add-remove-columns" icon="pencil" @click="${() => attributePickerModalOpen()}"></or-icon><or-table hidden .id="${panelName}-attribute-table" .options="{stickyFirstColumn:true}"></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>@@ -449,7 +450,7 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Asscontent = html`${attrs.sort((attr1, attr2) => attr1.name! < attr2.name! ? -1 : attr1.name! > attr2.name! ? 1 : 0).map((attr) => {let style = styles ? styles[attr.name!] : undefined;- return getField(attr.name!, false, style, getAttributeTemplate(asset, attr, viewerConfig, panelConfig));+ return getField(attr.name!, false, style, getAttributeTemplate(asset, attr, hostElement, viewerConfig, panelConfig));})}`;}@@ -457,16 +458,16 @@ export function getPanelContent(panelName: string, asset: Asset, attributes: Assreturn content;}-export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {+export function getAttributeTemplate(asset: Asset, attribute: AssetAttribute, hostElement: LitElement, viewerConfig: AssetViewerConfig, panelConfig: PanelConfig) {if (viewerConfig.attributeViewProvider) {- const result = viewerConfig.attributeViewProvider(asset, attribute, viewerConfig, panelConfig);+ const result = viewerConfig.attributeViewProvider(asset, attribute, hostElement, viewerConfig, panelConfig);if (result) {return result;}}return html`- <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>- `;+ <or-attribute-input dense .assetType="${asset!.type}" .attribute="${attribute}" .label="${i18next.t(attribute.name!)}"></or-attribute-input>+ `;}export function getField(name: string, isProperty: boolean, styles: { [style: string]: string } | undefined, content: TemplateResult | undefined): TemplateResult {@@ -514,7 +515,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElemgroup: {type: "group",// childAssetTypes: {- // "urn:openremote:asset:enviroment": {+ // "urn:openremote:asset:environment": {// availableAttributes: ["nO2"],// selectedAttributes: ["nO2"]// }@@ -652,7 +653,7 @@ export class OrAssetViewer extends subscribe(manager)(translate(i18next)(LitElem</div><div id="container" style="${this._viewerConfig.viewerStyles ? styleMap(this._viewerConfig.viewerStyles) : ""}">${this._viewerConfig.panels ? html`${Object.entries(this._viewerConfig.panels).map(([name, panelConfig]) => {- const panelTemplate = getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this._viewerConfig!, panelConfig, this.shadowRoot));+ const panelTemplate = getPanel(name, panelConfig, getPanelContent(name, this.asset!, this._attributes!, this, this._viewerConfig!, panelConfig));return panelTemplate || ``;})}` : ``}</div>