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