]>
Commit | Line | Data |
---|---|---|
44124980 | 1 | import { Component, ElementRef, OnInit } from 'angular2/core'; |
98b01bac | 2 | import { Router } from 'angular2/router'; |
dc8bc31b | 3 | |
98b01bac | 4 | // TODO: import it with systemjs |
dc8bc31b C |
5 | declare var jQuery:any; |
6 | ||
7 | @Component({ | |
8 | selector: 'my-videos-add', | |
9 | styleUrls: [ 'app/angular/videos/components/add/videos-add.component.css' ], | |
10 | templateUrl: 'app/angular/videos/components/add/videos-add.component.html' | |
11 | }) | |
12 | ||
13 | export class VideosAddComponent implements OnInit { | |
14 | fileToUpload: any; | |
15 | progressBar: { value: number; max: number; } = { value: 0, max: 0 }; | |
16 | ||
17 | private _form: any; | |
18 | ||
19 | constructor(private _router: Router, private _elementRef: ElementRef) {} | |
20 | ||
21 | ngOnInit() { | |
8c9c1942 | 22 | jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({ |
98b01bac C |
23 | url: '/api/v1/videos', |
24 | dataType: 'json', | |
dc8bc31b C |
25 | singleFileUploads: true, |
26 | multipart: true, | |
dc8bc31b C |
27 | autoupload: false, |
28 | ||
29 | add: (e, data) => { | |
30 | this._form = data; | |
31 | this.fileToUpload = data['files'][0]; | |
32 | }, | |
33 | ||
34 | progressall: (e, data) => { | |
35 | this.progressBar.value = data.loaded; | |
86e054b2 C |
36 | // The server is a little bit slow to answer (has to seed the video) |
37 | // So we add more time to the progress bar (+10%) | |
38 | this.progressBar.max = data.total + (0.1 * data.total); | |
dc8bc31b C |
39 | }, |
40 | ||
41 | done: (e, data) => { | |
86e054b2 | 42 | this.progressBar.value = this.progressBar.max; |
98b01bac C |
43 | console.log('Video uploaded.'); |
44 | ||
dc8bc31b C |
45 | // Print all the videos once it's finished |
46 | this._router.navigate(['VideosList']); | |
47 | } | |
48 | }); | |
49 | } | |
50 | ||
51 | uploadFile() { | |
52 | this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray(); | |
53 | this._form.submit(); | |
54 | } | |
55 | } |