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 all commits
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
- PercentileHistoricComponent and HistoricComponent now automatically choose a sensible dropdown
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would have preferred something more specific than "sensible", i.e., explicitly match the default from the API.

default for the historic baseline parameter

## [0.2.1] - 2017-11-07
### Added
Expand Down
1 change: 1 addition & 0 deletions src/lib/modules/api/models/historic-range.model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

export interface HistoricRange {
start_year: string;
end_year: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ export class HistoricComponent implements AfterViewInit, OnInit {
@Output() historicParamSelected = new EventEmitter<HistoricIndicatorQueryParams>();

historicForm: FormGroup;
public historicRangeOptions: string[] = [];

// default form values
private defaultHistoric = null;
public historicRangeOptions: number[] = [];

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],
});

this.historicForm.valueChanges.debounceTime(700).subscribe(form => {
Expand All @@ -57,9 +54,11 @@ 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('');
this.historicRangeOptions = data.map(h => parseInt(h.start_year, 10));
if (!this.extraParams.historic_range) {
const latestHistoricRange = Math.max(...this.historicRangeOptions);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ellipsis for an array builder, neat

this.historicForm.setValue({historicCtl: latestHistoricRange});
}
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,9 @@ export class PercentileHistoricComponent implements AfterViewInit, OnInit {
@Output() percentileHistoricParamSelected = new EventEmitter<PercentileHistoricIndicatorQueryParams>();

percentileHistoricForm: FormGroup;
public historicRangeOptions: string[] = [];
public historicRangeOptions: number[] = [];

// 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],
percentileCtl: [this.extraParams.percentile || this.defaultPercentile, Validators.required]
});

Expand All @@ -65,9 +64,14 @@ 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('');
this.historicRangeOptions = data.map(h => parseInt(h.start_year, 10));
if (!this.extraParams.historic_range) {
const latestHistoricRange = Math.max(...this.historicRangeOptions);
this.percentileHistoricForm.setValue({
historicCtl: latestHistoricRange,
percentileCtl: this.percentileHistoricForm.controls.percentileCtl.value
});
}
});
}
}