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