2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
|
|
|
|
import { Filter, Value} from './searchHelperClasses.class';
|
|
|
|
import {Open} from '../../utils/modal/open.component';
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'search-filter',
|
|
|
|
templateUrl: 'searchFilter.component.html'
|
|
|
|
})
|
|
|
|
|
|
|
|
export class SearchFilterComponent {
|
|
|
|
|
|
|
|
@Input() filter:Filter;
|
|
|
|
@Input() showResultCount:boolean = true;
|
|
|
|
@Input() isDisabled:boolean = false;
|
|
|
|
@Input() addShowMore:boolean = true;
|
2018-02-05 14:14:59 +01:00
|
|
|
@Input() connectCommunityId:string
|
2017-12-19 13:53:46 +01:00
|
|
|
public showAll:boolean = false;
|
|
|
|
public _maxCharacters:number =28;
|
|
|
|
|
|
|
|
@Output() toggleModal = new EventEmitter();
|
|
|
|
|
|
|
|
@Output() modalChange = new EventEmitter();
|
2018-07-19 12:52:29 +02:00
|
|
|
@Output() onFilterChange = new EventEmitter();
|
|
|
|
keyword = "";
|
|
|
|
sortBy = "num";
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
public isOpen:boolean=false;
|
|
|
|
|
2018-07-19 12:52:29 +02:00
|
|
|
// filterModalChange() {
|
|
|
|
// console.info("Modal Changed");
|
|
|
|
// this.modalChange.emit({
|
|
|
|
// value: true
|
|
|
|
// });
|
|
|
|
// //this.close();
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
constructor () {
|
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
|
|
|
|
|
|
|
}
|
|
|
|
public _formatTitle(title,length){
|
|
|
|
return (((title+" ("+length+")").length >this._maxCharacters)?(title.substring(0,(this._maxCharacters - (" ("+length+")").length - ('...').length))+"..."):title+" ("+((length >= 99)?length+"+":length)+")")
|
|
|
|
}
|
|
|
|
private _formatName(value){
|
|
|
|
return value.name;//(((value.name+" ("+value.number+")").length >this._maxCharacters)?(value.name.substring(0,(this._maxCharacters - (" ("+value.number+")").length - ('...').length))+"..."):value.name)
|
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
// toggleShowAll(){
|
|
|
|
// this.showAll = !this.showAll;
|
|
|
|
// if(this.showAll == false) {
|
|
|
|
// this.reorderFilterValues();
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
filterKeywords(value){
|
|
|
|
if(this.keyword.length > 0){
|
|
|
|
if(value.toLowerCase().indexOf(this.keyword.toLowerCase()) ==-1){
|
|
|
|
return false;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
}
|
|
|
|
return true;
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
filterChange(selected:boolean){
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.info("filter change: "+selected);
|
2017-12-19 13:53:46 +01:00
|
|
|
if(selected){
|
|
|
|
this.filter.countSelectedValues++;
|
|
|
|
// this.reorderFilterValues();
|
|
|
|
}else{
|
|
|
|
this.filter.countSelectedValues--;
|
|
|
|
// this.reorderFilterValues();
|
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
this.onFilterChange.emit({
|
|
|
|
value: this.filter
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
getSelectedValues(filter, sortBy:string = "num"):any{
|
2017-12-19 13:53:46 +01:00
|
|
|
var selected = [];
|
|
|
|
if(filter.countSelectedValues >0){
|
|
|
|
for (var i=0; i < filter.values.length; i++){
|
|
|
|
if(filter.values[i].selected){
|
|
|
|
selected.push(filter.values[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
if(sortBy == "name"){
|
|
|
|
|
|
|
|
selected.sort((n1,n2)=> {
|
|
|
|
if (n1.name > n2.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n1.name < n2.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
return selected;
|
|
|
|
|
|
|
|
}
|
2018-07-25 15:20:54 +02:00
|
|
|
getNotSelectedValues(filter, sortBy:string = "num"):any{
|
2017-12-19 13:53:46 +01:00
|
|
|
var notSselected = [];
|
2018-07-25 15:20:54 +02:00
|
|
|
//if(filter.countSelectedValues >0){
|
2017-12-19 13:53:46 +01:00
|
|
|
for (var i=0; i < filter.values.length; i++){
|
|
|
|
if(!filter.values[i].selected){
|
|
|
|
notSselected.push(filter.values[i]);
|
|
|
|
}
|
|
|
|
}
|
2018-07-25 15:20:54 +02:00
|
|
|
//}else {
|
|
|
|
// notSselected = filter.values;
|
|
|
|
//}
|
2018-07-19 12:52:29 +02:00
|
|
|
|
|
|
|
if(sortBy == "name"){
|
|
|
|
|
|
|
|
notSselected.sort((n1,n2)=> {
|
|
|
|
if (n1.name > n2.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (n1.name < n2.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
});
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
return notSselected;
|
|
|
|
}
|
2018-07-19 12:52:29 +02:00
|
|
|
// reorderFilterValues() {
|
|
|
|
// for(let value of this.filter.values) {
|
|
|
|
// if(value.selected) {
|
|
|
|
// let index: number = this.filter.values.indexOf(value);
|
|
|
|
// let selectedValue:Value = this.filter.values[index];
|
|
|
|
//
|
|
|
|
// this.filter.values.splice(index, 1);
|
|
|
|
// this.filter.values.splice(0, 0, selectedValue);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
// sliceSelected() {
|
|
|
|
// let values: Value[] = [];
|
|
|
|
//
|
|
|
|
// for(let value of this.filter.values) {
|
|
|
|
// if(value.selected) {
|
|
|
|
// let index: number = this.filter.values.indexOf(value);
|
|
|
|
// let selectedValue:Value = this.filter.values[index];
|
|
|
|
//
|
|
|
|
// this.filter.values.splice(index, 1);
|
|
|
|
// this.filter.values.splice(0, 0, selectedValue);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
2018-07-19 12:52:29 +02:00
|
|
|
// toggle() {
|
|
|
|
// this.toggleModal.emit({
|
|
|
|
// value: this.filter
|
|
|
|
// });
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
|
|
|
|
open() {
|
|
|
|
this.isOpen = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
close() {
|
|
|
|
this.isOpen = false;
|
|
|
|
}
|
|
|
|
|
2018-07-19 12:52:29 +02:00
|
|
|
// filterChange2(selected:boolean){
|
|
|
|
//
|
|
|
|
// console.info("filter change2");
|
|
|
|
// if(selected){
|
|
|
|
// this.filter.countSelectedValues++;
|
|
|
|
// // this.reorderFilterValues();
|
|
|
|
// }else{
|
|
|
|
// this.filter.countSelectedValues--;
|
|
|
|
// // this.reorderFilterValues();
|
|
|
|
// }
|
|
|
|
// this.close();
|
|
|
|
// }
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
}
|