1
|
import {Component, OnInit} from "@angular/core";
|
2
|
import {RepositoryService} from "../../services/repository.service";
|
3
|
import {ActivatedRoute, Router} from "@angular/router";
|
4
|
import {AuthenticationService} from "../../services/authentication.service";
|
5
|
import {Repository} from "../../domain/typeScriptClasses";
|
6
|
import {Observable} from "rxjs/Observable";
|
7
|
import {ReportResponseWrapper} from "../../domain/usageStatsClasses";
|
8
|
import {loadingRepoMessage} from "../../domain/shared-messages";
|
9
|
|
10
|
|
11
|
@Component({
|
12
|
selector: 'metrics-usagestats-report',
|
13
|
templateUrl: './metrics-usagestats-report.component.html'
|
14
|
})
|
15
|
|
16
|
export class MetricsUsagestatsReportComponent implements OnInit {
|
17
|
|
18
|
errorMessage: string;
|
19
|
loadingMessage: string;
|
20
|
title: string;
|
21
|
|
22
|
repo: Repository;
|
23
|
repoId: string;
|
24
|
shownRepoId: string;
|
25
|
shownOpenaireId: string;
|
26
|
issnToShow: string = '';
|
27
|
chosen_report: string;
|
28
|
|
29
|
userEmail: string;
|
30
|
beginDate: string = '';
|
31
|
endDate: string = '';
|
32
|
itemIdentifier: string = '';
|
33
|
itemDataType: string = '';
|
34
|
granularity: string = 'Monthly';
|
35
|
|
36
|
constructor(private repoService: RepositoryService,
|
37
|
private route: ActivatedRoute,
|
38
|
private router: Router,
|
39
|
private authService: AuthenticationService) {}
|
40
|
|
41
|
ngOnInit() {
|
42
|
this.getParams();
|
43
|
this.getUserEmail();
|
44
|
this.getRepo();
|
45
|
}
|
46
|
|
47
|
getParams() {
|
48
|
this.repoId = this.route.snapshot.paramMap.get('id');
|
49
|
this.chosen_report = this.route.snapshot.paramMap.get('reportID');
|
50
|
this.shownRepoId = this.convertToDisplayedFormat(this.repoId);
|
51
|
console.log(`shownRepoId is ${this.repoId}`);
|
52
|
this.title = `${this.chosen_report} report`;
|
53
|
}
|
54
|
|
55
|
convertToDisplayedFormat(input: string) {
|
56
|
const tempArray = this.repoId.split('____::');
|
57
|
return tempArray[0] + ':' + tempArray[1];
|
58
|
}
|
59
|
|
60
|
getUserEmail() {
|
61
|
this.userEmail = this.authService.getUserEmail();
|
62
|
}
|
63
|
|
64
|
getRepo() {
|
65
|
this.loadingMessage = loadingRepoMessage;
|
66
|
this.repoService.getRepositoryById(this.repoId).subscribe(
|
67
|
repo => this.repo = repo,
|
68
|
error => {
|
69
|
console.log(error);
|
70
|
this.loadingMessage = '';
|
71
|
this.errorMessage = 'The repository could not be retrieved';
|
72
|
},
|
73
|
() => {
|
74
|
this.loadingMessage = '';
|
75
|
if (this.repo.piwikInfo) {
|
76
|
this.shownOpenaireId = this.convertToDisplayedFormat(this.repo.piwikInfo.openaireId);
|
77
|
}
|
78
|
if (this.repo.issn){
|
79
|
this.issnToShow = this.repo.issn.slice(0, 4)+ '-' + this.repo.issn.toString().slice(4);
|
80
|
}
|
81
|
this.title = `${this.chosen_report} report for ${this.repo.officialName}`;
|
82
|
// TODO: UNCOMMENT
|
83
|
/*if ( this.authService.getUserEmail() !== this.repo.registeredBy ) {
|
84
|
this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
|
85
|
}*/
|
86
|
}
|
87
|
);
|
88
|
}
|
89
|
|
90
|
updateBeginDate(event: any) {
|
91
|
this.beginDate = event.target.value;
|
92
|
}
|
93
|
|
94
|
updateEndDate(event: any) {
|
95
|
this.endDate = event.target.value;
|
96
|
}
|
97
|
|
98
|
updateItemDataType(event: any) {
|
99
|
this.itemDataType = event.target.value;
|
100
|
}
|
101
|
|
102
|
updateItemIdentifier(event: any) {
|
103
|
this.itemIdentifier = event.target.value;
|
104
|
}
|
105
|
|
106
|
updateGranularity(event: any) {
|
107
|
this.granularity = event.target.value;
|
108
|
}
|
109
|
|
110
|
goToReport() {
|
111
|
this.router.navigate(['/getImpact/usagestats-report-results'], {
|
112
|
queryParams: {
|
113
|
report: this.chosen_report,
|
114
|
beginDate: this.beginDate,
|
115
|
endDate: this.endDate,
|
116
|
repoId: this.shownRepoId,
|
117
|
itemDataType: this.itemDataType,
|
118
|
itemIdentifier: this.itemIdentifier,
|
119
|
granularity: this.granularity
|
120
|
}
|
121
|
});
|
122
|
|
123
|
/*const params = new URLSearchParams();
|
124
|
|
125
|
params.append('Report', this.chosen_report);
|
126
|
params.append('Release', '4');
|
127
|
params.append('RequestorID', this.authService.getUserEmail());
|
128
|
params.append('BeginDate', this.beginDate);
|
129
|
params.append('EndDate', this.endDate);
|
130
|
params.append('RepositoryIdentifier', this.shownRepoId);
|
131
|
if (this.itemIdentifier) {
|
132
|
params.append('ItemIdentifier', this.itemIdentifier);
|
133
|
}
|
134
|
if (this.itemDataType) {
|
135
|
params.append('ItemDataType', this.itemDataType);
|
136
|
}
|
137
|
params.append('Pretty', 'Pretty');
|
138
|
|
139
|
let url = `http://beta.services.openaire.eu/usagestats/sushilite/GetReport/?${params}`;
|
140
|
console.log(`going to: ${url}`);
|
141
|
|
142
|
window.location.href = url;*/
|
143
|
}
|
144
|
|
145
|
}
|