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