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
    let body = document.getElementsByTagName('body')[0];
35
    body.classList.remove("top_bar_active");   //remove the class
36
    body.classList.remove("page_heading_active");
37
    body.classList.remove("landing");
38
    body.classList.add("dashboard");
39
  }
40

    
41
  readRepoId() {
42
    this.repoId = this.route.snapshot.paramMap.get('id');
43
    this.repoName = `repository with id \'${this.repoId}\'`;
44
  }
45

    
46
  getRepo() {
47
    if (this.repoId) {
48
      this.loadingMessage = loadingRepoMessage;
49
      this.repoService.getRepositoryById(this.repoId).subscribe(
50
        repo => {
51
          this.repo = repo;
52
        },
53
        error => {
54
          console.log(error);
55
          this.loadingMessage = '';
56
          this.errorMessage = loadingRepoError;
57
        },
58
        () => {
59
          this.loadingMessage = '';
60
          if (this.repo) {
61
            this.repoName = this.repo.officialName;
62
              this.getAllAggregationHistory();
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)