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