]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - client/src/app/app.component.ts
Fix tests
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
... / ...
CommitLineData
1import { Component } from '@angular/core';
2import { HTTP_PROVIDERS } from '@angular/http';
3import { Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Routes } from '@angular/router';
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';
19import { SearchService } from './shared'; // Temporary
20
21@Routes([
22 {
23 path: '/users/login',
24 component: LoginComponent
25 },
26 {
27 path: '/videos/list',
28 component: VideoListComponent
29 },
30 {
31 path: '/videos/watch/:id',
32 component: VideoWatchComponent
33 },
34 {
35 path: '/videos/add',
36 component: VideoAddComponent
37 },
38 {
39 path: '/',
40 component: VideoListComponent
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, SearchService ]
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(['/videos/list', params]);
79 } else {
80 this.router.navigate(['/videos/list']);
81 }
82 }
83
84 // FIXME
85 logout() {
86 // this._authService.logout();
87 }
88
89 makeFriends() {
90 this.friendService.makeFriends().subscribe(
91 status => {
92 if (status === 409) {
93 alert('Already made friends!');
94 } else {
95 alert('Made friends!');
96 }
97 },
98 error => alert(error)
99 );
100 }
101
102 quitFriends() {
103 this.friendService.quitFriends().subscribe(
104 status => {
105 alert('Quit friends!');
106 },
107 error => alert(error)
108 );
109 }
110}