From 8f993e10e47e03f01bc15e6e996ddb264389c4f3 Mon Sep 17 00:00:00 2001 From: Jenny Fung Date: Fri, 1 Sep 2017 13:14:32 -0400 Subject: [PATCH] Clean up after model refactor rebase, PR #231 --- src/app/charts/chart.component.html | 8 +++++++- .../basetemp.component.html | 5 +++-- .../basetemp.component.ts | 19 ++++++++++++------- .../extra-params.constants.ts | 7 +------ src/app/charts/line-graph.component.ts | 2 +- src/app/login/login.component.spec.ts | 2 +- ... basetemp-indicator-query-params.model.ts} | 0 src/app/services/indicator.service.ts | 10 +++++----- 8 files changed, 30 insertions(+), 23 deletions(-) rename src/app/models/{basetemp-indicator-query-opts.model.ts => basetemp-indicator-query-params.model.ts} (100%) diff --git a/src/app/charts/chart.component.html b/src/app/charts/chart.component.html index c8eba25c..15d910ec 100644 --- a/src/app/charts/chart.component.html +++ b/src/app/charts/chart.component.html @@ -10,7 +10,13 @@

(thresholdParamSelected)="onThresholdSelected($event)"> - +
+ + +
diff --git a/src/app/charts/extra-params-components/basetemp.component.html b/src/app/charts/extra-params-components/basetemp.component.html index cfd1f6dd..bc1d2915 100644 --- a/src/app/charts/extra-params-components/basetemp.component.html +++ b/src/app/charts/extra-params-components/basetemp.component.html @@ -4,9 +4,10 @@ Show {{indicator.label | lowercase}} with base temperature
+ step="1" + formControlName="basetempCtl">
- diff --git a/src/app/charts/extra-params-components/basetemp.component.ts b/src/app/charts/extra-params-components/basetemp.component.ts index 84aaff09..ba058165 100644 --- a/src/app/charts/extra-params-components/basetemp.component.ts +++ b/src/app/charts/extra-params-components/basetemp.component.ts @@ -2,6 +2,7 @@ import { AfterViewInit, Component, EventEmitter, Input, Output, OnInit } from '@ import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import { Indicator } from '../../models/indicator.model'; +import { BasetempIndicatorQueryParams } from '../../models/basetemp-indicator-query-params.model'; import * as _ from 'lodash'; @@ -16,7 +17,8 @@ import * as _ from 'lodash'; export class BasetempComponent implements AfterViewInit, OnInit { @Input() indicator: Indicator; - @Input() extraParams: any; + @Input() extraParams: BasetempIndicatorQueryParams; + @Output() basetempParamSelected = new EventEmitter(); basetempForm: FormGroup; @@ -24,7 +26,11 @@ export class BasetempComponent implements AfterViewInit, OnInit { private defaultBasetemp = 50; private defaultBasetempUnit = 'F'; - @Output() basetempParamSelected = new EventEmitter(); + public basetempUnits: any[] = [ + {'key': 'K', 'label': 'Kelvin'}, + {'key': 'F', 'label': 'Farenheit'}, + {'key': 'C', 'label': 'Centigrade'} + ]; constructor(private formBuilder: FormBuilder) {} @@ -36,10 +42,10 @@ export class BasetempComponent implements AfterViewInit, OnInit { ngAfterViewInit() { // Since valueChanges triggers initially before parent is ready, wait until // parent is ready here and trigger it to draw chart with extra parameters. - this.basetempParamSelected.emit({data: { + this.basetempParamSelected.emit({ 'basetemp': this.basetempForm.controls.basetempCtl.value, 'basetemp_units': this.basetempForm.controls.basetempUnitCtl.value - }}); + }); } createForm() { @@ -49,11 +55,10 @@ export class BasetempComponent implements AfterViewInit, OnInit { }); this.basetempForm.valueChanges.debounceTime(700).subscribe(form => { - this.basetempParamSelected.emit({data: { - 'event': event, + this.basetempParamSelected.emit({ 'basetemp': form.basetempCtl, 'basetemp_units': form.basetempUnitCtl - }}); + }); }); } } \ No newline at end of file diff --git a/src/app/charts/extra-params-components/extra-params.constants.ts b/src/app/charts/extra-params-components/extra-params.constants.ts index 38f38772..6f418245 100644 --- a/src/app/charts/extra-params-components/extra-params.constants.ts +++ b/src/app/charts/extra-params-components/extra-params.constants.ts @@ -15,12 +15,7 @@ const basetempIndicatorNames = [ const extraParamsIndicatorNames = thresholdIndicatorNames; export function isBasetempIndicator(indicatorName: string): boolean { - for (const basetempName of basetempIndicatorNames) { - if (indicatorName === basetempName) { - return true; - } - } - return false; + return basetempIndicatorNames.indexOf(indicatorName) !== -1; } export function isThresholdIndicator(indicatorName: string): boolean { diff --git a/src/app/charts/line-graph.component.ts b/src/app/charts/line-graph.component.ts index 6da5b64a..f11bf860 100644 --- a/src/app/charts/line-graph.component.ts +++ b/src/app/charts/line-graph.component.ts @@ -115,7 +115,7 @@ export class LineGraphComponent implements OnChanges, AfterContentInit { /* Will setup the chart basics */ private setup(): void { - this.margin = { top: 10, right: 40, bottom: 30, left: 50 }; + this.margin = { top: 10, right: 50, bottom: 30, left: 60 }; this.width = $('.chart').width() - this.margin.left - this.margin.right; this.height = $('.line-graph').height() - this.margin.top - this.margin.bottom; this.xScale = D3.scaleTime().range([0, this.width]); diff --git a/src/app/login/login.component.spec.ts b/src/app/login/login.component.spec.ts index afdab36a..60cc5cf3 100644 --- a/src/app/login/login.component.spec.ts +++ b/src/app/login/login.component.spec.ts @@ -31,7 +31,7 @@ import { } from '../lab'; import { ThresholdComponent, - BasetempComponent } from '../charts/extra-params-components/threshold.component'; + BasetempComponent } from '../charts/extra-params-components'; import { NavbarComponent } from '../navbar/navbar.component'; import { DashboardComponent } from '../dashboard/dashboard.component'; diff --git a/src/app/models/basetemp-indicator-query-opts.model.ts b/src/app/models/basetemp-indicator-query-params.model.ts similarity index 100% rename from src/app/models/basetemp-indicator-query-opts.model.ts rename to src/app/models/basetemp-indicator-query-params.model.ts diff --git a/src/app/services/indicator.service.ts b/src/app/services/indicator.service.ts index f4ab2f7c..fec063a0 100644 --- a/src/app/services/indicator.service.ts +++ b/src/app/services/indicator.service.ts @@ -8,7 +8,7 @@ import { Indicator } from '../models/indicator.model'; import { IndicatorRequestOpts } from '../models/indicator-request-opts.model'; import { ThresholdIndicatorQueryParams } from '../models/threshold-indicator-query-params.model'; import { BasetempIndicatorQueryParams } from '../models/basetemp-indicator-query-params.model'; -import { IndicatorQueryParams } from '../models/indicator-query-params.model';\ +import { IndicatorQueryParams } from '../models/indicator-query-params.model'; import { ApiHttp } from '../auth/api-http.service'; import { apiHost } from '../constants'; @@ -46,13 +46,13 @@ export class IndicatorService { // append extra parameters, if needed if (isBasetempIndicator(options.indicator.name)) { - const basetempOpts: BasetempIndicatorQueryOpts = options; + const basetempOpts = options.params as BasetempIndicatorQueryParams; // abort request if chart is in flux (these parameters are required) - if (!basetempOpts.params.basetemp) { + if (!basetempOpts.basetemp) { return Observable.of({url: ''}); } - searchParams.append('basetemp', basetempOpts.params.basetemp.toString()); - searchParams.append('basetemp_units', basetempOpts.params.basetemp_units); + searchParams.append('basetemp', basetempOpts.basetemp.toString()); + searchParams.append('basetemp_units', basetempOpts.basetemp_units); } if (options.params.years) {