1 |
57555
|
k.triantaf
|
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 |
57574
|
k.triantaf
|
import {IndicatorUtils} from "../utils/indicator-utils";
|
5 |
57555
|
k.triantaf
|
|
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 |
57594
|
k.triantaf
|
/**
|
22 |
|
|
* All charts and numbers
|
23 |
|
|
*/
|
24 |
57555
|
k.triantaf
|
public charts: Indicator[] = [];
|
25 |
|
|
public numbers: Indicator[] = [];
|
26 |
57594
|
k.triantaf
|
/**
|
27 |
|
|
* Displayed chart and numbers base on Top filters
|
28 |
|
|
*/
|
29 |
57555
|
k.triantaf
|
public displayCharts: Indicator[] = [];
|
30 |
|
|
public displayNumbers: Indicator[] = [];
|
31 |
57594
|
k.triantaf
|
/**
|
32 |
|
|
* Top filters
|
33 |
|
|
*/
|
34 |
57555
|
k.triantaf
|
public chartType: string = 'all';
|
35 |
57594
|
k.triantaf
|
public privacy: string = 'all';
|
36 |
|
|
public status: string = 'all';
|
37 |
57555
|
k.triantaf
|
public keyword: string = null;
|
38 |
57594
|
k.triantaf
|
/**
|
39 |
|
|
* Grid or List View
|
40 |
|
|
*/
|
41 |
57555
|
k.triantaf
|
public grid: boolean = true;
|
42 |
|
|
|
43 |
|
|
constructor(private sideBarService: SideBarService) {}
|
44 |
|
|
|
45 |
|
|
ngOnInit(): void {
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
ngOnChanges(changes: SimpleChanges): void {
|
49 |
57594
|
k.triantaf
|
if(this.canEdit) {
|
50 |
57555
|
k.triantaf
|
this.charts = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
|
51 |
|
|
subCategories[this.subcategoryIndex].charts;
|
52 |
57591
|
k.triantaf
|
this.displayCharts = this.filterChartType(this.filterPrivacy(
|
53 |
57594
|
k.triantaf
|
this.filterStatus(this.filterByKeyword(this.charts, this.keyword), this.status),
|
54 |
|
|
this.privacy),
|
55 |
57591
|
k.triantaf
|
this.chartType
|
56 |
|
|
);
|
57 |
57555
|
k.triantaf
|
this.numbers = this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].
|
58 |
|
|
subCategories[this.subcategoryIndex].numbers;
|
59 |
57591
|
k.triantaf
|
this.displayNumbers = this.filterPrivacy(this.filterStatus(
|
60 |
|
|
this.filterByKeyword(this.numbers, this.keyword),
|
61 |
57594
|
k.triantaf
|
this.status),
|
62 |
|
|
this.privacy);
|
63 |
57555
|
k.triantaf
|
}
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
onChartTypeChange(value) {
|
67 |
|
|
this.displayCharts = this.filterChartType(this.charts, value);
|
68 |
|
|
}
|
69 |
|
|
|
70 |
|
|
onPrivacyChange(value) {
|
71 |
|
|
this.displayCharts = this.filterPrivacy(this.charts, value);
|
72 |
|
|
this.displayNumbers = this.filterPrivacy(this.numbers, value);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
onStatusChange(value) {
|
76 |
|
|
this.displayCharts = this.filterStatus(this.charts, value);
|
77 |
|
|
this.displayNumbers = this.filterStatus(this.numbers, value);
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
onKeywordChange(value) {
|
81 |
|
|
this.displayCharts = this.filterByKeyword(this.charts, value);
|
82 |
|
|
this.displayNumbers = this.filterByKeyword(this.numbers, value);
|
83 |
|
|
}
|
84 |
|
|
|
85 |
|
|
filterChartType(indicators: Indicator[], value): Indicator[] {
|
86 |
|
|
if (value === 'all') {
|
87 |
|
|
return indicators;
|
88 |
|
|
} else {
|
89 |
|
|
return indicators.filter(indicator =>
|
90 |
|
|
indicator.indicatorPaths.filter(indicatorPath => indicatorPath.type === value).length > 0);
|
91 |
|
|
}
|
92 |
|
|
}
|
93 |
|
|
|
94 |
|
|
filterPrivacy(indicators: Indicator[], value): Indicator[] {
|
95 |
|
|
if (value === 'all') {
|
96 |
|
|
return indicators;
|
97 |
|
|
} else {
|
98 |
|
|
return indicators.filter(indicator => indicator.isPublic === (value === 'public'));
|
99 |
|
|
}
|
100 |
|
|
}
|
101 |
|
|
|
102 |
|
|
filterStatus(indicators: Indicator[], value): Indicator[] {
|
103 |
|
|
if (value === 'all') {
|
104 |
|
|
return indicators;
|
105 |
|
|
} else {
|
106 |
|
|
return indicators.filter(indicator => indicator.isActive === (value === 'active'));
|
107 |
|
|
}
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
filterByKeyword(indicators: Indicator[], value): Indicator[] {
|
111 |
|
|
if (value === null || value === '') {
|
112 |
|
|
return indicators;
|
113 |
|
|
} else {
|
114 |
|
|
return indicators.filter(indicator => indicator.name.includes(value) || indicator.description.includes(value));
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
|
118 |
|
|
get open(): boolean {
|
119 |
|
|
return this.sideBarService.open;
|
120 |
|
|
}
|
121 |
|
|
|
122 |
57594
|
k.triantaf
|
get canEdit() {
|
123 |
|
|
return this.stakeholder &&
|
124 |
|
|
this.stakeholder.topics[this.topicIndex] &&
|
125 |
|
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
|
126 |
|
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex];
|
127 |
|
|
}
|
128 |
|
|
|
129 |
57555
|
k.triantaf
|
public toggleOpen(event = null) {
|
130 |
|
|
if (!event) {
|
131 |
|
|
this.sideBarService.setOpen(!this.open);
|
132 |
|
|
} else if (event && event['value'] === true) {
|
133 |
|
|
this.sideBarService.setOpen(false);
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
|
137 |
|
|
public changeGrid(value) {
|
138 |
|
|
this.grid = value;
|
139 |
|
|
}
|
140 |
|
|
}
|