diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-03-14 13:50:19 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-03-14 13:50:19 +0100 |
commit | dc8bc31be517a53e8fbe7100cfe45cd73f596de0 (patch) | |
tree | c0b0d6641dd352dafff93b8fd33ddb262b59aa47 /client/angular/videos/components/add | |
parent | bd324a669218f9ed302f7f54b36ee535d25c9733 (diff) | |
download | PeerTube-dc8bc31be517a53e8fbe7100cfe45cd73f596de0.tar.gz PeerTube-dc8bc31be517a53e8fbe7100cfe45cd73f596de0.tar.zst PeerTube-dc8bc31be517a53e8fbe7100cfe45cd73f596de0.zip |
Angular application :first draft
Diffstat (limited to 'client/angular/videos/components/add')
3 files changed, 116 insertions, 0 deletions
diff --git a/client/angular/videos/components/add/videos-add.component.html b/client/angular/videos/components/add/videos-add.component.html new file mode 100644 index 000000000..5f28ae650 --- /dev/null +++ b/client/angular/videos/components/add/videos-add.component.html | |||
@@ -0,0 +1,39 @@ | |||
1 | <h3>Upload a video</h3> | ||
2 | |||
3 | <form (ngSubmit)="uploadFile()" #videoForm="ngForm"> | ||
4 | <div class="form-group"> | ||
5 | <label for="name">Video name</label> | ||
6 | <input | ||
7 | type="text" class="form-control" name="name" id="name" required | ||
8 | ngControl="name" #name="ngForm" | ||
9 | > | ||
10 | <div [hidden]="name.valid || name.pristine" class="alert alert-danger"> | ||
11 | Name is required | ||
12 | </div> | ||
13 | </div> | ||
14 | |||
15 | <div class="btn btn-default btn-file"> | ||
16 | <span>Select the video...</span> | ||
17 | <input type="file" name="input_video" id="input_video"> | ||
18 | </div> | ||
19 | |||
20 | <span *ngIf="fileToUpload">{{ fileToUpload.name }}</span> | ||
21 | |||
22 | <div class="form-group"> | ||
23 | <label for="description">Description</label> | ||
24 | <textarea | ||
25 | name="description" id="description" class="form-control" placeholder="Description..." required | ||
26 | ngControl="description" #description="ngForm" | ||
27 | > | ||
28 | </textarea> | ||
29 | <div [hidden]="description.valid || description.pristine" class="alert alert-danger"> | ||
30 | A description is required | ||
31 | </div> | ||
32 | </div> | ||
33 | |||
34 | <div id="progress" *ngIf="progressBar.max !== 0"> | ||
35 | <progress [value]="progressBar.value" [max]="progressBar.max"></progress> | ||
36 | </div> | ||
37 | |||
38 | <input type="submit" value="Upload" class="btn btn-default" [disabled]="!videoForm.form.valid || !fileToUpload"> | ||
39 | </form> | ||
diff --git a/client/angular/videos/components/add/videos-add.component.scss b/client/angular/videos/components/add/videos-add.component.scss new file mode 100644 index 000000000..f4187088b --- /dev/null +++ b/client/angular/videos/components/add/videos-add.component.scss | |||
@@ -0,0 +1,25 @@ | |||
1 | .btn-file { | ||
2 | position: relative; | ||
3 | overflow: hidden; | ||
4 | } | ||
5 | |||
6 | .btn-file input[type=file] { | ||
7 | position: absolute; | ||
8 | top: 0; | ||
9 | right: 0; | ||
10 | min-width: 100%; | ||
11 | min-height: 100%; | ||
12 | font-size: 100px; | ||
13 | text-align: right; | ||
14 | filter: alpha(opacity=0); | ||
15 | opacity: 0; | ||
16 | outline: none; | ||
17 | background: white; | ||
18 | cursor: inherit; | ||
19 | display: block; | ||
20 | } | ||
21 | |||
22 | .name_file { | ||
23 | display: inline-block; | ||
24 | margin-left: 10px; | ||
25 | } | ||
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 @@ | |||
1 | import {Component, ElementRef, Inject, OnInit} from 'angular2/core'; | ||
2 | import {Router} from 'angular2/router'; | ||
3 | import {NgForm} from 'angular2/common'; | ||
4 | |||
5 | import {Video} from '../../models/video'; | ||
6 | |||
7 | declare var jQuery:any; | ||
8 | |||
9 | @Component({ | ||
10 | selector: 'my-videos-add', | ||
11 | styleUrls: [ 'app/angular/videos/components/add/videos-add.component.css' ], | ||
12 | templateUrl: 'app/angular/videos/components/add/videos-add.component.html' | ||
13 | }) | ||
14 | |||
15 | export class VideosAddComponent implements OnInit { | ||
16 | fileToUpload: any; | ||
17 | progressBar: { value: number; max: number; } = { value: 0, max: 0 }; | ||
18 | |||
19 | private _form: any; | ||
20 | |||
21 | constructor(private _router: Router, private _elementRef: ElementRef) {} | ||
22 | |||
23 | ngOnInit() { | ||
24 | jQuery(this._elementRef.nativeElement).find('#input_video').fileupload({ | ||
25 | singleFileUploads: true, | ||
26 | multipart: true, | ||
27 | url: '/api/v1/videos', | ||
28 | autoupload: false, | ||
29 | |||
30 | add: (e, data) => { | ||
31 | this._form = data; | ||
32 | this.fileToUpload = data['files'][0]; | ||
33 | }, | ||
34 | |||
35 | progressall: (e, data) => { | ||
36 | this.progressBar.value = data.loaded; | ||
37 | this.progressBar.max= data.total; | ||
38 | }, | ||
39 | |||
40 | done: (e, data) => { | ||
41 | console.log('finished'); | ||
42 | // Print all the videos once it's finished | ||
43 | this._router.navigate(['VideosList']); | ||
44 | } | ||
45 | }); | ||
46 | } | ||
47 | |||
48 | uploadFile() { | ||
49 | this._form.formData = jQuery(this._elementRef.nativeElement).find('form').serializeArray(); | ||
50 | this._form.submit(); | ||
51 | } | ||
52 | } | ||