Project

General

Profile

1
import {Component, Input, } from '@angular/core';
2
import {RouterHelper} from '../../utils/routerHelper.class';
3

    
4
@Component({
5
    selector: 'browse-statistic',
6
    templateUrl: 'browseStatistic.component.html'
7

    
8
})
9
export class BrowseStatisticComponent {
10

    
11
  @Input() public baseUrl:string = "";
12
  @Input() public filter:any = "";
13
  private _maxCharacters = 30;
14
  public viewAll = false;
15
  public routerHelper:RouterHelper = new RouterHelper();
16
  keyword = "";
17
  sortBy = "num";
18
  constructor () {
19

    
20
  }
21

    
22
  public ngOnInit() {
23

    
24

    
25
  }
26

    
27
      quote(str:string){
28
        return '"'+str+'"';
29
      }
30

    
31
  public _formatName(value){
32
    let maxLineLength = 29;
33
    //3 space before number + parenthesis
34
    if(value.name.length+value.number.toLocaleString().length +3> maxLineLength){
35
      return value.name.substr(0, (maxLineLength - 3 -3 - value.number.toLocaleString().length))+'...';
36
    }
37

    
38
    return value.name;
39
  }
40
  filterKeywords(value){
41
    if(this.keyword.length > 0){
42
      if(value.toLowerCase().indexOf(this.keyword.toLowerCase()) ==-1){
43
        return false;
44
      }
45
    }
46
    return true;
47
  }
48

    
49
  getValues(filter, sortBy:string = "num"):any{
50

    
51
    if(sortBy == "name"){
52
      var array = filter.values.slice();
53
      array.sort((n1,n2)=> {
54
        if (n1.name > n2.name) {
55
            return 1;
56
        }
57

    
58
        if (n1.name < n2.name) {
59
            return -1;
60
        }
61

    
62
        return 0;
63
      });
64
      return array;
65
    }else{
66
      return filter.values;
67
    }
68

    
69

    
70
  }
71
}
(7-7/44)