Project

General

Profile

1
import { Component, OnInit } from '@angular/core';
2
import { ActivatedRoute, Router } from '@angular/router';
3
import {AggregationDetails, Repository} from '../../domain/typeScriptClasses';
4
import { RepositoryService } from '../../services/repository.service';
5
import { loadingAggregationHistory, loadingAggregationHistoryError, loadingRepoError,
6
         loadingRepoMessage, noAggregationHistory } from '../../domain/shared-messages';
7
import { AuthenticationService } from '../../services/authentication.service';
8

    
9
@Component ({
10
  selector: 'app-compatibility-fullhistory-monitor-repo',
11
  templateUrl: 'compatibility-monitor-fullHistory-repo.component.html'
12
})
13

    
14
export class CompatibilityMonitorFullHistoryRepoComponent implements OnInit {
15
  loadingMessage: string;
16
  errorMessage: string;
17
  noAggregations: string;
18

    
19
  repoId = '';
20
  repoName = '';
21
  repo: Repository;
22

    
23
  aggregationsMap: Map<string, AggregationDetails[]> = new Map<string, AggregationDetails[]>();
24
  years: string[] = [];
25

    
26
  constructor(private route: ActivatedRoute,
27
              private router: Router,
28
              private repoService: RepositoryService,
29
              private authService: AuthenticationService) {}
30

    
31
  ngOnInit() {
32
    this.readRepoId();
33
    this.getRepo();
34
  }
35

    
36
  readRepoId() {
37
    this.repoId = this.route.snapshot.paramMap.get('id');
38
    this.repoName = `repository with id \'${this.repoId}\'`;
39
  }
40

    
41
  getRepo() {
42
    if (this.repoId) {
43
      this.loadingMessage = loadingRepoMessage;
44
      this.repoService.getRepositoryById(this.repoId).subscribe(
45
        repo => {
46
          this.repo = repo;
47
        },
48
        error => {
49
          console.log(error);
50
          this.loadingMessage = '';
51
          this.errorMessage = loadingRepoError;
52
        },
53
        () => {
54
          this.loadingMessage = '';
55
          if (this.repo) {
56
            this.repoName = this.repo.officialName;
57
            if ( this.authService.activateFrontAuthorization &&
58
                 (this.authService.getUserEmail() !== this.repo.registeredBy.trim()) ) {
59
              this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
60
            } else {
61
              this.getAllAggregationHistory();
62
            }
63
          } else {
64
            this.errorMessage = loadingRepoError;
65
          }
66
        }
67
      );
68
    }
69
  }
70

    
71
  getAllAggregationHistory() {
72
    this.loadingMessage = loadingAggregationHistory;
73
    this.repoService.getRepositoryAggregationsByYear(this.repo.id).subscribe(
74
      aggr => this.aggregationsMap = aggr,
75
      error => {
76
        this.loadingMessage = '';
77
        this.errorMessage = loadingAggregationHistoryError;
78
      },
79
      () => {
80
        this.loadingMessage = '';
81
        this.years = Object.keys(this.aggregationsMap);
82
        if ( this.years.length === 0 ) {
83
          this.noAggregations = noAggregationHistory;
84
        } else {
85
          this.years.sort( (a, b)  => ( a > b ? -1 : 1 ) );
86
        }
87
      }
88
    );
89
  }
90

    
91
}
(2-2/17)