1
|
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
|
2
|
import { RepositorySnippet } from '../../domain/typeScriptClasses';
|
3
|
import { RepositoryService } from '../../services/repository.service';
|
4
|
import { AuthenticationService } from '../../services/authentication.service';
|
5
|
import { loadingReposMessage, loadingUserRepoInfoEmpty, reposRetrievalError } from '../../domain/shared-messages';
|
6
|
|
7
|
@Component ({
|
8
|
selector: 'repository-tiles',
|
9
|
templateUrl: 'repository-tiles.component.html'
|
10
|
})
|
11
|
|
12
|
export class RepositoryTilesComponent implements OnInit {
|
13
|
reposOfUser: RepositorySnippet[] = [];
|
14
|
// tilesView: boolean;
|
15
|
errorMessage: string;
|
16
|
warningMessage: string;
|
17
|
loadingMessage: string;
|
18
|
|
19
|
@Input() parent: string = '';
|
20
|
@Input() tilesView: boolean = true;
|
21
|
@Output() emitNoRepos: EventEmitter<boolean> = new EventEmitter<boolean>();
|
22
|
|
23
|
constructor(private authService: AuthenticationService,
|
24
|
private repoService: RepositoryService) {}
|
25
|
|
26
|
ngOnInit() {
|
27
|
// this.tilesView = true;
|
28
|
this.getReposOfUser();
|
29
|
}
|
30
|
|
31
|
getReposOfUser(): void {
|
32
|
this.loadingMessage = loadingReposMessage;
|
33
|
this.repoService.getRepositoriesSnippetsOfUser()
|
34
|
.subscribe(
|
35
|
repos => this.reposOfUser = repos.sort( function(a, b) {
|
36
|
if (a.officialname < b.officialname) {
|
37
|
return -1;
|
38
|
} else if (a.officialname > b.officialname) {
|
39
|
return 1;
|
40
|
} else {
|
41
|
return 0;
|
42
|
}
|
43
|
}),
|
44
|
error => {
|
45
|
console.log(error);
|
46
|
this.loadingMessage = '';
|
47
|
this.errorMessage = reposRetrievalError;
|
48
|
},
|
49
|
() => {
|
50
|
this.loadingMessage = '';
|
51
|
if (!this.reposOfUser || !this.reposOfUser.length) {
|
52
|
this.warningMessage = loadingUserRepoInfoEmpty;
|
53
|
this.emitNoRepos.emit(true);
|
54
|
} else {
|
55
|
this.emitNoRepos.emit(false);
|
56
|
}
|
57
|
}
|
58
|
);
|
59
|
}
|
60
|
|
61
|
getLinkToNext(repo: RepositorySnippet): string {
|
62
|
if (this.parent === 'metrics') {
|
63
|
if (repo.piwikInfo) {
|
64
|
if (repo.piwikInfo.validated === true) {
|
65
|
return `show_metrics/${repo.id}`;
|
66
|
} else if (repo.piwikInfo.validated === false) {
|
67
|
return `instructions/${repo.id}`;
|
68
|
}
|
69
|
} else {
|
70
|
return `enable/${repo.id}`;
|
71
|
}
|
72
|
} else if (this.parent === 'sourcesUpdate' || this.parent === 'compatibilityMonitor') {
|
73
|
return repo.id;
|
74
|
}
|
75
|
}
|
76
|
|
77
|
getBadgeCSS(repo: RepositorySnippet): string {
|
78
|
if (this.parent === 'metrics') {
|
79
|
if (repo.piwikInfo) {
|
80
|
if (repo.piwikInfo.validated === true) {
|
81
|
return 'uk-badge uk-badge-success';
|
82
|
} else if (repo.piwikInfo.validated === false) {
|
83
|
return 'uk-badge uk-badge-warning';
|
84
|
}
|
85
|
} else {
|
86
|
return 'uk-badge uk-badge-danger';
|
87
|
}
|
88
|
}
|
89
|
}
|
90
|
|
91
|
getBadgeText(repo: RepositorySnippet): string {
|
92
|
if (this.parent === 'metrics') {
|
93
|
if (repo.piwikInfo) {
|
94
|
if (repo.piwikInfo.validated === true) {
|
95
|
return 'enabled';
|
96
|
} else if ( repo.piwikInfo.validated === false ) {
|
97
|
return 'enabling in progress';
|
98
|
}
|
99
|
} else {
|
100
|
return 'not enabled';
|
101
|
}
|
102
|
}
|
103
|
}
|
104
|
|
105
|
}
|