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