2019-06-03 15:20:36 +02:00
|
|
|
import {Component, EventEmitter, Input, Output} from '@angular/core';
|
2020-02-13 15:44:51 +01:00
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
2017-12-19 13:53:46 +01:00
|
|
|
|
2020-02-11 12:58:51 +01:00
|
|
|
import {AdvancedField, Filter} from '../searchUtils/searchHelperClasses.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {SearchFields} from '../../utils/properties/searchFields';
|
2017-12-19 13:53:46 +01:00
|
|
|
import {Dates} from '../../utils/string-utils.class';
|
2019-06-03 15:20:36 +02:00
|
|
|
import {EnvProperties} from '../../utils/properties/env-properties';
|
2020-04-03 18:00:19 +02:00
|
|
|
import {SearchCustomFilter} from "./searchUtils.class";
|
2020-11-11 15:43:13 +01:00
|
|
|
import {Subscriber} from "rxjs";
|
2020-11-18 17:06:27 +01:00
|
|
|
import {properties} from "../../../../environments/environment";
|
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;
|
2020-01-31 16:12:51 +01:00
|
|
|
@Input() advancedSearchLink;
|
|
|
|
@Input() advancedSearchLinkParameters;
|
|
|
|
@Input() simpleView:boolean = false;
|
|
|
|
@Input() formPlaceholderText = "Type Keywords...";
|
2018-10-01 17:02:14 +02:00
|
|
|
@Input() pageTitle;
|
2017-12-19 13:53:46 +01:00
|
|
|
@Output() queryChange = new EventEmitter();
|
2020-02-19 16:35:48 +01:00
|
|
|
@Input()resultTypes;
|
2020-02-11 12:58:51 +01:00
|
|
|
@Input() quickFilter:{filter: Filter, selected:boolean, filterId:string, value:string};
|
2019-05-22 12:50:32 +02:00
|
|
|
validDateFrom: boolean = true;
|
|
|
|
validDateTo: boolean = true;
|
2020-04-03 18:00:19 +02:00
|
|
|
@Input() customFilter: SearchCustomFilter;
|
2017-12-19 13:53:46 +01:00
|
|
|
newFieldId:string;
|
|
|
|
newFieldName:string;
|
|
|
|
fieldList:{[id:string]:any[]} = {};
|
|
|
|
public searchFields:SearchFields = new SearchFields();
|
2020-02-11 12:58:51 +01:00
|
|
|
properties:EnvProperties;
|
2019-06-03 15:20:36 +02:00
|
|
|
public operators: {name:string, id:string}[] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
|
2020-02-13 15:44:51 +01:00
|
|
|
selectedEntity;
|
|
|
|
selectedEntitySimpleUrl;
|
|
|
|
selectedEntityAdvancedUrl;
|
2020-02-25 16:40:56 +01:00
|
|
|
@Input() entitiesSelection:boolean;
|
2020-08-13 13:15:10 +02:00
|
|
|
@Input() showSwitchSearchLink:boolean = true;
|
2020-11-11 15:43:13 +01:00
|
|
|
sub;
|
2020-02-13 15:44:51 +01:00
|
|
|
constructor (private route: ActivatedRoute, private router: Router) {
|
2020-02-11 12:58:51 +01:00
|
|
|
|
|
|
|
}
|
2020-11-11 15:43:13 +01:00
|
|
|
ngOnDestroy() {
|
|
|
|
if (this.sub instanceof Subscriber) {
|
|
|
|
this.sub.unsubscribe();
|
|
|
|
}
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
ngOnInit() {
|
2020-02-13 15:44:51 +01:00
|
|
|
this.selectedEntity = this.entityType;
|
2018-02-05 14:14:59 +01:00
|
|
|
|
2020-11-18 17:06:27 +01:00
|
|
|
this.properties = properties;
|
|
|
|
|
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;
|
|
|
|
}
|
2020-02-13 15:44:51 +01:00
|
|
|
simpleEntityChanged($event){
|
|
|
|
this.selectedEntity = $event.entity;
|
|
|
|
this.selectedEntitySimpleUrl = $event.simpleUrl;
|
|
|
|
this.selectedEntityAdvancedUrl = $event.advancedUrl;
|
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
simpleKeywordChanged($event){
|
2020-02-13 15:44:51 +01:00
|
|
|
// this.selectedFields[0].value = $event.value;
|
|
|
|
if(this.selectedEntity == this.entityType) {
|
|
|
|
this.queryChanged();
|
|
|
|
}else{
|
|
|
|
this.router.navigate([this.selectedEntitySimpleUrl], {queryParams:{q:this.selectedFields[0].value,op:"and"}});
|
|
|
|
}
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
queryChanged() {
|
2019-05-22 12:50:32 +02:00
|
|
|
this.validDateFrom = true;
|
|
|
|
this.validDateTo = true;
|
|
|
|
|
|
|
|
this.selectedFields.forEach(selectedField => {
|
|
|
|
if(selectedField.type == 'date') {
|
|
|
|
if (selectedField.dateValue.type.indexOf("range") != -1) {
|
|
|
|
if(!Dates.isValidDate(Dates.getDateToString(selectedField.dateValue.from))) {
|
|
|
|
//console.info("INVALID: isValidDate FROM");
|
|
|
|
this.validDateFrom = false;
|
|
|
|
}
|
|
|
|
if(!Dates.isValidDate(Dates.getDateToString(selectedField.dateValue.to))) {
|
|
|
|
//console.info("INVALID: isValidDate TO");
|
|
|
|
this.validDateTo = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
if(this.validDateFrom && this.validDateTo) {
|
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
this.queryChange.emit({
|
2020-01-31 16:12:51 +01:00
|
|
|
|
2017-12-19 13:53:46 +01:00
|
|
|
});
|
2019-05-22 12:50:32 +02:00
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
2020-01-31 16:12:51 +01:00
|
|
|
if(this.selectedFields.length == 1){
|
|
|
|
this.selectedFields[index] = new AdvancedField(this.newFieldId,this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, this.fieldIdsMap[this.newFieldId].type, "", "and");
|
|
|
|
}else{
|
2017-12-19 13:53:46 +01:00
|
|
|
this.selectedFields.splice(index, 1);
|
2020-01-31 16:12:51 +01:00
|
|
|
}
|
2020-02-25 16:40:56 +01:00
|
|
|
//if only one filter left, set the operator to and
|
|
|
|
if(this.selectedFields.length==1){
|
|
|
|
this.selectedFields[0].operatorId = "and";
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2020-07-21 14:41:08 +02:00
|
|
|
updatedValueLabel($event,index:number){
|
|
|
|
this.selectedFields[index].valueLabel = $event.value;
|
|
|
|
}
|
2017-12-19 13:53:46 +01:00
|
|
|
listUpdated($event,fieldId:number){
|
|
|
|
this.fieldList[fieldId] = $event.value;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|