]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/angular/app/app.component.ts
Add search with field choose support in 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 console.log(search);
72 if (search.value !== '') {
73 this._router.navigate(['VideosList', { search: search.value, field: search.field }]);
74 } else {
75 this._router.navigate(['VideosList']);
76 }
77 }
78
79 logout() {
80 // this._authService.logout();
81 }
82
83 makeFriends() {
84 this._friendsService.makeFriends().subscribe(
85 status => {
86 if (status === 409) {
87 alert('Already made friends!');
88 } else {
89 alert('Made friends!');
90 }
91 },
92 error => alert(error)
93 );
94 }
95
96 quitFriends() {
97 this._friendsService.quitFriends().subscribe(
98 status => {
99 alert('Quit friends!');
100 },
101 error => alert(error)
102 );
103 }
104 }