]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.component.ts
2a1486fb24a05aefc751d4e7f9bcd37867135f4b
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
1 import { Component } from '@angular/core';
2 import { HTTP_PROVIDERS } from '@angular/http';
3 import { Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Routes } from '@angular/router';
4
5 import { FriendService } from './friends';
6 import { LoginComponent } from './login';
7 import {
8 AuthService,
9 AuthStatus,
10 Search,
11 SearchComponent
12 } from './shared';
13 import {
14 VideoAddComponent,
15 VideoListComponent,
16 VideoWatchComponent,
17 VideoService
18 } from './videos';
19 import { 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
40 @Component({
41 selector: 'my-app',
42 template: require('./app.component.html'),
43 styles: [ require('./app.component.scss') ],
44 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
45 providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService, SearchService ]
46 })
47
48 export class AppComponent {
49 choices = [];
50 isLoggedIn: boolean;
51
52 constructor(
53 private authService: AuthService,
54 private friendService: FriendService,
55 private router: Router
56 ) {
57 this.isLoggedIn = this.authService.isLoggedIn();
58
59 this.authService.loginChangedSource.subscribe(
60 status => {
61 if (status === AuthStatus.LoggedIn) {
62 this.isLoggedIn = true;
63 }
64 }
65 );
66 }
67
68 onSearch(search: Search) {
69 if (search.value !== '') {
70 const params = {
71 field: search.field,
72 search: search.value
73 };
74 this.router.navigate(['/videos/list', params]);
75 } else {
76 this.router.navigate(['/videos/list']);
77 }
78 }
79
80 // FIXME
81 logout() {
82 // this._authService.logout();
83 }
84
85 makeFriends() {
86 this.friendService.makeFriends().subscribe(
87 status => {
88 if (status === 409) {
89 alert('Already made friends!');
90 } else {
91 alert('Made friends!');
92 }
93 },
94 error => alert(error)
95 );
96 }
97
98 quitFriends() {
99 this.friendService.quitFriends().subscribe(
100 status => {
101 alert('Quit friends!');
102 },
103 error => alert(error)
104 );
105 }
106 }