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";
|
|
|
|
|
|
|
|
@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();
|
|
|
|
|
|
|
|
constructor() {}
|
|
|
|
|
|
|
|
ngOnInit() {}
|
|
|
|
|
|
|
|
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-02-17 15:19:14 +01:00
|
|
|
}
|