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