Skip to content
This repository has been archived by the owner on Aug 21, 2023. It is now read-only.

Create and use HISTORIC_RANGE_DEFAULT in extra params components #15

Merged
merged 3 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/lib/modules/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export { ClimateModel } from './models/climate-model.model';
export { DataPoint } from './models/data-point.model';
export { Dataset } from './models/dataset.model';
export { HistoricIndicatorQueryParams } from './models/historic-indicator-query-params.model';
export { HistoricRange } from './models/historic-range.model';
export { HistoricRange, HISTORIC_RANGE_DEFAULT } from './models/historic-range.model';
export { IndicatorParameter } from './models/indicator-parameter.model';
export { IndicatorQueryParams } from './models/indicator-query-params.model';
export { IndicatorRequestOpts } from './models/indicator-request-opts.model';
Expand Down
2 changes: 2 additions & 0 deletions src/lib/modules/api/models/historic-range.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export const HISTORIC_RANGE_DEFAULT = '1971';

export interface HistoricRange {
start_year: string;
end_year: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AfterViewInit, Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';

import { HistoricRange } from '../../../api/models/historic-range.model';
import { HistoricRange, HISTORIC_RANGE_DEFAULT } from '../../../api/models/historic-range.model';
import { HistoricIndicatorQueryParams } from '../../../api/models/historic-indicator-query-params.model';
import { HistoricRangeService } from '../../../api/services/historic-range.service';
import { Indicator } from '../../../api/models/indicator.model';
Expand All @@ -23,9 +23,6 @@ export class HistoricComponent implements AfterViewInit, OnInit {
historicForm: FormGroup;
public historicRangeOptions: string[] = [];

// default form values
private defaultHistoric = null;

constructor(private formBuilder: FormBuilder,
private historicRangeService: HistoricRangeService) {}

Expand All @@ -45,7 +42,7 @@ export class HistoricComponent implements AfterViewInit, OnInit {

createForm() {
this.historicForm = this.formBuilder.group({
historicCtl: [this.extraParams.historic_range || this.defaultHistoric],
historicCtl: [this.extraParams.historic_range || HISTORIC_RANGE_DEFAULT],
});

this.historicForm.valueChanges.debounceTime(700).subscribe(form => {
Expand All @@ -58,8 +55,6 @@ export class HistoricComponent implements AfterViewInit, OnInit {
getHistoricRanges() {
this.historicRangeService.list().subscribe(data => {
this.historicRangeOptions = data.map(h => h.start_year);
// add empty option, as this is not a required parameter
this.historicRangeOptions.unshift('');
});
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AfterViewInit, Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';

import { HistoricRange } from '../../../api/models/historic-range.model';
import { HistoricRange, HISTORIC_RANGE_DEFAULT } from '../../../api/models/historic-range.model';
import { PercentileHistoricIndicatorQueryParams } from '../../../api/models/percentile-historic-indicator-query-params.model';
import { HistoricRangeService } from '../../../api/services/historic-range.service';
import { Indicator } from '../../../api/models/indicator.model';
Expand All @@ -24,7 +24,6 @@ export class PercentileHistoricComponent implements AfterViewInit, OnInit {
public historicRangeOptions: string[] = [];

// default form values
private defaultHistoric = null;
private defaultPercentile = 50;

constructor(private formBuilder: FormBuilder,
Expand All @@ -47,7 +46,7 @@ export class PercentileHistoricComponent implements AfterViewInit, OnInit {

createForm() {
this.percentileHistoricForm = this.formBuilder.group({
historicCtl: [this.extraParams.historic_range || this.defaultHistoric],
historicCtl: [this.extraParams.historic_range || HISTORIC_RANGE_DEFAULT],
percentileCtl: [this.extraParams.percentile || this.defaultPercentile, Validators.required]
});

Expand All @@ -66,8 +65,6 @@ export class PercentileHistoricComponent implements AfterViewInit, OnInit {
getHistoricRanges() {
this.historicRangeService.list().subscribe(data => {
this.historicRangeOptions = data.map(h => h.start_year);
// add empty option, as this is not a required parameter
this.historicRangeOptions.unshift('');
});
}
}