]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/angular/app/app.component.ts
Change api output for videos
[github/Chocobozzz/PeerTube.git] / client / angular / app / app.component.ts
1 import { Component, ElementRef } from 'angular2/core';
2 import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS, Router } from 'angular2/router';
3 import { HTTP_PROVIDERS } from 'angular2/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/services/videos.service';
9 import { FriendsService } from '../friends/services/friends.service';
10
11 @RouteConfig([
12 {
13 path: '/videos/list',
14 name: 'VideosList',
15 component: VideosListComponent,
16 useAsDefault: true
17 },
18 {
19 path: '/videos/watch/:id',
20 name: 'VideosWatch',
21 component: VideosWatchComponent
22 },
23 {
24 path: '/videos/add',
25 name: 'VideosAdd',
26 component: VideosAddComponent
27 }
28 ])
29
30 @Component({
31 selector: 'my-app',
32 templateUrl: 'app/angular/app/app.component.html',
33 styleUrls: [ 'app/angular/app/app.component.css' ],
34 directives: [ ROUTER_DIRECTIVES ],
35 providers: [ ROUTER_PROVIDERS, HTTP_PROVIDERS, ElementRef, VideosService, FriendsService ]
36 })
37
38 export class AppComponent {
39 constructor(private _friendsService: FriendsService, private _router: Router) {}
40
41 doSearch(search: string) {
42 if (search !== '') {
43 this._router.navigate(['VideosList', { search: search }]);
44 } else {
45 this._router.navigate(['VideosList']);
46 }
47 }
48
49 makeFriends() {
50 this._friendsService.makeFriends().subscribe(
51 status => {
52 if (status === 409) {
53 alert('Already made friends!');
54 } else {
55 alert('Made friends!');
56 }
57 },
58 error => alert(error)
59 )
60 }
61
62 quitFriends() {
63 this._friendsService.quitFriends().subscribe(
64 status => {
65 alert('Quit friends!');
66 },
67 error => alert(error)
68 )
69 }
70 }