1
|
import {SafeResourceUrl} from "@angular/platform-browser";
|
2
|
|
3
|
export const ChartHelper = {
|
4
|
prefix: "((__",
|
5
|
suffix: "__))"
|
6
|
};
|
7
|
|
8
|
export type StakeholderType = 'funder' | 'ri' | 'project' | 'organization';
|
9
|
export type IndicatorType = 'number' | 'chart';
|
10
|
export type IndicatorSize = 'small' | 'medium' | 'large';
|
11
|
export type IndicatorPathType = 'table' | 'bar' | 'column' | 'pie' | 'line' | 'other';
|
12
|
export type SourceType = 'statistics' | 'search' | 'metrics' | 'stats-tool' | 'old' | 'image';
|
13
|
export type Visibility = 'PUBLIC' | 'PRIVATE' | 'RESTRICTED';
|
14
|
|
15
|
export class Stakeholder {
|
16
|
_id: string;
|
17
|
type: StakeholderType;
|
18
|
name: string;
|
19
|
index_id;
|
20
|
index_name: string;
|
21
|
index_shortName: string;
|
22
|
alias: string;
|
23
|
defaultId: string;
|
24
|
visibility: Visibility;
|
25
|
creationDate: Date = null;
|
26
|
updateDate: Date;
|
27
|
logoUrl: string;
|
28
|
isUpload: boolean = false;
|
29
|
description: string;
|
30
|
topics: any[];
|
31
|
|
32
|
constructor(_id: string, type: StakeholderType, index_id, index_name: string, index_shortName: string, alias: string, visibility: Visibility, logoUrl: string, defaultId: string = null, description: string = null) {
|
33
|
this._id = _id;
|
34
|
this.type = type;
|
35
|
this.index_id = index_id;
|
36
|
this.index_name = index_name;
|
37
|
this.index_shortName = index_shortName;
|
38
|
this.defaultId = defaultId;
|
39
|
this.alias = alias;
|
40
|
this.visibility = visibility;
|
41
|
this.logoUrl = logoUrl;
|
42
|
this.description = description;
|
43
|
this.topics = [];
|
44
|
}
|
45
|
}
|
46
|
|
47
|
export class StakeholderInfo extends Stakeholder {
|
48
|
isManager: boolean = false;
|
49
|
isMember: boolean = false;
|
50
|
}
|
51
|
|
52
|
export class Topic {
|
53
|
_id: string;
|
54
|
name: string;
|
55
|
alias: string;
|
56
|
description: string;
|
57
|
visibility: Visibility;
|
58
|
creationDate: Date = null;
|
59
|
updateDate: Date;
|
60
|
defaultId: string;
|
61
|
categories: Category[];
|
62
|
icon: string;
|
63
|
|
64
|
constructor(name: string, description: string, alias: string, visibility:Visibility, defaultId: string = null, icon: string = null) {
|
65
|
this._id = null;
|
66
|
this.name = name;
|
67
|
this.description = description;
|
68
|
this.alias = alias;
|
69
|
this.visibility = visibility;
|
70
|
this.defaultId = defaultId;
|
71
|
this.categories = [];
|
72
|
this.icon = icon;
|
73
|
}
|
74
|
}
|
75
|
|
76
|
export class Category {
|
77
|
_id: string;
|
78
|
name: string;
|
79
|
alias: string;
|
80
|
description: string;
|
81
|
creationDate: Date = null;
|
82
|
updateDate: Date;
|
83
|
visibility: Visibility;
|
84
|
defaultId: string;
|
85
|
subCategories: SubCategory[];
|
86
|
|
87
|
constructor(name: string, description: string, alias: string, visibility: Visibility, defaultId: string = null) {
|
88
|
this._id = null;
|
89
|
this.name = name;
|
90
|
this.description = description;
|
91
|
this.alias = alias;
|
92
|
this.visibility = visibility;
|
93
|
this.defaultId = defaultId;
|
94
|
this.subCategories = [];
|
95
|
}
|
96
|
}
|
97
|
|
98
|
export class SubCategory {
|
99
|
_id: string;
|
100
|
name: string;
|
101
|
alias: string;
|
102
|
description: string;
|
103
|
creationDate: Date = null;
|
104
|
updateDate: Date;
|
105
|
visibility: Visibility;
|
106
|
defaultId: string;
|
107
|
charts: Section[];
|
108
|
numbers: Section[];
|
109
|
|
110
|
constructor(name: string, description: string, alias: string, visibility: Visibility, defaultId: string = null) {
|
111
|
this._id = null;
|
112
|
this.name = name;
|
113
|
this.description = description;
|
114
|
this.alias = alias;
|
115
|
this.visibility = visibility;
|
116
|
this.defaultId = defaultId;
|
117
|
this.charts = [];
|
118
|
this.numbers = [];
|
119
|
}
|
120
|
|
121
|
}
|
122
|
|
123
|
export class Section {
|
124
|
_id: string;
|
125
|
title: string;
|
126
|
defaultId: string;
|
127
|
creationDate: Date = null;
|
128
|
updateDate: Date;
|
129
|
stakeholderAlias: string;
|
130
|
type: IndicatorType;
|
131
|
indicators: Indicator[];
|
132
|
|
133
|
constructor(type: IndicatorType, title: string = null, defaultId: string = null, stakeholderAlias: string = null) {
|
134
|
this._id = null;
|
135
|
this.title = title;
|
136
|
this.type = type;
|
137
|
this.defaultId = defaultId;
|
138
|
this.stakeholderAlias = stakeholderAlias;
|
139
|
this.indicators = [];
|
140
|
}
|
141
|
}
|
142
|
|
143
|
export class Indicator {
|
144
|
_id: string;
|
145
|
name: string;
|
146
|
description: string;
|
147
|
additionalDescription: string;
|
148
|
creationDate: Date = null;
|
149
|
updateDate: Date;
|
150
|
type: IndicatorType;
|
151
|
width: IndicatorSize;
|
152
|
height: IndicatorSize;
|
153
|
tags: string[];
|
154
|
visibility: Visibility;
|
155
|
defaultId: string;
|
156
|
indicatorPaths: IndicatorPath[];
|
157
|
|
158
|
constructor(name: string, description: string, additionalDescription:string, type: IndicatorType, width: IndicatorSize,height: IndicatorSize, visibility: Visibility, indicatorPaths: IndicatorPath[], defaultId: string = null) {
|
159
|
this._id = null;
|
160
|
this.name = name;
|
161
|
this.description = description;
|
162
|
this.additionalDescription = additionalDescription;
|
163
|
this.type = type;
|
164
|
this.width = width;
|
165
|
this.height = height;
|
166
|
this.visibility = visibility;
|
167
|
this.defaultId = defaultId;
|
168
|
this.indicatorPaths = indicatorPaths;
|
169
|
}
|
170
|
|
171
|
}
|
172
|
|
173
|
export class IndicatorPath {
|
174
|
type: IndicatorPathType;
|
175
|
source: SourceType;
|
176
|
url: string;
|
177
|
safeResourceUrl: SafeResourceUrl; // initialize on front end
|
178
|
jsonPath: string[];
|
179
|
chartObject: string;
|
180
|
parameters: any;
|
181
|
filters: any;
|
182
|
filtersApplied: number = 0;
|
183
|
|
184
|
constructor(type: IndicatorPathType, source: SourceType, url: string, chartObject: string, jsonPath: string[]) {
|
185
|
this.type = type;
|
186
|
this.url = url;
|
187
|
this.source = source;
|
188
|
this.jsonPath = jsonPath;
|
189
|
this.chartObject = chartObject;
|
190
|
this.parameters = {};
|
191
|
this.filters = {};
|
192
|
this.filtersApplied = 0;
|
193
|
}
|
194
|
|
195
|
static createParameters(funderName: string = null, title: string = null, chartType: string = null): any {
|
196
|
return {
|
197
|
index_name: funderName,
|
198
|
title: title,
|
199
|
type: chartType
|
200
|
};
|
201
|
}
|
202
|
|
203
|
}
|
204
|
export type FilterType = "fundingL0"|"start_year" | "end_year" | "co-funded";
|
205
|
export class IndicatorFilterUtils{
|
206
|
static getFilter(field: string, filterType:FilterType) {
|
207
|
if(["publication", "software", "dataset", "other", "result"].indexOf(field)!=-1){
|
208
|
return this.getResultFilter(field,filterType);
|
209
|
}else if (field == "project"){
|
210
|
return this.getProjectFilter(filterType);
|
211
|
}
|
212
|
//TODO uncomment to add other options --> following doesn't work
|
213
|
/* else if (field == "country"){
|
214
|
return this.getCountryFilter(filterType);
|
215
|
}else if (field == "organization"){
|
216
|
return this.getOrganizationFilter(filterType);
|
217
|
}*/
|
218
|
|
219
|
}
|
220
|
static getResultFilter(dbType: string = null, filterType:FilterType) {
|
221
|
if (filterType == "fundingL0") {
|
222
|
return '{"groupFilters":[{"field":"' + dbType + '.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
223
|
} else if (filterType == "start_year") {
|
224
|
return '{"groupFilters":[{"field":"' + dbType + '.year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
225
|
} else if (filterType == "end_year") {
|
226
|
return '{"groupFilters":[{"field":"' + dbType + '.year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
227
|
}else if (filterType == "co-funded") {
|
228
|
return '{"groupFilters":[{"field":"' + dbType + '.No of funders","type":">","values":["1"]}],"op":"AND"}';
|
229
|
}
|
230
|
}
|
231
|
static getProjectFilter( filterType:FilterType) {
|
232
|
if (filterType == "fundingL0") {
|
233
|
return '{"groupFilters":[{"field":"project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
234
|
} else if (filterType == "start_year") {
|
235
|
return '{"groupFilters":[{"field":"project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
236
|
} else if (filterType == "end_year") {
|
237
|
return '{"groupFilters":[{"field":"project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
238
|
}
|
239
|
}
|
240
|
static getOrganizationFilter( filterType:FilterType) {
|
241
|
if (filterType == "fundingL0") {
|
242
|
return '{"groupFilters":[{"field":"organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
243
|
} else if (filterType == "start_year") {
|
244
|
return '{"groupFilters":[{"field":"organization.project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
245
|
} else if (filterType == "end_year") {
|
246
|
return '{"groupFilters":[{"field":"organization.project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
247
|
}
|
248
|
}
|
249
|
static getCountryFilter( filterType:FilterType) {
|
250
|
if (filterType == "fundingL0") {
|
251
|
return '{"groupFilters":[{"field":"country.organization.project.funding level 0","type":"=","values":["' + ChartHelper.prefix + 'fundingL0' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
252
|
} else if (filterType == "start_year") {
|
253
|
return '{"groupFilters":[{"field":"country.organization.project.start year","type":">=","values":["' + ChartHelper.prefix + 'start_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
254
|
} else if (filterType == "end_year") {
|
255
|
return '{"groupFilters":[{"field":"country.organization.project.start year","type":"<=","values":["' + ChartHelper.prefix + 'end_year' + ChartHelper.suffix + '"]}],"op":"AND"}';
|
256
|
}
|
257
|
}
|
258
|
|
259
|
static filterIndexOf(filterToAdd, currentFilters):any{
|
260
|
for(let fi =0; fi< currentFilters.length; fi++){
|
261
|
for(let gfi =0; gfi< currentFilters[fi]["groupFilters"].length; gfi++ ){
|
262
|
if(currentFilters[fi]["groupFilters"][gfi].field == filterToAdd['groupFilters'][0]['field'] && currentFilters[fi]["groupFilters"][gfi].type == filterToAdd['groupFilters'][0]['type']){
|
263
|
return {"filter":fi, "groupFilter":gfi};
|
264
|
}
|
265
|
}
|
266
|
}
|
267
|
return null;
|
268
|
}
|
269
|
}
|