diff options
Diffstat (limited to 'client/app/app.component.ts')
-rw-r--r-- | client/app/app.component.ts | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/client/app/app.component.ts b/client/app/app.component.ts new file mode 100644 index 000000000..c94ff79a7 --- /dev/null +++ b/client/app/app.component.ts | |||
@@ -0,0 +1,109 @@ | |||
1 | import { Component } from '@angular/core'; | ||
2 | import { HTTP_PROVIDERS } from '@angular/http'; | ||
3 | import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated'; | ||
4 | |||
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'; | ||
18 | |||
19 | @RouteConfig([ | ||
20 | { | ||
21 | path: '/users/login', | ||
22 | name: 'UserLogin', | ||
23 | component: UserLoginComponent | ||
24 | }, | ||
25 | { | ||
26 | path: '/videos/list', | ||
27 | name: 'VideosList', | ||
28 | component: VideoListComponent, | ||
29 | useAsDefault: true | ||
30 | }, | ||
31 | { | ||
32 | path: '/videos/watch/:id', | ||
33 | name: 'VideosWatch', | ||
34 | component: VideoWatchComponent | ||
35 | }, | ||
36 | { | ||
37 | path: '/videos/add', | ||
38 | name: 'VideosAdd', | ||
39 | component: VideoAddComponent | ||
40 | } | ||
41 | ]) | ||
42 | |||
43 | @Component({ | ||
44 | selector: 'my-app', | ||
45 | templateUrl: 'client/app/app.component.html', | ||
46 | styleUrls: [ 'client/app/app.component.css' ], | ||
47 | directives: [ ROUTER_DIRECTIVES, SearchComponent ], | ||
48 | providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideoService, FriendService, AuthService ] | ||
49 | }) | ||
50 | |||
51 | export class AppComponent { | ||
52 | isLoggedIn: boolean; | ||
53 | search_field: string = name; | ||
54 | choices = [ ]; | ||
55 | |||
56 | constructor(private _friendService: FriendService, | ||
57 | private _authService: AuthService, | ||
58 | private _router: Router | ||
59 | |||
60 | ) { | ||
61 | this.isLoggedIn = this._authService.isLoggedIn(); | ||
62 | |||
63 | this._authService.loginChanged$.subscribe( | ||
64 | status => { | ||
65 | if (status === AuthStatus.LoggedIn) { | ||
66 | this.isLoggedIn = true; | ||
67 | } | ||
68 | } | ||
69 | ); | ||
70 | } | ||
71 | |||
72 | onSearch(search: Search) { | ||
73 | if (search.value !== '') { | ||
74 | const params = { | ||
75 | search: search.value, | ||
76 | field: search.field | ||
77 | }; | ||
78 | this._router.navigate(['VideosList', params]); | ||
79 | } else { | ||
80 | this._router.navigate(['VideosList']); | ||
81 | } | ||
82 | } | ||
83 | |||
84 | logout() { | ||
85 | // this._authService.logout(); | ||
86 | } | ||
87 | |||
88 | makeFriends() { | ||
89 | this._friendService.makeFriends().subscribe( | ||
90 | status => { | ||
91 | if (status === 409) { | ||
92 | alert('Already made friends!'); | ||
93 | } else { | ||
94 | alert('Made friends!'); | ||
95 | } | ||
96 | }, | ||
97 | error => alert(error) | ||
98 | ); | ||
99 | } | ||
100 | |||
101 | quitFriends() { | ||
102 | this._friendService.quitFriends().subscribe( | ||
103 | status => { | ||
104 | alert('Quit friends!'); | ||
105 | }, | ||
106 | error => alert(error) | ||
107 | ); | ||
108 | } | ||
109 | } | ||