From 41a2aee38cf812510010da09de9bae53590ec119 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 27 May 2016 16:23:10 +0200 Subject: Follow the angular styleguide for the directories structure --- client/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 +++++++++++ client/app/videos/video-add/video-add.component.ts | 68 ++++++++++++++++++++++ 4 files changed, 143 insertions(+) create mode 100644 client/app/videos/video-add/index.ts create mode 100644 client/app/videos/video-add/video-add.component.html create mode 100644 client/app/videos/video-add/video-add.component.scss create mode 100644 client/app/videos/video-add/video-add.component.ts (limited to 'client/app/videos/video-add') diff --git a/client/app/videos/video-add/index.ts b/client/app/videos/video-add/index.ts new file mode 100644 index 000000000..79488e851 --- /dev/null +++ b/client/app/videos/video-add/index.ts @@ -0,0 +1 @@ +export * from './video-add.component'; diff --git a/client/app/videos/video-add/video-add.component.html b/client/app/videos/video-add/video-add.component.html new file mode 100644 index 000000000..80d229cb8 --- /dev/null +++ b/client/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/app/videos/video-add/video-add.component.scss b/client/app/videos/video-add/video-add.component.scss new file mode 100644 index 000000000..01195f017 --- /dev/null +++ b/client/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/app/videos/video-add/video-add.component.ts b/client/app/videos/video-add/video-add.component.ts new file mode 100644 index 000000000..ca583a103 --- /dev/null +++ b/client/app/videos/video-add/video-add.component.ts @@ -0,0 +1,68 @@ +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 '../../users/index'; + +// TODO: import it with systemjs +declare var jQuery:any; + +@Component({ + selector: 'my-videos-add', + styleUrls: [ 'client/app/videos/video-add/video-add.component.css' ], + templateUrl: 'client/app/videos/video-add/video-add.component.html', + directives: [ PROGRESSBAR_DIRECTIVES ], + pipes: [ BytesPipe ] +}) + +export class VideoAddComponent implements OnInit { + user: User; + fileToUpload: any; + progressBar: { value: number; max: number; } = { value: 0, max: 0 }; + + private _form: any; + + constructor( + private _router: Router, private _elementRef: ElementRef, + private _authService: AuthService + ) {} + + 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.headers = this._authService.getRequestHeader().toJSON(); + this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray(); + this._form.submit(); + } +} -- cgit v1.2.3