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