Project

General

Profile

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

    
8
@Component({
9
    selector: 'advanced-search-form',
10
    template: `
11
        <form class="">
12
            <div *ngFor="let selectedField of selectedFields; let i = index" class="form-group  form-inline">
13
                <div *ngIf = "i != 0" class="input-group">
14
                    <button  type="button" id="dropdownMenu1" data-toggle="dropdown" class="btn btn-default dropdown-toggle" aria-haspopup="true" aria-expanded="true">
15
                        {{selectedField.operatorId}}
16
                    </button>
17
                    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
18
                        <li *ngFor="let op of operators">
19
                            <a (click)="fieldOperatorChanged(i, op.id, op.id)">{{op.id}}</a>
20
                        </li>
21
                    </ul>
22
                </div>
23
                <div class="input-group">
24
                    <div class="input-group-btn">
25
                    <button  class="btn btn-default btn-disabled"  type="button">
26
                        {{selectedField.name}}
27
                    </button>
28
                        <!--button aria-expanded="false" aria-haspopup="true" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="dropdownMenu1" type="button">
29
                            {{selectedField.name}}
30
                        </button>
31
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
32
                            <li *ngFor="let id of fieldIds">
33
                                <a (click)="fieldIdsChanged(i, id)">{{fieldIdsMap[id].name}}</a>
34
                            </li>
35
                        </ul-->
36
                    </div>
37
                    <input *ngIf = "fieldIdsMap[selectedField.id].type == 'keyword'"  type="text" class="form-control" placeholder="Type keywords..." [(ngModel)]="selectedField.value" name="value[{{i}}]">
38

    
39

    
40
                    <div *ngIf = "fieldIdsMap[selectedField.id].type == 'vocabulary'" class="input-group">
41
                    <static-autocomplete2  [(vocabularyId)] = selectedField.id [(list)] = this.fieldList[selectedField.id]  [entityName] = "entityType" [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:"  [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
42
                    </div>
43
                    <div *ngIf = "fieldIdsMap[selectedField.id].type == 'refine'" class="input-group">
44
                    <static-autocomplete2 [(list)] = this.fieldList[selectedField.id] [entityName] = "entityType" [fieldName] = fieldIdsMap[selectedField.id].indexField [selectedValue]=selectedField.value [showSelected]=true [placeHolderMessage] = "'Search for '+selectedField.name" title = "Languages:"  [multipleSelections]=false (selectedValueChanged)="valueChanged($event,i)" (listUpdated) = "listUpdated($event,selectedField.id)"></static-autocomplete2>
45
                    </div>
46
                    <div *ngIf = "fieldIdsMap[selectedField.id].type == 'boolean'" class="input-group">
47
                       <span class="input-group-addon">
48
                          <input type="radio" [(ngModel)]="selectedField.value"  [name]=selectedField.id value="true">Yes<br>
49
                      </span>
50
                      <span class="input-group-addon">
51
                        <input type="radio" [(ngModel)]="selectedField.value"  [name]=selectedField.id value="false">No<br>
52
                      </span>
53
                  </div>
54
                </div>
55

    
56

    
57
                <button type="button" class="btn btn-danger" *ngIf="selectedFields.length > 1" (click)="removeField(i)">
58
                    <span class="glyphicon glyphicon-minus" aria-hidden="true"></span>
59
                </button>
60
            </div>
61
            <div  class="form-group  form-inline">
62
              <div class=" input-group">
63
                  <div class="input-group-btn">
64
                    <button aria-expanded="false" aria-haspopup="true" class="btn btn-default dropdown-toggle" data-toggle="dropdown" id="dropdownMenu1" type="button">
65
                      {{fieldIdsMap[newFieldId].name}}
66
                    </button>
67
                    <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
68
                        <li *ngFor="let id of fieldIds">
69
                            <a (click)="fieldIdsChanged(i, id)">{{fieldIdsMap[id].name}}</a>
70
                        </li>
71
                    </ul>
72
                  </div>
73
                  <button type="button" class="btn btn-success" (click)="addField()">
74
                      <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
75
                  </button>
76
              </div>
77
            </div>
78

    
79

    
80

    
81
            <button (click)="queryChanged()"  type="submit" class="btn btn-default">Search</button>
82
        </form>
83

    
84
    `
85
})
86
///[style.width]="'120px'"
87
export class AdvancedSearchFormComponent {
88
  @Input() entityType;
89
  @Input() fieldIds:  string[];
90
  @Input() fieldIdsMap:{ [key:string]:{ name:string, operator:string, type:string, indexField:string }} ;
91
  @Input() selectedFields:AdvancedField[];
92
  @Output() queryChange  = new EventEmitter();
93
  newFieldId:string;
94
  fieldList:{[id:string]:any[]} = {};
95
  private searchFields:SearchFields = new SearchFields();
96

    
97
  private operators:  [{name:string, id:string}] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
98
    constructor () {
99
      console.log("Constr: Advanced search form");
100
     }
101

    
102
    ngOnInit() {
103
      console.log("Init: Advanced search form");
104
      for(var i = 0; i < this.fieldIds.length; i++){
105
        this.fieldList[this.fieldIds[i]]=[];
106
      }
107
      this.newFieldId = this.fieldIds[0];
108
     }
109

    
110
    queryChanged() {
111
        this.queryChange.emit({
112
            // selectedFields: this.selectedFields,
113
            // selectedQuantifiers: this.selectedQuantifiers,
114
            // keywords: this.keywords
115
        });
116
    }
117

    
118
    addField() {
119
        console.info("add filter"+this.fieldIds[0]+this.fieldIdsMap[this.fieldIds[0]].name+this.fieldIdsMap[this.fieldIds[0]].type);
120
        var type = this.fieldIdsMap[this.newFieldId].type;
121
        if(type == "boolean"){
122
          this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name, type, "true", "and"));
123
        }else{
124
          this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].name, type, "", "and"));
125
        }
126

    
127
    }
128

    
129
    removeField(index: number) {
130
        console.info("remove filter");
131
        this.selectedFields.splice(index, 1);
132

    
133
    }
134

    
135
    fieldOperatorChanged(index: number, operatorId: string, operatorName: string) {
136
         this.selectedFields[index].operatorId = operatorId;
137
         this.selectedFields[index].operatorName = operatorName;
138
    }
139

    
140
    fieldIdsChanged(index: number,id) {
141
         this.newFieldId = id;
142
        //  this.selectedFields[index].id = id;
143
        //  this.selectedFields[index].name = this.fieldIdsMap[id].name;
144
        // //  this.selectedFields[index].type = "keyword";
145
        //  this.selectedFields[index].type = this.fieldIdsMap[id].type;
146
        //  this.selectedFields[index].value = "";
147
    }
148
    valueChanged($event,index:number){
149
      this.selectedFields[index].value = $event.value;
150
    }
151
    listUpdated($event,fieldId:number){
152
      this.fieldList[fieldId] = $event.value;
153
    }
154
}
(1-1/9)