]>
Commit | Line | Data |
---|---|---|
230809ef | 1 | import { Component } from '@angular/core'; |
230809ef | 2 | import { HTTP_PROVIDERS } from '@angular/http'; |
41a2aee3 | 3 | import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated'; |
dc8bc31b | 4 | |
41a2aee3 C |
5 | import { FriendService } from './friends/index'; |
6 | import { Search, SearchComponent } from './shared/index'; | |
7 | import { | |
8 | UserLoginComponent, | |
9 | AuthService, | |
10 | AuthStatus | |
11 | } from './users/index'; | |
12 | import { | |
13 | VideoAddComponent, | |
14 | VideoListComponent, | |
15 | VideoWatchComponent, | |
16 | VideoService | |
17 | } from './videos/index'; | |
dc8bc31b C |
18 | |
19 | @RouteConfig([ | |
b1794c53 C |
20 | { |
21 | path: '/users/login', | |
22 | name: 'UserLogin', | |
23 | component: UserLoginComponent | |
24 | }, | |
dc8bc31b C |
25 | { |
26 | path: '/videos/list', | |
27 | name: 'VideosList', | |
41a2aee3 | 28 | component: VideoListComponent, |
dc8bc31b C |
29 | useAsDefault: true |
30 | }, | |
31 | { | |
32 | path: '/videos/watch/:id', | |
33 | name: 'VideosWatch', | |
41a2aee3 | 34 | component: VideoWatchComponent |
dc8bc31b C |
35 | }, |
36 | { | |
37 | path: '/videos/add', | |
38 | name: 'VideosAdd', | |
41a2aee3 | 39 | component: VideoAddComponent |
dc8bc31b C |
40 | } |
41 | ]) | |
42 | ||
43 | @Component({ | |
44 | selector: 'my-app', | |
41a2aee3 C |
45 | templateUrl: 'client/app/app.component.html', |
46 | styleUrls: [ 'client/app/app.component.css' ], | |
471bc22f | 47 | directives: [ ROUTER_DIRECTIVES, SearchComponent ], |
f0a397ee | 48 | providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService ] |
dc8bc31b C |
49 | }) |
50 | ||
51 | export class AppComponent { | |
ccf6ed16 | 52 | choices = []; |
4fd8aa32 | 53 | isLoggedIn: boolean; |
a99593ed | 54 | |
4fd8aa32 C |
55 | constructor( |
56 | private authService: AuthService, | |
57 | private friendService: FriendService, | |
58 | private router: Router | |
b1794c53 | 59 | ) { |
ccf6ed16 | 60 | this.isLoggedIn = this.authService.isLoggedIn(); |
b1794c53 | 61 | |
ccf6ed16 | 62 | this.authService.loginChangedSource.subscribe( |
b1794c53 C |
63 | status => { |
64 | if (status === AuthStatus.LoggedIn) { | |
65 | this.isLoggedIn = true; | |
66 | } | |
67 | } | |
68 | ); | |
69 | } | |
98b01bac | 70 | |
471bc22f | 71 | onSearch(search: Search) { |
471bc22f | 72 | if (search.value !== '') { |
a99593ed | 73 | const params = { |
4fd8aa32 C |
74 | field: search.field, |
75 | search: search.value | |
a99593ed | 76 | }; |
ccf6ed16 | 77 | this.router.navigate(['VideosList', params]); |
98b01bac | 78 | } else { |
ccf6ed16 | 79 | this.router.navigate(['VideosList']); |
98b01bac C |
80 | } |
81 | } | |
dc8bc31b | 82 | |
b1794c53 C |
83 | logout() { |
84 | // this._authService.logout(); | |
85 | } | |
86 | ||
dc8bc31b | 87 | makeFriends() { |
ccf6ed16 | 88 | this.friendService.makeFriends().subscribe( |
dc8bc31b C |
89 | status => { |
90 | if (status === 409) { | |
91 | alert('Already made friends!'); | |
98b01bac | 92 | } else { |
dc8bc31b C |
93 | alert('Made friends!'); |
94 | } | |
95 | }, | |
96 | error => alert(error) | |
44124980 | 97 | ); |
dc8bc31b C |
98 | } |
99 | ||
100 | quitFriends() { | |
ccf6ed16 | 101 | this.friendService.quitFriends().subscribe( |
dc8bc31b | 102 | status => { |
4fd8aa32 | 103 | alert('Quit friends!'); |
dc8bc31b C |
104 | }, |
105 | error => alert(error) | |
44124980 | 106 | ); |
dc8bc31b C |
107 | } |
108 | } |