Project

General

Profile

1 54479 myrto.kouk
import { Component, OnInit } from '@angular/core';
2
import { ActivatedRoute, Router } from '@angular/router';
3 58098 stefania.m
import { AggregationDetails, Repository } from '../../../domain/typeScriptClasses';
4
import { RepositoryService } from '../../../services/repository.service';
5
import { loadingAggregationHistory, loadingAggregationHistoryError, noAggregationHistory } from '../../../domain/shared-messages';
6
import { SharedService } from "../../../services/shared.service";
7 54479 myrto.kouk
8
@Component ({
9
  selector: 'app-compatibility-fullhistory-monitor-repo',
10
  templateUrl: 'compatibility-monitor-fullHistory-repo.component.html'
11
})
12
13
export class CompatibilityMonitorFullHistoryRepoComponent implements OnInit {
14
  loadingMessage: string;
15
  errorMessage: string;
16
  noAggregations: string;
17
18
  repoName = '';
19
  repo: Repository;
20
21
  aggregationsMap: Map<string, AggregationDetails[]> = new Map<string, AggregationDetails[]>();
22
  years: string[] = [];
23
24
  constructor(private route: ActivatedRoute,
25
              private router: Router,
26
              private repoService: RepositoryService,
27 58098 stefania.m
              private sharedService: SharedService) {}
28 54479 myrto.kouk
29
  ngOnInit() {
30 58098 stefania.m
31
    if(this.sharedService.getRepository()) {
32
      this.repo = this.sharedService.getRepository();
33 62389 andreas.ma
      this.repoName = this.repo.officialname;
34 58098 stefania.m
      this.getAllAggregationHistory();
35
    }
36
37
    this.sharedService.repository$.subscribe(
38
      r => {
39
        this.repo = r;
40
        if (this.repo) {
41 62389 andreas.ma
          this.repoName = this.repo.officialname;
42 58098 stefania.m
          this.getAllAggregationHistory();
43
        }
44
      }
45
    );
46
47 57098 stefania.m
    let body = document.getElementsByTagName('body')[0];
48
    body.classList.remove("top_bar_active");   //remove the class
49 57150 stefania.m
    body.classList.remove("page_heading_active");
50 58065 stefania.m
    body.classList.remove("landing");
51
    body.classList.add("dashboard");
52 54479 myrto.kouk
  }
53
54
  getAllAggregationHistory() {
55
    this.loadingMessage = loadingAggregationHistory;
56
    this.repoService.getRepositoryAggregationsByYear(this.repo.id).subscribe(
57
      aggr => this.aggregationsMap = aggr,
58
      error => {
59
        this.loadingMessage = '';
60
        this.errorMessage = loadingAggregationHistoryError;
61
      },
62
      () => {
63
        this.loadingMessage = '';
64
        this.years = Object.keys(this.aggregationsMap);
65
        if ( this.years.length === 0 ) {
66
          this.noAggregations = noAggregationHistory;
67
        } else {
68
          this.years.sort( (a, b)  => ( a > b ? -1 : 1 ) );
69
        }
70
      }
71
    );
72
  }
73
74
}