1
|
import { Component, Input, OnInit } from '@angular/core';
|
2
|
import { Repository } 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
|
import {BrokerService} from "../../services/broker.service";
|
7
|
|
8
|
@Component ({
|
9
|
selector: 'repository-tiles',
|
10
|
templateUrl: 'repository-tiles.component.html'
|
11
|
})
|
12
|
|
13
|
export class RepositoryTilesComponent implements OnInit {
|
14
|
reposOfUser: Repository[] = [];
|
15
|
tilesView: boolean;
|
16
|
errorMessage: string;
|
17
|
warningMessage: string;
|
18
|
loadingMessage: string;
|
19
|
|
20
|
@Input() parent: string = '';
|
21
|
|
22
|
constructor(private authService: AuthenticationService,
|
23
|
private repoService: RepositoryService) {}
|
24
|
|
25
|
ngOnInit() {
|
26
|
this.tilesView = true;
|
27
|
this.getReposOfUser();
|
28
|
}
|
29
|
|
30
|
getReposOfUser(): void {
|
31
|
this.loadingMessage = loadingReposMessage;
|
32
|
this.repoService.getRepositoriesOfUser(this.authService.getUserEmail())
|
33
|
.subscribe(
|
34
|
repos => this.reposOfUser = repos.sort( function(a,b){
|
35
|
if(a.officialName<b.officialName){
|
36
|
return -1;
|
37
|
} else if(a.officialName>b.officialName){
|
38
|
return 1;
|
39
|
} else {
|
40
|
return 0;
|
41
|
}
|
42
|
}),
|
43
|
error => {
|
44
|
console.log(error);
|
45
|
this.loadingMessage = '';
|
46
|
this.errorMessage = reposRetrievalError;
|
47
|
},
|
48
|
() => {
|
49
|
this.loadingMessage = '';
|
50
|
if (!this.reposOfUser || !this.reposOfUser.length) {
|
51
|
this.warningMessage = loadingUserRepoInfoEmpty;
|
52
|
}
|
53
|
}
|
54
|
);
|
55
|
}
|
56
|
|
57
|
getLinkToNext(repo: Repository): string {
|
58
|
if (this.parent == 'metrics') {
|
59
|
if (repo.piwikInfo) {
|
60
|
if (repo.piwikInfo.validated === true) {
|
61
|
return `show_metrics/${repo.id}`;
|
62
|
} else if (repo.piwikInfo.validated === false) {
|
63
|
return `instructions/${repo.id}`;
|
64
|
}
|
65
|
} else {
|
66
|
return `enable/${repo.id}`;
|
67
|
}
|
68
|
} else if(this.parent == 'sourcesUpdate' || this.parent == 'compatibilityMonitor'){
|
69
|
return repo.id;
|
70
|
/*} else if(this.parent == 'contentEvents') {
|
71
|
return repo.officialName;*/
|
72
|
}
|
73
|
}
|
74
|
|
75
|
getBadgeCSS(repo: Repository): string {
|
76
|
if (this.parent == 'metrics') {
|
77
|
if (repo.piwikInfo) {
|
78
|
if (repo.piwikInfo.validated === true) {
|
79
|
return 'uk-badge uk-badge-success';
|
80
|
} else if (repo.piwikInfo.validated === false) {
|
81
|
return 'uk-badge uk-badge-warning';
|
82
|
}
|
83
|
} else {
|
84
|
return 'uk-badge uk-badge-danger';
|
85
|
}
|
86
|
/*} else if(this.parent=='contentEvents'){
|
87
|
return 'el-meta uk-margin uk-text-meta';*/
|
88
|
}
|
89
|
}
|
90
|
|
91
|
getBadgeText(repo: Repository): 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
|
/*} else if(this.parent=='contentEvents') {
|
104
|
return this.getRepoEvents(repo);*/
|
105
|
}
|
106
|
}
|
107
|
|
108
|
getRepoEvents(repo: Repository): string {
|
109
|
return '0';
|
110
|
}
|
111
|
|
112
|
toggleTiles(){
|
113
|
this.tilesView = !this.tilesView;
|
114
|
}
|
115
|
|
116
|
}
|