Skip to content

Commit

Permalink
fix: avoid chart settings api call for anonymous user (#139)
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy authored Apr 19, 2021
1 parent e1f690a commit f827e71
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions src/app/item-detail/analyze-charts/analyze-charts.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Component, Input, OnInit } from '@angular/core';
import { customChartSettings } from 'src/app/graphs/item-detail';
import * as Highcharts from 'highcharts';
import { ItemsApiService } from 'src/app/items-api.service';
import { Observable } from 'rxjs';

@Component({
selector: 'app-analyze-charts',
Expand All @@ -13,6 +12,7 @@ export class AnalyzeChartsComponent implements OnInit {

@Input() params: { projectName: string, scenarioName: string, id: string };
@Input() chartLines: ChartLines;
@Input() isAnonymous: boolean;
Highcharts: typeof Highcharts = Highcharts;
customChartsOptions = {
...customChartSettings(), series: []
Expand All @@ -34,12 +34,15 @@ export class AnalyzeChartsComponent implements OnInit {
}

ngOnInit() {
if (this.isAnonymous) {
return;
}
this.itemApiService
.fetchItemChartSettings(this.params.projectName, this.params.scenarioName, this.params.id)
.subscribe(_ => {
this.updateChart(_);
this.preloadedSeries = _;
});
.fetchItemChartSettings(this.params.projectName, this.params.scenarioName, this.params.id)
.subscribe(_ => {
this.updateChart(_);
this.preloadedSeries = _;
});
}

chartUpdated(event: [{ name: string, metric: string }]) {
Expand Down Expand Up @@ -80,6 +83,9 @@ export class AnalyzeChartsComponent implements OnInit {
}

private saveChartSettings(event) {
if (this.isAnonymous) {
return;
}
this.itemApiService.upsertItemChartSettings(
this.params.projectName,
this.params.scenarioName,
Expand Down
2 changes: 1 addition & 1 deletion src/app/item-detail/item-detail.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ <h6 class="card-header bg-transparent">Overall Chart</h6>
<ng-template ngbNavContent>
<div class="row chart-fix charts">
<div class="col">
<app-analyze-charts [chartLines]="chartLines" [params]="itemParams"></app-analyze-charts>
<app-analyze-charts [chartLines]="chartLines" [params]="itemParams" [isAnonymous]="isAnonymous"></app-analyze-charts>
</div>
</div>

Expand Down

0 comments on commit f827e71

Please sign in to comment.