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