1
|
import { Component, OnInit } from '@angular/core';
|
2
|
import { RepositoryService } from "../../services/repository.service";
|
3
|
import { SharedService } from "../../services/shared.service";
|
4
|
import { RepositorySnippet } from "../../domain/typeScriptClasses";
|
5
|
import { Router } from "@angular/router";
|
6
|
|
7
|
@Component ({
|
8
|
selector: 'app-join',
|
9
|
templateUrl: './join.component.html',
|
10
|
})
|
11
|
|
12
|
export class JoinComponent implements OnInit {
|
13
|
|
14
|
repositoriesOfUser: RepositorySnippet[];
|
15
|
|
16
|
loadingMessage: string;
|
17
|
|
18
|
constructor(private repositoryService: RepositoryService,
|
19
|
private sharedService: SharedService,
|
20
|
private router: Router) {
|
21
|
}
|
22
|
|
23
|
ngOnInit() {
|
24
|
|
25
|
this.loadingMessage = ' ';
|
26
|
|
27
|
let body = document.getElementsByTagName('body')[0];
|
28
|
body.classList.remove("landing");
|
29
|
body.classList.add("dashboard");
|
30
|
|
31
|
if(this.sharedService.getRepositoriesOfUser() && this.sharedService.getRepositoriesOfUser().length>0) {
|
32
|
this.repositoriesOfUser = this.sharedService.getRepositoriesOfUser();
|
33
|
if(this.repositoriesOfUser.length>0)
|
34
|
this.router.navigate([`/repository/${this.repositoriesOfUser[0].id}/dashboard`]);
|
35
|
else
|
36
|
this.loadingMessage = null;
|
37
|
} else {
|
38
|
this.getReposOfUser();
|
39
|
}
|
40
|
|
41
|
}
|
42
|
|
43
|
getReposOfUser(): void {
|
44
|
this.repositoryService.getRepositoriesOfUser()
|
45
|
.subscribe(
|
46
|
repos => {
|
47
|
this.repositoriesOfUser = repos;
|
48
|
if(this.repositoriesOfUser.length>0)
|
49
|
this.router.navigate([`/repository/${this.repositoriesOfUser[0].id}/dashboard`]);
|
50
|
else
|
51
|
this.loadingMessage = null;
|
52
|
},
|
53
|
error => { console.log(error); }
|
54
|
);
|
55
|
}
|
56
|
}
|