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
import { SharedService } from "../../../services/shared.service";
8

    
9
@Component({
10
  selector: 'metrics-usagestats-report',
11
  templateUrl: './metrics-usagestats-report.component.html'
12
})
13

    
14
export class MetricsUsagestatsReportComponent implements OnInit {
15

    
16
  errorMessage: string;
17
  loadingMessage: string;
18
  title: string;
19

    
20
  repo: Repository;
21
  // repoId: string;
22
  shownRepoId: string;
23
  shownOpenaireId: string;
24
  useCurrentRepo: boolean;
25
  issnToShow = '';
26
  chosen_report: string;
27

    
28
  userEmail: string;
29
  beginDate = '';
30
  endDate = '';
31
  itemIdentifier = '';
32
  itemDataType = '';
33
  granularity = 'Monthly';
34

    
35
  constructor(private repoService: RepositoryService,
36
              private sharedService: SharedService,
37
              private route: ActivatedRoute,
38
              private router: Router,
39
              private authService: AuthenticationService) {}
40

    
41
  ngOnInit() {
42

    
43
    if(this.sharedService.getRepository()) {
44
      this.repo = this.sharedService.getRepository();
45
      this.getInfo();
46
    }
47

    
48
    this.sharedService.repository$.subscribe(
49
      r => {
50
        this.repo = r;
51
        this.getInfo();
52
      }
53
    );
54

    
55
    let body = document.getElementsByTagName('body')[0];
56
    body.classList.remove("top_bar_active");   //remove the class
57
    body.classList.remove("page_heading_active");
58
    body.classList.remove("landing");
59
    body.classList.add("dashboard");
60
  }
61

    
62
  getInfo() {
63
    this.getParams();
64
    this.getUserEmail();
65
    if (this.repo.piwikInfo) {
66
      this.shownOpenaireId = this.convertToDisplayedFormat(this.repo.piwikInfo.openaireId);
67
    }
68
    if (this.repo.issn && this.repo.issn !== 'null') {
69
      this.shownRepoId = this.repo.issn.slice(0, 4) + '-' + this.repo.issn.toString().slice(4);
70
    }
71
    this.title = `${this.chosen_report} report for ${this.repo.officialname}`;
72
  }
73

    
74
  getParams() {
75
    // this.repoId = this.route.snapshot.paramMap.get('id');
76
    this.chosen_report = this.route.snapshot.paramMap.get('reportID');
77
    this.shownRepoId = this.convertToDisplayedFormat(this.repo.id);
78
    console.log(`shownRepoId is ${this.repo.id}`);
79
    this.title = `${this.chosen_report} report`;
80
    if (this.chosen_report !== 'RR1') {
81
      this.useCurrentRepo = true;
82
    }
83
  }
84

    
85
  convertToDisplayedFormat(input: string) {
86
    const tempArray = this.repo.id.split('____::');
87
    return tempArray[0] + ':' + tempArray[1];
88
  }
89

    
90
  getUserEmail() {
91
    this.userEmail = this.authService.getUserEmail();
92
  }
93

    
94
  // getRepo() {
95
  //   this.loadingMessage = loadingRepoMessage;
96
  //   this.repoService.getRepositoryById(this.repoId).subscribe(
97
  //     repo => this.repo = repo,
98
  //     error => {
99
  //       console.log(error);
100
  //       this.loadingMessage = '';
101
  //         this.errorMessage = 'The repository could not be retrieved';
102
  //     },
103
  //     () => {
104
  //       this.loadingMessage = '';
105
  //       if (this.repo.piwikInfo) {
106
  //         this.shownOpenaireId = this.convertToDisplayedFormat(this.repo.piwikInfo.openaireId);
107
  //       }
108
  //       if (this.repo.issn && this.repo.issn !== 'null') {
109
  //         this.shownRepoId = this.repo.issn.slice(0, 4) + '-' + this.repo.issn.toString().slice(4);
110
  //       }
111
  //       this.title = `${this.chosen_report} report for ${this.repo.officialName}`;
112
  //     }
113
  //   );
114
  // }
115

    
116
  updateBeginDate(event: any) {
117
    this.beginDate = event.target.value;
118
  }
119

    
120
  updateEndDate(event: any) {
121
    this.endDate = event.target.value;
122
  }
123

    
124
  updateItemDataType(event: any) {
125
    this.itemDataType = event.target.value;
126
  }
127

    
128
  updateItemIdentifier(event: any) {
129
    this.itemIdentifier = event.target.value;
130
  }
131

    
132
  updateGranularity(event: any) {
133
    this.granularity = event.target.value;
134
  }
135

    
136
  updateUseCurrentRepo(event: any) {
137
    this.useCurrentRepo = event.target.value;
138
  }
139

    
140
  goToReport() {
141
    if (!this.useCurrentRepo) { this.shownRepoId = ''; }
142
    this.router.navigate(['usagestats-report-results'], {
143
      relativeTo: this.route.parent,
144
      queryParams: {
145
        report: this.chosen_report,
146
        beginDate: this.beginDate,
147
        endDate: this.endDate,
148
        repoId: this.shownRepoId,
149
        itemDataType: this.itemDataType,
150
        itemIdentifier: this.itemIdentifier,
151
        granularity: this.granularity
152
      }
153
    });
154

    
155
    /*const params = new URLSearchParams();
156

    
157
    params.append('Report', this.chosen_report);
158
    params.append('Release', '4');
159
    params.append('RequestorID', this.authService.getUserEmail());
160
    params.append('BeginDate', this.beginDate);
161
    params.append('EndDate', this.endDate);
162
    params.append('RepositoryIdentifier', this.shownRepoId);
163
    if (this.itemIdentifier) {
164
      params.append('ItemIdentifier', this.itemIdentifier);
165
    }
166
    if (this.itemDataType) {
167
      params.append('ItemDataType', this.itemDataType);
168
    }
169
    params.append('Pretty', 'Pretty');
170

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

    
174
    window.location.href = url;*/
175
  }
176

    
177
}
(11-11/15)