]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/angular/videos/components/add/videos-add.component.ts
Add pagination support to the client
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / add / videos-add.component.ts
index 8ff6cfec87db6f350f9ca3e2dd33b761419102b8..f801cecbb1075ced77aaa5ba1de6e731d4d977f2 100644 (file)
@@ -1,8 +1,8 @@
-import { Component, ElementRef, Inject, OnInit } from 'angular2/core';
-import { Router } from 'angular2/router';
-import { NgForm } from 'angular2/common';
+import { Component, ElementRef, OnInit } from '@angular/core';
+import { Router } from '@angular/router-deprecated';
 
-import { Video } from '../../models/video';
+import { AuthService } from '../../../users/services/auth.service';
+import { User } from '../../../users/models/user';
 
 // TODO: import it with systemjs
 declare var jQuery:any;
@@ -14,15 +14,20 @@ declare var jQuery:any;
 })
 
 export class VideosAddComponent implements OnInit {
+  user: User;
   fileToUpload: any;
   progressBar: { value: number; max: number; } = { value: 0, max: 0 };
 
   private _form: any;
 
-  constructor(private _router: Router, private _elementRef: ElementRef) {}
+  constructor(
+    private _router: Router, private _elementRef: ElementRef,
+    private _authService: AuthService
+  ) {}
 
   ngOnInit() {
-    jQuery(this._elementRef.nativeElement).find('#input_video').fileupload({
+    this.user = User.load();
+    jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
       url: '/api/v1/videos',
       dataType: 'json',
       singleFileUploads: true,
@@ -36,10 +41,13 @@ export class VideosAddComponent implements OnInit {
 
       progressall: (e, data) => {
         this.progressBar.value = data.loaded;
-        this.progressBar.max= data.total;
+        // The server is a little bit slow to answer (has to seed the video)
+        // So we add more time to the progress bar (+10%)
+        this.progressBar.max = data.total + (0.1 * data.total);
       },
 
       done: (e, data) => {
+        this.progressBar.value = this.progressBar.max;
         console.log('Video uploaded.');
 
         // Print all the videos once it's finished
@@ -49,6 +57,7 @@ export class VideosAddComponent implements OnInit {
   }
 
   uploadFile() {
+    this._form.headers = this._authService.getRequestHeader().toJSON();
     this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();
     this._form.submit();
   }