1
|
import {Component, Input} from '@angular/core';
|
2
|
import {ActivatedRoute, Router} from '@angular/router';
|
3
|
import {Location, TitleCasePipe} from '@angular/common';
|
4
|
import {DomSanitizer, Meta, Title} from '@angular/platform-browser';
|
5
|
import {EnvProperties} from '../openaireLibrary/utils/properties/env-properties';
|
6
|
import {ErrorCodes} from '../openaireLibrary/utils/properties/errorCodes';
|
7
|
import {StatisticsService} from '../utils/services/statistics.service';
|
8
|
import {ConfigurationService} from '../openaireLibrary/utils/configuration/configuration.service';
|
9
|
import {PiwikService} from '../openaireLibrary/utils/piwik/piwik.service';
|
10
|
import {
|
11
|
availableCharts,
|
12
|
availableEntitiesMap,
|
13
|
StatisticsDisplay,
|
14
|
StatisticsSummary
|
15
|
} from "../openaireLibrary/connect/statistics/statisticsEntities";
|
16
|
import {PiwikHelper} from '../utils/piwikHelper';
|
17
|
import {CommunityCharts} from "../openaireLibrary/connect/statistics/communityCharts";
|
18
|
import {CommunityService} from "../openaireLibrary/connect/community/community.service";
|
19
|
import {Subscriber, Subscription} from "rxjs";
|
20
|
import {properties} from "../../environments/environment";
|
21
|
|
22
|
|
23
|
@Component({
|
24
|
selector: 'statistics',
|
25
|
templateUrl: 'statistics.component.html',
|
26
|
})
|
27
|
|
28
|
export class StatisticsComponent {
|
29
|
public pageTitle = "OpenAIRE";
|
30
|
properties: EnvProperties = properties;
|
31
|
@Input() communityId = null;
|
32
|
@Input() currentMode = 'showInMonitor';
|
33
|
communityInfo: any = null;
|
34
|
entitiesList: string[] = [];
|
35
|
entitiesMap: Map<string, string> = availableEntitiesMap;
|
36
|
chartCatsList: string[] = availableCharts;
|
37
|
//allowedCharts = {};
|
38
|
allowedCharts: Map<string, string[]> = new Map<string, string[]>();
|
39
|
allowedEntities: string[] = [];
|
40
|
//allowedChartsMode = {showInMonitor: {}/, showInDashboard: {}};
|
41
|
allowedChartsMode = {showInMonitor: new Map<string, string[]>(), showInDashboard: new Map<string, string[]>()};
|
42
|
allowedEntitiesMode = {showInMonitor: [], showInDashboard: []};
|
43
|
|
44
|
statisticsSum: StatisticsSummary = null;
|
45
|
statisticsDisplay: StatisticsDisplay = null;
|
46
|
chartTitlesMode = {showInMonitor: {}, showInDashboard: {}};
|
47
|
chartsInfoMap: {};
|
48
|
|
49
|
displayedTimeline: string;
|
50
|
displayedTimelineUrl: string;
|
51
|
displayedGraph: string;
|
52
|
displayedGraphUrl: string;
|
53
|
displayedProjectChart: string;
|
54
|
displayedProjectChartUrl: string;
|
55
|
displayedEntity: string;
|
56
|
public errorCodes: ErrorCodes = new ErrorCodes();
|
57
|
status = null;
|
58
|
communityName = null;
|
59
|
|
60
|
subs: Subscription[] = [];
|
61
|
|
62
|
constructor(
|
63
|
private route: ActivatedRoute,
|
64
|
private _router: Router,
|
65
|
private location: Location,
|
66
|
private _meta: Meta,
|
67
|
private _title: Title,
|
68
|
private _piwikService: PiwikService,
|
69
|
private _statisticsService: StatisticsService,
|
70
|
private _configService: ConfigurationService,
|
71
|
private titleCase: TitleCasePipe,
|
72
|
private _communityService: CommunityService,
|
73
|
private sanitizer: DomSanitizer) {
|
74
|
|
75
|
}
|
76
|
|
77
|
public ngOnInit() {
|
78
|
if (this.currentMode == "showInMonitor") {
|
79
|
var description = "open access, research, scientific publication, European Commission, EC, FP7, ERC, Horizon 2020, H2020, search, projects ";
|
80
|
var title = "Monitor";
|
81
|
|
82
|
this._title.setTitle(title);
|
83
|
this._meta.updateTag({content: description}, "name='description'");
|
84
|
this._meta.updateTag({content: description}, "property='og:description'");
|
85
|
this._meta.updateTag({content: title}, "property='og:title'");
|
86
|
}
|
87
|
var url = properties.domain + properties.baseLink + this._router.url;
|
88
|
this._meta.updateTag({content: url}, "property='og:url'");
|
89
|
this.subs.push(this._communityService.getCommunityAsObservable().subscribe(
|
90
|
community => {
|
91
|
if(community) {
|
92
|
this.communityId = community.communityId;
|
93
|
if (this.currentMode == "showInMonitor" && this.properties.enablePiwikTrack && (typeof document !== 'undefined')) {
|
94
|
this.subs.push(this._piwikService.trackView(this.properties, "Monitor " + this.communityId, PiwikHelper.siteIDs[this.communityId]).subscribe());
|
95
|
}
|
96
|
this.communityName = community.shortTitle;
|
97
|
this.createChartUrlMap();
|
98
|
this.createStatisticsObjects();
|
99
|
}
|
100
|
}));
|
101
|
|
102
|
}
|
103
|
|
104
|
public ngOnDestroy() {
|
105
|
for (let sub of this.subs) {
|
106
|
if (sub instanceof Subscriber) {
|
107
|
sub.unsubscribe();
|
108
|
}
|
109
|
}
|
110
|
}
|
111
|
|
112
|
getCamelCaseString(inputString: string) {
|
113
|
return this.titleCase.transform(inputString);
|
114
|
}
|
115
|
|
116
|
createStatisticsObjects() {
|
117
|
// console.log(" Stats! "+ this.properties.statisticsAPIURL);
|
118
|
this.status = this.errorCodes.LOADING;
|
119
|
this.subs.push(this._statisticsService.getCommunityStatistics(this.properties, this.communityId).subscribe(
|
120
|
res => {
|
121
|
if (res) {
|
122
|
this.statisticsSum = res;
|
123
|
if (res["other"]) { //hack because in stats API the entity name is "other" while in admin API is "orp". This component uses also "orp" name
|
124
|
this.statisticsSum["orp"] = res["other"];
|
125
|
}
|
126
|
this.getDisplayOptions();
|
127
|
} else {
|
128
|
console.error("Error getting community statistics for community with id: " + this.communityId);
|
129
|
this.status = this.errorCodes.ERROR;
|
130
|
}
|
131
|
},
|
132
|
error => {
|
133
|
//console.log(error);
|
134
|
this.handleError("Error getting community statistics for community with id: " + this.communityId, error);
|
135
|
this.status = this.errorCodes.ERROR;
|
136
|
}));
|
137
|
}
|
138
|
|
139
|
getDisplayOptions() {
|
140
|
this.subs.push(this._statisticsService.getCommunityAdminStatisticsChoices(this.properties, this.communityId)
|
141
|
.subscribe(
|
142
|
res => {
|
143
|
this.statisticsDisplay = res;
|
144
|
|
145
|
this.getCommunityInfo();
|
146
|
this.status = this.errorCodes.DONE;
|
147
|
|
148
|
},
|
149
|
error => {
|
150
|
//console.log(error);
|
151
|
this.handleError("Error getting community statistics choices by administrators for community with id: " + this.communityId, error);
|
152
|
this.status = this.errorCodes.ERROR;
|
153
|
}
|
154
|
));
|
155
|
}
|
156
|
|
157
|
|
158
|
getCommunityInfo() {
|
159
|
// console.log(`calling ${this.properties.adminToolsAPIURL}/communityFull/${this.communityId}`);
|
160
|
this.subs.push(this._configService.communityInformationState.subscribe(
|
161
|
res => {
|
162
|
this.communityInfo = res;
|
163
|
/*for(let i=0; i<this.communityInfo.entities.length; i++){
|
164
|
|
165
|
if (this.communityInfo.entities[i]["isEnabled"] ) {
|
166
|
this.entitiesList.push(this.communityInfo.entities[i]['pid']);
|
167
|
}
|
168
|
}
|
169
|
console.log(this.entitiesList);*/
|
170
|
this.initializeDisplayedCharts()
|
171
|
},
|
172
|
error => {
|
173
|
//console.log(error)
|
174
|
this.handleError("Error getting community with id: " + this.communityId, error);
|
175
|
this.initializeDisplayedCharts();
|
176
|
}
|
177
|
));
|
178
|
}
|
179
|
|
180
|
initializeDisplayedCharts() {
|
181
|
let firstEntity: string;
|
182
|
this.entitiesList = Array.from(this.entitiesMap.keys());
|
183
|
|
184
|
this.allowedChartsMode[this.currentMode] = this.allowedCharts;
|
185
|
this.allowedEntitiesMode[this.currentMode] = this.allowedEntities;
|
186
|
let titles = [];
|
187
|
// console.log('this.entitiesList is',this.entitiesList);
|
188
|
// console.log(`my current mode is: ${this.currentMode}`);
|
189
|
for (let entity of this.entitiesList) {
|
190
|
if (this.statisticsDisplay.entities[entity] && this.statisticsSum[entity].total && this.communityInfo.entities.filter(x => x['pid'] == entity && x['isEnabled'] === true).length) {
|
191
|
this.allowedChartsMode.showInDashboard[entity] = [];
|
192
|
this.allowedChartsMode.showInMonitor[entity] = [];
|
193
|
for (let chart of this.chartCatsList) {
|
194
|
if (this.statisticsSum[entity].total &&
|
195
|
this.statisticsDisplay.entities[entity].charts.map[chart] &&
|
196
|
this.statisticsDisplay.entities[entity].charts.map[chart]["showInDashboard"] &&
|
197
|
this.chartsInfoMap[entity + this.getCamelCaseString(chart)].url) {
|
198
|
this.allowedChartsMode.showInDashboard[entity].push(entity + this.getCamelCaseString(chart));
|
199
|
if (titles.indexOf("dashboard" + this.chartsInfoMap[entity + this.getCamelCaseString(chart)].title) == -1) {
|
200
|
titles.push("dashboard" + this.chartsInfoMap[entity + this.getCamelCaseString(chart)].title);
|
201
|
this.chartTitlesMode.showInDashboard[entity + this.getCamelCaseString(chart)] = true;
|
202
|
} else {
|
203
|
this.chartTitlesMode.showInDashboard[entity + this.getCamelCaseString(chart)] = false;
|
204
|
}
|
205
|
|
206
|
// console.log(`added ${entity} - ${chart} to allowedCharts`);
|
207
|
}
|
208
|
if (this.statisticsSum[entity].total &&
|
209
|
this.statisticsDisplay.entities[entity].charts.map[chart] &&
|
210
|
this.statisticsDisplay.entities[entity].charts.map[chart]["showInMonitor"] &&
|
211
|
this.chartsInfoMap[entity + this.getCamelCaseString(chart)].url) {
|
212
|
this.allowedChartsMode.showInMonitor[entity].push(entity + this.getCamelCaseString(chart));
|
213
|
if (titles.indexOf("monitor" + this.chartsInfoMap[entity + this.getCamelCaseString(chart)].title) == -1) {
|
214
|
titles.push("monitor" + this.chartsInfoMap[entity + this.getCamelCaseString(chart)].title);
|
215
|
this.chartTitlesMode.showInMonitor[entity + this.getCamelCaseString(chart)] = true;
|
216
|
} else {
|
217
|
this.chartTitlesMode.showInMonitor[entity + this.getCamelCaseString(chart)] = false;
|
218
|
}
|
219
|
// console.log(`added ${entity} - ${chart} to allowedCharts`);
|
220
|
|
221
|
}
|
222
|
}
|
223
|
if (this.allowedChartsMode.showInMonitor[entity].length) {
|
224
|
// console.log(`added ${entity} to allowedEntities`);
|
225
|
this.allowedEntitiesMode.showInMonitor.push(entity);
|
226
|
if (!firstEntity) {
|
227
|
firstEntity = entity;
|
228
|
this.onChangeEntity(entity);
|
229
|
}
|
230
|
}
|
231
|
if (this.allowedChartsMode.showInDashboard[entity].length) {
|
232
|
// console.log(`added ${entity} to allowedEntities`);
|
233
|
this.allowedEntitiesMode.showInDashboard.push(entity);
|
234
|
if (!firstEntity) {
|
235
|
firstEntity = entity;
|
236
|
this.onChangeEntity(entity);
|
237
|
}
|
238
|
}
|
239
|
}
|
240
|
}
|
241
|
|
242
|
}
|
243
|
|
244
|
createChartUrlMap() {
|
245
|
|
246
|
let communityCharts: CommunityCharts = new CommunityCharts(this.sanitizer);
|
247
|
this.chartsInfoMap = communityCharts.getChartsForCommunity(this.communityId, this.communityName, this.properties);
|
248
|
}
|
249
|
|
250
|
|
251
|
onChangeEntity(entity: string) {
|
252
|
this.displayedEntity = entity;
|
253
|
// console.log(`displayed entity is ${entity}`);
|
254
|
// console.log(`statisticsSum[${entity}].total is ${this.statisticsSum[entity].total}`);
|
255
|
|
256
|
if (this.statisticsSum[entity].total &&
|
257
|
this.allowedEntities.filter(x => x == entity).length) {
|
258
|
|
259
|
// console.log(`found ${entity} in allowedEntities`);
|
260
|
this.displayedTimeline = `${entity}Timeline`;
|
261
|
this.displayedTimelineUrl = this.chartsInfoMap[this.displayedTimeline].url;
|
262
|
// console.log(`displayed Timeline is: ${this.displayedTimeline}`);
|
263
|
this.displayedGraph = `${entity}Graph`;
|
264
|
this.displayedGraphUrl = this.chartsInfoMap[this.displayedGraph].url;
|
265
|
// console.log(`displayed Graph is: ${this.displayedGraph}`);
|
266
|
if (this.allowedCharts[entity]) {
|
267
|
let firstProjectChart = this.allowedCharts[entity].filter(x => x.includes(entity + 'Project'));
|
268
|
if (firstProjectChart[0]) {
|
269
|
this.changeDisplayedProjectChart(firstProjectChart[0]);
|
270
|
} else {
|
271
|
this.displayedProjectChart = '';
|
272
|
this.displayedProjectChartUrl = '';
|
273
|
// console.log(`displayed ProjectChart is: ${this.displayedProjectChart}`);
|
274
|
}
|
275
|
}
|
276
|
} else {
|
277
|
this.displayedTimeline = '';
|
278
|
this.displayedTimelineUrl = '';
|
279
|
// console.log(`displayed Timeline is: ${this.displayedTimeline}`);
|
280
|
this.displayedGraph = '';
|
281
|
this.displayedGraphUrl = '';
|
282
|
// console.log(`displayed Graph is: ${this.displayedGraph}`);
|
283
|
}
|
284
|
}
|
285
|
|
286
|
changeDisplayedProjectChart(chartName: string) {
|
287
|
this.displayedProjectChart = chartName;
|
288
|
this.displayedProjectChartUrl = this.chartsInfoMap[this.displayedProjectChart].url;
|
289
|
// console.log(`displayed ProjectChart is: ${this.displayedProjectChart}`);
|
290
|
}
|
291
|
|
292
|
private handleError(message: string, error) {
|
293
|
console.error("Statistics (Monitor) Page: " + message, error);
|
294
|
}
|
295
|
}
|
296
|
|
297
|
|
298
|
@Component({
|
299
|
selector: 'statistics-for-dashboard',
|
300
|
template: ''
|
301
|
// templateUrl: 'statistics-for-dashboard.component.html',
|
302
|
})
|
303
|
|
304
|
export class StatisticsForDashboardComponent extends StatisticsComponent {
|
305
|
ngOnInit() {
|
306
|
super.ngOnInit();
|
307
|
}
|
308
|
|
309
|
}
|