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