aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/app.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/app.component.ts')
-rw-r--r--client/src/app/app.component.ts109
1 files changed, 109 insertions, 0 deletions
diff --git a/client/src/app/app.component.ts b/client/src/app/app.component.ts
new file mode 100644
index 000000000..81b700a21
--- /dev/null
+++ b/client/src/app/app.component.ts
@@ -0,0 +1,109 @@
1import { Component } from '@angular/core';
2import { HTTP_PROVIDERS } from '@angular/http';
3import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
4
5import { FriendService } from './friends';
6import { LoginComponent } from './login';
7import {
8 AuthService,
9 AuthStatus,
10 Search,
11 SearchComponent
12} from './shared';
13import {
14 VideoAddComponent,
15 VideoListComponent,
16 VideoWatchComponent,
17 VideoService
18} from './videos';
19
20@RouteConfig([
21 {
22 path: '/users/login',
23 name: 'UserLogin',
24 component: LoginComponent
25 },
26 {
27 path: '/videos/list',
28 name: 'VideosList',
29 component: VideoListComponent,
30 useAsDefault: true
31 },
32 {
33 path: '/videos/watch/:id',
34 name: 'VideosWatch',
35 component: VideoWatchComponent
36 },
37 {
38 path: '/videos/add',
39 name: 'VideosAdd',
40 component: VideoAddComponent
41 }
42])
43
44@Component({
45 selector: 'my-app',
46 template: require('./app.component.html'),
47 styles: [ require('./app.component.scss') ],
48 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
49 providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService ]
50})
51
52export class AppComponent {
53 choices = [];
54 isLoggedIn: boolean;
55
56 constructor(
57 private authService: AuthService,
58 private friendService: FriendService,
59 private router: Router
60 ) {
61 this.isLoggedIn = this.authService.isLoggedIn();
62
63 this.authService.loginChangedSource.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 field: search.field,
76 search: search.value
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}