Project

General

Profile

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
  }
44

    
45
  getParams() {
46
    this.repoId = this.route.snapshot.paramMap.get('id');
47
    this.chosen_report = this.route.snapshot.paramMap.get('reportID');
48
    this.shownRepoId = this.convertToDisplayedFormat(this.repoId);
49
    console.log(`shownRepoId is ${this.repoId}`);
50
    this.title = `${this.chosen_report} report`;
51
    if (this.chosen_report !== 'RR1') {
52
      this.useCurrentRepo = true;
53
    }
54
  }
55

    
56
  convertToDisplayedFormat(input: string) {
57
    const tempArray = this.repoId.split('____::');
58
    return tempArray[0] + ':' + tempArray[1];
59
  }
60

    
61
  getUserEmail() {
62
    this.userEmail = this.authService.getUserEmail();
63
  }
64

    
65
  getRepo() {
66
    this.loadingMessage = loadingRepoMessage;
67
    this.repoService.getRepositoryById(this.repoId).subscribe(
68
      repo => this.repo = repo,
69
      error => {
70
        console.log(error);
71
        this.loadingMessage = '';
72
          this.errorMessage = 'The repository could not be retrieved';
73
      },
74
      () => {
75
        this.loadingMessage = '';
76
        if (this.repo.piwikInfo) {
77
          this.shownOpenaireId = this.convertToDisplayedFormat(this.repo.piwikInfo.openaireId);
78
        }
79
        if (this.repo.issn && this.repo.issn !== 'null') {
80
          this.shownRepoId = this.repo.issn.slice(0, 4) + '-' + this.repo.issn.toString().slice(4);
81
        }
82
        this.title = `${this.chosen_report} report for ${this.repo.officialName}`;
83
        if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.repo.registeredBy.trim()) ) {
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
  updateUseCurrentRepo(event: any) {
111
    this.useCurrentRepo = event.target.value;
112
  }
113

    
114
  goToReport() {
115
    if (!this.useCurrentRepo) { this.shownRepoId = ''; }
116
    this.router.navigate(['/getImpact/usagestats-report-results'], {
117
      queryParams: {
118
        report: this.chosen_report,
119
        beginDate: this.beginDate,
120
        endDate: this.endDate,
121
        repoId: this.shownRepoId,
122
        itemDataType: this.itemDataType,
123
        itemIdentifier: this.itemIdentifier,
124
        granularity: this.granularity
125
      }
126
    });
127

    
128
    /*const params = new URLSearchParams();
129

    
130
    params.append('Report', this.chosen_report);
131
    params.append('Release', '4');
132
    params.append('RequestorID', this.authService.getUserEmail());
133
    params.append('BeginDate', this.beginDate);
134
    params.append('EndDate', this.endDate);
135
    params.append('RepositoryIdentifier', this.shownRepoId);
136
    if (this.itemIdentifier) {
137
      params.append('ItemIdentifier', this.itemIdentifier);
138
    }
139
    if (this.itemDataType) {
140
      params.append('ItemDataType', this.itemDataType);
141
    }
142
    params.append('Pretty', 'Pretty');
143

    
144
    let url = `http://beta.services.openaire.eu/usagestats/sushilite/GetReport/?${params}`;
145
    console.log(`going to: ${url}`);
146

    
147
    window.location.href = url;*/
148
  }
149

    
150
}
(11-11/17)