Skip to content

armgit / core

Public Imported from GitHub
0

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

use config to render card

Vincente40287af3b92
diff --git a/ui/app/main/src/components/pages/page-insights.ts b/ui/app/main/src/components/pages/page-insights.ts
index e3eee2b4b..d1b073bac 100644
--- a/ui/app/main/src/components/pages/page-insights.ts
+++ b/ui/app/main/src/components/pages/page-insights.ts
@@ -110,8 +110,8 @@ const viewerConfig: DataViewerConfig = {
gridRowStart: "1"
},
defaults: [{
- assetId:"5442Ite2XVp3Ky9X2y647a",
- attributes: ["UVIndex"]
+ assetId:"4m4dWZUAV4IepHKc8Wwv85",
+ attributes: ["light1PowerConsumption"]
}]
}
}
@@ -125,7 +125,7 @@ class PageInsights extends connect(store)(LitElement) {
}
@property()
- protected _assetId;
+ private _assetId: string = "";
protected render(): TemplateResult | void {
@@ -137,7 +137,7 @@ class PageInsights extends connect(store)(LitElement) {
<div class="row">
<or-data-viewer .config="${viewerConfig}"></or-data-viewer>
</div>
- <or-attribute-card .assetId="${this._assetId}" .attributeName="${attributeName}"></or-attribute-card>
+ <or-attribute-card .assetId="${viewerConfig.panels["chart"].defaults[0].assetId}" .attributeName="${viewerConfig.panels["chart"].defaults[0].attributes[0]}"></or-attribute-card>
</div>
</div>
`;
diff --git a/ui/component/or-attribute-card/src/index.ts b/ui/component/or-attribute-card/src/index.ts
index c36bbb28a..6519b0ad4 100644
--- a/ui/component/or-attribute-card/src/index.ts
+++ b/ui/component/or-attribute-card/src/index.ts
@@ -93,10 +93,10 @@ const style = css`
export class OrAttributeCard extends LitElement {
@property()
- public assetId: string = "";
+ public assetId!: string;
@property()
- public attributeName: string = "";
+ public attributeName!: string;
@property()
private data: ValueDatapoint<any>[] = [];
@@ -285,8 +285,6 @@ export class OrAttributeCard extends LitElement {
protected async getData() {
const thisMoment = moment(this.now);
- this.asset = await this.getAssetById(this.assetId);
-
const currentPeriod = {
start: thisMoment.startOf(this.period).toDate().getTime(),
end: thisMoment.endOf(this.period).toDate().getTime()
@@ -296,14 +294,14 @@ export class OrAttributeCard extends LitElement {
end: thisMoment.clone().subtract(1, this.period).endOf(this.period).toDate().getTime()
};
- const p1 = this.getDatapointsByAttribute(this.asset.id!, currentPeriod.start, currentPeriod.end)
+ const p1 = this.getDatapointsByAttribute(this.assetId, currentPeriod.start, currentPeriod.end)
.then((datapoints: ValueDatapoint<any>[]) => {
this.data = datapoints || [];
this.mainValue = this.getHighestValue(this.sanitizeDataPoints(this.data));
return this.mainValue;
});
- const p2 = this.getDatapointsByAttribute(this.asset.id!, lastPeriod.start, lastPeriod.end)
+ const p2 = this.getDatapointsByAttribute(this.assetId, lastPeriod.start, lastPeriod.end)
.then((datapoints: ValueDatapoint<any>[]) => {
this.mainValueLastPeriod = this.getHighestValue(this.sanitizeDataPoints(datapoints));
return this.mainValueLastPeriod;