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
|
import { SharedService } from "../../../services/shared.service";
|
10
|
|
11
|
@Component ({
|
12
|
selector: 'metrics-show',
|
13
|
templateUrl: 'metrics-show.component.html'
|
14
|
})
|
15
|
|
16
|
export class MetricsShowComponent implements OnInit {
|
17
|
errorMessage: string;
|
18
|
loadingMessage: string;
|
19
|
|
20
|
repoId: string;
|
21
|
piwik: PiwikInfo;
|
22
|
repoMetrics: MetricsInfo;
|
23
|
pageViews = '--';
|
24
|
totalViews = '--';
|
25
|
totalDownloads = '--';
|
26
|
viewsUrl: SafeResourceUrl;
|
27
|
downloadsUrl: SafeResourceUrl;
|
28
|
|
29
|
constructor(
|
30
|
private route: ActivatedRoute,
|
31
|
private router: Router,
|
32
|
private sanitizer: DomSanitizer,
|
33
|
private piwikService: PiwikService,
|
34
|
private repoService: RepositoryService,
|
35
|
private authService: AuthenticationService,
|
36
|
private sharedService: SharedService) {}
|
37
|
|
38
|
ngOnInit() {
|
39
|
|
40
|
if(this.sharedService.getRepository()) {
|
41
|
this.repoId = this.sharedService.getRepository().id;
|
42
|
this.piwik = this.sharedService.getRepository().piwikInfo;
|
43
|
this.getMetrics();
|
44
|
}
|
45
|
|
46
|
this.sharedService.repository$.subscribe(
|
47
|
r => {
|
48
|
this.repoId = r.id;
|
49
|
this.piwik = r.piwikInfo;
|
50
|
this.getMetrics();
|
51
|
}
|
52
|
);
|
53
|
|
54
|
let body = document.getElementsByTagName('body')[0];
|
55
|
body.classList.remove("top_bar_active"); //remove the class
|
56
|
body.classList.remove("page_heading_active");
|
57
|
body.classList.remove("landing");
|
58
|
body.classList.add("dashboard");
|
59
|
}
|
60
|
|
61
|
getMetrics() {
|
62
|
this.loadingMessage = loadingMetrics;
|
63
|
this.repoService.getMetricsInfoForRepository(this.repoId).subscribe(
|
64
|
metrics => {
|
65
|
this.repoMetrics = metrics;
|
66
|
if (this.repoMetrics.metricsNumbers.pageviews) {
|
67
|
this.pageViews = this.repoMetrics.metricsNumbers.pageviews;
|
68
|
}
|
69
|
if (this.repoMetrics.metricsNumbers.total_views) {
|
70
|
this.totalViews = this.repoMetrics.metricsNumbers.total_views;
|
71
|
}
|
72
|
if (this.repoMetrics.metricsNumbers.total_downloads) {
|
73
|
this.totalDownloads = this.repoMetrics.metricsNumbers.total_downloads;
|
74
|
}
|
75
|
this.getViewsUrl();
|
76
|
this.getDownloadsUrl();
|
77
|
},
|
78
|
error => {
|
79
|
this.loadingMessage = '';
|
80
|
this.errorMessage = loadingMetricsError;
|
81
|
console.log(error);
|
82
|
},
|
83
|
() => {
|
84
|
this.loadingMessage = '';
|
85
|
this.errorMessage = '';
|
86
|
}
|
87
|
);
|
88
|
}
|
89
|
|
90
|
|
91
|
getViewsUrl () {
|
92
|
|
93
|
let encodedURL = encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly views","type":"line","query":{"name":"usagestats.views.monthly", "parameters":["' + this.piwik.openaireId + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"Monthly views"}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
|
94
|
this.viewsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(`${this.repoMetrics.diagramsBaseURL}chart?json=${encodedURL}`);
|
95
|
|
96
|
// this.viewsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
|
97
|
// `${this.repoMetrics.diagramsBaseURL}merge.php?com=query
|
98
|
// &data=[{"query":"dtsrcRepoViews","dtsrcName":"${this.piwik.openaireId}",
|
99
|
// "table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],
|
100
|
// "xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,
|
101
|
// "sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"",
|
102
|
// "xaxistitle":"","yaxisheaders":["Monthly views"],"generalxaxis":"","theme":0,"in":[]}]
|
103
|
// &info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]
|
104
|
// &style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0, 1)","size":"18"},
|
105
|
// {"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)
|
106
|
// &colors[]=rgba(124,181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,1)
|
107
|
// &colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,1)&colors[]=rgba(241, 92, 128, 1)
|
108
|
// &colors[]=rgba(228, 211, 84,1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,1)
|
109
|
// &colors[]=rgba(145, 232, 225,1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false`
|
110
|
// );
|
111
|
}
|
112
|
|
113
|
getDownloadsUrl () {
|
114
|
|
115
|
let encodedURL = encodeURIComponent('{"library":"HighCharts","chartDescription":{"queries":[{"name":"Monthly downloads","type":"line","query":{"name":"usagestats.downloads.monthly", "parameters":["' + this.piwik.openaireId + '"], "profile":"OpenAIRE All-inclusive" }}],"chart":{"backgroundColor":"#FFFFFFFF","borderColor":"#335cadff","borderRadius":0,"borderWidth":0,"plotBorderColor":"#ccccccff","plotBorderWidth":0},"title":{"text":""},"subtitle":{},"yAxis":{"title":{"text":"Monthly views"}},"xAxis":{"title":{}},"lang":{"noData":"No Data available for the Query"},"exporting":{"enabled":false},"plotOptions":{"series":{"dataLabels":{"enabled":false}}},"legend":{"enabled":false},"credits":{"href":null,"enabled":true,"text":"Created by OpenAIRE via HighCharts"}}}');
|
116
|
this.downloadsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(`${this.repoMetrics.diagramsBaseURL}chart?json=${encodedURL}`);
|
117
|
|
118
|
// this.downloadsUrl = this.sanitizer.bypassSecurityTrustResourceUrl(
|
119
|
// `${this.repoMetrics.diagramsBaseURL}merge.php?com=query
|
120
|
// &data=[{"query":"dtsrcRepoDownloads","dtsrcName":"${this.piwik.openaireId}",
|
121
|
// "table":"","fields":[{"fld":"sum","agg":"sum","type":"chart","yaxis":1,"c":false}],
|
122
|
// "xaxis":{"name":"month","agg":"sum"},"group":"","color":"","type":"chart","size":30,
|
123
|
// "sort":"xaxis","xStyle":{"r":-30,"s":"0","l":"-","ft":"-","wt":"-"},"title":"","subtitle":"",
|
124
|
// "xaxistitle":"","yaxisheaders":["Monthly downloads"],"generalxaxis":"","theme":0,"in":[]}]
|
125
|
// &info_types=["spline"]&stacking=&steps=false&fontFamily=Courier&spacing=[5,0,0,0]
|
126
|
// &style=[{"color":"rgba(0, 0, 0, 1)","size":"18"},{"color":"rgba(0, 0, 0,1)","size":"18"},
|
127
|
// {"color":"000000","size":""},{"color":"000000","size":""}]&backgroundColor=rgba(255,255,255,1)
|
128
|
// &colors[]=rgba(124, 181, 236, 1)&colors[]=rgba(67, 67, 72, 1)&colors[]=rgba(144, 237, 125,1)
|
129
|
// &colors[]=rgba(247, 163, 92, 1)&colors[]=rgba(128, 133, 233,1)&colors[]=rgba(241, 92, 128, 1)
|
130
|
// &colors[]=rgba(228, 211, 84,1)&colors[]=rgba(43, 144, 143, 1)&colors[]=rgba(244, 91, 91,1)
|
131
|
// &colors[]=rgba(145, 232, 225,1)&xlinew=0&ylinew=1&legends=true&tooltips=true&persistent=false`
|
132
|
// );
|
133
|
}
|
134
|
|
135
|
}
|