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; fix for widget error flash on Insights (#1364)

Martin Peeters1847b27393be
diff --git a/ui/component/or-dashboard-builder/src/widgets/attribute-input-widget.ts b/ui/component/or-dashboard-builder/src/widgets/attribute-input-widget.ts
index 6e67541d2..c5114b69a 100644
--- a/ui/component/or-dashboard-builder/src/widgets/attribute-input-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/attribute-input-widget.ts
@@ -1,10 +1,10 @@
import {css, html, PropertyValues, TemplateResult } from "lit";
import {OrAssetWidget} from "../util/or-asset-widget";
import {WidgetConfig} from "../util/widget-config";
-import {Attribute, AttributeRef, WellknownMetaItems} from "@openremote/model";
+import {AttributeRef, WellknownMetaItems} from "@openremote/model";
import {WidgetManifest} from "../util/or-widget";
import {WidgetSettings} from "../util/widget-settings";
-import { customElement, query, queryAll } from "lit/decorators.js";
+import { customElement, query, queryAll, state } from "lit/decorators.js";
import {AttributeInputSettings} from "../settings/attribute-input-settings";
import { when } from "lit/directives/when.js";
import {throttle} from "lodash";
@@ -22,7 +22,7 @@ function getDefaultWidgetConfig() {
attributeRefs: [],
readonly: false,
showHelperText: true
- } as AttributeInputWidgetConfig
+ } as AttributeInputWidgetConfig;
}
const styling = css`
@@ -45,6 +45,9 @@ export class AttributeInputWidget extends OrAssetWidget {
protected widgetConfig!: AttributeInputWidgetConfig;
+ @state()
+ protected _loading = false;
+
@query("#widget-wrapper")
protected widgetWrapperElem?: HTMLElement;
@@ -85,7 +88,7 @@ export class AttributeInputWidget extends OrAssetWidget {
delete this.resizeObserver;
}
- protected updated(changedProps: PropertyValues) {
+ protected willUpdate(changedProps: PropertyValues) {
// If widgetConfig, and the attributeRefs of them have changed...
if(changedProps.has("widgetConfig") && this.widgetConfig) {
@@ -106,12 +109,15 @@ export class AttributeInputWidget extends OrAssetWidget {
this.resizeObserver.observe(this.widgetWrapperElem);
}
- return super.updated(changedProps);
+ return super.willUpdate(changedProps);
}
protected loadAssets(attributeRefs: AttributeRef[]) {
+ this._loading = true;
this.fetchAssets(attributeRefs).then((assets) => {
this.loadedAssets = assets;
+ }).finally(() => {
+ this._loading = false;
});
}
@@ -120,7 +126,11 @@ export class AttributeInputWidget extends OrAssetWidget {
const attribute = (config.attributeRefs.length > 0 && this.loadedAssets[0]?.attributes) ? this.loadedAssets[0].attributes[config.attributeRefs[0].name!] : undefined;
const readOnlyMetaItem = Util.getMetaValue(WellknownMetaItems.READONLY, attribute);
return html`
- ${when(config.attributeRefs.length > 0 && attribute && this.loadedAssets && this.loadedAssets.length > 0, () => {
+ ${when(this._loading, () => {
+ return html`
+ <or-loading-indicator></or-loading-indicator>
+ `;
+ }, () => when(config.attributeRefs.length > 0 && attribute && this.loadedAssets && this.loadedAssets.length > 0, () => {
return html`
<div id="widget-wrapper">
<or-attribute-input class="attr-input" fullWidth
@@ -132,12 +142,14 @@ export class AttributeInputWidget extends OrAssetWidget {
.hasHelperText="${config.showHelperText}"
></or-attribute-input>
</div>
- `
- }, () => html`
- <div style="height: 100%; display: flex; justify-content: center; align-items: center;">
- <span><or-translate value="noAttributesConnected"></or-translate></span>
- </div>
- `)}
+ `;
+ }, () => {
+ return html`
+ <div style="height: 100%; display: flex; justify-content: center; align-items: center;">
+ <span><or-translate value="noAttributesConnected"></or-translate></span>
+ </div>
+ `;
+ }))}
`;
}
}
diff --git a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts b/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts
index f7c88ccea..6bd183829 100644
--- a/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/chart-widget.ts
@@ -87,6 +87,9 @@ export class ChartWidget extends OrAssetWidget {
@state()
protected datapointQuery!: AssetDatapointQueryUnion;
+ @state()
+ protected _loading = false;
+
// Override of widgetConfig with extended type
protected widgetConfig!: ChartWidgetConfig;
@@ -141,39 +144,36 @@ export class ChartWidget extends OrAssetWidget {
if(changedProps.has('widgetConfig') && this.widgetConfig) {
this.datapointQuery = this.widgetConfig.datapointQuery;
- }
-
- return super.willUpdate(changedProps);
- }
-
- // WebComponent lifecycle method, that occurs AFTER every state update
- protected updated(changedProps: Map<string, any>) {
- super.updated(changedProps);
- // If widgetConfig, and the attributeRefs of them have changed...
- if(changedProps.has("widgetConfig") && this.widgetConfig) {
const attributeRefs = this.widgetConfig.attributeRefs;
const missingAssets = attributeRefs?.filter((attrRef: AttributeRef) => !this.isAttributeRefLoaded(attrRef));
if (missingAssets.length > 0) {
-
- // Fetch the new list of assets
- this.fetchAssets(attributeRefs).then((assets) => {
- this.loadedAssets = assets;
- this.assetAttributes = attributeRefs?.map((attrRef: AttributeRef) => {
- const assetIndex = assets.findIndex((asset) => asset.id === attrRef.id);
- const foundAsset = assetIndex >= 0 ? assets[assetIndex] : undefined;
- return foundAsset && foundAsset.attributes ? [assetIndex, foundAsset.attributes[attrRef.name!]] : undefined;
- }).filter((indexAndAttr: any) => !!indexAndAttr) as [number, Attribute<any>][];
- });
-
+ this.loadAssets(attributeRefs);
}
}
- return super.updated(changedProps);
+
+ return super.willUpdate(changedProps);
+ }
+
+ protected loadAssets(attributeRefs: AttributeRef[]) {
+ this._loading = true;
+ this.fetchAssets(attributeRefs).then((assets) => {
+ this.loadedAssets = assets;
+ this.assetAttributes = attributeRefs?.map((attrRef: AttributeRef) => {
+ const assetIndex = assets.findIndex((asset) => asset.id === attrRef.id);
+ const foundAsset = assetIndex >= 0 ? assets[assetIndex] : undefined;
+ return foundAsset && foundAsset.attributes ? [assetIndex, foundAsset.attributes[attrRef.name!]] : undefined;
+ }).filter((indexAndAttr: any) => !!indexAndAttr) as [number, Attribute<any>][];
+ }).finally(() => {
+ this._loading = false;
+ });
}
protected render(): TemplateResult {
return html`
- ${when(this.loadedAssets && this.assetAttributes && this.loadedAssets.length > 0 && this.assetAttributes.length > 0, () => {
+ ${when(this._loading, () => html`
+ <or-loading-indicator></or-loading-indicator>
+ `, () => when(this.loadedAssets && this.assetAttributes && this.loadedAssets.length > 0 && this.assetAttributes.length > 0, () => {
return html`
<or-chart .assets="${this.loadedAssets}" .assetAttributes="${this.assetAttributes}" .rightAxisAttributes="${this.widgetConfig.rightAxisAttributes}"
.showLegend="${(this.widgetConfig?.showLegend != null) ? this.widgetConfig?.showLegend : true}"
@@ -188,8 +188,8 @@ export class ChartWidget extends OrAssetWidget {
<div style="height: 100%; display: flex; justify-content: center; align-items: center;">
<span><or-translate value="noAttributesConnected"></or-translate></span>
</div>
- `
- })}
+ `;
+ }))}
`;
}
diff --git a/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts b/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts
index 91f816ad0..d0c47ebe0 100644
--- a/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/gateway-widget.ts
@@ -42,7 +42,7 @@ function getDefaultWidgetConfig(): GatewayWidgetConfig {
return {
type: GatewayTunnelInfoType.HTTPS,
target: "localhost",
- targetPort: 443,
+ targetPort: 443
};
}
@@ -98,7 +98,7 @@ export class GatewayWidget extends OrWidget {
super.disconnectedCallback();
}
- protected firstUpdated(_changedProps: PropertyValues) {
+ protected firstUpdated(changedProps: PropertyValues) {
if(this.widgetConfig) {
// Apply a timeout of 500 millis, so the tunnel has time to close upon disconnectedCallback() of a different widget.
@@ -117,8 +117,9 @@ export class GatewayWidget extends OrWidget {
this._loading = false;
});
- }, 500)
+ }, 500);
}
+ return super.firstUpdated(changedProps);
}
protected render(): TemplateResult {
diff --git a/ui/component/or-dashboard-builder/src/widgets/gauge-widget.ts b/ui/component/or-dashboard-builder/src/widgets/gauge-widget.ts
index 066193097..bf6b5c5dd 100644
--- a/ui/component/or-dashboard-builder/src/widgets/gauge-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/gauge-widget.ts
@@ -2,7 +2,7 @@ import {html, TemplateResult} from "lit";
import {customElement, state} from "lit/decorators.js";
import {OrAssetWidget} from "../util/or-asset-widget";
import {WidgetConfig} from "../util/widget-config";
-import {Asset, Attribute, AttributeRef} from "@openremote/model";
+import {Attribute, AttributeRef} from "@openremote/model";
import {OrWidget, WidgetManifest} from "../util/or-widget";
import {WidgetSettings} from "../util/widget-settings";
import {GaugeSettings} from "../settings/gauge-settings";
@@ -35,6 +35,9 @@ export class GaugeWidget extends OrAssetWidget {
// Override of widgetConfig with extended type
protected widgetConfig!: GaugeWidgetConfig;
+ @state()
+ protected _loading = false;
+
static getManifest(): WidgetManifest {
return {
displayName: "Gauge",
@@ -50,16 +53,15 @@ export class GaugeWidget extends OrAssetWidget {
getDefaultConfig(): GaugeWidgetConfig {
return getDefaultWidgetConfig();
}
- }
+ };
}
public refreshContent(force: boolean) {
this.loadAssets(this.widgetConfig.attributeRefs);
}
- // WebComponent lifecycle method, that occurs AFTER every state update
- protected updated(changedProps: Map<string, any>) {
- super.updated(changedProps);
+ // WebComponent lifecycle method, that occurs DURING every state update
+ protected willUpdate(changedProps: Map<string, any>) {
// If widgetConfig, and the attributeRefs of them have changed...
if(changedProps.has("widgetConfig") && this.widgetConfig) {
@@ -74,10 +76,11 @@ export class GaugeWidget extends OrAssetWidget {
}
}
- return super.updated(changedProps);
+ return super.willUpdate(changedProps);
}
protected loadAssets(attributeRefs: AttributeRef[]) {
+ this._loading = true;
this.fetchAssets(attributeRefs).then((assets) => {
this.loadedAssets = assets;
this.assetAttributes = attributeRefs?.map((attrRef: AttributeRef) => {
@@ -85,13 +88,19 @@ export class GaugeWidget extends OrAssetWidget {
const foundAsset = assetIndex >= 0 ? assets[assetIndex] : undefined;
return foundAsset && foundAsset.attributes ? [assetIndex, foundAsset.attributes[attrRef.name!]] : undefined;
}).filter((indexAndAttr: any) => !!indexAndAttr) as [number, Attribute<any>][];
+ }).finally(() => {
+ this._loading = false;
});
}
protected render(): TemplateResult {
return html`
- ${when(this.loadedAssets && this.assetAttributes && this.loadedAssets.length > 0 && this.assetAttributes.length > 0, () => {
+ ${when(this._loading, () => {
+ return html`
+ <or-loading-indicator></or-loading-indicator>
+ `;
+ }, () => when(this.loadedAssets && this.assetAttributes && this.loadedAssets.length > 0 && this.assetAttributes.length > 0, () => {
return html`
<or-gauge .asset="${this.loadedAssets[0]}" .assetAttribute="${this.assetAttributes[0]}" .thresholds="${this.widgetConfig.thresholds}"
.decimals="${this.widgetConfig.decimals}" .min="${this.widgetConfig.min}" .max="${this.widgetConfig.max}"
@@ -103,8 +112,8 @@ export class GaugeWidget extends OrAssetWidget {
<div style="height: 100%; display: flex; justify-content: center; align-items: center;">
<span><or-translate value="noAttributeConnected"></or-translate></span>
</div>
- `
- })}
+ `;
+ }))}
`;
}
diff --git a/ui/component/or-dashboard-builder/src/widgets/image-widget.ts b/ui/component/or-dashboard-builder/src/widgets/image-widget.ts
index a73aa7fef..b6f4570b5 100644
--- a/ui/component/or-dashboard-builder/src/widgets/image-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/image-widget.ts
@@ -101,7 +101,7 @@ export class ImageWidget extends OrAssetWidget {
return [...super.styles, styling];
}
- updated(changedProps: PropertyValues) {
+ willUpdate(changedProps: PropertyValues) {
if(changedProps.has('widgetConfig') && this.widgetConfig) {
const attributeRefs = this.widgetConfig.attributeRefs;
@@ -110,6 +110,8 @@ export class ImageWidget extends OrAssetWidget {
this.loadAssets();
}
}
+
+ return super.willUpdate(changedProps);
}
protected loadAssets() {
diff --git a/ui/component/or-dashboard-builder/src/widgets/kpi-widget.ts b/ui/component/or-dashboard-builder/src/widgets/kpi-widget.ts
index c3c5b4625..b3b49e9ae 100644
--- a/ui/component/or-dashboard-builder/src/widgets/kpi-widget.ts
+++ b/ui/component/or-dashboard-builder/src/widgets/kpi-widget.ts
@@ -1,4 +1,5 @@
-import { customElement } from "lit/decorators.js";
+import { customElement, state } from "lit/decorators.js";
+import { when } from "lit/directives/when.js";
import {OrAssetWidget} from "../util/or-asset-widget";
import {OrWidget, WidgetManifest} from "../util/or-widget";
import {WidgetSettings} from "../util/widget-settings";
@@ -31,6 +32,9 @@ export class KpiWidget extends OrAssetWidget {
protected widgetConfig!: KpiWidgetConfig;
+ @state()
+ protected _loading = false;
+
static getManifest(): WidgetManifest {
return {
displayName: "KPI",
@@ -53,8 +57,7 @@ export class KpiWidget extends OrAssetWidget {
this.loadAssets(this.widgetConfig.attributeRefs);
}
- protected updated(changedProps: Map<string, any>) {
- super.updated(changedProps);
+ protected willUpdate(changedProps: Map<string, any>) {
// If widgetConfig, and the attributeRefs of them have changed...
if(changedProps.has("widgetConfig") && this.widgetConfig) {
@@ -69,10 +72,11 @@ export class KpiWidget extends OrAssetWidget {
}
}
- return super.updated(changedProps);
+ return super.willUpdate(changedProps);
}
protected loadAssets(attributeRefs: AttributeRef[]) {
+ this._loading = true;
this.fetchAssets(attributeRefs).then((assets) => {
this.loadedAssets = assets;
this.assetAttributes = attributeRefs?.map((attrRef: AttributeRef) => {
@@ -80,12 +84,22 @@ export class KpiWidget extends OrAssetWidget {
const foundAsset = assetIndex >= 0 ? assets[assetIndex] : undefined;
return foundAsset && foundAsset.attributes ? [assetIndex, foundAsset.attributes[attrRef.name!]] : undefined;
}).filter((indexAndAttr: any) => !!indexAndAttr) as [number, Attribute<any>][];
+ }).finally(() => {
+ this._loading = false;
});
}
protected render(): TemplateResult {
return html`
- <div style="height: 100%; overflow: hidden;">
+ <div style="position: relative; height: 100%; overflow: hidden;">
+ ${when(this._loading, () => {
+ // Have to use `position: absolute` with white background due to rendering inconsistencies in or-attribute-card
+ return html`
+ <div style="position: absolute; top: -5%; width: 100%; height: 105%; background: white; z-index: 1;">
+ <or-loading-indicator></or-loading-indicator>
+ </div>
+ `;
+ })}
<or-attribute-card .assets="${this.loadedAssets}" .assetAttributes="${this.assetAttributes}" .period="${this.widgetConfig.period}"
.deltaFormat="${this.widgetConfig.deltaFormat}" .mainValueDecimals="${this.widgetConfig.decimals}"
showControls="${this.widgetConfig?.showTimestampControls}" showTitle="${false}" style="height: 100%;">