Project

General

Profile

1
import {Component, Input, Output, EventEmitter, ElementRef} 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, FieldDetails} from '../../utils/properties/searchFields';
7
import {Dates} from '../../utils/string-utils.class';
8

    
9
@Component({
10
    selector: 'advanced-search-form',
11
    templateUrl: 'advancedSearchForm.component.html'
12
})
13
export class AdvancedSearchFormComponent {
14
  @Input() entityType;
15
  @Input() fieldIds:  string[];
16
  @Input() fieldIdsMap;
17
  @Input() selectedFields:AdvancedField[];
18
  @Input() isDisabled: boolean = false;
19

    
20
  @Output() queryChange  = new EventEmitter();
21
  newFieldId:string;
22
  newFieldName:string;
23
  fieldList:{[id:string]:any[]} = {};
24
  public searchFields:SearchFields = new SearchFields();
25

    
26
  public operators:  [{name:string, id:string}] = this.searchFields.ADVANCED_SEARCH_OPERATORS;
27
    constructor () {
28
     }
29

    
30
    ngOnInit() {
31
      for(var i = 0; i < this.fieldIds.length; i++){
32
        this.fieldList[this.fieldIds[i]]=[];
33
      }
34
      this.newFieldId = this.fieldIds[0];
35
      this.newFieldName = this.fieldIdsMap[this.newFieldId].name;
36
     }
37

    
38
    queryChanged() {
39
        this.queryChange.emit({
40
            // selectedFields: this.selectedFields,
41
            // selectedQuantifiers: this.selectedQuantifiers,
42
            // keywords: this.keywords
43
        });
44
    }
45

    
46
    addField() {
47
        this.newFieldId = this.fieldIds[0];
48
        var type = this.fieldIdsMap[this.newFieldId].type;
49
        if(type == "boolean"){
50
          this.selectedFields.push(new AdvancedField(this.newFieldId,this.fieldIdsMap[this.newFieldId].param, this.fieldIdsMap[this.newFieldId].name, type, "true", "and"));
51
        }else{
52
          this.selectedFields.push(new AdvancedField(this.newFieldId, this.fieldIdsMap[this.newFieldId].param,this.fieldIdsMap[this.newFieldId].name, type, "", "and"));
53
        }
54

    
55
    }
56

    
57
    removeField(index: number) {
58
        this.selectedFields.splice(index, 1);
59

    
60
    }
61

    
62
    fieldOperatorChanged(index: number, operatorId: string, operatorName: string) {
63
         this.selectedFields[index].operatorId = operatorId;
64
         this.selectedFields[index].operatorName = operatorName;
65
    }
66
    validateDate(index: number, value: string){
67
      this.selectedFields[index].valid = Dates.isValidYear(value);
68
    }
69

    
70
    fieldIdsChanged(index: number, fieldId:string ) {
71
      console.log("Field index::"+index + "  " + this.selectedFields[index].id + " function id:" +fieldId);
72

    
73
          var id= this.fieldIds[0];
74
          this.selectedFields[index].name = this.fieldIdsMap[id].name;
75
         this.selectedFields[index].type = this.fieldIdsMap[id].type;
76
         this.selectedFields[index].value = "";
77
         this.selectedFields[index].param = this.fieldIdsMap[id].param;
78

    
79
         var id =fieldId;//this.selectedFields[index].id;
80
         this.selectedFields[index].name = this.fieldIdsMap[id].name;
81
         this.selectedFields[index].type = this.fieldIdsMap[id].type;
82
         this.selectedFields[index].value = "";
83
         this.selectedFields[index].param = this.fieldIdsMap[id].param;
84
         if(this.fieldIdsMap[id].type == "boolean"){
85
           this.selectedFields[index].value = "true";
86
         }
87
    }
88
    valueChanged($event,index:number){
89
      this.selectedFields[index].value = $event.value;
90
    }
91
    listUpdated($event,fieldId:number){
92
      this.fieldList[fieldId] = $event.value;
93
    }
94

    
95
}
(2-2/36)