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-monitor-repo',
|
11
|
templateUrl: 'compatibility-monitor-repo.component.html'
|
12
|
})
|
13
|
|
14
|
export class CompatibilityMonitorRepoComponent implements OnInit {
|
15
|
loadingMessage: string;
|
16
|
errorMessage: string;
|
17
|
noAggregations: string;
|
18
|
|
19
|
repoId = '';
|
20
|
repoName = '';
|
21
|
repo: Repository;
|
22
|
|
23
|
latestAggregations: AggregationDetails[] = [];
|
24
|
|
25
|
constructor(private route: ActivatedRoute,
|
26
|
private router: Router,
|
27
|
private repoService: RepositoryService,
|
28
|
private authService: AuthenticationService) {}
|
29
|
|
30
|
ngOnInit() {
|
31
|
this.readRepoId();
|
32
|
this.getRepo();
|
33
|
let body = document.getElementsByTagName('body')[0];
|
34
|
body.classList.remove("top_bar_active"); //remove the class
|
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
|
if ( this.authService.activateFrontAuthorization &&
|
59
|
(this.authService.getUserEmail() !== this.repo.registeredBy.trim()) ) {
|
60
|
this.router.navigateByUrl('/403-forbidden', { skipLocationChange: true });
|
61
|
} else {
|
62
|
this.getLatestAggregationHistory();
|
63
|
}
|
64
|
} else {
|
65
|
this.errorMessage = loadingRepoError;
|
66
|
}
|
67
|
}
|
68
|
);
|
69
|
}
|
70
|
}
|
71
|
|
72
|
getLatestAggregationHistory() {
|
73
|
this.loadingMessage = loadingAggregationHistory;
|
74
|
this.repoService.getRepositoryAggregations(this.repo.id).subscribe(
|
75
|
aggr => this.latestAggregations = aggr,
|
76
|
error => {
|
77
|
this.loadingMessage = '';
|
78
|
this.errorMessage = loadingAggregationHistoryError;
|
79
|
},
|
80
|
() => {
|
81
|
this.loadingMessage = '';
|
82
|
if ( !this.latestAggregations || (this.latestAggregations.length === 0) ) {
|
83
|
this.noAggregations = noAggregationHistory;
|
84
|
}
|
85
|
}
|
86
|
);
|
87
|
}
|
88
|
|
89
|
}
|