1
|
import {
|
2
|
AfterViewInit,
|
3
|
ChangeDetectorRef,
|
4
|
Component,
|
5
|
Input,
|
6
|
OnChanges,
|
7
|
OnDestroy,
|
8
|
OnInit,
|
9
|
SimpleChanges,
|
10
|
ViewChild
|
11
|
} from "@angular/core";
|
12
|
import {
|
13
|
Indicator,
|
14
|
IndicatorPath, IndicatorSize,
|
15
|
IndicatorType,
|
16
|
Section,
|
17
|
Stakeholder,
|
18
|
Visibility
|
19
|
} from "../openaireLibrary/monitor/entities/stakeholder";
|
20
|
import {IndicatorUtils, StakeholderUtils} from "../utils/indicator-utils";
|
21
|
import {FormArray, FormBuilder, FormControl, FormGroup, Validators} from "@angular/forms";
|
22
|
import {AlertModal} from "../openaireLibrary/utils/modal/alert";
|
23
|
import {StatisticsService} from "../utils/services/statistics.service";
|
24
|
import {HelperFunctions} from "../openaireLibrary/utils/HelperFunctions.class";
|
25
|
import {DomSanitizer, SafeResourceUrl} from "@angular/platform-browser";
|
26
|
import {StakeholderService} from "../openaireLibrary/monitor/services/stakeholder.service";
|
27
|
import {EnvProperties} from "../openaireLibrary/utils/properties/env-properties";
|
28
|
import {Subscriber} from "rxjs";
|
29
|
import {LayoutService} from "../openaireLibrary/dashboard/sharedComponents/sidebar/layout.service";
|
30
|
import {Router} from "@angular/router";
|
31
|
import {Session} from "../openaireLibrary/login/utils/helper.class";
|
32
|
import {UserManagementService} from "../openaireLibrary/services/user-management.service";
|
33
|
|
34
|
declare var UIkit;
|
35
|
|
36
|
@Component({
|
37
|
selector: 'indicators',
|
38
|
templateUrl: './indicators.component.html',
|
39
|
styleUrls: ['indicators.component.css']
|
40
|
})
|
41
|
export class IndicatorsComponent implements OnInit, OnDestroy, OnChanges, AfterViewInit {
|
42
|
|
43
|
@Input()
|
44
|
public properties: EnvProperties = null;
|
45
|
@Input()
|
46
|
public topicIndex: number = 0;
|
47
|
@Input()
|
48
|
public categoryIndex: number = 0;
|
49
|
@Input()
|
50
|
public subcategoryIndex: number = 0;
|
51
|
public stakeholder: Stakeholder = null;
|
52
|
public user = null;
|
53
|
public preview: string;
|
54
|
public indicatorUtils: IndicatorUtils = new IndicatorUtils();
|
55
|
public stakeholderUtils: StakeholderUtils = new StakeholderUtils();
|
56
|
public numberIndicatorFb: FormGroup;
|
57
|
public chartIndicatorFb: FormGroup;
|
58
|
public chartSections: FormArray;
|
59
|
public numberSections: FormArray;
|
60
|
/**
|
61
|
* Editable indicator
|
62
|
*/
|
63
|
public section: Section;
|
64
|
public indicator: Indicator;
|
65
|
public index: number = -1;
|
66
|
/**
|
67
|
* Displayed chart and numbers base on Top filters
|
68
|
*/
|
69
|
public displayCharts: Section[] = [];
|
70
|
public displayNumbers: Section[] = [];
|
71
|
/**
|
72
|
* Top filters
|
73
|
*/
|
74
|
@Input()
|
75
|
public filters: FormGroup;
|
76
|
/**
|
77
|
* Toggles
|
78
|
*/
|
79
|
// public grid: boolean = true;
|
80
|
public editing: boolean = false;
|
81
|
/** Safe Urls*/
|
82
|
public safeUrls: Map<string, SafeResourceUrl> = new Map<string, SafeResourceUrl>([]);
|
83
|
public numberResults: Map<string, number> = new Map<string, number>();
|
84
|
private subscriptions: any[] = [];
|
85
|
private urlSubscriptions: any[] = [];
|
86
|
@ViewChild('editChartModal') editChartModal: AlertModal;
|
87
|
@ViewChild('editNumberModal') editNumberModal: AlertModal;
|
88
|
@ViewChild('deleteModal') deleteModal: AlertModal;
|
89
|
//@ViewChild('deleteAllModal') deleteAllModal: AlertModal;
|
90
|
//@ViewChild('deleteAndDisconnectModal') deleteAndDisconnectModal: AlertModal;
|
91
|
//@ViewChild('deleteChartSectionModal') deleteChartSectionModal: AlertModal;
|
92
|
//@ViewChild('deleteNumberSectionModal') deleteNumberSectionModal: AlertModal;
|
93
|
@ViewChild('deleteSectionModal') deleteSectionModal: AlertModal;
|
94
|
public sectionTypeToDelete: string;
|
95
|
public sectionChildrenActionOnDelete: string;
|
96
|
public indicatorChildrenActionOnDelete: string;
|
97
|
|
98
|
urlParameterizedMessage = null;
|
99
|
|
100
|
constructor(private layoutService: LayoutService,
|
101
|
private stakeholderService: StakeholderService,
|
102
|
private statisticsService: StatisticsService,
|
103
|
private userManagementService: UserManagementService,
|
104
|
private fb: FormBuilder,
|
105
|
private router: Router,
|
106
|
private cdr: ChangeDetectorRef,
|
107
|
private sanitizer: DomSanitizer) {
|
108
|
}
|
109
|
|
110
|
ngOnInit(): void {
|
111
|
this.subscriptions.push(this.userManagementService.getUserInfo().subscribe(user => {
|
112
|
this.user = user;
|
113
|
}));
|
114
|
this.subscriptions.push(this.stakeholderService.getStakeholderAsObservable().subscribe(stakeholder => {
|
115
|
this.stakeholder = stakeholder;
|
116
|
if (this.stakeholder) {
|
117
|
this.buildFilters();
|
118
|
this.buildSections();
|
119
|
this.filterCharts();
|
120
|
this.filterNumbers();
|
121
|
this.setPreview();
|
122
|
}
|
123
|
}));
|
124
|
}
|
125
|
|
126
|
ngOnDestroy(): void {
|
127
|
this.subscriptions.forEach(value => {
|
128
|
if (value instanceof Subscriber) {
|
129
|
value.unsubscribe();
|
130
|
} else if (value instanceof Function) {
|
131
|
value();
|
132
|
}
|
133
|
});
|
134
|
this.urlSubscriptions.forEach(value => {
|
135
|
if (value instanceof Subscriber) {
|
136
|
value.unsubscribe();
|
137
|
}
|
138
|
});
|
139
|
}
|
140
|
|
141
|
ngAfterViewInit(): void {
|
142
|
this.initReorder();
|
143
|
}
|
144
|
|
145
|
ngOnChanges(changes: SimpleChanges): void {
|
146
|
if (this.canEdit) {
|
147
|
if (changes.topicIndex || changes.categoryIndex || changes.subcategoryIndex) {
|
148
|
this.buildFilters();
|
149
|
this.initReorder();
|
150
|
}
|
151
|
this.filterCharts();
|
152
|
this.filterNumbers();
|
153
|
}
|
154
|
this.setPreview();
|
155
|
}
|
156
|
|
157
|
setNumberIndicators() {
|
158
|
this.numberResults.clear();
|
159
|
let urls: Map<string, [number, number][]> = new Map<string, [number, number][]>();
|
160
|
this.numbers.forEach((section, i) => {
|
161
|
section.indicators.forEach((number, j) => {
|
162
|
let url = this.indicatorUtils.getFullUrlWithFilters(this.stakeholder, number.indicatorPaths[0]);
|
163
|
const pair = JSON.stringify([number.indicatorPaths[0].source, url]);
|
164
|
const indexes = urls.get(pair) ? urls.get(pair) : [];
|
165
|
indexes.push([i, j]);
|
166
|
urls.set(pair, indexes);
|
167
|
});
|
168
|
});
|
169
|
urls.forEach((indexes, pair) => {
|
170
|
pair = JSON.parse(pair);
|
171
|
this.subscriptions.push(this.statisticsService.getNumbers(this.statisticsService.getSourceType(pair[0]), pair[1]).subscribe(response => {
|
172
|
indexes.forEach(([i, j]) => {
|
173
|
let result = JSON.parse(JSON.stringify(response));
|
174
|
this.numbers[i].indicators[j].indicatorPaths[0].jsonPath.forEach(jsonPath => {
|
175
|
if (result) {
|
176
|
result = result[jsonPath];
|
177
|
}
|
178
|
});
|
179
|
this.numberResults.set(i + '-' + j, result);
|
180
|
});
|
181
|
}));
|
182
|
});
|
183
|
}
|
184
|
|
185
|
setPreview() {
|
186
|
if (this.stakeholder) {
|
187
|
this.preview = '/' + this.stakeholder.alias;
|
188
|
if (this.stakeholder.topics[this.topicIndex]) {
|
189
|
this.preview = '/' + this.stakeholder.alias + '/' + this.stakeholder.topics[this.topicIndex].alias;
|
190
|
if (this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]) {
|
191
|
this.preview += '/' + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].alias;
|
192
|
if (this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) {
|
193
|
this.preview += '/' + this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].alias;
|
194
|
}
|
195
|
}
|
196
|
}
|
197
|
}
|
198
|
}
|
199
|
|
200
|
initReorder() {
|
201
|
this.subscriptions.forEach(value => {
|
202
|
if (value instanceof Function) {
|
203
|
value();
|
204
|
}
|
205
|
});
|
206
|
if (document !== undefined) {
|
207
|
let callback = (list, type: IndicatorType): void => {
|
208
|
let items: HTMLCollection = list.current.children;
|
209
|
let reordered = [];
|
210
|
for (let i = 0; i < items.length; i++) {
|
211
|
if (items.item(i).id) {
|
212
|
reordered.push(items.item(i).id);
|
213
|
}
|
214
|
}
|
215
|
this.reorderIndicators(list.current.id.toString().split('-')[1], type, reordered);
|
216
|
};
|
217
|
this.numbers.forEach((section) => {
|
218
|
this.subscriptions.push(UIkit.util.on(document, 'moved', '#number-' + section._id, (list): void => {
|
219
|
callback(list, "number");
|
220
|
}));
|
221
|
this.subscriptions.push(UIkit.util.on(document, 'added', '#number-' + section._id, (list): void => {
|
222
|
callback(list, "number");
|
223
|
}));
|
224
|
this.subscriptions.push(UIkit.util.on(document, 'removed', '#number-' + section._id, (list): void => {
|
225
|
callback(list, "number");
|
226
|
}));
|
227
|
});
|
228
|
this.charts.forEach((section) => {
|
229
|
this.subscriptions.push(UIkit.util.on(document, 'moved', '#chart-' + section._id, (list): void => {
|
230
|
callback(list, "chart");
|
231
|
}));
|
232
|
this.subscriptions.push(UIkit.util.on(document, 'added', '#chart-' + section._id, (list): void => {
|
233
|
callback(list, "chart");
|
234
|
}));
|
235
|
this.subscriptions.push(UIkit.util.on(document, 'removed', '#chart-' + section._id, (list): void => {
|
236
|
callback(list, "chart");
|
237
|
}));
|
238
|
});
|
239
|
}
|
240
|
}
|
241
|
|
242
|
hide(element: any) {
|
243
|
UIkit.dropdown(element).hide();
|
244
|
}
|
245
|
|
246
|
private buildFilters() {
|
247
|
this.subscriptions.push(this.filters.get('chartType').valueChanges.subscribe(value => {
|
248
|
this.onChartTypeChange(value);
|
249
|
}));
|
250
|
|
251
|
this.subscriptions.push(this.filters.get('status').valueChanges.subscribe(value => {
|
252
|
this.onStatusChange(value);
|
253
|
}));
|
254
|
this.subscriptions.push(this.filters.get('keyword').valueChanges.subscribe(value => {
|
255
|
this.onKeywordChange(value);
|
256
|
}));
|
257
|
}
|
258
|
|
259
|
private buildSections() {
|
260
|
this.numberSections = this.fb.array([]);
|
261
|
this.numbers.forEach(section => {
|
262
|
this.numberSections.push(this.fb.group({
|
263
|
_id: this.fb.control(section._id),
|
264
|
title: this.fb.control(section.title),
|
265
|
creationDate: this.fb.control(section.creationDate),
|
266
|
stakeholderAlias: this.fb.control(section.stakeholderAlias),
|
267
|
defaultId: this.fb.control(section.defaultId),
|
268
|
type: this.fb.control(section.type),
|
269
|
indicators: this.fb.control(section.indicators)
|
270
|
}));
|
271
|
});
|
272
|
this.chartSections = this.fb.array([]);
|
273
|
this.charts.forEach(section => {
|
274
|
this.chartSections.push(this.fb.group({
|
275
|
_id: this.fb.control(section._id),
|
276
|
title: this.fb.control(section.title),
|
277
|
creationDate: this.fb.control(section.creationDate),
|
278
|
stakeholderAlias: this.fb.control(section.stakeholderAlias),
|
279
|
defaultId: this.fb.control(section.defaultId),
|
280
|
type: this.fb.control(section.type),
|
281
|
indicators: this.fb.control(section.indicators)
|
282
|
}));
|
283
|
});
|
284
|
}
|
285
|
|
286
|
filterCharts() {
|
287
|
this.displayCharts = this.filterChartType(
|
288
|
this.filterStatus(this.filterByKeyword(HelperFunctions.copy(this.charts), this.filters.value.keyword),
|
289
|
this.filters.value.status),
|
290
|
this.filters.value.chartType
|
291
|
);
|
292
|
this.displayCharts.forEach(section => {
|
293
|
section.indicators.forEach(indicator => {
|
294
|
indicator.indicatorPaths.forEach(indicatorPath => {
|
295
|
let url = this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath);
|
296
|
if (!this.safeUrls.get('url')) {
|
297
|
indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
|
298
|
this.safeUrls.set(url, indicatorPath.safeResourceUrl);
|
299
|
}
|
300
|
});
|
301
|
})
|
302
|
});
|
303
|
this.buildSections();
|
304
|
}
|
305
|
|
306
|
filterNumbers() {
|
307
|
this.displayNumbers = this.filterStatus(
|
308
|
this.filterByKeyword(HelperFunctions.copy(this.numbers), this.filters.value.keyword),
|
309
|
this.filters.value.status);
|
310
|
this.buildSections();
|
311
|
this.setNumberIndicators();
|
312
|
}
|
313
|
|
314
|
onChartTypeChange(value) {
|
315
|
this.displayCharts = this.filterChartType(HelperFunctions.copy(this.charts), value);
|
316
|
}
|
317
|
|
318
|
|
319
|
onStatusChange(value) {
|
320
|
this.displayCharts = this.filterStatus(HelperFunctions.copy(this.charts), value);
|
321
|
this.displayNumbers = this.filterStatus(HelperFunctions.copy(this.numbers), value);
|
322
|
}
|
323
|
|
324
|
onKeywordChange(value) {
|
325
|
this.displayCharts = this.filterByKeyword(HelperFunctions.copy(this.charts), value);
|
326
|
this.displayNumbers = this.filterByKeyword(HelperFunctions.copy(this.numbers), value);
|
327
|
}
|
328
|
|
329
|
private filterChartType(sections: Section[], value): Section[] {
|
330
|
if (value !== 'all') {
|
331
|
sections.forEach(section =>
|
332
|
section.indicators = section.indicators.filter(indicator =>
|
333
|
indicator.indicatorPaths.filter(indicatorPath => indicatorPath.type === value).length > 0));
|
334
|
}
|
335
|
return sections;
|
336
|
}
|
337
|
|
338
|
|
339
|
private filterStatus(sections: Section[], value): Section[] {
|
340
|
if (value !== 'all') {
|
341
|
sections.forEach(section =>
|
342
|
section.indicators = section.indicators.filter(indicator => indicator.visibility === value));
|
343
|
}
|
344
|
return sections;
|
345
|
}
|
346
|
|
347
|
private filterByKeyword(sections: Section[], value): Section[] {
|
348
|
if (value !== null && value !== '') {
|
349
|
sections.forEach(section =>
|
350
|
section.indicators = section.indicators.filter(indicator => (indicator.name && indicator.name.toLowerCase().includes(value.toLowerCase()))
|
351
|
|| (indicator.description && indicator.description.toLowerCase().includes(value.toLowerCase()))
|
352
|
|| (indicator.additionalDescription && indicator.additionalDescription.toLowerCase().includes(value.toLowerCase()))
|
353
|
|| indicator.indicatorPaths.filter(indicatorPath => (indicatorPath.parameters && indicatorPath.parameters.title &&
|
354
|
indicatorPath.parameters.title.includes(value.toLowerCase()))).length > 0));
|
355
|
}
|
356
|
return sections;
|
357
|
}
|
358
|
|
359
|
get charts(): Section[] {
|
360
|
if (this.stakeholder.topics[this.topicIndex] &&
|
361
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
|
362
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) {
|
363
|
return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts;
|
364
|
} else {
|
365
|
return [];
|
366
|
}
|
367
|
}
|
368
|
|
369
|
set charts(sections: Section[]) {
|
370
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].charts = sections;
|
371
|
}
|
372
|
|
373
|
get numbers(): Section[] {
|
374
|
if (this.stakeholder.topics[this.topicIndex] &&
|
375
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
|
376
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]) {
|
377
|
return this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers;
|
378
|
} else {
|
379
|
return [];
|
380
|
}
|
381
|
}
|
382
|
|
383
|
set numbers(sections: Section[]) {
|
384
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex].numbers = sections;
|
385
|
}
|
386
|
|
387
|
get open(): boolean {
|
388
|
return this.layoutService.open;
|
389
|
}
|
390
|
|
391
|
get canReorder(): boolean {
|
392
|
return this.filters.value.chartType === 'all' &&
|
393
|
this.filters.value.status === 'all' && this.filters.value.keyword === '' && !this.editing;
|
394
|
}
|
395
|
|
396
|
get canEdit() {
|
397
|
return this.stakeholder &&
|
398
|
this.stakeholder.topics[this.topicIndex] &&
|
399
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex] &&
|
400
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex];
|
401
|
}
|
402
|
|
403
|
public get numberIndicatorPaths(): FormArray {
|
404
|
return this.numberIndicatorFb.get('indicatorPaths') as FormArray;
|
405
|
}
|
406
|
|
407
|
public get chartIndicatorPaths(): FormArray {
|
408
|
return this.chartIndicatorFb.get('indicatorPaths') as FormArray;
|
409
|
}
|
410
|
|
411
|
public getNumberClassBySize(size: IndicatorSize) {
|
412
|
if(size === 'small') {
|
413
|
return 'uk-width-1-4@xl uk-width-1-3@l uk-width-1-2@m uk-width-1-1';
|
414
|
} else if(size === 'medium') {
|
415
|
return 'uk-width-1-3@l uk-width-1-2@m uk-width-1-1';
|
416
|
} else {
|
417
|
return 'uk-width-1-2@l uk-width-1-1@m uk-width-1-1';
|
418
|
}
|
419
|
}
|
420
|
|
421
|
public getChartClassBySize(size: IndicatorSize) {
|
422
|
if(size === 'small') {
|
423
|
return 'uk-width-1-3@xl uk-width-1-2@m uk-width-1-1';
|
424
|
} else if(size === 'medium') {
|
425
|
return 'uk-width-1-2@l uk-width-1-1';
|
426
|
} else {
|
427
|
return 'uk-width-1-1';
|
428
|
}
|
429
|
}
|
430
|
|
431
|
public addJsonPath(index: number) {
|
432
|
if (index == 0 && this.getJsonPath(index).getRawValue()[index].indexOf(",") != -1) {
|
433
|
//if in the first path there are more than one paaths comma separated, split them and autogenerate the forms
|
434
|
let paths = this.getJsonPath(index).getRawValue()[index].split(",");
|
435
|
for (let i = 0; i < paths.length; i++) {
|
436
|
if (i != 0) {
|
437
|
this.getJsonPath(index).push(this.fb.control('', Validators.required));
|
438
|
}
|
439
|
}
|
440
|
this.getJsonPath(index).setValue(paths)
|
441
|
return;
|
442
|
}
|
443
|
this.getJsonPath(index).push(this.fb.control('', Validators.required));
|
444
|
}
|
445
|
|
446
|
public removeJsonPath(i: number, j: number) {
|
447
|
this.getJsonPath(i).removeAt(j);
|
448
|
if (this.getJsonPath(i).length !== this.getCurrentJsonPath(i).length) {
|
449
|
this.getJsonPath(i).markAsDirty();
|
450
|
}
|
451
|
}
|
452
|
|
453
|
public validateJsonPath(index: number) {
|
454
|
let indicatorPath: FormGroup = <FormGroup>this.numberIndicatorPaths.at(index);
|
455
|
if(this.indicator.defaultId === null) {
|
456
|
this.getJsonPath(index).disable();
|
457
|
}
|
458
|
indicatorPath.get('result').setErrors({validating: true});
|
459
|
this.subscriptions.push(this.statisticsService.getNumbers(null, indicatorPath.get('url').value).subscribe(response => {
|
460
|
let result = JSON.parse(JSON.stringify(response));
|
461
|
this.getJsonPath(index).controls.forEach(jsonPath => {
|
462
|
if (result) {
|
463
|
result = result[jsonPath.value];
|
464
|
}
|
465
|
});
|
466
|
setTimeout(() => {
|
467
|
if(this.indicator.defaultId === null) {
|
468
|
this.getJsonPath(index).enable();
|
469
|
}
|
470
|
indicatorPath.get('result').setErrors(null);
|
471
|
console.debug(result);
|
472
|
if(typeof result === 'string' || typeof result === 'number') {
|
473
|
result = Number(result);
|
474
|
if (result !== Number.NaN) {
|
475
|
indicatorPath.get('result').setValue(result);
|
476
|
} else {
|
477
|
indicatorPath.get('result').setValue(null);
|
478
|
}
|
479
|
} else {
|
480
|
indicatorPath.get('result').setValue(null);
|
481
|
}
|
482
|
}, 500);
|
483
|
}));
|
484
|
}
|
485
|
|
486
|
public getJsonPath(index: number): FormArray {
|
487
|
return this.numberIndicatorPaths.at(index).get('jsonPath') as FormArray;
|
488
|
}
|
489
|
|
490
|
public getCurrentJsonPath(index: number): string[] {
|
491
|
return this.section.indicators[this.index].indicatorPaths[index].jsonPath;
|
492
|
}
|
493
|
|
494
|
public getParameters(index: number): FormArray {
|
495
|
return this.chartIndicatorPaths.at(index).get('parameters') as FormArray;
|
496
|
}
|
497
|
|
498
|
public getParameter(index: number, key: string): FormControl {
|
499
|
return this.getParameters(index).controls.filter(control => control.value.key === key)[0] as FormControl;
|
500
|
}
|
501
|
|
502
|
private getSecureUrlByStakeHolder(indicatorPath: IndicatorPath) {
|
503
|
return this.sanitizer.bypassSecurityTrustResourceUrl(
|
504
|
this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)));
|
505
|
}
|
506
|
|
507
|
private getUrlByStakeHolder(indicatorPath: IndicatorPath) {
|
508
|
return this.statisticsService.getChartUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath));
|
509
|
}
|
510
|
|
511
|
public addNumberIndicatorPath(url: string = '', parameters: FormArray = new FormArray([]), source: string = 'stats-tool', jsonPath: FormArray = new FormArray([])) {
|
512
|
if (jsonPath.length === 0) {
|
513
|
jsonPath.push(this.fb.control('', Validators.required));
|
514
|
}
|
515
|
this.numberIndicatorPaths.push(this.fb.group({
|
516
|
url: this.fb.control(url, Validators.required),
|
517
|
jsonPath: jsonPath,
|
518
|
result: this.fb.control(0, Validators.required),
|
519
|
// parameters: parameters,
|
520
|
source: this.fb.control(source, Validators.required)
|
521
|
}
|
522
|
));
|
523
|
for (let index = 0; index < this.numberIndicatorPaths.length; index++) {
|
524
|
if(this.numberIndicatorPaths.at(index).get('url').valid) {
|
525
|
this.validateJsonPath(index);
|
526
|
}
|
527
|
if(this.indicator.defaultId === null) {
|
528
|
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
|
529
|
this.numberIndicatorPaths.at(index).get('result').setValue(null);
|
530
|
if (this.numberIndicatorPaths.at(index).get('url').valid) {
|
531
|
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByNumberUrl(this.statisticsService.getNumberSource(value), value, this.stakeholder, this.numberIndicatorPaths.at(index).get('jsonPath').value, this.statisticsService.numberSources.get(this.statisticsService.getNumberSource(value)));
|
532
|
if ((indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1)
|
533
|
|| (!indicatorPath.chartObject && indicatorPath.url.indexOf("index_id") == -1 && indicatorPath.url.indexOf("index_name") == -1 && (indicatorPath.url).indexOf("index_shortName") == -1)) {
|
534
|
// default profile
|
535
|
if (this.stakeholder.defaultId == null) {
|
536
|
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."
|
537
|
} else {
|
538
|
this.urlParameterizedMessage = "This indicator couldn't be generated properly. Please make sure chart data is for the current stakeholder."
|
539
|
}
|
540
|
} else {
|
541
|
this.urlParameterizedMessage = null;
|
542
|
}
|
543
|
if (this.indicator.indicatorPaths[index]) {
|
544
|
this.indicator.indicatorPaths[index] = indicatorPath;
|
545
|
} else {
|
546
|
this.indicator.indicatorPaths.push(indicatorPath);
|
547
|
}
|
548
|
if (indicatorPath.source) {
|
549
|
this.numberIndicatorPaths.at(index).get('source').setValue(indicatorPath.source);
|
550
|
}
|
551
|
if(indicatorPath.jsonPath.length > 1 && this.getJsonPath(index).length ==1 ) {
|
552
|
let paths = indicatorPath.jsonPath;
|
553
|
for (let i = 0; i < paths.length; i++) {
|
554
|
if (i == this.getJsonPath(index).length) {
|
555
|
this.getJsonPath(index).push(this.fb.control('', Validators.required));
|
556
|
}
|
557
|
}
|
558
|
this.getJsonPath(index).setValue(paths)
|
559
|
}
|
560
|
} else {
|
561
|
this.urlParameterizedMessage = null;
|
562
|
}
|
563
|
})
|
564
|
);
|
565
|
|
566
|
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('jsonPath').valueChanges.subscribe(value => {
|
567
|
if (this.indicator.indicatorPaths[index]) {
|
568
|
this.indicator.indicatorPaths[index].jsonPath = value;
|
569
|
}
|
570
|
this.numberIndicatorPaths.at(index).get('result').setValue(null);
|
571
|
})
|
572
|
);
|
573
|
this.subscriptions.push(this.numberIndicatorPaths.at(index).get('source').valueChanges.subscribe(value => {
|
574
|
if (this.indicator.indicatorPaths[index]) {
|
575
|
this.indicator.indicatorPaths[index].source = value;
|
576
|
}
|
577
|
})
|
578
|
);
|
579
|
} else {
|
580
|
this.numberIndicatorPaths.at(index).get('url').disable();
|
581
|
this.numberIndicatorPaths.at(index).get('jsonPath').disable();
|
582
|
this.numberIndicatorPaths.at(index).get('source').disable();
|
583
|
}
|
584
|
}
|
585
|
}
|
586
|
|
587
|
public addChartIndicatorPath(value: string = '', parameters: FormArray = new FormArray([]), disableUrl: boolean = false, type: string = null) {
|
588
|
this.chartIndicatorPaths.push(this.fb.group({
|
589
|
url: this.fb.control(value, [Validators.required,
|
590
|
Validators.pattern('https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.' +
|
591
|
'[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.' +
|
592
|
'[a-zA-Z0-9]+\.[^\s]{2,}')]),
|
593
|
parameters: parameters,
|
594
|
type: this.fb.control(type)
|
595
|
}
|
596
|
));
|
597
|
if (disableUrl) {
|
598
|
for (let index = 0; index < this.chartIndicatorPaths.length; index++) {
|
599
|
this.chartIndicatorPaths.at(index).get('url').disable();
|
600
|
}
|
601
|
} else {
|
602
|
for (let index = 0; index < this.chartIndicatorPaths.length; index++) {
|
603
|
this.urlSubscriptions.push(this.chartIndicatorPaths.at(index).get('url').valueChanges.subscribe(value => {
|
604
|
if (this.chartIndicatorPaths.at(index).get('url').valid) {
|
605
|
let indicatorPath: IndicatorPath = this.indicatorUtils.generateIndicatorByChartUrl(this.statisticsService.getChartSource(value), value, this.chartIndicatorPaths.at(index).get('type').value, this.stakeholder);
|
606
|
if (indicatorPath.chartObject && Object.keys(indicatorPath.parameters).indexOf("index_id") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_name") == -1 && Object.keys(indicatorPath.parameters).indexOf("index_shortName") == -1) {
|
607
|
// default profile
|
608
|
if (this.stakeholder.defaultId == null) {
|
609
|
this.urlParameterizedMessage = "This chart couldn't be generated properly. Stakeholders based on this profile may not inherit the data correctly."
|
610
|
} else {
|
611
|
this.urlParameterizedMessage = "This chart couldn't be generated properly. Please make sure chart data is for the current stakeholder."
|
612
|
}
|
613
|
} else {
|
614
|
this.urlParameterizedMessage = null;
|
615
|
}
|
616
|
(this.chartIndicatorPaths.at(index) as FormGroup).get('type').setValue(indicatorPath.type);
|
617
|
let parameters = this.getParametersAsFormArray(indicatorPath);
|
618
|
(this.chartIndicatorPaths.at(index) as FormGroup).setControl('parameters', parameters);
|
619
|
if (!this.indicator.indicatorPaths[index]) {
|
620
|
this.indicator.indicatorPaths[index] = indicatorPath;
|
621
|
this.indicator.indicatorPaths[index].safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
|
622
|
} else {
|
623
|
indicatorPath.safeResourceUrl = this.indicator.indicatorPaths[index].safeResourceUrl;
|
624
|
this.indicator.indicatorPaths[index] = indicatorPath;
|
625
|
}
|
626
|
} else {
|
627
|
this.urlParameterizedMessage = null;
|
628
|
}
|
629
|
})
|
630
|
);
|
631
|
}
|
632
|
}
|
633
|
}
|
634
|
|
635
|
private getJsonPathAsFormArray(indicatorPath: IndicatorPath): FormArray {
|
636
|
let jsonPath = this.fb.array([]);
|
637
|
if (indicatorPath.jsonPath) {
|
638
|
indicatorPath.jsonPath.forEach(path => {
|
639
|
jsonPath.push(this.fb.control(path, Validators.required));
|
640
|
});
|
641
|
}
|
642
|
return jsonPath;
|
643
|
}
|
644
|
|
645
|
private getParametersAsFormArray(indicatorPath: IndicatorPath): FormArray {
|
646
|
let parameters = this.fb.array([]);
|
647
|
if (indicatorPath.parameters) {
|
648
|
Object.keys(indicatorPath.parameters).forEach(key => {
|
649
|
if (this.indicatorUtils.ignoredParameters.indexOf(key) === -1) {
|
650
|
if (this.indicatorUtils.parametersValidators.has(key)) {
|
651
|
parameters.push(this.fb.group({
|
652
|
key: this.fb.control(key),
|
653
|
value: this.fb.control(indicatorPath.parameters[key], this.indicatorUtils.parametersValidators.get(key))
|
654
|
}));
|
655
|
} else {
|
656
|
parameters.push(this.fb.group({
|
657
|
key: this.fb.control(key),
|
658
|
value: this.fb.control(indicatorPath.parameters[key])
|
659
|
}));
|
660
|
}
|
661
|
}
|
662
|
});
|
663
|
}
|
664
|
return parameters;
|
665
|
}
|
666
|
|
667
|
public editNumberIndicatorOpen(section: Section, id = null) {
|
668
|
this.urlParameterizedMessage = null;
|
669
|
this.section = section;
|
670
|
this.index = (id) ? section.indicators.findIndex(value => value._id === id) : -1;
|
671
|
if (this.index !== -1) {
|
672
|
this.indicator = HelperFunctions.copy(this.section.indicators[this.index]);
|
673
|
this.numberIndicatorFb = this.fb.group({
|
674
|
_id: this.fb.control(this.indicator._id),
|
675
|
name: this.fb.control(this.indicator.name, Validators.required),
|
676
|
description: this.fb.control(this.indicator.description),
|
677
|
creationDate: this.fb.control(this.indicator.creationDate),
|
678
|
additionalDescription: this.fb.control(this.indicator.additionalDescription),
|
679
|
visibility: this.fb.control(this.indicator.visibility),
|
680
|
indicatorPaths: this.fb.array([], Validators.required),
|
681
|
type: this.fb.control(this.indicator.type),
|
682
|
width: this.fb.control(this.indicator.width),
|
683
|
height: this.fb.control(this.indicator.height),
|
684
|
defaultId: this.fb.control(this.indicator.defaultId)
|
685
|
});
|
686
|
this.indicator.indicatorPaths.forEach(indicatorPath => {
|
687
|
this.addNumberIndicatorPath(this.statisticsService.getNumberUrl(indicatorPath.source, this.indicatorUtils.getFullUrl(this.stakeholder, indicatorPath)), indicatorPath.parameters, indicatorPath.source, this.getJsonPathAsFormArray(indicatorPath));
|
688
|
});
|
689
|
} else {
|
690
|
this.indicator = new Indicator('', '', '', 'number', 'small', 'small', "PUBLIC", []);
|
691
|
this.numberIndicatorFb = this.fb.group({
|
692
|
_id: this.fb.control(this.indicator._id),
|
693
|
name: this.fb.control(this.indicator.name, Validators.required),
|
694
|
description: this.fb.control(this.indicator.description),
|
695
|
additionalDescription: this.fb.control(this.indicator.additionalDescription),
|
696
|
visibility: this.fb.control(this.indicator.visibility),
|
697
|
indicatorPaths: this.fb.array([], Validators.required),
|
698
|
type: this.fb.control(this.indicator.type),
|
699
|
width: this.fb.control(this.indicator.width),
|
700
|
height: this.fb.control(this.indicator.height),
|
701
|
defaultId: this.fb.control(this.indicator.defaultId)
|
702
|
});
|
703
|
this.addNumberIndicatorPath();
|
704
|
}
|
705
|
if (this.indicator.defaultId) {
|
706
|
setTimeout(() => {
|
707
|
this.numberIndicatorFb.get('description').disable();
|
708
|
}, 0);
|
709
|
}
|
710
|
this.editNumberModal.cancelButtonText = 'Cancel';
|
711
|
this.editNumberModal.okButtonLeft = false;
|
712
|
this.editNumberModal.alertMessage = false;
|
713
|
if (this.index === -1) {
|
714
|
this.editNumberModal.alertTitle = 'Create a new number indicator';
|
715
|
this.editNumberModal.okButtonText = 'Save';
|
716
|
} else {
|
717
|
this.editNumberModal.alertTitle = 'Edit number indicator\'s information';
|
718
|
this.editNumberModal.okButtonText = 'Save Changes';
|
719
|
}
|
720
|
this.editNumberModal.open();
|
721
|
}
|
722
|
|
723
|
public editChartIndicatorOpen(section: Section, id = null) {
|
724
|
this.urlParameterizedMessage = null;
|
725
|
this.urlSubscriptions.forEach(value => {
|
726
|
if (value instanceof Subscriber) {
|
727
|
value.unsubscribe();
|
728
|
}
|
729
|
});
|
730
|
this.section = section;
|
731
|
this.index = (id) ? section.indicators.findIndex(value => value._id === id) : -1;
|
732
|
if (this.index !== -1) {
|
733
|
this.indicator = HelperFunctions.copy(this.section.indicators[this.index]);
|
734
|
this.chartIndicatorFb = this.fb.group({
|
735
|
_id: this.fb.control(this.indicator._id),
|
736
|
name: this.fb.control(this.indicator.name),
|
737
|
creationDate: this.fb.control(this.indicator.creationDate),
|
738
|
description: this.fb.control(this.indicator.description),
|
739
|
additionalDescription: this.fb.control(this.indicator.additionalDescription),
|
740
|
visibility: this.fb.control(this.indicator.visibility),
|
741
|
indicatorPaths: this.fb.array([]),
|
742
|
width: this.fb.control(this.indicator.width),
|
743
|
height: this.fb.control(this.indicator.height),
|
744
|
defaultId: this.fb.control(this.indicator.defaultId)
|
745
|
});
|
746
|
this.indicator.indicatorPaths.forEach(indicatorPath => {
|
747
|
this.addChartIndicatorPath(this.getUrlByStakeHolder(indicatorPath),
|
748
|
this.getParametersAsFormArray(indicatorPath), this.indicator.defaultId !== null, indicatorPath.type);
|
749
|
indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
|
750
|
});
|
751
|
} else {
|
752
|
this.indicator = new Indicator('', '', '', 'chart', 'medium', 'medium', "PUBLIC", []);
|
753
|
this.chartIndicatorFb = this.fb.group({
|
754
|
_id: this.fb.control(this.indicator._id),
|
755
|
name: this.fb.control(this.indicator.name),
|
756
|
description: this.fb.control(this.indicator.description),
|
757
|
additionalDescription: this.fb.control(this.indicator.additionalDescription),
|
758
|
visibility: this.fb.control(this.indicator.visibility),
|
759
|
indicatorPaths: this.fb.array([]),
|
760
|
width: this.fb.control(this.indicator.width, Validators.required),
|
761
|
height: this.fb.control(this.indicator.height, Validators.required),
|
762
|
defaultId: this.fb.control(this.indicator.defaultId)
|
763
|
});
|
764
|
this.addChartIndicatorPath();
|
765
|
}
|
766
|
if (this.indicator.defaultId) {
|
767
|
setTimeout(() => {
|
768
|
this.chartIndicatorFb.get('description').disable();
|
769
|
}, 0);
|
770
|
}
|
771
|
this.editChartModal.cancelButtonText = 'Cancel';
|
772
|
this.editChartModal.okButtonLeft = false;
|
773
|
this.editChartModal.alertMessage = false;
|
774
|
if (this.index === -1) {
|
775
|
this.editChartModal.alertTitle = 'Create a new chart indicator';
|
776
|
this.editChartModal.okButtonText = 'Save';
|
777
|
} else {
|
778
|
this.editChartModal.alertTitle = 'Edit chart indicator\'s information';
|
779
|
this.editChartModal.okButtonText = 'Save Changes';
|
780
|
}
|
781
|
this.editChartModal.open();
|
782
|
}
|
783
|
|
784
|
saveIndicator() {
|
785
|
this.editing = true;
|
786
|
if (this.indicator.type === 'chart') {
|
787
|
this.chartIndicatorFb.get('description').enable();
|
788
|
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, true);
|
789
|
this.section = this.charts.find(section => section._id === this.section._id);
|
790
|
} else {
|
791
|
this.numberIndicatorFb.get('description').enable();
|
792
|
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.numberIndicatorFb.value, this.indicator.indicatorPaths, this.indicator.type, false);
|
793
|
this.section = this.numbers.find(section => section._id === this.section._id);
|
794
|
}
|
795
|
let path = [
|
796
|
this.stakeholder._id,
|
797
|
this.stakeholder.topics[this.topicIndex]._id,
|
798
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
799
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id,
|
800
|
this.section._id
|
801
|
];
|
802
|
this.subscriptions.push(this.stakeholderService.saveElement(this.properties.monitorServiceAPIURL, this.indicator, path).subscribe(indicator => {
|
803
|
if (this.index !== -1) {
|
804
|
this.section.indicators[this.index] = indicator;
|
805
|
} else {
|
806
|
this.section.indicators.push(indicator);
|
807
|
}
|
808
|
if (this.indicator.type === "chart") {
|
809
|
this.filterCharts();
|
810
|
this.chartIndicatorFb = null;
|
811
|
} else {
|
812
|
this.filterNumbers();
|
813
|
this.numberIndicatorFb = null;
|
814
|
}
|
815
|
UIkit.notification('Indicator has been <b>successfully saved</b>', {
|
816
|
status: 'success',
|
817
|
timeout: 6000,
|
818
|
pos: 'bottom-right'
|
819
|
});
|
820
|
this.editing = false;
|
821
|
}, error => {
|
822
|
this.chartIndicatorFb = null;
|
823
|
UIkit.notification(error.error.message, {
|
824
|
status: 'danger',
|
825
|
timeout: 6000,
|
826
|
pos: 'bottom-right'
|
827
|
});
|
828
|
this.editing = false;
|
829
|
}));
|
830
|
}
|
831
|
|
832
|
reorderIndicators(sectionId: string, type: IndicatorType, indicatorIds: string[]) {
|
833
|
this.editing = true;
|
834
|
let path = [
|
835
|
this.stakeholder._id,
|
836
|
this.stakeholder.topics[this.topicIndex]._id,
|
837
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
838
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id,
|
839
|
sectionId
|
840
|
];
|
841
|
this.subscriptions.push(this.stakeholderService.reorderIndicators(this.properties.monitorServiceAPIURL, path, indicatorIds, type).subscribe(indicators => {
|
842
|
if (type === 'chart') {
|
843
|
this.charts.find(section => section._id === sectionId).indicators = indicators;
|
844
|
this.filterCharts();
|
845
|
} else {
|
846
|
this.numbers.find(section => section._id === sectionId).indicators = indicators;
|
847
|
this.filterNumbers();
|
848
|
}
|
849
|
this.editing = false;
|
850
|
}));
|
851
|
}
|
852
|
|
853
|
hasDifference(index: number): boolean {
|
854
|
let hasDifference = false;
|
855
|
this.chartIndicatorPaths.at(index).value.parameters.forEach((parameter) => {
|
856
|
if (parameter.value !== this.indicator.indicatorPaths[index].parameters[parameter.key]) {
|
857
|
hasDifference = true;
|
858
|
return;
|
859
|
}
|
860
|
});
|
861
|
return hasDifference || this.indicator.indicatorPaths[index].safeResourceUrl.toString() !==
|
862
|
this.getSecureUrlByStakeHolder(this.indicator.indicatorPaths[index]).toString();
|
863
|
}
|
864
|
|
865
|
public get isAdministrator(): boolean {
|
866
|
return Session.isPortalAdministrator(this.user);
|
867
|
}
|
868
|
public get isCurator(): boolean {
|
869
|
return this.isAdministrator || Session.isMonitorCurator(this.user);
|
870
|
}
|
871
|
refreshIndicator() {
|
872
|
this.indicator = this.indicatorUtils.generateIndicatorByForm(this.chartIndicatorFb.value, this.indicator.indicatorPaths, 'chart', true);
|
873
|
this.indicator.indicatorPaths.forEach(indicatorPath => {
|
874
|
indicatorPath.safeResourceUrl = this.getSecureUrlByStakeHolder(indicatorPath);
|
875
|
});
|
876
|
}
|
877
|
|
878
|
deleteIndicatorOpen(section: Section, indicatorId: string, type: string, childrenAction: string = null) {
|
879
|
this.indicatorChildrenActionOnDelete = null;
|
880
|
if (childrenAction == "delete") {
|
881
|
this.indicatorChildrenActionOnDelete = childrenAction;
|
882
|
} else if (childrenAction == "disconnect") {
|
883
|
this.indicatorChildrenActionOnDelete = childrenAction;
|
884
|
}
|
885
|
|
886
|
this.section = section;
|
887
|
if (type === 'chart') {
|
888
|
this.index = this.charts.find(value => value._id == section._id).indicators.findIndex(value => value._id == indicatorId);
|
889
|
} else {
|
890
|
this.index = this.numbers.find(value => value._id == section._id).indicators.findIndex(value => value._id == indicatorId);
|
891
|
}
|
892
|
this.indicator = section.indicators.find(value => value._id == indicatorId);
|
893
|
this.deleteModal.alertTitle = 'Delete indicator';
|
894
|
this.deleteModal.cancelButtonText = 'No';
|
895
|
this.deleteModal.okButtonText = 'Yes';
|
896
|
this.deleteModal.open();
|
897
|
}
|
898
|
|
899
|
deleteIndicator() {
|
900
|
this.editing = true;
|
901
|
let path = [
|
902
|
this.stakeholder._id,
|
903
|
this.stakeholder.topics[this.topicIndex]._id,
|
904
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
905
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id,
|
906
|
this.section._id,
|
907
|
this.indicator._id
|
908
|
];
|
909
|
this.subscriptions.push(this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path, this.indicatorChildrenActionOnDelete).subscribe(() => {
|
910
|
if (this.indicator.type === 'chart') {
|
911
|
this.charts.find(section => section._id === this.section._id).indicators.splice(this.index, 1);
|
912
|
this.filterCharts();
|
913
|
} else {
|
914
|
this.numbers.find(section => section._id === this.section._id).indicators.splice(this.index, 1);
|
915
|
this.filterNumbers();
|
916
|
}
|
917
|
UIkit.notification('Indicator has been <b>successfully deleted</b>', {
|
918
|
status: 'success',
|
919
|
timeout: 6000,
|
920
|
pos: 'bottom-right'
|
921
|
});
|
922
|
this.editing = false;
|
923
|
}, error => {
|
924
|
UIkit.notification(error.error.message, {
|
925
|
status: 'danger',
|
926
|
timeout: 6000,
|
927
|
pos: 'bottom-right'
|
928
|
});
|
929
|
this.editing = false;
|
930
|
}));
|
931
|
}
|
932
|
|
933
|
changeIndicatorStatus(sectionId: string, indicator: Indicator, visibility: Visibility) {
|
934
|
this.editing = true;
|
935
|
let path = [
|
936
|
this.stakeholder._id,
|
937
|
this.stakeholder.topics[this.topicIndex]._id,
|
938
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
939
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id,
|
940
|
sectionId,
|
941
|
indicator._id
|
942
|
];
|
943
|
this.subscriptions.push(this.stakeholderService.changeVisibility(this.properties.monitorServiceAPIURL, path, visibility).subscribe(visibility => {
|
944
|
indicator.visibility = visibility;
|
945
|
UIkit.notification('Indicator has been <b>successfully changed</b> to ' + indicator.visibility.toLowerCase(), {
|
946
|
status: 'success',
|
947
|
timeout: 6000,
|
948
|
pos: 'bottom-right'
|
949
|
});
|
950
|
this.editing = false;
|
951
|
}, error => {
|
952
|
UIkit.notification('An error has been occurred. Try again later', {
|
953
|
status: 'danger',
|
954
|
timeout: 6000,
|
955
|
pos: 'bottom-right'
|
956
|
});
|
957
|
this.editing = false;
|
958
|
}));
|
959
|
}
|
960
|
|
961
|
/*toggleIndicatorAccess(sectionId: string, indicator: Indicator) {
|
962
|
this.editing = true;
|
963
|
let path = [
|
964
|
this.stakeholder._id,
|
965
|
this.stakeholder.topics[this.topicIndex]._id,
|
966
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
967
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id,
|
968
|
sectionId,
|
969
|
indicator._id
|
970
|
];
|
971
|
this.stakeholderService.toggleAccess(this.properties.monitorServiceAPIURL, path).subscribe(visibility => {
|
972
|
indicator.visibility = visibility;
|
973
|
UIkit.notification('Indicator has been <b>successfully changed</b> to ' + (visibility?'public':'private'), {
|
974
|
status: 'success',
|
975
|
timeout: 6000,
|
976
|
pos: 'bottom-right'
|
977
|
});
|
978
|
this.editing = false;
|
979
|
}, error => {
|
980
|
UIkit.notification(error.error.message, {
|
981
|
status: 'danger',
|
982
|
timeout: 6000,
|
983
|
pos: 'bottom-right'
|
984
|
});
|
985
|
this.editing = false;
|
986
|
});
|
987
|
}*/
|
988
|
|
989
|
saveSection(section: Section, index: number, type: IndicatorType = "chart") {
|
990
|
this.editing = true;
|
991
|
let path = [
|
992
|
this.stakeholder._id,
|
993
|
this.stakeholder.topics[this.topicIndex]._id,
|
994
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
995
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id
|
996
|
];
|
997
|
this.subscriptions.push(this.stakeholderService.saveSection(this.properties.monitorServiceAPIURL, section, path, index).subscribe(section => {
|
998
|
if (type === 'chart') {
|
999
|
this.charts[index] = section;
|
1000
|
this.filterCharts();
|
1001
|
} else {
|
1002
|
this.numbers[index] = section;
|
1003
|
this.filterNumbers();
|
1004
|
}
|
1005
|
this.initReorder();
|
1006
|
UIkit.notification('Section has been <b>successfully saved</b>', {
|
1007
|
status: 'success',
|
1008
|
timeout: 6000,
|
1009
|
pos: 'bottom-right'
|
1010
|
});
|
1011
|
this.editing = false;
|
1012
|
}, error => {
|
1013
|
UIkit.notification(error.error.message, {
|
1014
|
status: 'danger',
|
1015
|
timeout: 6000,
|
1016
|
pos: 'bottom-right'
|
1017
|
});
|
1018
|
this.editing = false;
|
1019
|
}));
|
1020
|
}
|
1021
|
|
1022
|
createSection(index = -1, type: IndicatorType = 'chart') {
|
1023
|
this.editing = true;
|
1024
|
this.section = new Section(type, null, null, this.stakeholder.alias);
|
1025
|
let path = [
|
1026
|
this.stakeholder._id,
|
1027
|
this.stakeholder.topics[this.topicIndex]._id,
|
1028
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
1029
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id
|
1030
|
];
|
1031
|
this.subscriptions.push(this.stakeholderService.saveSection(this.properties.monitorServiceAPIURL, this.section, path, index).subscribe(section => {
|
1032
|
if (type === 'chart') {
|
1033
|
if (index !== -1) {
|
1034
|
this.charts.splice(index, 0, section);
|
1035
|
} else {
|
1036
|
this.charts.push(section);
|
1037
|
}
|
1038
|
this.filterCharts();
|
1039
|
} else {
|
1040
|
if (index !== -1) {
|
1041
|
this.numbers.splice(index, 0, section);
|
1042
|
} else {
|
1043
|
this.numbers.push(section);
|
1044
|
}
|
1045
|
this.filterNumbers();
|
1046
|
}
|
1047
|
this.initReorder();
|
1048
|
UIkit.notification('Section has been <b>successfully created</b>', {
|
1049
|
status: 'success',
|
1050
|
timeout: 6000,
|
1051
|
pos: 'bottom-right'
|
1052
|
});
|
1053
|
this.editing = false;
|
1054
|
}, error => {
|
1055
|
UIkit.notification(error.error.message, {
|
1056
|
status: 'danger',
|
1057
|
timeout: 6000,
|
1058
|
pos: 'bottom-right'
|
1059
|
});
|
1060
|
this.editing = false;
|
1061
|
}));
|
1062
|
}
|
1063
|
|
1064
|
// deleteNumberSectionOpen(section: Section, index: number) {
|
1065
|
// this.section = section;
|
1066
|
// this.index = index;
|
1067
|
// this.deleteNumberSectionModal.alertTitle = 'Delete Section';
|
1068
|
// this.deleteNumberSectionModal.cancelButtonText = 'No';
|
1069
|
// this.deleteNumberSectionModal.okButtonText = 'Yes';
|
1070
|
// this.deleteNumberSectionModal.open();
|
1071
|
// }
|
1072
|
//
|
1073
|
// deleteChartSectionOpen(section: Section, index: number) {
|
1074
|
// this.section = section;
|
1075
|
// this.index = index;
|
1076
|
// this.deleteChartSectionModal.alertTitle = 'Delete Section';
|
1077
|
// this.deleteChartSectionModal.cancelButtonText = 'No';
|
1078
|
// this.deleteChartSectionModal.okButtonText = 'Yes';
|
1079
|
// this.deleteChartSectionModal.open();
|
1080
|
// }
|
1081
|
|
1082
|
deleteSectionOpen(section: Section, index: number, type: IndicatorType, childrenAction: string = null) {
|
1083
|
if (!this.editing && !section.defaultId) {
|
1084
|
this.sectionTypeToDelete = type;
|
1085
|
this.sectionChildrenActionOnDelete = null;
|
1086
|
if (childrenAction == "delete") {
|
1087
|
this.sectionChildrenActionOnDelete = childrenAction;
|
1088
|
} else if (childrenAction == "disconnect") {
|
1089
|
this.sectionChildrenActionOnDelete = childrenAction;
|
1090
|
}
|
1091
|
|
1092
|
this.section = section;
|
1093
|
this.index = index;
|
1094
|
this.deleteSectionModal.alertTitle = 'Delete Section';
|
1095
|
this.deleteSectionModal.cancelButtonText = 'No';
|
1096
|
this.deleteSectionModal.okButtonText = 'Yes';
|
1097
|
this.deleteSectionModal.open();
|
1098
|
}
|
1099
|
}
|
1100
|
|
1101
|
deleteSection() {
|
1102
|
this.editing = true;
|
1103
|
let path = [
|
1104
|
this.stakeholder._id,
|
1105
|
this.stakeholder.topics[this.topicIndex]._id,
|
1106
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex]._id,
|
1107
|
this.stakeholder.topics[this.topicIndex].categories[this.categoryIndex].subCategories[this.subcategoryIndex]._id,
|
1108
|
this.section._id
|
1109
|
];
|
1110
|
this.subscriptions.push(this.stakeholderService.deleteElement(this.properties.monitorServiceAPIURL, path, this.sectionChildrenActionOnDelete).subscribe(() => {
|
1111
|
if (this.sectionTypeToDelete === "chart") {
|
1112
|
this.charts.splice(this.index, 1);
|
1113
|
this.filterCharts();
|
1114
|
} else {
|
1115
|
this.numbers.splice(this.index, 1);
|
1116
|
this.filterNumbers();
|
1117
|
}
|
1118
|
this.initReorder();
|
1119
|
UIkit.notification('Section has been <b>successfully deleted</b>', {
|
1120
|
status: 'success',
|
1121
|
timeout: 6000,
|
1122
|
pos: 'bottom-right'
|
1123
|
});
|
1124
|
this.editing = false;
|
1125
|
}, error => {
|
1126
|
UIkit.notification(error.error.message, {
|
1127
|
status: 'danger',
|
1128
|
timeout: 6000,
|
1129
|
pos: 'bottom-right'
|
1130
|
});
|
1131
|
this.editing = false;
|
1132
|
}));
|
1133
|
}
|
1134
|
}
|