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
    let body = document.getElementsByTagName('body')[0];
44
    body.classList.remove("top_bar_active");   //remove the class
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
    if (this.chosen_report !== 'RR1') {
54
      this.useCurrentRepo = true;
55
    }
56
  }
57

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

    
63
  getUserEmail() {
64
    this.userEmail = this.authService.getUserEmail();
65
  }
66

    
67
  getRepo() {
68
    this.loadingMessage = loadingRepoMessage;
69
    this.repoService.getRepositoryById(this.repoId).subscribe(
70
      repo => this.repo = repo,
71
      error => {
72
        console.log(error);
73
        this.loadingMessage = '';
74
          this.errorMessage = 'The repository could not be retrieved';
75
      },
76
      () => {
77
        this.loadingMessage = '';
78
        if (this.repo.piwikInfo) {
79
          this.shownOpenaireId = this.convertToDisplayedFormat(this.repo.piwikInfo.openaireId);
80
        }
81
        if (this.repo.issn && this.repo.issn !== 'null') {
82
          this.shownRepoId = this.repo.issn.slice(0, 4) + '-' + this.repo.issn.toString().slice(4);
83
        }
84
        this.title = `${this.chosen_report} report for ${this.repo.officialName}`;
85
        if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.repo.registeredBy.trim()) ) {
86
          this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
87
        }
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
}
(11-11/17)