]>
Commit | Line | Data |
---|---|---|
230809ef C |
1 | import { Component } from '@angular/core'; |
2 | import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from '@angular/router-deprecated'; | |
3 | import { HTTP_PROVIDERS } from '@angular/http'; | |
dc8bc31b C |
4 | |
5 | import { VideosAddComponent } from '../videos/components/add/videos-add.component'; | |
6 | import { VideosListComponent } from '../videos/components/list/videos-list.component'; | |
7 | import { VideosWatchComponent } from '../videos/components/watch/videos-watch.component'; | |
8 | import { VideosService } from '../videos/services/videos.service'; | |
9 | import { FriendsService } from '../friends/services/friends.service'; | |
b1794c53 C |
10 | import { UserLoginComponent } from '../users/components/login/login.component'; |
11 | import { AuthService } from '../users/services/auth.service'; | |
12 | import { AuthStatus } from '../users/models/authStatus'; | |
dc8bc31b C |
13 | |
14 | @RouteConfig([ | |
b1794c53 C |
15 | { |
16 | path: '/users/login', | |
17 | name: 'UserLogin', | |
18 | component: UserLoginComponent | |
19 | }, | |
dc8bc31b C |
20 | { |
21 | path: '/videos/list', | |
22 | name: 'VideosList', | |
23 | component: VideosListComponent, | |
24 | useAsDefault: true | |
25 | }, | |
26 | { | |
27 | path: '/videos/watch/:id', | |
28 | name: 'VideosWatch', | |
29 | component: VideosWatchComponent | |
30 | }, | |
31 | { | |
32 | path: '/videos/add', | |
33 | name: 'VideosAdd', | |
34 | component: VideosAddComponent | |
35 | } | |
36 | ]) | |
37 | ||
38 | @Component({ | |
39 | selector: 'my-app', | |
40 | templateUrl: 'app/angular/app/app.component.html', | |
41 | styleUrls: [ 'app/angular/app/app.component.css' ], | |
42 | directives: [ ROUTER_DIRECTIVES ], | |
eb4e088a | 43 | providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideosService, FriendsService, AuthService ] |
dc8bc31b C |
44 | }) |
45 | ||
46 | export class AppComponent { | |
b1794c53 C |
47 | isLoggedIn: boolean; |
48 | ||
49 | constructor(private _friendsService: FriendsService, | |
50 | private _authService: AuthService, | |
51 | private _router: Router | |
52 | ) { | |
1553e15d | 53 | this.isLoggedIn = this._authService.isLoggedIn(); |
b1794c53 C |
54 | |
55 | this._authService.loginChanged$.subscribe( | |
56 | status => { | |
57 | if (status === AuthStatus.LoggedIn) { | |
58 | this.isLoggedIn = true; | |
59 | } | |
60 | } | |
61 | ); | |
62 | } | |
98b01bac C |
63 | |
64 | doSearch(search: string) { | |
65 | if (search !== '') { | |
66 | this._router.navigate(['VideosList', { search: search }]); | |
67 | } else { | |
68 | this._router.navigate(['VideosList']); | |
69 | } | |
70 | } | |
dc8bc31b | 71 | |
b1794c53 C |
72 | logout() { |
73 | // this._authService.logout(); | |
74 | } | |
75 | ||
dc8bc31b C |
76 | makeFriends() { |
77 | this._friendsService.makeFriends().subscribe( | |
78 | status => { | |
79 | if (status === 409) { | |
80 | alert('Already made friends!'); | |
98b01bac | 81 | } else { |
dc8bc31b C |
82 | alert('Made friends!'); |
83 | } | |
84 | }, | |
85 | error => alert(error) | |
44124980 | 86 | ); |
dc8bc31b C |
87 | } |
88 | ||
89 | quitFriends() { | |
90 | this._friendsService.quitFriends().subscribe( | |
91 | status => { | |
92 | alert('Quit friends!'); | |
93 | }, | |
94 | error => alert(error) | |
44124980 | 95 | ); |
dc8bc31b C |
96 | } |
97 | } |