Project

General

Profile

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

    
13
@Component ({
14
  selector: 'app-compatibility-monitor-repo',
15
  templateUrl: 'compatibility-monitor-repo.component.html'
16
})
17

    
18
export class CompatibilityMonitorRepoComponent implements OnInit {
19
  loadingMessage: string;
20
  errorMessage: string;
21
  noAggregations: string;
22

    
23
  repoId: string = '';
24
  repoName: string = '';
25
  repo: Repository;
26

    
27
  aggregations: Aggregations;
28

    
29
  constructor(private route: ActivatedRoute,
30
              private repoService: RepositoryService) {}
31

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

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

    
42
  getRepo(){
43
    if (this.repoId) {
44
      this.loadingMessage = loadingRepoMessage;
45
      this.repoService.getRepositoryById(this.repoId).subscribe(
46
        repo => {
47
          this.repo = repo;
48
        },
49
        error => {
50
          console.log(error);
51
          this.loadingMessage = '';
52
          this.errorMessage = loadingRepoError;
53
        },
54
        () => {
55
          this.loadingMessage = '';
56
          if (this.repo) {
57
            this.repoName = this.repo.officialName;
58
            this.getAggregationHistory();
59
          } else {
60
            this.errorMessage = loadingRepoError;
61
          }
62
        }
63
      );
64
    }
65
  }
66

    
67
  getAggregationHistory() {
68
    this.loadingMessage = loadingAggregationHistory;
69
    this.repoService.getRepositoryAggregations(this.repo.id).subscribe(
70
      aggr => this.aggregations = aggr,
71
      error => {
72
        this.loadingMessage = '';
73
        this.errorMessage = loadingAggregationHistoryError;
74
      },
75
      () => {
76
        this.loadingMessage = '';
77
        if (this.aggregations && !this.aggregations.aggregationHistory.length) {
78
          this.noAggregations = noAggregationHistory;
79
        }
80
      }
81
    );
82
  }
83
}
(2-2/15)