]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/app.component.ts
Client: Update to Angular RC4
[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 } from '@angular/router';
4
5 import { FriendService } from './friends';
6 import {
7 AuthService,
8 AuthStatus,
9 Search,
10 SearchComponent,
11 SearchService
12 } from './shared';
13 import { VideoService } from './videos';
14
15 @Component({
16 selector: 'my-app',
17 template: require('./app.component.html'),
18 styles: [ require('./app.component.scss') ],
19 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
20 providers: [ AuthService, FriendService, HTTP_PROVIDERS, VideoService, SearchService ]
21 })
22
23 export class AppComponent {
24 choices = [];
25 isLoggedIn: boolean;
26
27 constructor(
28 private authService: AuthService,
29 private friendService: FriendService,
30 private router: Router
31 ) {
32 this.isLoggedIn = this.authService.isLoggedIn();
33
34 this.authService.loginChangedSource.subscribe(
35 status => {
36 if (status === AuthStatus.LoggedIn) {
37 this.isLoggedIn = true;
38 }
39 }
40 );
41 }
42
43 onSearch(search: Search) {
44 if (search.value !== '') {
45 const params = {
46 field: search.field,
47 search: search.value
48 };
49
50 this.router.navigate(['/videos/list', params]);
51 } else {
52 this.router.navigate(['/videos/list']);
53 }
54 }
55
56 // FIXME
57 logout() {
58 // this._authService.logout();
59 }
60
61 makeFriends() {
62 this.friendService.makeFriends().subscribe(
63 status => {
64 if (status === 409) {
65 alert('Already made friends!');
66 } else {
67 alert('Made friends!');
68 }
69 },
70 error => alert(error)
71 );
72 }
73
74 quitFriends() {
75 this.friendService.quitFriends().subscribe(
76 status => {
77 alert('Quit friends!');
78 },
79 error => alert(error)
80 );
81 }
82 }