]>
Commit | Line | Data |
---|---|---|
230809ef | 1 | import { Component } from '@angular/core'; |
230809ef | 2 | import { HTTP_PROVIDERS } from '@angular/http'; |
00a44645 | 3 | import { Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Routes } from '@angular/router'; |
dc8bc31b | 4 | |
4a6995be C |
5 | import { FriendService } from './friends'; |
6 | import { LoginComponent } from './login'; | |
41a2aee3 | 7 | import { |
41a2aee3 | 8 | AuthService, |
a840d396 C |
9 | AuthStatus, |
10 | Search, | |
11 | SearchComponent | |
4a6995be | 12 | } from './shared'; |
41a2aee3 C |
13 | import { |
14 | VideoAddComponent, | |
15 | VideoListComponent, | |
16 | VideoWatchComponent, | |
17 | VideoService | |
4a6995be | 18 | } from './videos'; |
00a44645 | 19 | import { SearchService } from './shared'; // Temporary |
dc8bc31b | 20 | |
00a44645 | 21 | @Routes([ |
b1794c53 C |
22 | { |
23 | path: '/users/login', | |
a840d396 | 24 | component: LoginComponent |
b1794c53 | 25 | }, |
dc8bc31b C |
26 | { |
27 | path: '/videos/list', | |
00a44645 | 28 | component: VideoListComponent |
dc8bc31b C |
29 | }, |
30 | { | |
31 | path: '/videos/watch/:id', | |
41a2aee3 | 32 | component: VideoWatchComponent |
dc8bc31b C |
33 | }, |
34 | { | |
35 | path: '/videos/add', | |
41a2aee3 | 36 | component: VideoAddComponent |
70af9a0d C |
37 | }, |
38 | { | |
39 | path: '/', | |
40 | component: VideoListComponent | |
dc8bc31b C |
41 | } |
42 | ]) | |
43 | ||
44 | @Component({ | |
45 | selector: 'my-app', | |
4a6995be C |
46 | template: require('./app.component.html'), |
47 | styles: [ require('./app.component.scss') ], | |
471bc22f | 48 | directives: [ ROUTER_DIRECTIVES, SearchComponent ], |
00a44645 | 49 | providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService, SearchService ] |
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 | }; |
00a44645 | 78 | this.router.navigate(['/videos/list', params]); |
98b01bac | 79 | } else { |
00a44645 | 80 | this.router.navigate(['/videos/list']); |
98b01bac C |
81 | } |
82 | } | |
dc8bc31b | 83 | |
00a44645 | 84 | // FIXME |
b1794c53 C |
85 | logout() { |
86 | // this._authService.logout(); | |
87 | } | |
88 | ||
dc8bc31b | 89 | makeFriends() { |
ccf6ed16 | 90 | this.friendService.makeFriends().subscribe( |
dc8bc31b C |
91 | status => { |
92 | if (status === 409) { | |
93 | alert('Already made friends!'); | |
98b01bac | 94 | } else { |
dc8bc31b C |
95 | alert('Made friends!'); |
96 | } | |
97 | }, | |
98 | error => alert(error) | |
44124980 | 99 | ); |
dc8bc31b C |
100 | } |
101 | ||
102 | quitFriends() { | |
ccf6ed16 | 103 | this.friendService.quitFriends().subscribe( |
dc8bc31b | 104 | status => { |
4fd8aa32 | 105 | alert('Quit friends!'); |
dc8bc31b C |
106 | }, |
107 | error => alert(error) | |
44124980 | 108 | ); |
dc8bc31b C |
109 | } |
110 | } |