From 399a2450ffb75bbb2415097291d017ba176079e7 Mon Sep 17 00:00:00 2001 From: Jason Kulatunga Date: Mon, 16 May 2022 19:19:36 -0700 Subject: [PATCH] make sure we can change the temperature duration key for the chart. --- .../dashboard/dashboard.component.html | 11 +++---- .../modules/dashboard/dashboard.component.ts | 29 ++++++++++++++++++- .../modules/dashboard/dashboard.resolvers.ts | 2 +- .../modules/dashboard/dashboard.service.ts | 12 +++++++- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/webapp/frontend/src/app/modules/dashboard/dashboard.component.html b/webapp/frontend/src/app/modules/dashboard/dashboard.component.html index 8e321c4..7c517b9 100644 --- a/webapp/frontend/src/app/modules/dashboard/dashboard.component.html +++ b/webapp/frontend/src/app/modules/dashboard/dashboard.component.html @@ -126,19 +126,20 @@ matTooltip="not yet implemented" mat-button [matMenuTriggerFor]="tempRangeMenu"> - 1 week + {{tempDurationKey}} - - - + + + +
- ; + @ViewChild("tempChart", { static: false }) tempChart: ChartComponent; /** * Constructor @@ -283,6 +285,31 @@ export class DashboardComponent implements OnInit, AfterViewInit, OnDestroy } } + /* + + DURATION_KEY_WEEK = "week" + DURATION_KEY_MONTH = "month" + DURATION_KEY_YEAR = "year" + DURATION_KEY_FOREVER = "forever" + */ + + changeSummaryTempDuration(durationKey: string){ + this.tempDurationKey = durationKey + + this._smartService.getSummaryTempData(durationKey) + .subscribe((data) => { + + // given a list of device temp history, override the data in the "summary" object. + for(const wwn in this.data.data.summary) { + // console.log(`Updating ${wwn}, length: ${this.data.data.summary[wwn].temp_history.length}`) + this.data.data.summary[wwn].temp_history = data.data.temp_history[wwn] || [] + } + + // Prepare the chart series data + this.tempChart.updateSeries(this._deviceDataTemperatureSeries()) + }); + } + /** * Track by function for ngFor loops * diff --git a/webapp/frontend/src/app/modules/dashboard/dashboard.resolvers.ts b/webapp/frontend/src/app/modules/dashboard/dashboard.resolvers.ts index 419105b..eb29b48 100644 --- a/webapp/frontend/src/app/modules/dashboard/dashboard.resolvers.ts +++ b/webapp/frontend/src/app/modules/dashboard/dashboard.resolvers.ts @@ -31,6 +31,6 @@ export class DashboardResolver implements Resolve */ resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable { - return this._dashboardService.getData(); + return this._dashboardService.getSummaryData(); } } diff --git a/webapp/frontend/src/app/modules/dashboard/dashboard.service.ts b/webapp/frontend/src/app/modules/dashboard/dashboard.service.ts index f73704c..ed91799 100644 --- a/webapp/frontend/src/app/modules/dashboard/dashboard.service.ts +++ b/webapp/frontend/src/app/modules/dashboard/dashboard.service.ts @@ -44,7 +44,7 @@ export class DashboardService /** * Get data */ - getData(): Observable + getSummaryData(): Observable { return this._httpClient.get(getBasePath() + '/api/summary').pipe( tap((response: any) => { @@ -52,4 +52,14 @@ export class DashboardService }) ); } + + getSummaryTempData(durationKey: string): Observable + { + let params = {} + if(durationKey){ + params["duration_key"] = durationKey + } + + return this._httpClient.get(getBasePath() + '/api/summary/temp', {params: params}); + } }