1
|
import {
|
2
|
ChartHelper, FilterType,
|
3
|
Indicator, IndicatorFilterUtils,
|
4
|
IndicatorPath, IndicatorPathType, IndicatorType,
|
5
|
SourceType,
|
6
|
Stakeholder,
|
7
|
SubCategory,
|
8
|
Topic, Visibility
|
9
|
} from "../openaireLibrary/monitor/entities/stakeholder";
|
10
|
import {AbstractControl, ValidatorFn, Validators} from "@angular/forms";
|
11
|
import {Option} from "../openaireLibrary/sharedComponents/input/input.component";
|
12
|
import {Session} from "../openaireLibrary/login/utils/helper.class";
|
13
|
|
14
|
export class StakeholderUtils {
|
15
|
statuses: Option[] = [
|
16
|
{value: 'PUBLIC', label: 'Public'},
|
17
|
{value: 'RESTRICTED', label: 'Restricted'},
|
18
|
{value: 'PRIVATE', label: 'Private'}
|
19
|
];
|
20
|
|
21
|
types: Option[] = [
|
22
|
{value: 'funder', label: 'Funder'},
|
23
|
{value: 'ri', label: 'Reasearch Initiative'},
|
24
|
{value: 'project', label: 'Project'},
|
25
|
{value: 'organization', label: 'Organization'}
|
26
|
];
|
27
|
getTypesByUserRoles(user, id:string = null):Option[]{
|
28
|
let types = [];
|
29
|
for(let type of this.types){
|
30
|
if(Session.isCurator(type.value, user)|| Session.isPortalAdministrator(user)|| (id && Session.isManager(type.value, id, user))){
|
31
|
types.push(type);
|
32
|
}
|
33
|
}
|
34
|
return types;
|
35
|
}
|
36
|
visibility: Option[] = [
|
37
|
{icon: 'world', value: "PUBLIC", label: 'Public'},
|
38
|
{icon: 'lock', value: "RESTRICTED", label: 'Restricted'},
|
39
|
{icon: 'users', value: "PRIVATE", label: 'Private'},
|
40
|
];
|
41
|
|
42
|
isActive: Option[] = [
|
43
|
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
|
44
|
{icon: 'brightness_1', value: false, label: 'Inactive'},
|
45
|
];
|
46
|
|
47
|
visibilityIcon: Map<Visibility, string> = new Map<Visibility, string> ([
|
48
|
["PUBLIC", 'earth'],
|
49
|
["PRIVATE", 'lock'],
|
50
|
["RESTRICTED", 'group']
|
51
|
]);
|
52
|
|
53
|
isActiveIcon: string = 'brightness_1';
|
54
|
|
55
|
public createFunderFromDefaultProfile(funder: Stakeholder, defaultTopics: Topic[]): Stakeholder {
|
56
|
funder.topics = defaultTopics;
|
57
|
for (let topic of funder.topics) {
|
58
|
// console.log('id:' + topic._id);
|
59
|
topic.defaultId = topic._id;
|
60
|
topic._id = null;
|
61
|
// console.log('defaultId:' + topic.defaultId);
|
62
|
for (let category of topic.categories) {
|
63
|
category.defaultId = category._id;
|
64
|
category._id = null;
|
65
|
let subTokeep: SubCategory[] = [];
|
66
|
for (let subCategory of category.subCategories) {
|
67
|
subCategory.defaultId = subCategory._id;
|
68
|
subCategory._id = null;
|
69
|
if (!subCategory.recommendedFor || subCategory.recommendedFor.length == 0 || subCategory.recommendedFor.indexOf(funder.index_id) != -1) {
|
70
|
subTokeep.push(subCategory);
|
71
|
}
|
72
|
for (let section of subCategory.charts) {
|
73
|
let chartsTokeep: Indicator[] = [];
|
74
|
section.defaultId = section._id;
|
75
|
section.stakeholderAlias = funder.alias;
|
76
|
section._id = null;
|
77
|
for (let indicator of section.indicators) {
|
78
|
indicator.defaultId = indicator._id;
|
79
|
indicator._id = null;
|
80
|
if (!indicator.recommendedFor || indicator.recommendedFor.length == 0 || indicator.recommendedFor.indexOf(funder.index_id) != -1) {
|
81
|
chartsTokeep.push(indicator);
|
82
|
}
|
83
|
for (let indicatorPath of indicator.indicatorPaths) {
|
84
|
if (indicatorPath.parameters) {
|
85
|
Object.keys(indicatorPath.parameters).forEach(key => {
|
86
|
//TODO check before delete
|
87
|
/*if (indicatorPath.parameters[key].indexOf("_funder_name_") != -1) {
|
88
|
indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_name_", funder.index_name);
|
89
|
} else if (indicatorPath.parameters[key].indexOf("_funder_id_") != -1) {
|
90
|
indicatorPath.parameters[key] = indicatorPath.parameters[key].replace("_funder_id_", funder.index_id);
|
91
|
} else if (indicatorPath.parameters[key].indexOf("_fsn_") != -1) {
|
92
|
indicatorPath.parameters[key] = indicatorPath.parameters[key].toString().replace("_fsn_", funder.index_shortName.toLowerCase());
|
93
|
}*/
|
94
|
if (key == "index_name") {
|
95
|
indicatorPath.parameters[key] = funder.index_name;
|
96
|
} else if (key == "index_id" ) {
|
97
|
indicatorPath.parameters[key] = funder.index_id;
|
98
|
} else if (key == "index_shortName" ) {
|
99
|
indicatorPath.parameters[key] = funder.index_shortName.toLowerCase();
|
100
|
}
|
101
|
});
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
section.indicators = chartsTokeep;
|
106
|
}
|
107
|
for (let section of subCategory.numbers) {
|
108
|
section.defaultId = section._id;
|
109
|
section.stakeholderAlias = funder.alias;
|
110
|
section._id = null;
|
111
|
for(let indicator of section.indicators) {
|
112
|
indicator.defaultId = indicator._id;
|
113
|
indicator._id = null;
|
114
|
for (let indicatorPath of indicator.indicatorPaths) {
|
115
|
/* indicatorPath.url = indicatorPath.url.replace("index_id", encodeURIComponent(funder.index_id));
|
116
|
indicatorPath.url = indicatorPath.url.replace("index_name", encodeURIComponent(funder.index_name));
|
117
|
indicatorPath.url = indicatorPath.url.replace("index_shortName", encodeURIComponent(funder.index_shortName));*/
|
118
|
// if(indicatorPath.parameters) {
|
119
|
// indicatorPath.parameters.forEach((value: string, key: string) => {
|
120
|
// if (value.indexOf("_funder_name_")!=-1) {
|
121
|
// indicatorPath.parameters.set(key,value.toString().replace("_funder_name_", funder.index_name));
|
122
|
// }else if (value.indexOf("_fsn_")!=-1) {
|
123
|
// indicatorPath.parameters.set(key,value.toString().replace("_fsn_", funder.index_shortName.toLowerCase()));
|
124
|
// }
|
125
|
// });
|
126
|
// }
|
127
|
}
|
128
|
}
|
129
|
}
|
130
|
|
131
|
}
|
132
|
category.subCategories = subTokeep;
|
133
|
}
|
134
|
}
|
135
|
console.log (funder)
|
136
|
return funder;
|
137
|
}
|
138
|
|
139
|
aliasValidator(elements: any[]): ValidatorFn {
|
140
|
return (control: AbstractControl): { [key: string]: string } | null => {
|
141
|
if (control.value && elements.find(element =>
|
142
|
element.alias === control.value
|
143
|
)) {
|
144
|
return {'error': 'Alias already in use'};
|
145
|
}
|
146
|
return null;
|
147
|
}
|
148
|
}
|
149
|
|
150
|
generateAlias(name: string): string {
|
151
|
let alias = name.toLowerCase();
|
152
|
while (alias.includes('/') || alias.includes(' ')) {
|
153
|
alias = alias.replace(' / ', '-');
|
154
|
alias = alias.replace('/', '-');
|
155
|
alias = alias.replace(' ', '-');
|
156
|
}
|
157
|
return alias;
|
158
|
}
|
159
|
}
|
160
|
|
161
|
export class IndicatorUtils {
|
162
|
|
163
|
allChartTypes: Option[] = [
|
164
|
{value: 'pie', label: 'Pie'},
|
165
|
{value: 'table', label: 'Table'},
|
166
|
{value: 'line', label: 'Line'},
|
167
|
{value: 'column', label: 'Column'},
|
168
|
{value: 'bar', label: 'Bar'},
|
169
|
{value: 'other', label: 'Other'}
|
170
|
];
|
171
|
basicChartTypes:IndicatorPathType[] =["pie", "line", "column", "bar"];
|
172
|
defaultChartType:IndicatorPathType = "other";
|
173
|
indicatorSizes: Option[] = [
|
174
|
{value: 'small', label: 'Small(Enabled only for large screens)'},
|
175
|
{value: 'medium', label: 'Medium'},
|
176
|
{value: 'large', label: 'Large'}
|
177
|
];
|
178
|
|
179
|
allSourceTypes: Option[] = [
|
180
|
{value: 'search', label: 'Search'},
|
181
|
{value: 'statistics', label: 'Statistics'},
|
182
|
{value: 'metrics', label: 'Metrics'},
|
183
|
{value: 'stats-tool', label: 'Statistics tool'}
|
184
|
];
|
185
|
sourceTypes: Option[] = [
|
186
|
{value: 'stats-tool', label: 'Statistics tool'}
|
187
|
];
|
188
|
isPublic: Option[] = [
|
189
|
{icon: 'public', value: true, label: 'Public'},
|
190
|
{icon: 'lock', value: false, label: 'Private'},
|
191
|
];
|
192
|
|
193
|
isActive: Option[] = [
|
194
|
{icon: 'brightness_1', iconClass: '', value: true, label: 'Active'},
|
195
|
{icon: 'brightness_1', value: false, label: 'Inactive'},
|
196
|
];
|
197
|
|
198
|
chartTypesIcons: Map<string, string> = new Map([
|
199
|
['pie', 'pie_chart'],
|
200
|
['table', 'table_chart'],
|
201
|
['line', 'show_chart'],
|
202
|
['column', 'bar_chart'],
|
203
|
['bar', 'notes'],
|
204
|
['other', 'perm_media']
|
205
|
]);
|
206
|
getChartTypes(initialType){
|
207
|
let types: Option[]= [];
|
208
|
if(this.basicChartTypes.indexOf(initialType) != -1){
|
209
|
(this.allChartTypes).forEach(option => {
|
210
|
if(this.basicChartTypes.indexOf(option.value)!=-1){
|
211
|
types.push(option);
|
212
|
}
|
213
|
});
|
214
|
return types;
|
215
|
}else if(initialType == "table") {
|
216
|
(this.allChartTypes).forEach(option => {
|
217
|
if (initialType == option.value) {
|
218
|
types.push(option);
|
219
|
}
|
220
|
});
|
221
|
return types;
|
222
|
}else {
|
223
|
return this.allChartTypes;
|
224
|
}
|
225
|
}
|
226
|
isPublicIcon: Map<boolean, string> = new Map([
|
227
|
[true, 'public'],
|
228
|
[false, 'lock']
|
229
|
]);
|
230
|
|
231
|
isActiveIcon: string = 'brightness_1';
|
232
|
|
233
|
ignoredParameters = ['index_name','index_id','index_shortName'];
|
234
|
|
235
|
parametersValidators: Map<string, any> = new Map<string, any>([
|
236
|
['start_year', [Validators.required, Validators.pattern('^\\d+$')]],
|
237
|
['end_year', [Validators.required, Validators.pattern('^\\d+$')]]
|
238
|
]);
|
239
|
|
240
|
public getFullUrl(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null): string {
|
241
|
let replacedUrl =indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
|
242
|
if (indicatorPath.parameters) {
|
243
|
Object.keys(indicatorPath.parameters).forEach(key => {
|
244
|
let replacedValue = indicatorPath.parameters[key];
|
245
|
if (startYear && key == "start_year" && indicatorPath.filters["start_year"]) {
|
246
|
replacedValue = (replacedValue < startYear) ? startYear : replacedValue;
|
247
|
}
|
248
|
if (endYear && key == "end_year" && indicatorPath.filters["end_year"]) {
|
249
|
replacedValue = (replacedValue > endYear) ? endYear : replacedValue;
|
250
|
}
|
251
|
if (key == "index_id") {
|
252
|
replacedValue = stakeholder.index_id;
|
253
|
}
|
254
|
if (key == "index_name") {
|
255
|
replacedValue = stakeholder.index_name;
|
256
|
}
|
257
|
if (key == "index_shortName") {
|
258
|
replacedValue = stakeholder.index_shortName.toLowerCase();
|
259
|
}
|
260
|
|
261
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
|
262
|
});
|
263
|
}
|
264
|
if (indicatorPath.chartObject) {
|
265
|
if (fundingL0 && indicatorPath.filters["fundingL0"]) {
|
266
|
let newJsonObject = JSON.parse(replacedUrl);
|
267
|
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
|
268
|
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
|
269
|
queries["query"]["filters"] = [];
|
270
|
}
|
271
|
//TODO check how it works if the query already has a filter
|
272
|
queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["fundingL0"].replace(ChartHelper.prefix + "fundingL0" + ChartHelper.suffix, fundingL0)));
|
273
|
}
|
274
|
replacedUrl = JSON.stringify(newJsonObject);
|
275
|
}
|
276
|
if (startYear && indicatorPath.filters["start_year"]) {
|
277
|
let newJsonObject = JSON.parse(replacedUrl);
|
278
|
|
279
|
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
|
280
|
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
|
281
|
queries["query"]["filters"] = [];
|
282
|
}
|
283
|
//TODO check how it works if the query already has a filter
|
284
|
queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["start_year"].replace(ChartHelper.prefix + "start_year" + ChartHelper.suffix, startYear)));
|
285
|
}
|
286
|
replacedUrl = JSON.stringify(newJsonObject);
|
287
|
}
|
288
|
if (endYear && indicatorPath.filters["end_year"]) {
|
289
|
let newJsonObject = JSON.parse(replacedUrl);
|
290
|
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
|
291
|
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
|
292
|
queries["query"]["filters"] = [];
|
293
|
}
|
294
|
//TODO check how it works if the query already has a filter
|
295
|
queries["query"]["filters"].push(JSON.parse(indicatorPath.filters["end_year"].replace(ChartHelper.prefix + "end_year" + ChartHelper.suffix, endYear)));
|
296
|
}
|
297
|
replacedUrl = JSON.stringify(newJsonObject);
|
298
|
}
|
299
|
|
300
|
}
|
301
|
//For numbers (e.g from stats-api , search service, etc)
|
302
|
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) !=- 1){
|
303
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
|
304
|
}
|
305
|
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) !=- 1){
|
306
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
|
307
|
}
|
308
|
if(indicatorPath.url.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) !=- 1){
|
309
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
|
310
|
}
|
311
|
return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
|
312
|
}
|
313
|
public getFullUrlWithFilters(stakeholder:Stakeholder, indicatorPath: IndicatorPath, fundingL0: string = null, startYear: string = null, endYear: string = null, coFunded:boolean=false): string {
|
314
|
indicatorPath.filtersApplied = 0;
|
315
|
let replacedUrl = indicatorPath.chartObject?indicatorPath.chartObject:indicatorPath.url;
|
316
|
if (indicatorPath.parameters) {
|
317
|
Object.keys(indicatorPath.parameters).forEach(key => {
|
318
|
let replacedValue = indicatorPath.parameters[key];
|
319
|
if (startYear && key == "start_year") {
|
320
|
replacedValue = (replacedValue < startYear) ? startYear : replacedValue;
|
321
|
}
|
322
|
if (endYear && key == "end_year") {
|
323
|
replacedValue = (replacedValue > endYear) ? endYear : replacedValue;
|
324
|
}
|
325
|
if (key == "index_id") {
|
326
|
replacedValue = stakeholder.index_id;
|
327
|
}
|
328
|
if (key == "index_name") {
|
329
|
replacedValue = stakeholder.index_name;
|
330
|
}
|
331
|
if (key == "index_shortName") {
|
332
|
replacedValue = stakeholder.index_shortName.toLowerCase();
|
333
|
}
|
334
|
|
335
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + key + ChartHelper.suffix).join(replacedValue)
|
336
|
});
|
337
|
}
|
338
|
if (fundingL0) {
|
339
|
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
|
340
|
let filterResults = this.addFilter(replacedUrl, 'fundingL0', fundingL0);
|
341
|
replacedUrl = filterResults.url;
|
342
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
343
|
}
|
344
|
}
|
345
|
if (startYear) {
|
346
|
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
|
347
|
let filterResults = this.addFilter(replacedUrl, 'start_year', startYear);
|
348
|
replacedUrl = filterResults.url;
|
349
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
350
|
}
|
351
|
}
|
352
|
if (endYear ) {
|
353
|
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
|
354
|
let filterResults = this.addFilter(replacedUrl, 'end_year', endYear);
|
355
|
replacedUrl = filterResults.url;
|
356
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
357
|
}
|
358
|
}
|
359
|
if (coFunded ) {
|
360
|
if(indicatorPath.source == "stats-tool" && indicatorPath.chartObject) {
|
361
|
let filterResults = this.addFilter(replacedUrl, 'co-funded', endYear);
|
362
|
replacedUrl = filterResults.url;
|
363
|
indicatorPath.filtersApplied += filterResults.filtersApplied;
|
364
|
}
|
365
|
}
|
366
|
|
367
|
//For numbers
|
368
|
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_id' + ChartHelper.suffix) != -1) {
|
369
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_id' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_id))
|
370
|
}
|
371
|
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_name' + ChartHelper.suffix) != -1) {
|
372
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_name' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_name))
|
373
|
}
|
374
|
if (replacedUrl.indexOf(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix) != -1) {
|
375
|
replacedUrl = replacedUrl.split(ChartHelper.prefix + 'index_shortName' + ChartHelper.suffix).join(encodeURIComponent(stakeholder.index_shortName))
|
376
|
}
|
377
|
|
378
|
return (indicatorPath.chartObject?indicatorPath.url + encodeURIComponent(replacedUrl):replacedUrl);
|
379
|
|
380
|
}
|
381
|
private addFilter(replacedUrl, filterType:FilterType, filterValue){
|
382
|
let newJsonObject = JSON.parse(replacedUrl);
|
383
|
let filterApplied:boolean = false;
|
384
|
let queryIndex = 0;
|
385
|
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
|
386
|
|
387
|
if(queries["query"]["name"] && !queries["query"]["select"]){
|
388
|
|
389
|
if(queries["query"]["name"].indexOf("monitor.")==-1 || !queries["query"]["parameters"]){
|
390
|
continue;
|
391
|
}
|
392
|
if(filterType == 'fundingL0') {
|
393
|
let paramFields = queries["query"]["name"].split(".").slice(3);
|
394
|
let filterPosition = queries["query"]["name"].split(".").indexOf(filterType == "fundingL0" ? 'fl0' : filterType) ;
|
395
|
if (filterPosition != -1) {
|
396
|
//already filtered
|
397
|
//TODO double check if we need to override if the fl0 is already filtered
|
398
|
filterPosition -=3;
|
399
|
/* //update the value
|
400
|
if(paramFields.length == queries["query"]["parameters"].length ){
|
401
|
//ok
|
402
|
queries["query"]["parameters"][filterPosition] = filterValue;
|
403
|
}else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){
|
404
|
queries["query"]["parameters"][filterPosition + 2]=filterValue;
|
405
|
filterApplied = true;
|
406
|
}
|
407
|
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
|
408
|
queries["query"]["parameters"][(2* filterPosition) + 5]=filterValue;
|
409
|
}*/
|
410
|
//if applied with the same value mark as filtered
|
411
|
if(paramFields.length == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition] == filterValue){
|
412
|
filterApplied = true;
|
413
|
}else if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length && queries["query"]["parameters"][filterPosition + 2]==filterValue){
|
414
|
filterApplied = true;
|
415
|
}
|
416
|
} else {
|
417
|
// if((paramFields.length*2) == queries["query"]["parameters"].length){
|
418
|
// queries["query"]["parameters"].splice(paramFields.length, 0, filterValue);
|
419
|
// }
|
420
|
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
|
421
|
queries["query"]["parameters"].splice(paramFields.length + 1, 0, filterValue);
|
422
|
}
|
423
|
queries["query"]["name"] = queries["query"]["name"] + ".fl0";
|
424
|
queries["query"]["parameters"].push(filterValue);
|
425
|
filterApplied = true;
|
426
|
}
|
427
|
}else{
|
428
|
let paramFields = queries["query"]["name"].split(".").slice(3);
|
429
|
// console.debug("Field Params length:" + paramFields.length)
|
430
|
// console.debug(paramFields)
|
431
|
// console.debug("Parameters length:" + queries["query"]["parameters"].length)
|
432
|
|
433
|
if((paramFields.length + 2) == queries["query"]["parameters"].length || (paramFields.length*2 + 4) == queries["query"]["parameters"].length){
|
434
|
filterApplied = true;
|
435
|
if(filterType == "start_year"){
|
436
|
queries["query"]["parameters"][0] = parseInt(filterValue);
|
437
|
}else if(filterType == "end_year"){
|
438
|
queries["query"]["parameters"][1] = parseInt(filterValue);
|
439
|
}
|
440
|
}
|
441
|
if((paramFields.length*2 + 4) == queries["query"]["parameters"].length){
|
442
|
filterApplied = true;
|
443
|
if(filterType == "start_year"){
|
444
|
queries["query"]["parameters"][paramFields.length + 2] = parseInt(filterValue);
|
445
|
}else if(filterType == "end_year"){
|
446
|
queries["query"]["parameters"][paramFields.length + 3] = parseInt(filterValue);
|
447
|
}
|
448
|
}
|
449
|
}
|
450
|
// console.debug(queries["query"])
|
451
|
// it is a name query
|
452
|
continue;
|
453
|
}
|
454
|
if (!queries["query"]["filters"] || queries["query"]["filters"].length == 0) {
|
455
|
queries["query"]["filters"] = [];
|
456
|
}
|
457
|
let field = queries["query"]["select"][0]["field"];
|
458
|
let filterString = IndicatorFilterUtils.getFilter(field&&field.length > 0? field.split(".")[0]:"",filterType);
|
459
|
if(filterString){
|
460
|
let filter = JSON.parse(filterString);
|
461
|
let filterposition = IndicatorFilterUtils.filterIndexOf(filter,queries["query"]["filters"])
|
462
|
if(filterposition){
|
463
|
if(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] != filter['groupFilters'][0]["values"][0].replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)){
|
464
|
//change filter value
|
465
|
// queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] = filter['groupFilters'][0]["values"][0].replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue);
|
466
|
//add user filter value
|
467
|
// queries["query"]["filters"].push(JSON.parse(filterString.replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)));
|
468
|
// update colors
|
469
|
//if noit a pie, map and chart has more than one query
|
470
|
//
|
471
|
if(!newJsonObject.hasOwnProperty("mapDescription") && queries["type"]!="pie" && this.isComparingChart(newJsonObject, filter)) {
|
472
|
let activeColors = ["#7CB5EC", "#434348", "#8bbc21", "#910000", "#1aadce", "#492970", "#f28f43", "#77a1e5", "#c42525", "#a6c96a"];
|
473
|
let inActiveColors = ["#E4EFFB", "#D8D8D9", "#8bbc21", "#910000", "#1aadce", "#492970", "#f28f43", "#77a1e5", "#c42525", "#a6c96a"];
|
474
|
if (!newJsonObject[this.getDescriptionObjectName(newJsonObject)]["colors"]) {
|
475
|
newJsonObject[this.getDescriptionObjectName(newJsonObject)]["colors"] = activeColors;
|
476
|
}
|
477
|
newJsonObject[this.getDescriptionObjectName(newJsonObject)]["colors"][queryIndex] = inActiveColors[queryIndex];
|
478
|
filterApplied = true;
|
479
|
}else if (filterType == "start_year" || filterType == "end_year") {
|
480
|
//if has date filter already
|
481
|
if(filterType == "start_year" && parseInt(filterValue) > parseInt(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0])){
|
482
|
queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] = filterValue;
|
483
|
}else if(filterType == "end_year" && parseInt(filterValue) < parseInt(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0])) {
|
484
|
queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0] = filterValue;
|
485
|
}
|
486
|
filterApplied = true;
|
487
|
}
|
488
|
}else{
|
489
|
filterApplied = true;
|
490
|
}
|
491
|
}else {
|
492
|
queries["query"]["filters"].push(JSON.parse(filterString.replace(ChartHelper.prefix + filterType + ChartHelper.suffix, filterValue)));
|
493
|
filterApplied = true;
|
494
|
}
|
495
|
}
|
496
|
queryIndex++;
|
497
|
}
|
498
|
return { "url":JSON.stringify(newJsonObject), "filtersApplied":(filterApplied)?1:0};
|
499
|
}
|
500
|
|
501
|
isComparingChart(newJsonObject, filter,){
|
502
|
let queriesCount = this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)].length:newJsonObject[this.getDescriptionObjectName(newJsonObject)].length;
|
503
|
let values = [];
|
504
|
if(queriesCount < 2){
|
505
|
return false;
|
506
|
}
|
507
|
for (let queries of this.getQueryObjectName(newJsonObject)?newJsonObject[this.getDescriptionObjectName(newJsonObject)][this.getQueryObjectName(newJsonObject)]:newJsonObject[this.getDescriptionObjectName(newJsonObject)]) {
|
508
|
let filterposition = IndicatorFilterUtils.filterIndexOf(filter, queries["query"]["filters"]);
|
509
|
if (filterposition) {
|
510
|
if (values.indexOf(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]) == -1) {
|
511
|
values.push(queries["query"]["filters"][filterposition.filter]['groupFilters'][filterposition.groupFilter]["values"][0]);
|
512
|
}
|
513
|
}
|
514
|
}
|
515
|
// console.debug(values);
|
516
|
return values.length > 1;
|
517
|
}
|
518
|
generateIndicatorByForm(form: any, indicatorPaths: IndicatorPath[], type:IndicatorType, addParameters:boolean = true ): Indicator {
|
519
|
let indicator: Indicator = new Indicator(form.name, form.description, form.additionalDescription, type,
|
520
|
form.width, form.height, form.visibility, indicatorPaths, form.defaultId);
|
521
|
indicator._id = form._id;
|
522
|
form.indicatorPaths.forEach((indicatorPath, index) => {
|
523
|
indicator.indicatorPaths[index].type = indicatorPath.type;
|
524
|
if(addParameters) {
|
525
|
indicatorPath.parameters.forEach(parameter => {
|
526
|
indicator.indicatorPaths[index].parameters[parameter.key] = parameter.value;
|
527
|
if (parameter.key === 'type') {
|
528
|
indicator.indicatorPaths[index].type = parameter.value;
|
529
|
}
|
530
|
});
|
531
|
}
|
532
|
});
|
533
|
return indicator;
|
534
|
}
|
535
|
generateIndicatorByNumberUrl(source: SourceType, url: string, stakeholder:Stakeholder, jsonPath = [], sourceServices:string[] =[] ): IndicatorPath {
|
536
|
let indicatorPath = new IndicatorPath(null, source, url, null, jsonPath);
|
537
|
if (source === 'stats-tool') {
|
538
|
indicatorPath.url = url.split("json=")[0] + "json=";
|
539
|
indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
|
540
|
indicatorPath.chartObject = decodeURIComponent(url.indexOf("json=")!=-1?url.split("json=")[1]:"");
|
541
|
let chart = JSON.parse(indicatorPath.chartObject);
|
542
|
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
|
543
|
this.extractStakeHolders(chart, indicatorPath, stakeholder);
|
544
|
indicatorPath.chartObject = JSON.stringify(chart);
|
545
|
indicatorPath.jsonPath = ["data","0","0","0"];
|
546
|
// this.addResultFilters(chart, indicatorPath);
|
547
|
}else {
|
548
|
for( let service of sourceServices){
|
549
|
if(url.indexOf(service)!=-1){
|
550
|
url = url.split(service)[1] ;
|
551
|
}
|
552
|
}
|
553
|
try {
|
554
|
if (url.indexOf(encodeURIComponent(stakeholder.index_id)) !== -1) {
|
555
|
url = url.split(encodeURIComponent(stakeholder.index_id)).join(ChartHelper.prefix + "index_id" + ChartHelper.suffix);
|
556
|
}
|
557
|
if (url.indexOf(encodeURIComponent(stakeholder.index_name)) !== -1) {
|
558
|
url = url.split(encodeURIComponent(stakeholder.index_name)).join(ChartHelper.prefix + "index_name" + ChartHelper.suffix);
|
559
|
}
|
560
|
if (url.indexOf(encodeURIComponent(stakeholder.index_shortName)) !== -1) {
|
561
|
url = url.split(encodeURIComponent(stakeholder.index_shortName)).join(ChartHelper.prefix + "index_shortName" + ChartHelper.suffix);
|
562
|
}
|
563
|
indicatorPath.url = url;
|
564
|
} catch (e) {
|
565
|
console.error(e);
|
566
|
}
|
567
|
}
|
568
|
return indicatorPath;
|
569
|
}
|
570
|
generateIndicatorByChartUrl(source: SourceType, url: string, type: IndicatorPathType = null, stakeholder:Stakeholder): IndicatorPath {
|
571
|
let indicatorPath = new IndicatorPath(type, source, null, null, []);
|
572
|
try {
|
573
|
if (source === 'stats-tool') {
|
574
|
indicatorPath.url = url.split("json=")[0] + "json=";
|
575
|
indicatorPath.url = indicatorPath.url.split("/")[indicatorPath.url.split("/").length - 1];
|
576
|
indicatorPath.chartObject = decodeURIComponent(url.split("json=")[1]);
|
577
|
let chart = JSON.parse(indicatorPath.chartObject);
|
578
|
// console.debug(indicatorPath);
|
579
|
if (indicatorPath.url == "chart?json=") {
|
580
|
|
581
|
if (chart["library"] && (chart["library"] == "HighCharts" || chart["library"] == "eCharts" || chart["library"] == "HighMaps" )) {
|
582
|
indicatorPath.type = this.extractType(chart, indicatorPath);
|
583
|
} else {
|
584
|
indicatorPath.type = this.defaultChartType;
|
585
|
}
|
586
|
|
587
|
this.extractTitle(chart, indicatorPath);
|
588
|
this.extractSubTitle(chart, indicatorPath);
|
589
|
this.extractXTitle(chart, indicatorPath);
|
590
|
this.extractYTitle(chart, indicatorPath);
|
591
|
}else if(indicatorPath.url == "table?json="){
|
592
|
indicatorPath.type = "table";
|
593
|
}
|
594
|
if (indicatorPath.url == "chart?json=" || indicatorPath.url == "table?json=") {
|
595
|
// common for tables and other chart types
|
596
|
this.extractDataTitle(chart, indicatorPath);
|
597
|
this.parameterizeDefaultQuery(chart, indicatorPath, stakeholder);
|
598
|
this.extractStakeHolders(chart, indicatorPath, stakeholder);
|
599
|
this.extractStartYear(chart, indicatorPath);
|
600
|
this.extractEndYear(chart, indicatorPath);
|
601
|
indicatorPath.chartObject = JSON.stringify(chart);
|
602
|
}
|
603
|
} else if (source === 'old') {
|
604
|
indicatorPath.url = url.split("data=")[0].split("/stats/")[1] + "data=";
|
605
|
indicatorPath.chartObject = decodeURIComponent(url.split("data=")[1].split("&")[0]);
|
606
|
indicatorPath.type = type;
|
607
|
let chart = JSON.parse(indicatorPath.chartObject);
|
608
|
this.extractOldToolTitle(chart, indicatorPath);
|
609
|
this.extractOldToolXTitle(chart, indicatorPath);
|
610
|
this.extractOldToolYTitle(chart, indicatorPath);
|
611
|
indicatorPath.chartObject = JSON.stringify(chart);
|
612
|
} else {
|
613
|
indicatorPath.url = url;
|
614
|
indicatorPath.type = type;
|
615
|
}
|
616
|
}catch(e){
|
617
|
console.error(e);
|
618
|
indicatorPath.url = url;
|
619
|
indicatorPath.type = type;
|
620
|
}
|
621
|
// console.debug(indicatorPath.parameters);
|
622
|
// console.debug(indicatorPath.chartObject);
|
623
|
if(indicatorPath.type == null){
|
624
|
indicatorPath.type = this.defaultChartType;
|
625
|
}
|
626
|
return indicatorPath;
|
627
|
}
|
628
|
private getQueryObjectName(obj){
|
629
|
if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queriesInfo")){
|
630
|
return "queriesInfo";
|
631
|
}else if((obj[this.getDescriptionObjectName(obj)]).hasOwnProperty("queries")) {
|
632
|
return "queries";
|
633
|
}
|
634
|
}
|
635
|
private getDescriptionObjectName(obj){
|
636
|
if(obj.hasOwnProperty("mapDescription")){
|
637
|
return "mapDescription";
|
638
|
}else if(obj.hasOwnProperty("chartDescription")) {
|
639
|
return "chartDescription";
|
640
|
}else if(obj.hasOwnProperty("tableDescription") ){
|
641
|
return "tableDescription";
|
642
|
}else if(obj.hasOwnProperty("series") ){
|
643
|
return "series";
|
644
|
}
|
645
|
}
|
646
|
private extractType(obj, indicatorPath: IndicatorPath): IndicatorPathType {
|
647
|
let type = (obj[this.getDescriptionObjectName(obj)] && obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"])?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)][0]["type"]:"";
|
648
|
if (this.basicChartTypes.indexOf(type) == -1) {
|
649
|
type = this.defaultChartType;
|
650
|
} else {
|
651
|
obj[this.getDescriptionObjectName(obj)]["queries"][0]["type"] = ChartHelper.prefix + "type" + ChartHelper.suffix;
|
652
|
indicatorPath.parameters['type'] = type;
|
653
|
}
|
654
|
return type;
|
655
|
}
|
656
|
private extractStakeHolders(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
657
|
this.extractFunder(obj, indicatorPath, stakeholder);
|
658
|
this.extractRI(obj, indicatorPath, stakeholder);
|
659
|
this.extractOrganization(obj, indicatorPath, stakeholder);
|
660
|
}
|
661
|
private extractFunder(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
662
|
if(stakeholder.type != "funder"){
|
663
|
return;
|
664
|
}
|
665
|
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
|
666
|
if (!query["query"]["filters"]) {
|
667
|
return;
|
668
|
}
|
669
|
for (let filter of query["query"]["filters"]) {
|
670
|
if (filter["groupFilters"][0]["field"].indexOf(".funder") != -1) {
|
671
|
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
|
672
|
indicatorPath.parameters["index_name"] = stakeholder.index_name;
|
673
|
}else if (filter["groupFilters"][0]["field"].indexOf(".funder.id") != -1) {
|
674
|
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
|
675
|
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
|
676
|
}
|
677
|
}
|
678
|
}
|
679
|
}
|
680
|
|
681
|
private extractRI(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
682
|
if(stakeholder.type != "ri"){
|
683
|
return;
|
684
|
}
|
685
|
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
|
686
|
if (!query["query"]["filters"]) {
|
687
|
return;
|
688
|
}
|
689
|
for (let filter of query["query"]["filters"]) {
|
690
|
if (filter["groupFilters"][0]["field"].indexOf(".context.name") != -1) {
|
691
|
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
|
692
|
indicatorPath.parameters["index_name"] = stakeholder.index_name;
|
693
|
}else if (filter["groupFilters"][0]["field"].indexOf(".context.id") != -1) {
|
694
|
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
|
695
|
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
|
696
|
}
|
697
|
}
|
698
|
}
|
699
|
}
|
700
|
|
701
|
private extractOrganization(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
702
|
// works for publication.project.organization.name
|
703
|
// and publication.organization.name
|
704
|
if(stakeholder.type != "organization"){
|
705
|
return;
|
706
|
}
|
707
|
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
|
708
|
if (!query["query"]["filters"]) {
|
709
|
return;
|
710
|
}
|
711
|
for (let filter of query["query"]["filters"]) {
|
712
|
if (filter["groupFilters"][0]["field"].indexOf(".organization.name") != -1) {
|
713
|
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
|
714
|
indicatorPath.parameters["index_name"] = stakeholder.index_name;
|
715
|
}else if (filter["groupFilters"][0]["field"].indexOf(".organization.id") != -1) {
|
716
|
filter["groupFilters"][0]["values"][0] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
|
717
|
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName;
|
718
|
}
|
719
|
}
|
720
|
}
|
721
|
}
|
722
|
private extractStartYear(obj, indicatorPath: IndicatorPath) {
|
723
|
let start_year;
|
724
|
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
|
725
|
if (!query["query"]["filters"]) {
|
726
|
return;
|
727
|
}
|
728
|
for (let filter of query["query"]["filters"]) {
|
729
|
for (let gfilter of filter["groupFilters"]) {
|
730
|
if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf(">") != -1) {
|
731
|
start_year = gfilter["values"][0];
|
732
|
gfilter["values"][0] = ChartHelper.prefix + "start_year" + ChartHelper.suffix;
|
733
|
indicatorPath.parameters["start_year"] = start_year;
|
734
|
}
|
735
|
}
|
736
|
}
|
737
|
}
|
738
|
}
|
739
|
|
740
|
private extractEndYear(obj, indicatorPath: IndicatorPath) {
|
741
|
let end_year;
|
742
|
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
|
743
|
if (!query["query"]["filters"]) {
|
744
|
return;
|
745
|
}
|
746
|
for (let filter of query["query"]["filters"]) {
|
747
|
for (let gfilter of filter["groupFilters"]) {
|
748
|
if (gfilter["field"].indexOf(".year") != -1 && gfilter["type"].indexOf("<") != -1) {
|
749
|
end_year = gfilter["values"][0];
|
750
|
gfilter["values"][0] = ChartHelper.prefix + "end_year" + ChartHelper.suffix;
|
751
|
indicatorPath.parameters["end_year"] = end_year;
|
752
|
}
|
753
|
}
|
754
|
}
|
755
|
}
|
756
|
}
|
757
|
|
758
|
private parameterizeDefaultQuery(obj, indicatorPath: IndicatorPath, stakeholder:Stakeholder) {
|
759
|
let name = "";
|
760
|
for (let query of this.getQueryObjectName(obj)?obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]:obj[this.getDescriptionObjectName(obj)]) {
|
761
|
//monitor.{{stakeholderType}}.{{queryname}}
|
762
|
//parameters: stakeholderId*, type
|
763
|
if (query["query"]["name"]) {
|
764
|
name = query["query"]["name"];
|
765
|
let parameters = (query["query"]["parameters"])?query["query"]["parameters"]:[];
|
766
|
if(name.split('.')[0] == "rcd" && parameters.length > 0 && stakeholder.type=="ri") {
|
767
|
//rcd.{{queryname}}
|
768
|
parameters[0] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
|
769
|
indicatorPath.parameters["index_id"] = stakeholder.index_id;
|
770
|
}else if(name.split('.')[0] == "monitor" && parameters.length == 0 && stakeholder.type=="funder"){
|
771
|
// old saved queries without params
|
772
|
//monitor.{{funder_shortName}}.{{type}}.{{queryname}}
|
773
|
let stakeholderSN = name.split('.')[1];
|
774
|
query["query"]["name"] = name.split('.' + stakeholderSN + ".")[0] + "." + ChartHelper.prefix + "index_shortName" + ChartHelper.suffix +"." + name.split('.' + stakeholderSN + ".")[1];
|
775
|
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
|
776
|
}else if(name.split('.')[0] == "monitor" && parameters.length > 0 && name.split('.')[1] == stakeholder.type) {
|
777
|
// new parameterized queries
|
778
|
//monitor.{{type}}.{{queryname}}.{{param1 - id }}.{{param2 result-type}}.{{fl0}} --> params [start year, end year, id, result type, fl0]
|
779
|
|
780
|
let index = (name.split('.').slice(3).length +2 == parameters.length)?[2]:((name.split('.').slice(3).length * 2 + 4 == parameters.length)?[2,name.split('.').slice(3).length+4]:[0]);
|
781
|
for(let i of index) {
|
782
|
if (name.split('.').length > 3 && name.split('.')[3] == "id") {
|
783
|
parameters[i] = ChartHelper.prefix + "index_id" + ChartHelper.suffix;
|
784
|
indicatorPath.parameters["index_id"] = stakeholder.index_id;
|
785
|
} else if (name.split('.').length > 3 && name.split('.')[3] == "shortname") {
|
786
|
parameters[i] = ChartHelper.prefix + "index_shortName" + ChartHelper.suffix;
|
787
|
indicatorPath.parameters["index_shortName"] = stakeholder.index_shortName.toLowerCase();
|
788
|
} else if (name.split('.').length > 3 && name.split('.')[3] == "name") {
|
789
|
parameters[i] = ChartHelper.prefix + "index_name" + ChartHelper.suffix;
|
790
|
indicatorPath.parameters["index_name"] = stakeholder.index_name;
|
791
|
}
|
792
|
}
|
793
|
}
|
794
|
}
|
795
|
}
|
796
|
}
|
797
|
private extractDataTitle(obj, indicatorPath: IndicatorPath) {
|
798
|
let index = 0;
|
799
|
if(!obj[this.getDescriptionObjectName(obj)] || !obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]){
|
800
|
return;
|
801
|
}
|
802
|
for (let query of obj[this.getDescriptionObjectName(obj)][this.getQueryObjectName(obj)]) {
|
803
|
if (query["name"]) {
|
804
|
let name = query["name"];
|
805
|
query["name"] = ChartHelper.prefix + "data_title_"+index + ChartHelper.suffix;
|
806
|
indicatorPath.parameters["data_title_"+index] = name;
|
807
|
}
|
808
|
index++;
|
809
|
}
|
810
|
}
|
811
|
private extractTitle(obj, indicatorPath: IndicatorPath) {
|
812
|
let title = "";
|
813
|
if (obj[this.getDescriptionObjectName(obj)]["title"]) {
|
814
|
title = obj[this.getDescriptionObjectName(obj)]["title"]["text"];
|
815
|
obj[this.getDescriptionObjectName(obj)]["title"]["text"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
|
816
|
}else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["title"]) {
|
817
|
title = obj[this.getDescriptionObjectName(obj)]["options"]["title"];
|
818
|
obj[this.getDescriptionObjectName(obj)]["options"]["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
|
819
|
}
|
820
|
indicatorPath.parameters["title"] = title ? title : "";
|
821
|
}
|
822
|
|
823
|
private extractSubTitle(obj, indicatorPath: IndicatorPath) {
|
824
|
let subtitle = "";
|
825
|
if (obj[this.getDescriptionObjectName(obj)]["subtitle"]) {
|
826
|
subtitle = obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"];
|
827
|
obj[this.getDescriptionObjectName(obj)]["subtitle"]["text"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
|
828
|
indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
|
829
|
}else if (obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"] && obj[this.getDescriptionObjectName(obj)]["title"]["subtext"]) {
|
830
|
subtitle = obj[this.getDescriptionObjectName(obj)]["title"]["subtext"];
|
831
|
obj[this.getDescriptionObjectName(obj)]["title"]["subtext"] = ChartHelper.prefix + "subtitle" + ChartHelper.suffix;
|
832
|
indicatorPath.parameters["subtitle"] = subtitle ? subtitle : "";
|
833
|
}
|
834
|
}
|
835
|
|
836
|
private extractXTitle(obj, indicatorPath: IndicatorPath) {
|
837
|
let title = "";
|
838
|
if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]) {
|
839
|
title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"];
|
840
|
obj[this.getDescriptionObjectName(obj)]["xAxis"]["title"]["text"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
841
|
}else if (obj[this.getDescriptionObjectName(obj)]["options"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"]) {
|
842
|
title = obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"];
|
843
|
obj[this.getDescriptionObjectName(obj)]["options"]["hAxis"]["title"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
844
|
}else if (obj[this.getDescriptionObjectName(obj)]["xAxis"] && obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"]) {
|
845
|
title = obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"];
|
846
|
obj[this.getDescriptionObjectName(obj)]["xAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
847
|
}
|
848
|
indicatorPath.parameters["xAxisTitle"] = title ? title : "";
|
849
|
}
|
850
|
|
851
|
private extractYTitle(obj, indicatorPath: IndicatorPath) {
|
852
|
let title = "";
|
853
|
if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"] ) {
|
854
|
title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"];
|
855
|
obj[this.getDescriptionObjectName(obj)]["yAxis"]["title"]["text"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
856
|
}else if (obj[this.getDescriptionObjectName(obj)]["options"]&& obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"] && obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"]) {
|
857
|
title = obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"];
|
858
|
obj[this.getDescriptionObjectName(obj)]["options"]["vAxis"]["title"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
859
|
}else if (obj[this.getDescriptionObjectName(obj)]["yAxis"] && obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"]) {
|
860
|
title = obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"];
|
861
|
obj[this.getDescriptionObjectName(obj)]["yAxis"]["name"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
862
|
}
|
863
|
indicatorPath.parameters["yAxisTitle"] = title ? title : "";
|
864
|
}
|
865
|
|
866
|
private extractOldToolTitle(obj, indicatorPath: IndicatorPath) {
|
867
|
let title = "";
|
868
|
if (obj["title"]) {
|
869
|
title = obj["title"];
|
870
|
obj["title"] = ChartHelper.prefix + "title" + ChartHelper.suffix;
|
871
|
indicatorPath.parameters["title"] = title;
|
872
|
|
873
|
}
|
874
|
}
|
875
|
|
876
|
private extractOldToolXTitle(obj, indicatorPath: IndicatorPath) {
|
877
|
let title = "";
|
878
|
if (obj["xaxistitle"]) {
|
879
|
title = obj["xaxistitle"];
|
880
|
obj["xaxistitle"] = ChartHelper.prefix + "xAxisTitle" + ChartHelper.suffix;
|
881
|
indicatorPath.parameters["xAxisTitle"] = title;
|
882
|
}
|
883
|
}
|
884
|
|
885
|
private extractOldToolYTitle(obj, indicatorPath: IndicatorPath) {
|
886
|
let title = "";
|
887
|
if (obj["fieldsheaders"]) {
|
888
|
title = Array.isArray(obj["fieldsheaders"]) ? obj["fieldsheaders"][0] : obj["fieldsheaders"];
|
889
|
if (Array.isArray(obj["fieldsheaders"])) {
|
890
|
obj["fieldsheaders"][0] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
891
|
} else {
|
892
|
obj["fieldsheaders"] = ChartHelper.prefix + "yAxisTitle" + ChartHelper.suffix;
|
893
|
}
|
894
|
indicatorPath.parameters["yAxisTitle"] = title;
|
895
|
}
|
896
|
}
|
897
|
|
898
|
}
|