]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/angular/videos/components/add/videos-add.component.ts
Only display "upload video" in the menu if the user is logged in
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / add / videos-add.component.ts
1 import { Component, ElementRef, Inject, OnInit } from 'angular2/core';
2 import { Router } from 'angular2/router';
3 import { NgForm } from 'angular2/common';
4
5 import { Video } from '../../models/video';
6
7 // TODO: import it with systemjs
8 declare var jQuery:any;
9
10 @Component({
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'
14 })
15
16 export class VideosAddComponent implements OnInit {
17 fileToUpload: any;
18 progressBar: { value: number; max: number; } = { value: 0, max: 0 };
19
20 private _form: any;
21
22 constructor(private _router: Router, private _elementRef: ElementRef) {}
23
24 ngOnInit() {
25 jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
26 url: '/api/v1/videos',
27 dataType: 'json',
28 singleFileUploads: true,
29 multipart: true,
30 autoupload: false,
31
32 add: (e, data) => {
33 this._form = data;
34 this.fileToUpload = data['files'][0];
35 },
36
37 progressall: (e, data) => {
38 this.progressBar.value = data.loaded;
39 // The server is a little bit slow to answer (has to seed the video)
40 // So we add more time to the progress bar (+10%)
41 this.progressBar.max = data.total + (0.1 * data.total);
42 },
43
44 done: (e, data) => {
45 this.progressBar.value = this.progressBar.max;
46 console.log('Video uploaded.');
47
48 // Print all the videos once it's finished
49 this._router.navigate(['VideosList']);
50 }
51 });
52 }
53
54 uploadFile() {
55 this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();
56 this._form.submit();
57 }
58 }