Project

General

Profile

1

    
2
import { Filter, Value} from '../../searchPages/searchUtils/searchHelperClasses.class';
3
import { SearchFields, FieldDetails} from '../../utils/properties/searchFields';
4

    
5

    
6
export class RefineResultsUtils {
7

    
8

    
9
   public static parse (data, fields:string[], entityType:string, usedBy: string="search"):Filter[] {
10
         // var data = this.json.refineReuslts;
11

    
12
         var searchFields:SearchFields = new SearchFields();
13
         var filters:Filter[] = [];
14
         if(data && fields){
15
           for(let j=0; j<fields.length; j++) {
16

    
17
             var filter:Filter = new Filter();
18
             filter.title = searchFields.getFieldName(fields[j],entityType);
19
             filter.filterId = fields[j];
20
             filter.originalFilterId = fields[j];
21
             filter.filterType = searchFields.getFieldFilterType(fields[j], entityType, usedBy);
22
             filter.filterOperator = searchFields.getFieldOperator(fields[j]);
23
             filter.radioValue = "";
24
             //console.info("filter.title: "+filter.title+" filter.filterType: "+filter.filterType);
25

    
26
             let field = data[fields[j]];
27
             if(field){
28
               for(let i=0; i<field.length; i++) {
29
                 var value:Value = new Value();
30
                 value.name = field[i].name;
31
                 value.name =this.removePartAfterCharacters(value,"||");
32
                 value.number = field[i].count;
33
                 value.id = field[i].id;
34
                 if(RefineResultsUtils.includeValue(value)){
35
                   filter.values.push(value);
36
                 }
37

    
38

    
39
             }
40

    
41
               filters.push(filter);
42
           }
43
       }
44
     }
45
       return filters;
46
   }
47
   private static includeValue (field):boolean {
48
     if( !field || !field.name || field.name == "unidentified" || field.name == "Undetermined" ){
49
       return false;
50

    
51
     }
52
     return true;
53
   }
54
   private static removePartAfterCharacters(field, characters):string {
55
     if( field.name.indexOf(characters) !=-1){
56
       return field.name.split(characters)[0];
57

    
58
     }
59
     return field.name;
60
   }
61
   public static inParenthesisThePartAfterCharacters(field, characters):string {
62
     if( field.name.indexOf(characters) !=-1){
63
       return field.name.split(characters)[0]+" ("+field.name.split(characters)[1]+")";
64

    
65
     }
66
     return field.name;
67
   }
68
  public static keepPartAfterCharacters(name, characters):string {
69
    if( name.indexOf(characters) !=-1){
70
      return name.split(characters)[1];
71
    }
72
    return name;
73
  }
74
  }
(2-2/2)