]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/app/app.component.ts
Implement user requests autorizations in the client side
[github/Chocobozzz/PeerTube.git] / client / angular / app / app.component.ts
CommitLineData
dc8bc31b 1import { Component, ElementRef } from 'angular2/core';
98b01bac
C
2import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from 'angular2/router';
3import { HTTP_PROVIDERS } from 'angular2/http';
dc8bc31b
C
4
5import { VideosAddComponent } from '../videos/components/add/videos-add.component';
6import { VideosListComponent } from '../videos/components/list/videos-list.component';
7import { VideosWatchComponent } from '../videos/components/watch/videos-watch.component';
8import { VideosService } from '../videos/services/videos.service';
9import { FriendsService } from '../friends/services/friends.service';
b1794c53
C
10import { UserLoginComponent } from '../users/components/login/login.component';
11import { AuthService } from '../users/services/auth.service';
12import { AuthStatus } from '../users/models/authStatus';
dc8bc31b
C
13
14@RouteConfig([
b1794c53
C
15 {
16 path: '/users/login',
17 name: 'UserLogin',
18 component: UserLoginComponent
19 },
dc8bc31b
C
20 {
21 path: '/videos/list',
22 name: 'VideosList',
23 component: VideosListComponent,
24 useAsDefault: true
25 },
26 {
27 path: '/videos/watch/:id',
28 name: 'VideosWatch',
29 component: VideosWatchComponent
30 },
31 {
32 path: '/videos/add',
33 name: 'VideosAdd',
34 component: VideosAddComponent
35 }
36])
37
38@Component({
39 selector: 'my-app',
40 templateUrl: 'app/angular/app/app.component.html',
41 styleUrls: [ 'app/angular/app/app.component.css' ],
42 directives: [ ROUTER_DIRECTIVES ],
b1794c53
C
43 providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS,
44 ElementRef, VideosService, FriendsService,
45 AuthService
46 ]
dc8bc31b
C
47})
48
49export class AppComponent {
b1794c53
C
50 isLoggedIn: boolean;
51
52 constructor(private _friendsService: FriendsService,
53 private _authService: AuthService,
54 private _router: Router
55 ) {
1553e15d 56 this.isLoggedIn = this._authService.isLoggedIn();
b1794c53
C
57
58 this._authService.loginChanged$.subscribe(
59 status => {
60 if (status === AuthStatus.LoggedIn) {
61 this.isLoggedIn = true;
62 }
63 }
64 );
65 }
98b01bac
C
66
67 doSearch(search: string) {
68 if (search !== '') {
69 this._router.navigate(['VideosList', { search: search }]);
70 } else {
71 this._router.navigate(['VideosList']);
72 }
73 }
dc8bc31b 74
b1794c53
C
75 logout() {
76 // this._authService.logout();
77 }
78
dc8bc31b
C
79 makeFriends() {
80 this._friendsService.makeFriends().subscribe(
81 status => {
82 if (status === 409) {
83 alert('Already made friends!');
98b01bac 84 } else {
dc8bc31b
C
85 alert('Made friends!');
86 }
87 },
88 error => alert(error)
44124980 89 );
dc8bc31b
C
90 }
91
92 quitFriends() {
93 this._friendsService.quitFriends().subscribe(
94 status => {
95 alert('Quit friends!');
96 },
97 error => alert(error)
44124980 98 );
dc8bc31b
C
99 }
100}