]>
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 ], |
41a2aee3 | 48 | providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideoService, FriendService, AuthService ] |
dc8bc31b C |
49 | }) |
50 | ||
51 | export class AppComponent { | |
b1794c53 | 52 | isLoggedIn: boolean; |
471bc22f | 53 | search_field: string = name; |
41a2aee3 | 54 | choices = [ ]; |
b1794c53 | 55 | |
41a2aee3 | 56 | constructor(private _friendService: FriendService, |
b1794c53 C |
57 | private _authService: AuthService, |
58 | private _router: Router | |
a99593ed | 59 | |
b1794c53 | 60 | ) { |
1553e15d | 61 | this.isLoggedIn = this._authService.isLoggedIn(); |
b1794c53 C |
62 | |
63 | this._authService.loginChanged$.subscribe( | |
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 C |
74 | const params = { |
75 | search: search.value, | |
76 | field: search.field | |
77 | }; | |
78 | this._router.navigate(['VideosList', params]); | |
98b01bac C |
79 | } else { |
80 | this._router.navigate(['VideosList']); | |
81 | } | |
82 | } | |
dc8bc31b | 83 | |
b1794c53 C |
84 | logout() { |
85 | // this._authService.logout(); | |
86 | } | |
87 | ||
dc8bc31b | 88 | makeFriends() { |
41a2aee3 | 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() { | |
41a2aee3 | 102 | this._friendService.quitFriends().subscribe( |
dc8bc31b C |
103 | status => { |
104 | alert('Quit friends!'); | |
105 | }, | |
106 | error => alert(error) | |
44124980 | 107 | ); |
dc8bc31b C |
108 | } |
109 | } |