]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/app/app.component.ts
Add search with field choose support in client
[github/Chocobozzz/PeerTube.git] / client / angular / app / app.component.ts
CommitLineData
230809ef
C
1import { Component } from '@angular/core';
2import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from '@angular/router-deprecated';
3import { HTTP_PROVIDERS } from '@angular/http';
dc8bc31b 4
471bc22f
C
5import { DROPDOWN_DIRECTIVES} from 'ng2-bootstrap/components/dropdown';
6
dc8bc31b
C
7import { VideosAddComponent } from '../videos/components/add/videos-add.component';
8import { VideosListComponent } from '../videos/components/list/videos-list.component';
9import { VideosWatchComponent } from '../videos/components/watch/videos-watch.component';
501bc6c2 10import { VideosService } from '../videos/videos.service';
dc8bc31b 11import { FriendsService } from '../friends/services/friends.service';
b1794c53
C
12import { UserLoginComponent } from '../users/components/login/login.component';
13import { AuthService } from '../users/services/auth.service';
14import { AuthStatus } from '../users/models/authStatus';
471bc22f
C
15import { SearchComponent } from './search.component';
16import { Search } from './search';
dc8bc31b
C
17
18@RouteConfig([
b1794c53
C
19 {
20 path: '/users/login',
21 name: 'UserLogin',
22 component: UserLoginComponent
23 },
dc8bc31b
C
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' ],
471bc22f 46 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
eb4e088a 47 providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, VideosService, FriendsService, AuthService ]
dc8bc31b
C
48})
49
50export class AppComponent {
b1794c53 51 isLoggedIn: boolean;
471bc22f
C
52 search_field: string = name;
53 choices = [ ];
b1794c53
C
54
55 constructor(private _friendsService: FriendsService,
56 private _authService: AuthService,
57 private _router: Router
58 ) {
1553e15d 59 this.isLoggedIn = this._authService.isLoggedIn();
b1794c53
C
60
61 this._authService.loginChanged$.subscribe(
62 status => {
63 if (status === AuthStatus.LoggedIn) {
64 this.isLoggedIn = true;
65 }
66 }
67 );
68 }
98b01bac 69
471bc22f
C
70 onSearch(search: Search) {
71 console.log(search);
72 if (search.value !== '') {
73 this._router.navigate(['VideosList', { search: search.value, field: search.field }]);
98b01bac
C
74 } else {
75 this._router.navigate(['VideosList']);
76 }
77 }
dc8bc31b 78
b1794c53
C
79 logout() {
80 // this._authService.logout();
81 }
82
dc8bc31b
C
83 makeFriends() {
84 this._friendsService.makeFriends().subscribe(
85 status => {
86 if (status === 409) {
87 alert('Already made friends!');
98b01bac 88 } else {
dc8bc31b
C
89 alert('Made friends!');
90 }
91 },
92 error => alert(error)
44124980 93 );
dc8bc31b
C
94 }
95
96 quitFriends() {
97 this._friendsService.quitFriends().subscribe(
98 status => {
99 alert('Quit friends!');
100 },
101 error => alert(error)
44124980 102 );
dc8bc31b
C
103 }
104}