openaire-library/utils/rangeFilter/rangeFilter.component.ts

59 lines
1.5 KiB
TypeScript

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;
@Input() showQuickButtons:boolean = true;
public _maxCharacters:number =28;
public focusedInput: string = "";
@Input() yearMin: number = Dates.yearMin;
@Input() yearMax: number = Dates.yearMax;
@Input() mandatoryRange:boolean = false;
public currentYear: number = Dates.currentYear;
@Output() onFilterChange = new EventEmitter();
constructor() {}
ngOnInit() {}
public _formatTitle(title){
return ((title.length > this._maxCharacters)?(title.substring(0,(this._maxCharacters - ('...').length))+"..."):title);
}
yearChanged(yearsSelected: number = null){
if(yearsSelected != null) {
this.filter.selectedFromValue = (this.currentYear - yearsSelected) + "";
this.filter.selectedToValue = this.currentYear + "";
}
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;
}
stringToNum(value: string): number {
return +(value);
}
}