From 46d9fe9abbae49a57e72cc2e4e628be65e4c6eeb Mon Sep 17 00:00:00 2001 From: "k.triantafyllou" Date: Mon, 1 Aug 2022 22:26:01 +0300 Subject: [PATCH] Fix range filter initialization --- utils/rangeFilter/rangeFilter.component.html | 2 +- utils/rangeFilter/rangeFilter.component.ts | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/utils/rangeFilter/rangeFilter.component.html b/utils/rangeFilter/rangeFilter.component.html index 0ea1dedf..5159299d 100644 --- a/utils/rangeFilter/rangeFilter.component.html +++ b/utils/rangeFilter/rangeFilter.component.html @@ -10,7 +10,7 @@
-
+
- diff --git a/utils/rangeFilter/rangeFilter.component.ts b/utils/rangeFilter/rangeFilter.component.ts index 193d2de4..77ad9697 100644 --- a/utils/rangeFilter/rangeFilter.component.ts +++ b/utils/rangeFilter/rangeFilter.component.ts @@ -3,7 +3,7 @@ import {RangeFilter} from './rangeFilterHelperClasses.class'; import {Dates, StringUtils} from "../string-utils.class"; import {ActivatedRoute, Router} from "@angular/router"; import {properties} from "../../../../environments/environment"; -import {FormBuilder} from "@angular/forms"; +import {FormBuilder, FormGroup} from "@angular/forms"; @Component({ selector: 'range-filter', @@ -23,7 +23,7 @@ export class RangeFilterComponent { public currentYear: number = Dates.currentYear; public yearValidators = [StringUtils.inValidYearValidator(this.yearMin, this.yearMax)]; public formValidators = [StringUtils.fromYearAfterToYearValidator]; - public rangeForm; + public rangeForm: FormGroup; @Output() onFilterChange = new EventEmitter(); @Input() actionRoute:boolean = false; @@ -51,6 +51,8 @@ export class RangeFilterComponent { if(yearsSelected != null) { this.filter.selectedFromValue = (this.currentYear - yearsSelected) + ""; this.filter.selectedToValue = this.currentYear + ""; + this.rangeForm.get('yearFrom').setValue(this.filter.selectedFromValue); + this.rangeForm.get('yearTo').setValue(this.filter.selectedToValue); } else { this.filter.selectedFromValue = this.rangeForm.get('yearFrom').value; this.filter.selectedToValue = this.rangeForm.get('yearTo').value; @@ -63,25 +65,26 @@ export class RangeFilterComponent { clearFilter() { this.filter.selectedFromValue = null; this.filter.selectedToValue = null; + this.rangeForm.get('yearFrom').setValue(this.filter.selectedFromValue); + this.rangeForm.get('yearTo').setValue(this.filter.selectedToValue); + console.log(this.rangeForm); this.onFilterChange.emit({ value: this.filter }); } getFilterName(value){ - let name = value.name +" ("+ value.number.format()+")"; - return name; + return value.name + " (" + value.number.format() + ")"; } stringToNum(value: string): number { return +(value); } - getFilterUrl(year:number, selected:boolean){ - return properties.baseLink + (this._router.url.indexOf('year=range') == -1 ? this._router.url: (this._router.url.split("year=range"+this.filter.selectedFromValue+':'+this.filter.selectedToValue).join(''))) + (selected ? '' : (this._router.url.indexOf('?')!=-1?'&':'?') +'year=range'+(this.currentYear - year) + ':'+ this.currentYear); - } + getRoute(){ return properties.baseLink + this._router.url.split("?")[0]; } + getParams(year:number, selected:boolean){ let params = Object.assign({}, this.queryParams); if(!selected){