Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { Repository } from '../../domain/typeScriptClasses';
3
import { RepositoryService } from '../../services/repository.service';
4
import { AuthenticationService } from '../../services/authentication.service';
5
import { ActivatedRoute, Router } from '@angular/router';
6

    
7
@Component({
8
  selector: 'metrics-usagestats',
9
  templateUrl: 'metrics-usagestats.component.html'
10
})
11

    
12
export class MetricsUsagestatsComponent implements OnInit {
13

    
14
  errorMessage: string;
15
  title = 'Get usage statistics report';
16

    
17
  repo: Repository;
18
  repoId: string;
19

    
20
  constructor(private repoService: RepositoryService,
21
              private authService: AuthenticationService,
22
              private route: ActivatedRoute,
23
              private router: Router) {}
24

    
25
  ngOnInit() {
26
    this.getRepo();
27
    let body = document.getElementsByTagName('body')[0];
28
    body.classList.remove("top_bar_active");   //remove the class
29
  }
30

    
31
  getRepo() {
32
    this.repoId = this.route.snapshot.paramMap.get('id');
33

    
34
    if (this.repoId) {
35
      this.repoService.getRepositoryById(this.repoId).subscribe(
36
        repo => this.repo = repo,
37
        error => {
38
          console.log(error);
39
          this.errorMessage = 'The repository could not be retrieved';
40
        },
41
        () => {
42
          this.title = this.title + ' for ' + this.repo.officialName;
43
          console.log(this.authService.getUserEmail(), this.repo.registeredBy);
44
          if ( this.authService.activateFrontAuthorization && (this.authService.getUserEmail() !== this.repo.registeredBy.trim()) ) {
45
            this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
46
          }
47
        }
48
      );
49
    }
50
  }
51

    
52
}
(13-13/17)