1 /// <reference path="../../../../typings/globals/jquery/index.d.ts" />
2 /// <reference path="../../../../typings/globals/jquery.fileupload/index.d.ts" />
4 import { Component, ElementRef, OnInit } from '@angular/core';
5 import { Router } from '@angular/router-deprecated';
7 import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe';
8 import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar';
10 import { AuthService, User } from '../../shared';
13 selector: 'my-videos-add',
14 styles: [ require('./video-add.component.scss') ],
15 template: require('./video-add.component.html'),
16 directives: [ PROGRESSBAR_DIRECTIVES ],
20 export class VideoAddComponent implements OnInit {
23 progressBar: { value: number; max: number; } = { value: 0, max: 0 };
29 private authService: AuthService,
30 private elementRef: ElementRef,
31 private router: Router
35 this.user = User.load();
36 jQuery(this.elementRef.nativeElement).find('#videofile').fileupload({
37 url: '/api/v1/videos',
39 singleFileUploads: true,
45 this.fileToUpload = data['files'][0];
48 progressall: (e, data) => {
49 this.progressBar.value = data.loaded;
50 // The server is a little bit slow to answer (has to seed the video)
51 // So we add more time to the progress bar (+10%)
52 this.progressBar.max = data.total + (0.1 * data.total);
56 this.progressBar.value = this.progressBar.max;
57 console.log('Video uploaded.');
59 // Print all the videos once it's finished
60 this.router.navigate(['VideosList']);
64 const xhr = data.jqXHR;
65 if (xhr.status === 400) {
66 this.error = xhr.responseText;
68 this.error = 'Unknow error';
78 this.form.formData = jQuery(this.elementRef.nativeElement).find('form').serializeArray();
79 this.form.headers = this.authService.getRequestHeader().toJSON();