1
|
import { Component, Input, OnInit } from '@angular/core';
|
2
|
import { AuthenticationService } from '../../services/authentication.service';
|
3
|
import { BrokerService } from '../../services/broker.service';
|
4
|
import { ActivatedRoute, Router } from '@angular/router';
|
5
|
import { loadingRepoMessage, loadingUserRepoInfoEmpty, reposRetrievalError } from '../../domain/shared-messages';
|
6
|
|
7
|
@Component ({
|
8
|
selector: 'app-content-events',
|
9
|
templateUrl: 'content-events.component.html'
|
10
|
})
|
11
|
|
12
|
export class ContentEventsComponent implements OnInit {
|
13
|
datasourcesOfUser = [];
|
14
|
tilesView: boolean;
|
15
|
errorMessage: string;
|
16
|
noDatasourcesMessage: string;
|
17
|
loadingMessage: string;
|
18
|
|
19
|
@Input() parent = '';
|
20
|
|
21
|
constructor(private authService: AuthenticationService,
|
22
|
private brokerService: BrokerService,
|
23
|
private router: Router,
|
24
|
private route: ActivatedRoute) {}
|
25
|
|
26
|
ngOnInit() {
|
27
|
this.tilesView = true;
|
28
|
this.getDatasourcesOfUser();
|
29
|
}
|
30
|
|
31
|
|
32
|
getDatasourcesOfUser() {
|
33
|
this.loadingMessage = loadingRepoMessage;
|
34
|
this.brokerService.getDatasourcesOfUser(this.authService.getUserEmail()).subscribe(
|
35
|
res => {
|
36
|
this.datasourcesOfUser = res['datasourcesOfUser'];
|
37
|
},
|
38
|
error => {
|
39
|
console.log(error);
|
40
|
this.loadingMessage = '';
|
41
|
this.errorMessage = reposRetrievalError;
|
42
|
},
|
43
|
() => {
|
44
|
this.loadingMessage = '';
|
45
|
if (!this.datasourcesOfUser || !this.datasourcesOfUser.length) {
|
46
|
this.noDatasourcesMessage = loadingUserRepoInfoEmpty;
|
47
|
} else {
|
48
|
this.datasourcesOfUser.sort( function(a, b) {
|
49
|
if ( a['first']['value'] < b['first']['value'] ) {
|
50
|
return -1;
|
51
|
} else if (a['first']['value'] > b['first']['value']) {
|
52
|
return 1;
|
53
|
} else {
|
54
|
return 0;
|
55
|
}
|
56
|
});
|
57
|
}
|
58
|
}
|
59
|
);
|
60
|
}
|
61
|
|
62
|
toggleTiles() {
|
63
|
this.tilesView = !this.tilesView;
|
64
|
}
|
65
|
|
66
|
goToRepoEvents(repoName: string) {
|
67
|
const newName = repoName.replace(/\//g, '|');
|
68
|
this.router.navigate([newName], {relativeTo: this.route});
|
69
|
}
|
70
|
|
71
|
}
|