From 4a6995be18b15de1834a39c8921a0e4109671bb6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 3 Jun 2016 22:08:03 +0200 Subject: First draft to use webpack instead of systemjs --- client/src/app/videos/video-add/index.ts | 1 + .../app/videos/video-add/video-add.component.html | 41 +++++++++++++ .../app/videos/video-add/video-add.component.scss | 33 +++++++++++ .../app/videos/video-add/video-add.component.ts | 69 ++++++++++++++++++++++ 4 files changed, 144 insertions(+) create mode 100644 client/src/app/videos/video-add/index.ts create mode 100644 client/src/app/videos/video-add/video-add.component.html create mode 100644 client/src/app/videos/video-add/video-add.component.scss create mode 100644 client/src/app/videos/video-add/video-add.component.ts (limited to 'client/src/app/videos/video-add') diff --git a/client/src/app/videos/video-add/index.ts b/client/src/app/videos/video-add/index.ts new file mode 100644 index 000000000..79488e851 --- /dev/null +++ b/client/src/app/videos/video-add/index.ts @@ -0,0 +1 @@ +export * from './video-add.component'; diff --git a/client/src/app/videos/video-add/video-add.component.html b/client/src/app/videos/video-add/video-add.component.html new file mode 100644 index 000000000..80d229cb8 --- /dev/null +++ b/client/src/app/videos/video-add/video-add.component.html @@ -0,0 +1,41 @@ +

Upload a video

+ +
+
+ + +
+ Name is required +
+
+ +
+
+ Select the video... + +
+ + {{ fileToUpload.name }} +
+ +
+ + +
+ A description is required +
+
+ +
+ {{ progressBar.value | bytes }} / {{ progressBar.max | bytes }} +
+ + +
diff --git a/client/src/app/videos/video-add/video-add.component.scss b/client/src/app/videos/video-add/video-add.component.scss new file mode 100644 index 000000000..01195f017 --- /dev/null +++ b/client/src/app/videos/video-add/video-add.component.scss @@ -0,0 +1,33 @@ +.btn-file { + position: relative; + overflow: hidden; +} + +.btn-file input[type=file] { + position: absolute; + top: 0; + right: 0; + min-width: 100%; + min-height: 100%; + font-size: 100px; + text-align: right; + filter: alpha(opacity=0); + opacity: 0; + outline: none; + background: white; + cursor: inherit; + display: block; +} + +.name_file { + display: inline-block; + margin-left: 10px; +} + +.form-group { + margin-bottom: 10px; +} + +#progress { + margin-bottom: 10px; +} diff --git a/client/src/app/videos/video-add/video-add.component.ts b/client/src/app/videos/video-add/video-add.component.ts new file mode 100644 index 000000000..8df4f951b --- /dev/null +++ b/client/src/app/videos/video-add/video-add.component.ts @@ -0,0 +1,69 @@ +/// +/// + +import { Component, ElementRef, OnInit } from '@angular/core'; +import { Router } from '@angular/router-deprecated'; + +import { BytesPipe } from 'angular-pipes/src/math/bytes.pipe'; +import { PROGRESSBAR_DIRECTIVES } from 'ng2-bootstrap/components/progressbar'; + +import { AuthService, User } from '../../shared'; + +@Component({ + selector: 'my-videos-add', + styles: [ require('./video-add.component.scss') ], + template: require('./video-add.component.html'), + directives: [ PROGRESSBAR_DIRECTIVES ], + pipes: [ BytesPipe ] +}) + +export class VideoAddComponent implements OnInit { + fileToUpload: any; + progressBar: { value: number; max: number; } = { value: 0, max: 0 }; + user: User; + + private form: any; + + constructor( + private authService: AuthService, + private elementRef: ElementRef, + private router: Router + ) {} + + ngOnInit() { + this.user = User.load(); + jQuery(this.elementRef.nativeElement).find('#videofile').fileupload({ + url: '/api/v1/videos', + dataType: 'json', + 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; + // 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 + this.router.navigate(['VideosList']); + } + }); + } + + uploadFile() { + this.form.formData = jQuery(this.elementRef.nativeElement).find('form').serializeArray(); + this.form.headers = this.authService.getRequestHeader().toJSON(); + this.form.submit(); + } +} -- cgit v1.2.3