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
|
loadingMessage: string;
|
18
|
|
19
|
@Input() parent: string = '';
|
20
|
|
21
|
constructor(private authService: AuthenticationService,
|
22
|
private repoService: RepositoryService) {}
|
23
|
|
24
|
ngOnInit() {
|
25
|
this.tilesView = true;
|
26
|
this.getReposOfUser();
|
27
|
}
|
28
|
|
29
|
getReposOfUser(): void {
|
30
|
this.loadingMessage = loadingReposMessage;
|
31
|
this.repoService.getRepositoriesOfUser(this.authService.getUserEmail())
|
32
|
.subscribe(
|
33
|
repos => this.reposOfUser = repos.sort( function(a,b){
|
34
|
if(a.officialName<b.officialName){
|
35
|
return -1;
|
36
|
} else if(a.officialName>b.officialName){
|
37
|
return 1;
|
38
|
} else {
|
39
|
return 0;
|
40
|
}
|
41
|
}),
|
42
|
error => {
|
43
|
console.log(error);
|
44
|
this.loadingMessage = '';
|
45
|
this.errorMessage = reposRetrievalError;
|
46
|
},
|
47
|
() => {
|
48
|
this.loadingMessage = '';
|
49
|
if (!this.reposOfUser.length) {
|
50
|
this.errorMessage = loadingUserRepoInfoEmpty;
|
51
|
}
|
52
|
}
|
53
|
);
|
54
|
}
|
55
|
|
56
|
getLinkToNext(repo: Repository): string {
|
57
|
if (this.parent == 'metrics') {
|
58
|
if (repo.piwikInfo) {
|
59
|
if (repo.piwikInfo.validated === true) {
|
60
|
return `show_metrics/${repo.id}`;
|
61
|
} else if (repo.piwikInfo.validated === false) {
|
62
|
return `instructions/${repo.id}`;
|
63
|
}
|
64
|
} else {
|
65
|
return `enable/${repo.id}`;
|
66
|
}
|
67
|
} else if(this.parent == 'sourcesUpdate' || this.parent == 'compatibilityMonitor'){
|
68
|
return repo.id;
|
69
|
/*} else if(this.parent == 'contentEvents') {
|
70
|
return repo.officialName;*/
|
71
|
}
|
72
|
}
|
73
|
|
74
|
getBadgeCSS(repo: Repository): string {
|
75
|
if (this.parent == 'metrics') {
|
76
|
if (repo.piwikInfo) {
|
77
|
if (repo.piwikInfo.validated === true) {
|
78
|
return 'uk-badge uk-badge-success';
|
79
|
} else if (repo.piwikInfo.validated === false) {
|
80
|
return 'uk-badge uk-badge-warning';
|
81
|
}
|
82
|
} else {
|
83
|
return 'uk-badge uk-badge-danger';
|
84
|
}
|
85
|
/*} else if(this.parent=='contentEvents'){
|
86
|
return 'el-meta uk-margin uk-text-meta';*/
|
87
|
}
|
88
|
}
|
89
|
|
90
|
getBadgeText(repo: Repository): string {
|
91
|
if(this.parent=='metrics'){
|
92
|
if(repo.piwikInfo){
|
93
|
if(repo.piwikInfo.validated === true){
|
94
|
return 'enabled';
|
95
|
} else if ( repo.piwikInfo.validated === false ) {
|
96
|
return 'enabling in progress';
|
97
|
}
|
98
|
} else {
|
99
|
return 'not enabled';
|
100
|
}
|
101
|
|
102
|
/*} else if(this.parent=='contentEvents') {
|
103
|
return this.getRepoEvents(repo);*/
|
104
|
}
|
105
|
}
|
106
|
|
107
|
getRepoEvents(repo: Repository): string {
|
108
|
return '0';
|
109
|
}
|
110
|
|
111
|
toggleTiles(){
|
112
|
this.tilesView = !this.tilesView;
|
113
|
}
|
114
|
|
115
|
}
|