]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/app.component.ts
Use ng2-file-upload instead of jquery and add tags support to the video
[github/Chocobozzz/PeerTube.git] / client / src / app / app.component.ts
CommitLineData
230809ef 1import { Component } from '@angular/core';
230809ef 2import { HTTP_PROVIDERS } from '@angular/http';
41a2aee3 3import { RouteConfig, Router, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';
dc8bc31b 4
4a6995be
C
5import { FriendService } from './friends';
6import { LoginComponent } from './login';
41a2aee3 7import {
41a2aee3 8 AuthService,
a840d396
C
9 AuthStatus,
10 Search,
11 SearchComponent
4a6995be 12} from './shared';
41a2aee3
C
13import {
14 VideoAddComponent,
15 VideoListComponent,
16 VideoWatchComponent,
17 VideoService
4a6995be 18} from './videos';
dc8bc31b
C
19
20@RouteConfig([
b1794c53
C
21 {
22 path: '/users/login',
23 name: 'UserLogin',
a840d396 24 component: LoginComponent
b1794c53 25 },
dc8bc31b
C
26 {
27 path: '/videos/list',
28 name: 'VideosList',
41a2aee3 29 component: VideoListComponent,
dc8bc31b
C
30 useAsDefault: true
31 },
32 {
33 path: '/videos/watch/:id',
34 name: 'VideosWatch',
41a2aee3 35 component: VideoWatchComponent
dc8bc31b
C
36 },
37 {
38 path: '/videos/add',
39 name: 'VideosAdd',
41a2aee3 40 component: VideoAddComponent
dc8bc31b
C
41 }
42])
43
44@Component({
45 selector: 'my-app',
4a6995be
C
46 template: require('./app.component.html'),
47 styles: [ require('./app.component.scss') ],
471bc22f 48 directives: [ ROUTER_DIRECTIVES, SearchComponent ],
f0a397ee 49 providers: [ AuthService, FriendService, HTTP_PROVIDERS, ROUTER_PROVIDERS, VideoService ]
dc8bc31b
C
50})
51
52export class AppComponent {
ccf6ed16 53 choices = [];
4fd8aa32 54 isLoggedIn: boolean;
a99593ed 55
4fd8aa32
C
56 constructor(
57 private authService: AuthService,
58 private friendService: FriendService,
59 private router: Router
b1794c53 60 ) {
ccf6ed16 61 this.isLoggedIn = this.authService.isLoggedIn();
b1794c53 62
ccf6ed16 63 this.authService.loginChangedSource.subscribe(
b1794c53
C
64 status => {
65 if (status === AuthStatus.LoggedIn) {
66 this.isLoggedIn = true;
67 }
68 }
69 );
70 }
98b01bac 71
471bc22f 72 onSearch(search: Search) {
471bc22f 73 if (search.value !== '') {
a99593ed 74 const params = {
4fd8aa32
C
75 field: search.field,
76 search: search.value
a99593ed 77 };
ccf6ed16 78 this.router.navigate(['VideosList', params]);
98b01bac 79 } else {
ccf6ed16 80 this.router.navigate(['VideosList']);
98b01bac
C
81 }
82 }
dc8bc31b 83
b1794c53
C
84 logout() {
85 // this._authService.logout();
86 }
87
dc8bc31b 88 makeFriends() {
ccf6ed16 89 this.friendService.makeFriends().subscribe(
dc8bc31b
C
90 status => {
91 if (status === 409) {
92 alert('Already made friends!');
98b01bac 93 } else {
dc8bc31b
C
94 alert('Made friends!');
95 }
96 },
97 error => alert(error)
44124980 98 );
dc8bc31b
C
99 }
100
101 quitFriends() {
ccf6ed16 102 this.friendService.quitFriends().subscribe(
dc8bc31b 103 status => {
4fd8aa32 104 alert('Quit friends!');
dc8bc31b
C
105 },
106 error => alert(error)
44124980 107 );
dc8bc31b
C
108 }
109}