2020-02-17 15:19:14 +01:00
|
|
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
|
|
|
import { RangeFilter } from './rangeFilterHelperClasses.class';
|
|
|
|
import { Dates } from "../string-utils.class";
|
2020-10-20 11:11:15 +02:00
|
|
|
import {ActivatedRoute, Router} from "@angular/router";
|
|
|
|
import {Filter, Value} from "../../searchPages/searchUtils/searchHelperClasses.class";
|
|
|
|
import {properties} from "../../../../environments/environment";
|
2020-02-17 15:19:14 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'range-filter',
|
|
|
|
templateUrl: 'rangeFilter.component.html'
|
|
|
|
})
|
|
|
|
|
|
|
|
export class RangeFilterComponent {
|
|
|
|
|
|
|
|
@Input() filter:RangeFilter;
|
|
|
|
@Input() isDisabled:boolean = false;
|
2020-05-14 16:38:50 +02:00
|
|
|
@Input() showQuickButtons:boolean = true;
|
2020-02-17 15:19:14 +01:00
|
|
|
public _maxCharacters:number =28;
|
|
|
|
public focusedInput: string = "";
|
2020-07-10 10:16:58 +02:00
|
|
|
@Input() yearMin: number = Dates.yearMin;
|
|
|
|
@Input() yearMax: number = Dates.yearMax;
|
|
|
|
@Input() mandatoryRange:boolean = false;
|
2020-02-24 14:38:08 +01:00
|
|
|
public currentYear: number = Dates.currentYear;
|
2020-02-17 15:19:14 +01:00
|
|
|
|
|
|
|
@Output() onFilterChange = new EventEmitter();
|
2020-10-20 11:11:15 +02:00
|
|
|
@Input() actionRoute:boolean = false;
|
|
|
|
queryParams = {};
|
|
|
|
constructor(private _router: Router, private route: ActivatedRoute) {}
|
2020-02-17 15:19:14 +01:00
|
|
|
|
2020-10-20 11:11:15 +02:00
|
|
|
ngOnInit() {
|
|
|
|
this.route.queryParams.subscribe(params => {
|
|
|
|
this.queryParams = Object.assign({}, params);
|
|
|
|
});
|
|
|
|
}
|
2020-02-17 15:19:14 +01:00
|
|
|
|
|
|
|
public _formatTitle(title){
|
|
|
|
return ((title.length > this._maxCharacters)?(title.substring(0,(this._maxCharacters - ('...').length))+"..."):title);
|
|
|
|
}
|
|
|
|
|
2020-02-24 14:38:08 +01:00
|
|
|
yearChanged(yearsSelected: number = null){
|
|
|
|
if(yearsSelected != null) {
|
|
|
|
this.filter.selectedFromValue = (this.currentYear - yearsSelected) + "";
|
|
|
|
this.filter.selectedToValue = this.currentYear + "";
|
|
|
|
}
|
2020-02-17 15:19:14 +01:00
|
|
|
this.onFilterChange.emit({
|
|
|
|
value: this.filter
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
clearFilter() {
|
|
|
|
this.filter.selectedFromValue = null;
|
|
|
|
this.filter.selectedToValue = null;
|
|
|
|
this.onFilterChange.emit({
|
|
|
|
value: this.filter
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
getFilterName(value){
|
|
|
|
let name = value.name +" ("+ value.number.format()+")";
|
|
|
|
return name;
|
|
|
|
}
|
2020-03-16 11:06:47 +01:00
|
|
|
|
|
|
|
stringToNum(value: string): number {
|
|
|
|
return +(value);
|
|
|
|
}
|
2020-10-20 11:11:15 +02:00
|
|
|
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){
|
|
|
|
params['year'] = 'range'+(this.currentYear - year) + ':'+ this.currentYear;
|
|
|
|
}else{
|
|
|
|
delete params['year'];
|
|
|
|
}
|
2020-10-20 15:49:53 +02:00
|
|
|
|
|
|
|
delete params['page'];
|
2020-10-20 11:11:15 +02:00
|
|
|
return params;
|
|
|
|
}
|
2020-02-17 15:19:14 +01:00
|
|
|
}
|