Project

General

Profile

1
import {Component, OnInit} from "@angular/core";
2
import {RepositoryService} from "../../services/repository.service";
3
import {ActivatedRoute, Router} from "@angular/router";
4
import {AuthenticationService} from "../../services/authentication.service";
5
import {Repository} from "../../domain/typeScriptClasses";
6
import {Observable} from "rxjs/Observable";
7
import {ReportResponseWrapper} from "../../domain/usageStatsClasses";
8

    
9

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

    
15
export class MetricsUsagestatsComponent implements OnInit {
16

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

    
20
  repo: Repository;
21
  repoId: string;
22

    
23
  constructor(private repoService: RepositoryService,
24
              private authService: AuthenticationService,
25
              private route: ActivatedRoute,
26
              private router: Router) {}
27

    
28
  ngOnInit() {
29
    this.getRepo();
30
  }
31

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

    
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
          }
47
        }
48
      );
49
    }
50
  }
51

    
52
}
(12-12/16)