From dc8bc31be517a53e8fbe7100cfe45cd73f596de0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 14 Mar 2016 13:50:19 +0100 Subject: Angular application :first draft --- .../videos/components/add/videos-add.component.ts | 52 ++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 client/angular/videos/components/add/videos-add.component.ts (limited to 'client/angular/videos/components/add/videos-add.component.ts') diff --git a/client/angular/videos/components/add/videos-add.component.ts b/client/angular/videos/components/add/videos-add.component.ts new file mode 100644 index 000000000..97e3bb3b5 --- /dev/null +++ b/client/angular/videos/components/add/videos-add.component.ts @@ -0,0 +1,52 @@ +import {Component, ElementRef, Inject, OnInit} from 'angular2/core'; +import {Router} from 'angular2/router'; +import {NgForm} from 'angular2/common'; + +import {Video} from '../../models/video'; + +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 { + fileToUpload: any; + progressBar: { value: number; max: number; } = { value: 0, max: 0 }; + + private _form: any; + + constructor(private _router: Router, private _elementRef: ElementRef) {} + + ngOnInit() { + jQuery(this._elementRef.nativeElement).find('#input_video').fileupload({ + singleFileUploads: true, + multipart: true, + url: '/api/v1/videos', + autoupload: false, + + add: (e, data) => { + this._form = data; + this.fileToUpload = data['files'][0]; + }, + + progressall: (e, data) => { + this.progressBar.value = data.loaded; + this.progressBar.max= data.total; + }, + + done: (e, data) => { + console.log('finished'); + // Print all the videos once it's finished + this._router.navigate(['VideosList']); + } + }); + } + + uploadFile() { + this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray(); + this._form.submit(); + } +} -- cgit v1.2.3