1 import { Component, ElementRef, OnInit } from '@angular/core';
2 import { Router } from '@angular/router-deprecated';
4 import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
5 import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar';
7 import { AuthService, User } from '../../users/index';
9 // TODO: import it with systemjs
10 declare var jQuery:any;
13 selector: 'my-videos-add',
14 styleUrls: [ 'client/app/videos/video-add/video-add.component.css' ],
15 templateUrl: 'client/app/videos/video-add/video-add.component.html',
16 directives: [ PROGRESSBAR_DIRECTIVES ],
20 export class VideoAddComponent implements OnInit {
23 progressBar: { value: number; max: number; } = { value: 0, max: 0 };
28 private _router: Router, private _elementRef: ElementRef,
29 private _authService: AuthService
33 this.user = User.load();
34 jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
35 url: '/api/v1/videos',
37 singleFileUploads: true,
43 this.fileToUpload = data['files'][0];
46 progressall: (e, data) => {
47 this.progressBar.value = data.loaded;
48 // The server is a little bit slow to answer (has to seed the video)
49 // So we add more time to the progress bar (+10%)
50 this.progressBar.max = data.total + (0.1 * data.total);
54 this.progressBar.value = this.progressBar.max;
55 console.log('Video uploaded.');
57 // Print all the videos once it's finished
58 this._router.navigate(['VideosList']);
64 this._form.headers = this._authService.getRequestHeader().toJSON();
65 this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();