[ADF-5085] Adding possibility to search for future dates search-date-range component (#5525)

* [ADF-5085] Remove maxDate and set the max of the from date to the to date

* [ADF-5085] Add maxDate optional setting

* [ADF-5085] Add unit test for maxDate

* [ADF-5085] Add documentation for maxDate setting

* [ADF-5085] Unit tests for default and today value

* [ADF-5085] Refactor
This commit is contained in:
Baptiste Mahé
2020-03-04 11:29:29 +00:00
committed by GitHub
parent 24c728a8f5
commit b3d8fb9609
5 changed files with 56 additions and 9 deletions

View File

@@ -54,9 +54,8 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
id: string;
settings?: SearchWidgetSettings;
context?: SearchQueryBuilderService;
maxDate: any;
datePickerDateFormat = DEFAULT_FORMAT_DATE;
maxDate: any;
private onDestroy$ = new Subject<boolean>();
constructor(private dateAdapter: DateAdapter<Moment>,
@@ -102,7 +101,13 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
to: this.to
});
this.maxDate = this.dateAdapter.today().startOf('day');
if (this.settings && this.settings.maxDate) {
if (this.settings.maxDate === 'today') {
this.maxDate = this.dateAdapter.today().endOf('day');
} else {
this.maxDate = moment(this.settings.maxDate).endOf('day');
}
}
}
ngOnDestroy() {
@@ -161,4 +166,13 @@ export class SearchDateRangeComponent implements SearchWidget, OnInit, OnDestroy
event.srcElement.click();
}
getFromMaxDate(): any {
let maxDate: string;
if (!this.to.value || this.maxDate && (moment(this.maxDate).isBefore(this.to.value))) {
maxDate = this.maxDate;
} else {
maxDate = moment(this.to.value);
}
return maxDate;
}
}