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, noAggregationHistory } from '../../../domain/shared-messages';
6
import { SharedService } from "../../../services/shared.service";
7

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

    
13
export class CompatibilityMonitorRepoComponent implements OnInit {
14
  loadingMessage: string;
15
  errorMessage: string;
16
  noAggregations: string;
17

    
18
  repoName = '';
19
  repo: Repository;
20

    
21
  latestAggregations: AggregationDetails[] = [];
22

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

    
28
  ngOnInit() {
29

    
30
    if(this.sharedService.getRepository()) {
31
      this.repo = this.sharedService.getRepository();
32
      this.repoName = this.repo.officialname;
33
      this.getLatestAggregationHistory();
34
    }
35

    
36
    this.sharedService.repository$.subscribe(
37
      r => {
38
        this.repo = r;
39
        if (this.repo) {
40
          this.repoName = this.repo.officialname;
41
          this.getLatestAggregationHistory();
42
        }
43
      }
44
    );
45

    
46
    let body = document.getElementsByTagName('body')[0];
47
    body.classList.remove("top_bar_active");   //remove the class
48
    body.classList.remove("page_heading_active");
49
    body.classList.remove("landing");
50
    body.classList.add("dashboard");
51
  }
52

    
53
  getLatestAggregationHistory() {
54
    this.loadingMessage = loadingAggregationHistory;
55
    this.repoService.getRepositoryAggregations(this.repo.id).subscribe(
56
      aggr => this.latestAggregations = aggr,
57
      error => {
58
        this.loadingMessage = '';
59
        this.errorMessage = loadingAggregationHistoryError;
60
      },
61
      () => {
62
        this.loadingMessage = '';
63
        if ( !this.latestAggregations || (this.latestAggregations.length === 0) ) {
64
          this.noAggregations = noAggregationHistory;
65
        }
66
      }
67
    );
68
  }
69

    
70
}
(4-4/6)