aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/angular/videos/components
diff options
context:
space:
mode:
Diffstat (limited to 'client/angular/videos/components')
-rw-r--r--client/angular/videos/components/add/videos-add.component.ts15
-rw-r--r--client/angular/videos/components/list/videos-list.component.ts27
-rw-r--r--client/angular/videos/components/watch/videos-watch.component.ts12
3 files changed, 39 insertions, 15 deletions
diff --git a/client/angular/videos/components/add/videos-add.component.ts b/client/angular/videos/components/add/videos-add.component.ts
index 97e3bb3b5..8ff6cfec8 100644
--- a/client/angular/videos/components/add/videos-add.component.ts
+++ b/client/angular/videos/components/add/videos-add.component.ts
@@ -1,9 +1,10 @@
1import {Component, ElementRef, Inject, OnInit} from 'angular2/core'; 1import { Component, ElementRef, Inject, OnInit } from 'angular2/core';
2import {Router} from 'angular2/router'; 2import { Router } from 'angular2/router';
3import {NgForm} from 'angular2/common'; 3import { NgForm } from 'angular2/common';
4 4
5import {Video} from '../../models/video'; 5import { Video } from '../../models/video';
6 6
7// TODO: import it with systemjs
7declare var jQuery:any; 8declare var jQuery:any;
8 9
9@Component({ 10@Component({
@@ -22,9 +23,10 @@ export class VideosAddComponent implements OnInit {
22 23
23 ngOnInit() { 24 ngOnInit() {
24 jQuery(this._elementRef.nativeElement).find('#input_video').fileupload({ 25 jQuery(this._elementRef.nativeElement).find('#input_video').fileupload({
26 url: '/api/v1/videos',
27 dataType: 'json',
25 singleFileUploads: true, 28 singleFileUploads: true,
26 multipart: true, 29 multipart: true,
27 url: '/api/v1/videos',
28 autoupload: false, 30 autoupload: false,
29 31
30 add: (e, data) => { 32 add: (e, data) => {
@@ -38,7 +40,8 @@ export class VideosAddComponent implements OnInit {
38 }, 40 },
39 41
40 done: (e, data) => { 42 done: (e, data) => {
41 console.log('finished'); 43 console.log('Video uploaded.');
44
42 // Print all the videos once it's finished 45 // Print all the videos once it's finished
43 this._router.navigate(['VideosList']); 46 this._router.navigate(['VideosList']);
44 } 47 }
diff --git a/client/angular/videos/components/list/videos-list.component.ts b/client/angular/videos/components/list/videos-list.component.ts
index e5af87448..eb23ed1ff 100644
--- a/client/angular/videos/components/list/videos-list.component.ts
+++ b/client/angular/videos/components/list/videos-list.component.ts
@@ -1,8 +1,8 @@
1import {Component, OnInit} from 'angular2/core'; 1import { Component, OnInit } from 'angular2/core';
2import {ROUTER_DIRECTIVES} from 'angular2/router'; 2import { ROUTER_DIRECTIVES, RouteParams } from 'angular2/router';
3 3
4import {VideosService} from '../../services/videos.service'; 4import { VideosService } from '../../services/videos.service';
5import {Video} from '../../models/video'; 5import { Video } from '../../models/video';
6 6
7@Component({ 7@Component({
8 selector: 'my-videos-list', 8 selector: 'my-videos-list',
@@ -14,16 +14,29 @@ import {Video} from '../../models/video';
14export class VideosListComponent implements OnInit { 14export class VideosListComponent implements OnInit {
15 videos: Video[]; 15 videos: Video[];
16 16
17 private search: string;
18
17 constructor( 19 constructor(
18 private _videosService: VideosService 20 private _videosService: VideosService,
19 ) { } 21 routeParams: RouteParams
22 ) {
23 this.search = routeParams.get('search');
24 }
20 25
21 ngOnInit() { 26 ngOnInit() {
22 this.getVideos(); 27 this.getVideos();
23 } 28 }
24 29
25 getVideos() { 30 getVideos() {
26 this._videosService.getVideos().subscribe( 31 let observable = null;
32
33 if (this.search !== null) {
34 observable = this._videosService.searchVideos(this.search);
35 } else {
36 observable = this._videosService.getVideos()
37 }
38
39 observable.subscribe(
27 videos => this.videos = videos, 40 videos => this.videos = videos,
28 error => alert(error) 41 error => alert(error)
29 ); 42 );
diff --git a/client/angular/videos/components/watch/videos-watch.component.ts b/client/angular/videos/components/watch/videos-watch.component.ts
index e3a973820..da7f942db 100644
--- a/client/angular/videos/components/watch/videos-watch.component.ts
+++ b/client/angular/videos/components/watch/videos-watch.component.ts
@@ -1,8 +1,9 @@
1/// <reference path='../../../../typings/browser/ambient/webtorrent/webtorrent.d.ts' /> 1/// <reference path='../../../../typings/browser/ambient/webtorrent/webtorrent.d.ts' />
2 2
3import { Component, OnInit, ElementRef } from 'angular2/core'; 3import { Component, OnInit, ElementRef } from 'angular2/core';
4import { RouteParams } from 'angular2/router'; 4import { RouteParams, CanDeactivate, ComponentInstruction } from 'angular2/router';
5 5
6// TODO import it with systemjs
6declare var WebTorrent: any; 7declare var WebTorrent: any;
7 8
8import { Video } from '../../models/video'; 9import { Video } from '../../models/video';
@@ -14,7 +15,7 @@ import { VideosService } from '../../services/videos.service';
14 styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ] 15 styleUrls: [ 'app/angular/videos/components/watch/videos-watch.component.css' ]
15}) 16})
16 17
17export class VideosWatchComponent { 18export class VideosWatchComponent implements OnInit, CanDeactivate {
18 video: Video; 19 video: Video;
19 20
20 private client: any; 21 private client: any;
@@ -24,6 +25,7 @@ export class VideosWatchComponent {
24 private _routeParams: RouteParams, 25 private _routeParams: RouteParams,
25 private _elementRef: ElementRef 26 private _elementRef: ElementRef
26 ) { 27 ) {
28 // TODO: use a service
27 this.client = new WebTorrent({ dht: false }); 29 this.client = new WebTorrent({ dht: false });
28 } 30 }
29 31
@@ -47,4 +49,10 @@ export class VideosWatchComponent {
47 }) 49 })
48 }) 50 })
49 } 51 }
52
53 routerCanDeactivate(next: ComponentInstruction, prev: ComponentInstruction) : any {
54 console.log('Removing video from webtorrent.');
55 this.client.remove(this.video.magnetUri);
56 return true;
57 }
50} 58}