]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/app/app.component.ts
20c8c8724ff352cdab75eebd2f82946ff4a0f65a
[github/Chocobozzz/PeerTube.git] / client / app / app.component.ts
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 this.isLoggedIn = this.authService.isLoggedIn();
61
62 this.authService.loginChangedSource.subscribe(
63 status => {
64 if (status === AuthStatus.LoggedIn) {
65 this.isLoggedIn = true;
66 }
67 }
68 );
69 }
70
71 onSearch(search: Search) {
72 if (search.value !== '') {
73 const params = {
74 search: search.value,
75 field: search.field
76 };
77 this.router.navigate(['VideosList', params]);
78 } else {
79 this.router.navigate(['VideosList']);
80 }
81 }
82
83 logout() {
84 // this._authService.logout();
85 }
86
87 makeFriends() {
88 this.friendService.makeFriends().subscribe(
89 status => {
90 if (status === 409) {
91 alert('Already made friends!');
92 } else {
93 alert('Made friends!');
94 }
95 },
96 error => alert(error)
97 );
98 }
99
100 quitFriends() {
101 this.friendService.quitFriends().subscribe(
102 status => {
103 alert('Quit friends!');
104 },
105 error => alert(error)
106 );
107 }
108 }