Project

General

Profile

« Previous | Next » 

Revision 52836

added cookie-law banner - 403 authorization via ui and new usage-stats pages

View differences:

metrics-usagestats.component.ts
15 15
export class MetricsUsagestatsComponent implements OnInit {
16 16

  
17 17
  errorMessage: string;
18
  title: string = 'Get usage statistics report';
18 19

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

  
27
  userEmail: string;
28
  beginDate: string = '';
29
  endDate: string = '';
30
  itemIdentifier: string = '';
31
  itemDataType: string = '';
32
  granularity: string = 'Monthly';
33
  pretty: boolean = true;
23
  constructor(private repoService: RepositoryService,
24
              private authService: AuthenticationService,
25
              private route: ActivatedRoute,
26
              private router: Router) {}
34 27

  
35
  constructor(private repoService: RepositoryService, private route: ActivatedRoute, private router: Router, private authService: AuthenticationService) {}
36

  
37 28
  ngOnInit() {
38
    this.getRepoId();
39
    this.getUserEmail();
40 29
    this.getRepo();
41 30
  }
42 31

  
43
  getRepoId() {
32
  getRepo() {
44 33
    this.repoId = this.route.snapshot.paramMap.get('id');
45
    this.shownRepoId = this.convertToDisplayedFormat(this.repoId);
46
    console.log(`shownRepoId is ${this.repoId}`);
47
  }
48 34

  
49
  convertToDisplayedFormat(input: string) {
50
    const tempArray = this.repoId.split('____::');
51
    return tempArray[0] + ':' + tempArray[1];
52
  }
53

  
54
  onChooseReport(event: any) {
55
    this.chosen_report = event.target.value;
56
    console.log('chosen report is', this.chosen_report);
57
    this.disable_report_choice = true;
58
  }
59

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

  
64
  getRepo() {
65
    this.repoService.getRepositoryById(this.repoId).subscribe(
66
      repo => this.repo = repo,
67
      error => {
68
        console.log(error);
69
        this.errorMessage = 'The repository could not be retrieved';
70
      },
71
      () => {
72
        this.shownOpenaireId = this.convertToDisplayedFormat(this.repo.piwikInfo.openaireId);
73
        if (this.repo.issn){
74
          this.issnToShow = this.repo.issn.slice(0, 4)+ '-' + this.repo.issn.toString().slice(4);
35
    if (this.repoId) {
36
      this.repoService.getRepositoryById(this.repoId).subscribe(
37
        repo => this.repo = repo,
38
        error => {
39
          console.log(error);
40
          this.errorMessage = 'The repository could not be retrieved';
41
        },
42
        () => {
43
          this.title = this.title + ' for ' + this.repo.officialName;
44
          if ( this.authService.getUserEmail() !== this.repo.registeredBy ) {
45
            this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
46
          }
75 47
        }
76
      }
77
    );
48
      );
49
    }
78 50
  }
79 51

  
80
  updateBeginDate(event: any) {
81
    this.beginDate = event.target.value;
82
  }
83

  
84
  updateEndDate(event: any) {
85
    this.endDate = event.target.value;
86
  }
87

  
88
  updateItemDataType(event: any) {
89
    this.itemDataType = event.target.value;
90
  }
91

  
92
  updateItemIdentifier(event: any) {
93
    this.itemIdentifier = event.target.value;
94
  }
95

  
96
  updateGranularity(event: any) {
97
    this.granularity = event.target.value;
98
  }
99

  
100
  updatePretty(event: any) {
101
    this.pretty = !this.pretty;
102
  }
103

  
104
  goToReport() {
105
    /* additional field: */
106
    /*itemIdentifier: this.repo.piwikInfo.openaireId,*/
107
      /*this.router.navigate(['/getImpact/usagestats-report-results'], {
108
        queryParams: {
109
          report: this.chosen_report,
110
          beginDate: this.beginDate,
111
          endDate: this.endDate,
112
          repoId: this.shownRepoId,
113
          itemDataType: this.itemDataType,
114
          itemIdentifier: this.itemIdentifier,
115
          granularity: this.granularity,
116
          pretty: this.pretty
117
        }
118
      });*/
119

  
120
      const params = new URLSearchParams();
121

  
122
      params.append('Report', this.chosen_report);
123
      params.append('Release', '4');
124
      params.append('RequestorID', this.authService.getUserEmail());
125
      params.append('BeginDate', this.beginDate);
126
      params.append('EndDate', this.endDate);
127
      params.append('RepositoryIdentifier', this.shownRepoId);
128
      if (this.itemIdentifier) {
129
        params.append('ItemIdentifier', this.itemIdentifier);
130
      }
131
      if (this.itemDataType) {
132
        params.append('ItemDataType', this.itemDataType);
133
      }
134
      params.append('Granularity', this.granularity);
135
      if (this.pretty && this.pretty === true) {
136
        params.append('Pretty', 'Pretty');
137
      }
138

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

  
142
      window.location.href = url;
143
  }
144

  
145 52
}

Also available in: Unified diff