]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/angular/videos/components/add/videos-add.component.ts
Update to standard 7. Goodbye snake_case, I used to love you
[github/Chocobozzz/PeerTube.git] / client / angular / videos / components / add / videos-add.component.ts
CommitLineData
44124980 1import { Component, ElementRef, OnInit } from 'angular2/core';
98b01bac 2import { Router } from 'angular2/router';
dc8bc31b 3
1553e15d
C
4import { AuthService } from '../../../users/services/auth.service';
5import { User } from '../../../users/models/user';
6
98b01bac 7// TODO: import it with systemjs
dc8bc31b
C
8declare 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
16export class VideosAddComponent implements OnInit {
1553e15d 17 user: User;
dc8bc31b
C
18 fileToUpload: any;
19 progressBar: { value: number; max: number; } = { value: 0, max: 0 };
20
21 private _form: any;
22
1553e15d
C
23 constructor(
24 private _router: Router, private _elementRef: ElementRef,
25 private _authService: AuthService
26 ) {}
dc8bc31b
C
27
28 ngOnInit() {
1553e15d 29 this.user = User.load();
8c9c1942 30 jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
98b01bac
C
31 url: '/api/v1/videos',
32 dataType: 'json',
dc8bc31b
C
33 singleFileUploads: true,
34 multipart: true,
dc8bc31b
C
35 autoupload: false,
36
37 add: (e, data) => {
38 this._form = data;
39 this.fileToUpload = data['files'][0];
40 },
41
42 progressall: (e, data) => {
43 this.progressBar.value = data.loaded;
86e054b2
C
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);
dc8bc31b
C
47 },
48
49 done: (e, data) => {
86e054b2 50 this.progressBar.value = this.progressBar.max;
98b01bac
C
51 console.log('Video uploaded.');
52
dc8bc31b
C
53 // Print all the videos once it's finished
54 this._router.navigate(['VideosList']);
55 }
56 });
57 }
58
59 uploadFile() {
1553e15d 60 this._form.headers = this._authService.getRequestHeader().toJSON();
dc8bc31b
C
61 this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();
62 this._form.submit();
63 }
64}