Project

General

Profile

1
import {Component, Input, OnChanges, OnInit, SimpleChanges} from "@angular/core";
2
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service";
3
import {Indicator, Stakeholder} from "../utils/entities/stakeholder";
4
import {IndicatorUtils} from "../utils/Tools";
5

    
6
@Component({
7
  selector: 'indicators',
8
  templateUrl: './indicators.component.html'
9
})
10
export class IndicatorsComponent implements OnInit, OnChanges {
11

    
12
  @Input()
13
  public topicIndex: number = 0;
14
  @Input()
15
  public categoryIndex: number = 0;
16
  @Input()
17
  public subcategoryIndex: number = 0;
18
  @Input()
19
  public stakeholder: Stakeholder = null;
20
  public indicatorUtils: IndicatorUtils = new IndicatorUtils();
21
  public charts: Indicator[] = [];
22
  public numbers: Indicator[] = [];
23
  public displayCharts: Indicator[] = [];
24
  public displayNumbers: Indicator[] = [];
25
  public chartType: string = 'all';
26
  public isPublic: string = 'all';
27
  public isActive: string = 'all';
28
  public keyword: string = null;
29
  public grid: boolean = true;
30

    
31
  constructor(private sideBarService: SideBarService) {}
32

    
33
  ngOnInit(): void {
34
  }
35

    
36
  ngOnChanges(changes: SimpleChanges): void {
37
    if(this.stakeholder) {
38
      this.charts = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
39
        subCategories[this.subcategoryIndex].charts;
40
      this.displayCharts = this.charts;
41
      this.numbers = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
42
        subCategories[this.subcategoryIndex].numbers;
43
      this.displayNumbers = this.numbers;
44
    }
45
  }
46

    
47
  onChartTypeChange(value) {
48
    this.displayCharts = this.filterChartType(this.charts, value);
49
  }
50

    
51
  onPrivacyChange(value) {
52
    this.displayCharts = this.filterPrivacy(this.charts, value);
53
    this.displayNumbers = this.filterPrivacy(this.numbers, value);
54
  }
55

    
56
  onStatusChange(value) {
57
    this.displayCharts = this.filterStatus(this.charts, value);
58
    this.displayNumbers = this.filterStatus(this.numbers, value);
59
  }
60

    
61
  onKeywordChange(value) {
62
    this.displayCharts = this.filterByKeyword(this.charts, value);
63
    this.displayNumbers = this.filterByKeyword(this.numbers, value);
64
  }
65

    
66
  filterChartType(indicators: Indicator[], value): Indicator[] {
67
    if (value === 'all') {
68
      return indicators;
69
    } else {
70
      return indicators.filter(indicator =>
71
        indicator.indicatorPaths.filter(indicatorPath => indicatorPath.type === value).length > 0);
72
    }
73
  }
74

    
75
  filterPrivacy(indicators: Indicator[], value): Indicator[] {
76
    if (value === 'all') {
77
      return indicators;
78
    } else {
79
      return indicators.filter(indicator => indicator.isPublic === (value === 'public'));
80
    }
81
  }
82

    
83
  filterStatus(indicators: Indicator[], value): Indicator[] {
84
    if (value === 'all') {
85
      return indicators;
86
    } else {
87
      return indicators.filter(indicator => indicator.isActive === (value === 'active'));
88
    }
89
  }
90

    
91
  filterByKeyword(indicators: Indicator[], value): Indicator[] {
92
    if (value === null || value === '') {
93
      return indicators;
94
    } else {
95
      return indicators.filter(indicator => indicator.name.includes(value) || indicator.description.includes(value));
96
    }
97
  }
98

    
99
  get open(): boolean {
100
    return this.sideBarService.open;
101
  }
102

    
103
  public toggleOpen(event = null) {
104
    if (!event) {
105
      this.sideBarService.setOpen(!this.open);
106
    } else if (event && event['value'] === true) {
107
      this.sideBarService.setOpen(false);
108
    }
109
  }
110

    
111
  public changeGrid(value) {
112
    this.grid = value;
113
  }
114
}
(2-2/6)