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