1 import { Component, ElementRef, OnInit } from '@angular/core';
2 import { Router } from '@angular/router-deprecated';
4 import { AuthService } from '../../../users/services/auth.service';
5 import { User } from '../../../users/models/user';
7 // TODO: import it with systemjs
8 declare var jQuery:any;
11 selector: 'my-videos-add',
12 styleUrls: [ 'app/angular/videos/components/add/videos-add.component.css' ],
13 templateUrl: 'app/angular/videos/components/add/videos-add.component.html'
16 export class VideosAddComponent implements OnInit {
19 progressBar: { value: number; max: number; } = { value: 0, max: 0 };
24 private _router: Router, private _elementRef: ElementRef,
25 private _authService: AuthService
29 this.user = User.load();
30 jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
31 url: '/api/v1/videos',
33 singleFileUploads: true,
39 this.fileToUpload = data['files'][0];
42 progressall: (e, data) => {
43 this.progressBar.value = data.loaded;
44 // The server is a little bit slow to answer (has to seed the video)
45 // So we add more time to the progress bar (+10%)
46 this.progressBar.max = data.total + (0.1 * data.total);
50 this.progressBar.value = this.progressBar.max;
51 console.log('Video uploaded.');
53 // Print all the videos once it's finished
54 this._router.navigate(['VideosList']);
60 this._form.headers = this._authService.getRequestHeader().toJSON();
61 this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();