1
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
2
|
import {Observable} from 'rxjs/Observable';
|
3
|
import { Subject } from 'rxjs/Subject';
|
4
|
|
5
|
import {AdvancedField, OPERATOR} from '../searchUtils/searchHelperClasses.class';
|
6
|
import {SearchFields} from '../../utils/properties/searchFields';
|
7
|
import {Dates} from '../../utils/string-utils.class';
|
8
|
|
9
|
@Component({
|
10
|
selector: 'advanced-search-form',
|
11
|
template: `
|
12
|
<form class="">
|
13
|
<div *ngFor="let selectedField of selectedFields; let i = index" class="form-group form-inline">
|
14
|
<div *ngIf = "i != 0" class="input-group">
|
15
|
<button type="button" id="dropdownMenu1" data-toggle="dropdown" class="uk-button dropdown-toggle" aria-haspopup="true" aria-expanded="true">
|
16
|
{{selectedField.operatorId}}
|
17
|
</button>
|
18
|
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
19
|
<li *ngFor="let op of operators">
|
20
|
<a (click)="fieldOperatorChanged(i, op.id, op.id)">{{op.id}}</a>
|
21
|
</li>
|
22
|
</ul>
|
23
|
</div>
|
24
|
<div class="input-group">
|
25
|
<div class="input-group-btn">
|
26
|
<button class="uk-button btn-disabled" type="button">
|
27
|
{{selectedField.name}}
|
28
|
</button>
|
29
|
</div>
|
30
|
<input *ngIf = "fieldIdsMap[selectedField.id].type == 'keyword'" type="text" class="form-control" placeholder="Type keywords..." [(ngModel)]="selectedField.value" name="value[{{i}}]">
|
31
|
<input *ngIf = "fieldIdsMap[selectedField.id].type == 'year'" type="text" class="form-control" placeholder="Type Year..." [(ngModel)]="selectedField.value" name="value[{{i}}]" (keyup)=validateDate(i,selectedField.value)>
|
32
|
<!-- div *ngIf = "fieldIdsMap[selectedField.id].type == 'year' && !selectedField.valid" class="form-control-feedback">Not a valid year. Insert a date between 1000 - 3000</div-->
|
33
|
|
34
|
|
35
|
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'vocabulary'" class="input-group">
|
36
|
<static-autocomplete [(vocabularyId)] = selectedField.param [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete>
|
37
|
</div>
|
38
|
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'refine'" class="input-group">
|
39
|
<static-autocomplete [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = [selectedField.id] [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete>
|
40
|
</div>
|
41
|
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'entity'" class="input-group">
|
42
|
<entities-autocomplete [entityType]=selectedField.param [selectedValue]=selectedField.value [showSelected]=true
|
43
|
[placeHolderMessage] = "'Search for '+selectedField.name" [title] = "selectedField.name" [multipleSelections]=false
|
44
|
(selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)" >
|
45
|
</entities-autocomplete>
|
46
|
|
47
|
</div>
|
48
|
<div *ngIf = "fieldIdsMap[selectedField.id].type == 'boolean'" class="input-group">
|
49
|
<span class="input-group-addon">
|
50
|
<input type="radio" [(ngModel)]="selectedField.value" [name]=selectedField.param value="true">Yes<br>
|
51
|
</span>
|
52
|
<span class="input-group-addon">
|
53
|
<input type="radio" [(ngModel)]="selectedField.value" [name]=selectedField.param value="false">No<br>
|
54
|
</span>
|
55
|
</div>
|
56
|
</div>
|
57
|
|
58
|
<button type="button" class="btn btn-danger" *ngIf="selectedFields.length > 1" (click)="removeField(i)">
|
59
|
<span class="glyphicon glyphicon-minus" aria-hidden="true"></span>
|
60
|
</button>
|
61
|
</div>
|
62
|
<div class="form-group form-inline">
|
63
|
<div class=" input-group">
|
64
|
<div class="input-group-btn">
|
65
|
<button aria-expanded="false" aria-haspopup="true" class="uk-button dropdown-toggle" data-toggle="dropdown" id="dropdownMenu1" type="button">
|
66
|
{{fieldIdsMap[newFieldId].name}}
|
67
|
</button>
|
68
|
<ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
|
69
|
<li *ngFor="let id of fieldIds">
|
70
|
<a (click)="fieldIdsChanged(i, id)">{{fieldIdsMap[id].name}}</a>
|
71
|
</li>
|
72
|
</ul>
|
73
|
</div>
|
74
|
<button type="button" class="btn btn-success" (click)="addField()">
|
75
|
<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
76
|
</button>
|
77
|
</div>
|
78
|
</div>
|
79
|
|
80
|
|
81
|
|
82
|
<button (click)="queryChanged()" type="submit" class="uk-button">Search</button>
|
83
|
</form>
|
84
|
|
85
|
`
|
86
|
})
|
87
|
///[style.width]="'120px'"
|
88
|
export class AdvancedSearchFormComponent {
|
89
|
@Input() entityType;
|
90
|
@Input() fieldIds: string[];
|
91
|
@Input() fieldIdsMap;
|
92
|
@Input() selectedFields:AdvancedField[];
|
93
|
@Output() queryChange = new EventEmitter();
|
94
|
newFieldId:string;
|
95
|
fieldList:{[id:string]:any[]} = {};
|
96
|
public searchFields:SearchFields = new SearchFields();
|
97
|
|
98
|
public operators: [{name:string, id:string}] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
|
99
|
constructor () {
|
100
|
console.log("Constr: Advanced search form");
|
101
|
}
|
102
|
|
103
|
ngOnInit() {
|
104
|
console.log("Init: Advanced search form");
|
105
|
for(var i = 0; i < this.fieldIds.length; i++){
|
106
|
this.fieldList[this.fieldIds[i]]=[];
|
107
|
}
|
108
|
this.newFieldId = this.fieldIds[0];
|
109
|
}
|
110
|
|
111
|
queryChanged() {
|
112
|
this.queryChange.emit({
|
113
|
// selectedFields: this.selectedFields,
|
114
|
// selectedQuantifiers: this.selectedQuantifiers,
|
115
|
// keywords: this.keywords
|
116
|
});
|
117
|
}
|
118
|
|
119
|
addField() {
|
120
|
console.info("add filter"+this.fieldIds[0]+this.fieldIdsMap[this.fieldIds[0]].name+this.fieldIdsMap[this.fieldIds[0]].type);
|
121
|
var type = this.fieldIdsMap[this.newFieldId].type;
|
122
|
if(type == "boolean"){
|
123
|
this.selectedFields.push(new AdvancedField(this.newFieldId,this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, type, "true", "and"));
|
124
|
}else{
|
125
|
this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].param,this.fieldIdsMap[this.newFieldId].name, type, "", "and"));
|
126
|
}
|
127
|
|
128
|
}
|
129
|
|
130
|
removeField(index: number) {
|
131
|
console.info("remove filter");
|
132
|
this.selectedFields.splice(index, 1);
|
133
|
|
134
|
}
|
135
|
|
136
|
fieldOperatorChanged(index: number, operatorId: string, operatorName: string) {
|
137
|
this.selectedFields[index].operatorId = operatorId;
|
138
|
this.selectedFields[index].operatorName = operatorName;
|
139
|
}
|
140
|
validateDate(index: number, value: string){
|
141
|
this.selectedFields[index].valid = Dates.isValidYear(value);
|
142
|
}
|
143
|
|
144
|
fieldIdsChanged(index: number,id) {
|
145
|
this.newFieldId = id;
|
146
|
// this.selectedFields[index].id = id;
|
147
|
// this.selectedFields[index].name = this.fieldIdsMap[id].name;
|
148
|
// // this.selectedFields[index].type = "keyword";
|
149
|
// this.selectedFields[index].type = this.fieldIdsMap[id].type;
|
150
|
// this.selectedFields[index].value = "";
|
151
|
}
|
152
|
valueChanged($event,index:number){
|
153
|
this.selectedFields[index].value = $event.value;
|
154
|
}
|
155
|
listUpdated($event,fieldId:number){
|
156
|
this.fieldList[fieldId] = $event.value;
|
157
|
}
|
158
|
|
159
|
}
|