1
|
import { Component, OnInit } from '@angular/core';
|
2
|
import { ActivatedRoute, Router } from '@angular/router';
|
3
|
import { MetricsInfo, PiwikInfo } from '../../domain/typeScriptClasses';
|
4
|
import { PiwikService } from '../../services/piwik.service';
|
5
|
import { RepositoryService } from '../../services/repository.service';
|
6
|
import { loadingMetrics, loadingMetricsError } from '../../domain/shared-messages';
|
7
|
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser';
|
8
|
import { AuthenticationService } from '../../services/authentication.service';
|
9
|
|
10
|
@Component ({
|
11
|
selector: 'metrics-show',
|
12
|
templateUrl: 'metrics-show.component.html'
|
13
|
})
|
14
|
|
15
|
export class MetricsShowComponent implements OnInit {
|
16
|
errorMessage: string;
|
17
|
loadingMessage: string;
|
18
|
|
19
|
repoId: string;
|
20
|
piwik: PiwikInfo;
|
21
|
repoMetrics: MetricsInfo;
|
22
|
pageViews = '--';
|
23
|
totalViews = '--';
|
24
|
totalDownloads = '--';
|
25
|
viewsUrl: SafeResourceUrl;
|
26
|
downloadsUrl: SafeResourceUrl;
|
27
|
|
28
|
constructor(
|
29
|
private route: ActivatedRoute,
|
30
|
private router: Router,
|
31
|
private sanitizer: DomSanitizer,
|
32
|
private piwikService: PiwikService,
|
33
|
private repoService: RepositoryService,
|
34
|
private authService: AuthenticationService) {}
|
35
|
|
36
|
ngOnInit() {
|
37
|
this.repoId = this.route.snapshot.paramMap.get('id');
|
38
|
setTimeout(() => {
|
39
|
this.getPiwik();
|
40
|
}, 1000);
|
41
|
}
|
42
|
|
43
|
|
44
|
getPiwik() {
|
45
|
this.loadingMessage = loadingMetrics;
|
46
|
this.piwikService.getPiwikInfo(this.repoId).subscribe(
|
47
|
piwik => this.piwik = piwik,
|
48
|
error => {
|
49
|
this.loadingMessage = '';
|
50
|
this.errorMessage = loadingMetricsError;
|
51
|
console.log(error);
|
52
|
},
|
53
|
() => {
|
54
|
this.loadingMessage = '';
|
55
|
this.errorMessage = '';
|
56
|
if ( this.authService.activateFrontAuthorization &&
|
57
|
(this.authService.getUserEmail() !== this.piwik.requestorEmail.trim()) ) {
|
58
|
this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
|
59
|
} else {
|
60
|
this.getMetrics();
|
61
|
}
|
62
|
}
|
63
|
);
|
64
|
}
|
65
|
|
66
|
getMetrics() {
|
67
|
this.loadingMessage = loadingMetrics;
|
68
|
this.repoService.getMetricsInfoForRepository(this.repoId).subscribe(
|
69
|
metrics => {
|
70
|
this.repoMetrics = metrics;
|
71
|
if (this.repoMetrics.metricsNumbers.pageviews) {
|
72
|
this.pageViews = this.repoMetrics.metricsNumbers.pageviews;
|
73
|
}
|
74
|
if (this.repoMetrics.metricsNumbers.total_views) {
|
75
|
this.totalViews = this.repoMetrics.metricsNumbers.total_views;
|
76
|
}
|
77
|
if (this.repoMetrics.metricsNumbers.total_downloads) {
|
78
|
this.totalDownloads = this.repoMetrics.metricsNumbers.total_downloads;
|
79
|
}
|
80
|
this.getViewsUrl();
|
81
|
this.getDownloadsUrl();
|
82
|
},
|
83
|
error => {
|
84
|
this.loadingMessage = '';
|
85
|
this.errorMessage = loadingMetricsError;
|
86
|
console.log(error);
|
87
|
},
|
88
|
() => {
|
89
|
this.loadingMessage = '';
|
90
|
this.errorMessage = '';
|
91
|
}
|
92
|
);
|
93
|
}
|
94
|
|
95
|
|
96
|
getViewsUrl () {
|
97
|
this.viewsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
|
98
|
`${this.repoMetrics.diagramsBaseURL}merge.php?com=query
|
99
|
&data=[{"query":"dtsrcRepoViews","dtsrcName":"${this.piwik.openaireId}",
|
100
|
"table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],
|
101
|
"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,
|
102
|
"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"",
|
103
|
"xaxistitle":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]
|
104
|
&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]
|
105
|
&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},
|
106
|
{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)
|
107
|
&colors[]=rgba(124,181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,1)
|
108
|
&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,1)&colors[]=rgba(241, 92, 128, 1)
|
109
|
&colors[]=rgba(228, 211, 84,1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,1)
|
110
|
&colors[]=rgba(145, 232, 225,1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false`
|
111
|
);
|
112
|
}
|
113
|
|
114
|
getDownloadsUrl () {
|
115
|
this.downloadsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
|
116
|
`${this.repoMetrics.diagramsBaseURL}merge.php?com=query
|
117
|
&data=[{"query":"dtsrcRepoDownloads","dtsrcName":"${this.piwik.openaireId}",
|
118
|
"table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],
|
119
|
"xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,
|
120
|
"sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"",
|
121
|
"xaxistitle":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]
|
122
|
&info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]
|
123
|
&style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0,1)","size":"18"},
|
124
|
{"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)
|
125
|
&colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,1)
|
126
|
&colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,1)&colors[]=rgba(241, 92, 128, 1)
|
127
|
&colors[]=rgba(228, 211, 84,1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,1)
|
128
|
&colors[]=rgba(145, 232, 225,1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false`
|
129
|
);
|
130
|
}
|
131
|
|
132
|
}
|