2016-04-08 14:58:07 -04:00
|
|
|
import { Component, ElementRef, OnInit } from 'angular2/core';
|
2016-03-14 17:16:43 -04:00
|
|
|
import { Router } from 'angular2/router';
|
2016-03-14 08:50:19 -04:00
|
|
|
|
2016-04-14 16:07:46 -04:00
|
|
|
import { AuthService } from '../../../users/services/auth.service';
|
|
|
|
import { User } from '../../../users/models/user';
|
|
|
|
|
2016-03-14 17:16:43 -04:00
|
|
|
// TODO: import it with systemjs
|
2016-03-14 08:50:19 -04:00
|
|
|
declare var jQuery:any;
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'my-videos-add',
|
|
|
|
styleUrls: [ 'app/angular/videos/components/add/videos-add.component.css' ],
|
|
|
|
templateUrl: 'app/angular/videos/components/add/videos-add.component.html'
|
|
|
|
})
|
|
|
|
|
|
|
|
export class VideosAddComponent implements OnInit {
|
2016-04-14 16:07:46 -04:00
|
|
|
user: User;
|
2016-03-14 08:50:19 -04:00
|
|
|
fileToUpload: any;
|
|
|
|
progressBar: { value: number; max: number; } = { value: 0, max: 0 };
|
|
|
|
|
|
|
|
private _form: any;
|
|
|
|
|
2016-04-14 16:07:46 -04:00
|
|
|
constructor(
|
|
|
|
private _router: Router, private _elementRef: ElementRef,
|
|
|
|
private _authService: AuthService
|
|
|
|
) {}
|
2016-03-14 08:50:19 -04:00
|
|
|
|
|
|
|
ngOnInit() {
|
2016-04-14 16:07:46 -04:00
|
|
|
this.user = User.load();
|
2016-03-18 11:44:54 -04:00
|
|
|
jQuery(this._elementRef.nativeElement).find('#videofile').fileupload({
|
2016-03-14 17:16:43 -04:00
|
|
|
url: '/api/v1/videos',
|
|
|
|
dataType: 'json',
|
2016-03-14 08:50:19 -04:00
|
|
|
singleFileUploads: true,
|
|
|
|
multipart: true,
|
|
|
|
autoupload: false,
|
|
|
|
|
|
|
|
add: (e, data) => {
|
|
|
|
this._form = data;
|
|
|
|
this.fileToUpload = data['files'][0];
|
|
|
|
},
|
|
|
|
|
|
|
|
progressall: (e, data) => {
|
|
|
|
this.progressBar.value = data.loaded;
|
2016-03-16 16:22:21 -04:00
|
|
|
// 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);
|
2016-03-14 08:50:19 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
done: (e, data) => {
|
2016-03-16 16:22:21 -04:00
|
|
|
this.progressBar.value = this.progressBar.max;
|
2016-03-14 17:16:43 -04:00
|
|
|
console.log('Video uploaded.');
|
|
|
|
|
2016-03-14 08:50:19 -04:00
|
|
|
// Print all the videos once it's finished
|
|
|
|
this._router.navigate(['VideosList']);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
uploadFile() {
|
2016-04-14 16:07:46 -04:00
|
|
|
this._form.headers = this._authService.getRequestHeader().toJSON();
|
2016-03-14 08:50:19 -04:00
|
|
|
this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray();
|
|
|
|
this._form.submit();
|
|
|
|
}
|
|
|
|
}
|