Revision 57697
Added by Konstantinos Triantafyllou over 4 years ago
indicators.component.ts | ||
---|---|---|
1 |
import {AfterViewInit, Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from "@angular/core"; |
|
1 |
import {AfterViewInit, Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild} from "@angular/core";
|
|
2 | 2 |
import {SideBarService} from "../library/sharedComponents/sidebar/sideBar.service"; |
3 | 3 |
import {Indicator, IndicatorPath, Stakeholder} from "../utils/entities/stakeholder"; |
4 |
import {IndicatorUtils} from "../utils/indicator-utils"; |
|
4 |
import {IndicatorUtils, Option} from "../utils/indicator-utils";
|
|
5 | 5 |
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms"; |
6 | 6 |
import {AlertModal} from "../openaireLibrary/utils/modal/alert"; |
7 | 7 |
import {StatisticsService} from "../utils/services/statistics.service"; |
... | ... | |
9 | 9 |
import {DomSanitizer} from "@angular/platform-browser"; |
10 | 10 |
import {StakeholderService} from "../services/stakeholder.service"; |
11 | 11 |
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties"; |
12 |
import {Subscriber} from "rxjs"; |
|
12 | 13 |
|
13 | 14 |
declare var UIkit; |
14 | 15 |
|
... | ... | |
16 | 17 |
selector: 'indicators', |
17 | 18 |
templateUrl: './indicators.component.html' |
18 | 19 |
}) |
19 |
export class IndicatorsComponent implements OnInit, OnChanges {
|
|
20 |
export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
|
|
20 | 21 |
|
21 | 22 |
@Input() |
22 | 23 |
public properties: EnvProperties = null; |
... | ... | |
44 | 45 |
/** |
45 | 46 |
* Top filters |
46 | 47 |
*/ |
47 |
public chartType: string = 'all'; |
|
48 |
public privacy: string = 'all'; |
|
49 |
public status: string = 'all'; |
|
50 |
public keyword: string = null; |
|
48 |
public filters: FormGroup; |
|
49 |
public all: Option = { |
|
50 |
value: 'all', |
|
51 |
label: 'All' |
|
52 |
}; |
|
51 | 53 |
/** |
52 | 54 |
* Grid or List View |
53 | 55 |
*/ |
54 | 56 |
public grid: boolean = true; |
57 |
private subscriptions: any[] = []; |
|
55 | 58 |
|
56 | 59 |
@ViewChild('createIndicatorModal') createIndicatorModal: AlertModal; |
57 | 60 |
@ViewChild('editIndicatorModal') editIndicatorModal: AlertModal; |
61 |
@ViewChild('deleteIndicatorModal') deleteIndicatorModal: AlertModal; |
|
58 | 62 |
|
59 | 63 |
constructor(private sideBarService: SideBarService, |
60 | 64 |
private stakeholderService: StakeholderService, |
... | ... | |
64 | 68 |
} |
65 | 69 |
|
66 | 70 |
ngOnInit(): void { |
71 |
this.buildFilters(); |
|
72 |
} |
|
73 |
|
|
74 |
ngOnDestroy(): void { |
|
75 |
this.subscriptions.forEach(value => { |
|
76 |
if (value instanceof Subscriber) { |
|
77 |
value.unsubscribe(); |
|
78 |
} else if(value instanceof Function){ |
|
79 |
value(); |
|
80 |
} |
|
81 |
}); |
|
82 |
} |
|
83 |
|
|
84 |
ngAfterViewInit(): void { |
|
67 | 85 |
if (document !== undefined) { |
68 | 86 |
let callback = (list): void => { |
69 | 87 |
let items: HTMLCollection = list.current.children; |
70 | 88 |
let reordered = []; |
71 |
let indicators = []; |
|
72 | 89 |
for (let i = 0; i < items.length; i++) { |
73 | 90 |
if (items.item(i).id) { |
74 |
reordered.push(+items.item(i).id);
|
|
91 |
reordered.push(items.item(i).id); |
|
75 | 92 |
} |
76 | 93 |
} |
77 |
if(list.current.id === 'charts') { |
|
78 |
reordered.forEach((id, index) => { |
|
79 |
indicators[index] = HelperFunctions.copy(this.charts[id]); |
|
80 |
}); |
|
81 |
this.reorderIndicators('chart', indicators); |
|
82 |
} else if(list.current.id === 'numbers') { |
|
83 |
reordered.forEach((id, index) => { |
|
84 |
indicators[index] = HelperFunctions.copy(this.numbers[id]); |
|
85 |
}); |
|
86 |
this.reorderIndicators('number', indicators); |
|
87 |
} |
|
94 |
this.reorderIndicators(list.current.id , reordered); |
|
88 | 95 |
}; |
89 |
UIkit.util.on(document, 'moved', '#charts', callback);
|
|
90 |
UIkit.util.on(document, 'moved', '#numbers', callback);
|
|
96 |
this.subscriptions.push(UIkit.util.on(document, 'moved', '#chart', callback));
|
|
97 |
this.subscriptions.push(UIkit.util.on(document, 'moved', '#number', callback));
|
|
91 | 98 |
} |
92 | 99 |
} |
93 | 100 |
|
94 | 101 |
ngOnChanges(changes: SimpleChanges): void { |
95 | 102 |
if (this.canEdit) { |
103 |
this.buildFilters(); |
|
96 | 104 |
this.filterCharts(); |
97 | 105 |
this.filterNumbers(); |
98 | 106 |
} |
... | ... | |
110 | 118 |
this.grid = value; |
111 | 119 |
} |
112 | 120 |
|
121 |
private buildFilters() { |
|
122 |
this.filters = this.fb.group({ |
|
123 |
chartType: this.fb.control('all'), |
|
124 |
privacy: this.fb.control('all'), |
|
125 |
status: this.fb.control('all'), |
|
126 |
keyword: this.fb.control('') |
|
127 |
}); |
|
128 |
this.subscriptions.push(this.filters.get('chartType').valueChanges.subscribe( value => { |
|
129 |
this.onChartTypeChange(value); |
|
130 |
})); |
|
131 |
this.subscriptions.push(this.filters.get('privacy').valueChanges.subscribe( value => { |
|
132 |
this.onPrivacyChange(value); |
|
133 |
})); |
|
134 |
this.subscriptions.push(this.filters.get('status').valueChanges.subscribe( value => { |
|
135 |
this.onStatusChange(value); |
|
136 |
})); |
|
137 |
this.subscriptions.push(this.filters.get('keyword').valueChanges.subscribe( value => { |
|
138 |
this.onKeywordChange(value); |
|
139 |
})); |
|
140 |
} |
|
141 |
|
|
113 | 142 |
filterCharts() { |
114 | 143 |
this.displayCharts = this.filterChartType(this.filterPrivacy( |
115 |
this.filterStatus(this.filterByKeyword(this.charts, this.keyword), this.status), |
|
116 |
this.privacy), |
|
117 |
this.chartType |
|
144 |
this.filterStatus(this.filterByKeyword(this.charts, this.filters.value.keyword), |
|
145 |
this.filters.value.status), |
|
146 |
this.filters.value.privacy), |
|
147 |
this.filters.value.chartType |
|
118 | 148 |
); |
119 | 149 |
} |
120 | 150 |
|
121 | 151 |
filterNumbers() { |
122 | 152 |
this.displayNumbers = this.filterPrivacy(this.filterStatus( |
123 |
this.filterByKeyword(this.numbers, this.keyword), |
|
124 |
this.status), |
|
125 |
this.privacy); |
|
153 |
this.filterByKeyword(this.numbers, this.filters.value.keyword),
|
|
154 |
this.filters.value.status),
|
|
155 |
this.filters.value.privacy);
|
|
126 | 156 |
} |
127 | 157 |
|
128 | 158 |
onChartTypeChange(value) { |
... | ... | |
130 | 160 |
} |
131 | 161 |
|
132 | 162 |
onPrivacyChange(value) { |
163 |
console.log(value); |
|
133 | 164 |
this.displayCharts = this.filterPrivacy(this.charts, value); |
134 | 165 |
this.displayNumbers = this.filterPrivacy(this.numbers, value); |
135 | 166 |
} |
... | ... | |
157 | 188 |
if (value === 'all') { |
158 | 189 |
return indicators; |
159 | 190 |
} else { |
160 |
return indicators.filter(indicator => indicator.isPublic === (value === 'public'));
|
|
191 |
return indicators.filter(indicator => indicator.isPublic === value);
|
|
161 | 192 |
} |
162 | 193 |
} |
163 | 194 |
|
... | ... | |
165 | 196 |
if (value === 'all') { |
166 | 197 |
return indicators; |
167 | 198 |
} else { |
168 |
return indicators.filter(indicator => indicator.isActive === (value === 'active'));
|
|
199 |
return indicators.filter(indicator => indicator.isActive === value);
|
|
169 | 200 |
} |
170 | 201 |
} |
171 | 202 |
|
... | ... | |
173 | 204 |
if (value === null || value === '') { |
174 | 205 |
return indicators; |
175 | 206 |
} else { |
176 |
return indicators.filter(indicator => (indicator.name && indicator.name.includes(value))
|
|
177 |
|| (indicator.description && indicator.description.includes(value)));
|
|
207 |
return indicators.filter(indicator => (indicator.name && indicator.name.toLowerCase().includes(value.toLowerCase()))
|
|
208 |
|| (indicator.description && indicator.description.toLowerCase().includes(value.toLowerCase())));
|
|
178 | 209 |
} |
179 | 210 |
} |
180 | 211 |
|
... | ... | |
322 | 353 |
this.indicator.indicatorPaths.forEach(indicatorPath => { |
323 | 354 |
indicatorPath.safeResourceUrl = this.getUrlByStakeHolder(indicatorPath) |
324 | 355 |
}); |
325 |
}, 500);
|
|
356 |
}, (index === -1)?500:0);
|
|
326 | 357 |
} |
327 | 358 |
|
328 | 359 |
saveIndicator() { |
... | ... | |
344 | 375 |
}); |
345 | 376 |
} |
346 | 377 |
|
347 |
reorderIndicators(type: string, indicators: Indicator[]) {
|
|
378 |
reorderIndicators(type: string, indicatorIds: string[]) {
|
|
348 | 379 |
let path = [ |
349 | 380 |
this.stakeholder._id, |
350 | 381 |
this.stakeholder.topics[this.topicIndex]._id, |
351 | 382 |
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id, |
352 | 383 |
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id |
353 | 384 |
]; |
354 |
this.stakeholderService.reorderIndicators(this.properties.monitorServiceAPIURL, path, indicators, type). |
|
355 |
subscribe(() => { |
|
356 |
if(type === 'chart') { |
|
385 |
this.stakeholderService.reorderIndicators(this.properties.monitorServiceAPIURL, path, indicatorIds, type).subscribe(indicators => { |
|
386 |
if (type === 'chart') { |
|
357 | 387 |
this.charts = indicators; |
358 | 388 |
this.filterCharts(); |
359 | 389 |
} else { |
... | ... | |
371 | 401 |
}); |
372 | 402 |
this.indicatorPaths.at(index).markAsPristine({onlySelf: true}); |
373 | 403 |
} |
404 |
|
|
405 |
deleteIndicatorOpen(index: number, type: string = 'chart') { |
|
406 |
this.index = index; |
|
407 |
if(type === 'chart') { |
|
408 |
this.indicator = this.charts[index]; |
|
409 |
} else { |
|
410 |
this.indicator = this.numbers[index]; |
|
411 |
} |
|
412 |
this.deleteIndicatorModal.alertTitle = 'Delete ' + this.indicator.name; |
|
413 |
this.deleteIndicatorModal.cancelButtonText = 'No'; |
|
414 |
this.deleteIndicatorModal.okButtonText = 'Yes'; |
|
415 |
this.deleteIndicatorModal.message = 'This indicator will permanently be deleted. Are you sure you want to proceed?'; |
|
416 |
this.deleteIndicatorModal.open(); |
|
417 |
} |
|
418 |
|
|
419 |
deleteIndicator() { |
|
420 |
let path = [ |
|
421 |
this.stakeholder._id, |
|
422 |
this.stakeholder.topics[this.topicIndex]._id, |
|
423 |
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id, |
|
424 |
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id, |
|
425 |
this.indicator._id |
|
426 |
]; |
|
427 |
this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path).subscribe( () => { |
|
428 |
if(this.indicator.type === 'chart') { |
|
429 |
this.charts.splice(this.index, 1); |
|
430 |
} else { |
|
431 |
this.numbers.splice(this.index, 1); |
|
432 |
} |
|
433 |
this.stakeholderService.setStakeholder(this.stakeholder); |
|
434 |
}); |
|
435 |
} |
|
374 | 436 |
} |
Also available in: Unified diff
[Monitor Dashboard]: 1. Change inputs to materials. 2. Add fonts. 3. Add uikit.js on index 4. Add reorder functionality on indicators. 5. Fix height of header to 70px