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
|
|
7
|
|
8
|
@Component({
|
9
|
selector: 'metrics-usagestats',
|
10
|
templateUrl: 'metrics-usagestats.component.html'
|
11
|
})
|
12
|
|
13
|
export class MetricsUsagestatsComponent implements OnInit {
|
14
|
|
15
|
errorMessage: string;
|
16
|
|
17
|
repo: Repository;
|
18
|
repoId: string;
|
19
|
issnToShow: string = '';
|
20
|
chosen_report: string;
|
21
|
disable_report_choice: boolean;
|
22
|
|
23
|
userEmail: string;
|
24
|
beginDate: string = '';
|
25
|
endDate: string = '';
|
26
|
itemIdentifier: string = '';
|
27
|
itemDataType: string = '';
|
28
|
granularity: string;
|
29
|
pretty: boolean = true;
|
30
|
|
31
|
constructor(private repoService: RepositoryService, private route: ActivatedRoute, private router: Router, private authService: AuthenticationService) {}
|
32
|
|
33
|
ngOnInit() {
|
34
|
this.repoId = this.route.snapshot.paramMap.get('id');
|
35
|
this.getUserEmail();
|
36
|
this.getRepo();
|
37
|
}
|
38
|
|
39
|
onChooseReport(event: any) {
|
40
|
this.chosen_report = event.target.value;
|
41
|
console.log('chosen report is', this.chosen_report);
|
42
|
this.disable_report_choice = true;
|
43
|
}
|
44
|
|
45
|
getUserEmail() {
|
46
|
this.userEmail = this.authService.getUserEmail();
|
47
|
}
|
48
|
|
49
|
getRepo() {
|
50
|
this.repoService.getRepositoryById(this.repoId).subscribe(
|
51
|
repo => this.repo = repo,
|
52
|
error => {
|
53
|
console.log(error);
|
54
|
this.errorMessage = 'The repository could not be retrieved';
|
55
|
},
|
56
|
() => {
|
57
|
if (this.repo.issn){
|
58
|
this.issnToShow = this.repo.issn.slice(0, 4)+ '-' + this.repo.issn.toString().slice(4);
|
59
|
}
|
60
|
}
|
61
|
);
|
62
|
}
|
63
|
|
64
|
updateBeginDate(event: any) {
|
65
|
this.beginDate = event.target.value;
|
66
|
}
|
67
|
|
68
|
updateEndDate(event: any) {
|
69
|
this.endDate = event.target.value;
|
70
|
}
|
71
|
|
72
|
updateItemIdentifier(event: any) {
|
73
|
this.itemIdentifier = event.target.value;
|
74
|
}
|
75
|
|
76
|
updateItemDataType(event: any) {
|
77
|
this.itemDataType = event.target.value;
|
78
|
}
|
79
|
|
80
|
updateGranularity(event: any) {
|
81
|
this.granularity = event.target.value;
|
82
|
}
|
83
|
|
84
|
updatePretty(event: any) {
|
85
|
this.pretty = !this.pretty;
|
86
|
}
|
87
|
|
88
|
goToReport() {
|
89
|
let prettyString: string = '';
|
90
|
if (this.pretty) {
|
91
|
prettyString = `&Pretty=Pretty`;
|
92
|
}
|
93
|
|
94
|
let url = `http://beta.services.openaire.eu/usagestats/sushilite/GetReport/?Report=${this.chosen_report}=4&RequestorID=${this.userEmail}&BeginDate=${this.beginDate}&EndDate=${this.endDate}&RepositoryIdentifier=${this.repoId}&ItemIdentifier=${this.itemIdentifier}&Granularity=${this.granularity}${prettyString}`;
|
95
|
window.open(url,"_blank");
|
96
|
}
|
97
|
|
98
|
}
|