Fix range filter initialization

This commit is contained in:
Konstantinos Triantafyllou 2022-08-01 22:26:01 +03:00
parent 5cb7bc7cca
commit 46d9fe9abb
2 changed files with 11 additions and 8 deletions

View File

@ -10,7 +10,7 @@
<div>
<div class = "uk-animation-fade filterItem searchFilterItem uk-text-small">
<div class="searchFilterBoxValues ">
<form [class]="(isDisabled ? 'uk-disabled' : '') + ' uk-flex uk-flex-middle uk-flex-wrap'" [formGroup]="rangeForm" >
<form [class]="(isDisabled ? 'uk-disabled' : '') + ' uk-flex uk-flex-middle uk-flex-wrap'" [formGroup]="rangeForm">
<div input [formInput]="rangeForm.get('yearFrom')" [placeholder]="{label: 'e.g. ' + yearMin, static: true}"
inputClass="inner small" class=" uk-width-1-3"></div>
<span class="uk-margin-small-left uk-margin-small-right">-</span>

View File

@ -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){