diff options
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r-- | client/src/app/app.component.ts | 69 |
1 files changed, 6 insertions, 63 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts index b7a3d7c58..d6b83c684 100644 --- a/client/src/app/app.component.ts +++ b/client/src/app/app.component.ts | |||
@@ -1,73 +1,16 @@ | |||
1 | import { Component } from '@angular/core'; | 1 | import { Component } from '@angular/core'; |
2 | import { ActivatedRoute, Router, ROUTER_DIRECTIVES } from '@angular/router'; | 2 | import { Router } from '@angular/router'; |
3 | |||
4 | import { FriendService } from './friends'; | ||
5 | import { | ||
6 | AuthService, | ||
7 | AuthStatus, | ||
8 | SearchComponent, | ||
9 | SearchService | ||
10 | } from './shared'; | ||
11 | import { VideoService } from './videos'; | ||
12 | 3 | ||
13 | @Component({ | 4 | @Component({ |
14 | selector: 'my-app', | 5 | selector: 'my-app', |
15 | template: require('./app.component.html'), | 6 | templateUrl: './app.component.html', |
16 | styles: [ require('./app.component.scss') ], | 7 | styleUrls: [ './app.component.scss' ] |
17 | directives: [ ROUTER_DIRECTIVES, SearchComponent ], | ||
18 | providers: [ FriendService, VideoService, SearchService ] | ||
19 | }) | 8 | }) |
20 | 9 | ||
21 | export class AppComponent { | 10 | export class AppComponent { |
22 | choices = []; | 11 | constructor(private router: Router) {} |
23 | isLoggedIn: boolean; | ||
24 | |||
25 | constructor( | ||
26 | private authService: AuthService, | ||
27 | private friendService: FriendService, | ||
28 | private route: ActivatedRoute, | ||
29 | private router: Router | ||
30 | ) { | ||
31 | this.isLoggedIn = this.authService.isLoggedIn(); | ||
32 | |||
33 | this.authService.loginChangedSource.subscribe( | ||
34 | status => { | ||
35 | if (status === AuthStatus.LoggedIn) { | ||
36 | this.isLoggedIn = true; | ||
37 | console.log('Logged in.'); | ||
38 | } else if (status === AuthStatus.LoggedOut) { | ||
39 | this.isLoggedIn = false; | ||
40 | console.log('Logged out.'); | ||
41 | } else { | ||
42 | console.error('Unknown auth status: ' + status); | ||
43 | } | ||
44 | } | ||
45 | ); | ||
46 | } | ||
47 | |||
48 | logout() { | ||
49 | this.authService.logout(); | ||
50 | } | ||
51 | |||
52 | makeFriends() { | ||
53 | this.friendService.makeFriends().subscribe( | ||
54 | status => { | ||
55 | if (status === 409) { | ||
56 | alert('Already made friends!'); | ||
57 | } else { | ||
58 | alert('Made friends!'); | ||
59 | } | ||
60 | }, | ||
61 | error => alert(error) | ||
62 | ); | ||
63 | } | ||
64 | 12 | ||
65 | quitFriends() { | 13 | isInAdmin() { |
66 | this.friendService.quitFriends().subscribe( | 14 | return this.router.url.indexOf('/admin/') !== -1; |
67 | status => { | ||
68 | alert('Quit friends!'); | ||
69 | }, | ||
70 | error => alert(error) | ||
71 | ); | ||
72 | } | 15 | } |
73 | } | 16 | } |