2017-12-19 13:53:46 +01:00
|
|
|
import {Component, Input, Output, EventEmitter, ElementRef} from '@angular/core';
|
|
|
|
import {Observable} from 'rxjs/Observable';
|
|
|
|
import { Subject } from 'rxjs/Subject';
|
2018-02-05 14:14:59 +01:00
|
|
|
import {ActivatedRoute} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
import {AdvancedField, OPERATOR} from '../searchUtils/searchHelperClasses.class';
|
|
|
|
import {SearchFields, FieldDetails} from '../../utils/properties/searchFields';
|
|
|
|
import {Dates} from '../../utils/string-utils.class';
|
2018-02-05 14:14:59 +01:00
|
|
|
import{EnvProperties} from '../../utils/properties/env-properties';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'advanced-search-form',
|
|
|
|
templateUrl: 'advancedSearchForm.component.html'
|
|
|
|
})
|
|
|
|
export class AdvancedSearchFormComponent {
|
|
|
|
@Input() entityType;
|
|
|
|
@Input() fieldIds: string[];
|
|
|
|
@Input() fieldIdsMap;
|
|
|
|
@Input() selectedFields:AdvancedField[];
|
|
|
|
@Input() isDisabled: boolean = false;
|
2018-10-01 17:02:14 +02:00
|
|
|
@Input() simpleSearchLink;
|
|
|
|
@Input() pageTitle;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Output() queryChange = new EventEmitter();
|
|
|
|
newFieldId:string;
|
|
|
|
newFieldName:string;
|
|
|
|
fieldList:{[id:string]:any[]} = {};
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
2018-02-05 14:14:59 +01:00
|
|
|
properties:EnvProperties;
|
2017-12-19 13:53:46 +01:00
|
|
|
public operators: [{name:string, id:string}] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
|
2018-02-05 14:14:59 +01:00
|
|
|
constructor (private route: ActivatedRoute) {
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ngOnInit() {
|
2018-02-05 14:14:59 +01:00
|
|
|
this.route.data
|
|
|
|
.subscribe((data: { envSpecific: EnvProperties }) => {
|
|
|
|
this.properties = data.envSpecific;
|
|
|
|
|
|
|
|
});
|
2017-12-19 13:53:46 +01:00
|
|
|
for(var i = 0; i < this.fieldIds.length; i++){
|
|
|
|
this.fieldList[this.fieldIds[i]]=[];
|
|
|
|
}
|
|
|
|
this.newFieldId = this.fieldIds[0];
|
|
|
|
this.newFieldName = this.fieldIdsMap[this.newFieldId].name;
|
|
|
|
}
|
|
|
|
|
|
|
|
queryChanged() {
|
|
|
|
this.queryChange.emit({
|
|
|
|
// selectedFields: this.selectedFields,
|
|
|
|
// selectedQuantifiers: this.selectedQuantifiers,
|
|
|
|
// keywords: this.keywords
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
addField() {
|
|
|
|
this.newFieldId = this.fieldIds[0];
|
|
|
|
var type = this.fieldIdsMap[this.newFieldId].type;
|
|
|
|
if(type == "boolean"){
|
|
|
|
this.selectedFields.push(new AdvancedField(this.newFieldId,this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, type, "true", "and"));
|
|
|
|
}else{
|
|
|
|
this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].param,this.fieldIdsMap[this.newFieldId].name, type, "", "and"));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
removeField(index: number) {
|
|
|
|
this.selectedFields.splice(index, 1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldOperatorChanged(index: number, operatorId: string, operatorName: string) {
|
|
|
|
this.selectedFields[index].operatorId = operatorId;
|
|
|
|
this.selectedFields[index].operatorName = operatorName;
|
|
|
|
}
|
|
|
|
validateDate(index: number, value: string){
|
|
|
|
this.selectedFields[index].valid = Dates.isValidYear(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldIdsChanged(index: number, fieldId:string ) {
|
2019-02-14 11:15:44 +01:00
|
|
|
//console.log("Field index::"+index + " " + this.selectedFields[index].id + " function id:" +fieldId);
|
2017-12-19 13:53:46 +01:00
|
|
|
|
|
|
|
var id= this.fieldIds[0];
|
|
|
|
this.selectedFields[index].name = this.fieldIdsMap[id].name;
|
|
|
|
this.selectedFields[index].type = this.fieldIdsMap[id].type;
|
|
|
|
this.selectedFields[index].value = "";
|
|
|
|
this.selectedFields[index].param = this.fieldIdsMap[id].param;
|
|
|
|
|
|
|
|
var id =fieldId;//this.selectedFields[index].id;
|
|
|
|
this.selectedFields[index].name = this.fieldIdsMap[id].name;
|
|
|
|
this.selectedFields[index].type = this.fieldIdsMap[id].type;
|
|
|
|
this.selectedFields[index].value = "";
|
|
|
|
this.selectedFields[index].param = this.fieldIdsMap[id].param;
|
|
|
|
if(this.fieldIdsMap[id].type == "boolean"){
|
|
|
|
this.selectedFields[index].value = "true";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
valueChanged($event,index:number){
|
|
|
|
this.selectedFields[index].value = $event.value;
|
|
|
|
}
|
|
|
|
listUpdated($event,fieldId:number){
|
|
|
|
this.fieldList[fieldId] = $event.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|