diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2017-04-10 21:15:28 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2017-04-10 21:16:36 +0200 |
commit | d8e689b864749648d03cf4391fd4a475126f01cd (patch) | |
tree | 299713e3c056873ba6fff5247b8f49a542f0bf45 /client/src/app/videos/video-add | |
parent | a184c71b526000f60f00649d260638723d426e6a (diff) | |
download | PeerTube-d8e689b864749648d03cf4391fd4a475126f01cd.tar.gz PeerTube-d8e689b864749648d03cf4391fd4a475126f01cd.tar.zst PeerTube-d8e689b864749648d03cf4391fd4a475126f01cd.zip |
Client: add basic support for updating a video
Diffstat (limited to 'client/src/app/videos/video-add')
-rw-r--r-- | client/src/app/videos/video-add/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/videos/video-add/video-add.component.html | 128 | ||||
-rw-r--r-- | client/src/app/videos/video-add/video-add.component.scss | 57 | ||||
-rw-r--r-- | client/src/app/videos/video-add/video-add.component.ts | 230 |
4 files changed, 0 insertions, 416 deletions
diff --git a/client/src/app/videos/video-add/index.ts b/client/src/app/videos/video-add/index.ts deleted file mode 100644 index 79488e851..000000000 --- a/client/src/app/videos/video-add/index.ts +++ /dev/null | |||
@@ -1 +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 deleted file mode 100644 index 104747a8c..000000000 --- a/client/src/app/videos/video-add/video-add.component.html +++ /dev/null | |||
@@ -1,128 +0,0 @@ | |||
1 | <h3>Upload a video</h3> | ||
2 | |||
3 | <div *ngIf="error" class="alert alert-danger">{{ error }}</div> | ||
4 | |||
5 | <form novalidate [formGroup]="form"> | ||
6 | <div class="form-group"> | ||
7 | <label for="name">Name</label> | ||
8 | <input | ||
9 | type="text" class="form-control" id="name" | ||
10 | formControlName="name" | ||
11 | > | ||
12 | <div *ngIf="formErrors.name" class="alert alert-danger"> | ||
13 | {{ formErrors.name }} | ||
14 | </div> | ||
15 | </div> | ||
16 | |||
17 | <div class="form-group"> | ||
18 | <label for="nsfw">NSFW</label> | ||
19 | <input | ||
20 | type="checkbox" id="nsfw" | ||
21 | formControlName="nsfw" | ||
22 | > | ||
23 | </div> | ||
24 | |||
25 | <div class="form-group"> | ||
26 | <label for="category">Category</label> | ||
27 | <select class="form-control" id="category" formControlName="category"> | ||
28 | <option></option> | ||
29 | <option *ngFor="let category of videoCategories" [value]="category.id">{{ category.label }}</option> | ||
30 | </select> | ||
31 | |||
32 | <div *ngIf="formErrors.category" class="alert alert-danger"> | ||
33 | {{ formErrors.category }} | ||
34 | </div> | ||
35 | </div> | ||
36 | |||
37 | <div class="form-group"> | ||
38 | <label for="licence">Licence</label> | ||
39 | <select class="form-control" id="licence" formControlName="licence"> | ||
40 | <option></option> | ||
41 | <option *ngFor="let licence of videoLicences" [value]="licence.id">{{ licence.label }}</option> | ||
42 | </select> | ||
43 | |||
44 | <div *ngIf="formErrors.licence" class="alert alert-danger"> | ||
45 | {{ formErrors.licence }} | ||
46 | </div> | ||
47 | </div> | ||
48 | |||
49 | <div class="form-group"> | ||
50 | <label for="language">Language</label> | ||
51 | <select class="form-control" id="language" formControlName="language"> | ||
52 | <option></option> | ||
53 | <option *ngFor="let language of videoLanguages" [value]="language.id">{{ language.label }}</option> | ||
54 | </select> | ||
55 | |||
56 | <div *ngIf="formErrors.language" class="alert alert-danger"> | ||
57 | {{ formErrors.language }} | ||
58 | </div> | ||
59 | </div> | ||
60 | |||
61 | <div class="form-group"> | ||
62 | <label for="tags">Tags</label> <span class="little-information">(press enter to add the tag)</span> | ||
63 | <input | ||
64 | type="text" class="form-control" id="currentTag" | ||
65 | formControlName="currentTag" (keyup)="onTagKeyPress($event)" | ||
66 | > | ||
67 | <div *ngIf="formErrors.currentTag" class="alert alert-danger"> | ||
68 | {{ formErrors.currentTag }} | ||
69 | </div> | ||
70 | </div> | ||
71 | |||
72 | <div class="tags"> | ||
73 | <div class="label label-primary tag" *ngFor="let tag of tags"> | ||
74 | {{ tag }} | ||
75 | <span class="remove" (click)="removeTag(tag)">x</span> | ||
76 | </div> | ||
77 | </div> | ||
78 | |||
79 | <div *ngIf="tagsError" class="alert alert-danger"> | ||
80 | {{ tagsError }} | ||
81 | </div> | ||
82 | |||
83 | <div class="form-group"> | ||
84 | <label for="videofile">File</label> | ||
85 | <div class="btn btn-default btn-file" [ngClass]="{ 'disabled': filename !== null }" > | ||
86 | <span>Select the video...</span> | ||
87 | <input | ||
88 | type="file" name="videofile" id="videofile" | ||
89 | ng2FileSelect [uploader]="uploader" [disabled]="filename !== null" | ||
90 | (change)="fileChanged()" | ||
91 | > | ||
92 | </div> | ||
93 | </div> | ||
94 | |||
95 | <div class="file-to-upload"> | ||
96 | <div class="file" *ngIf="uploader.queue.length > 0"> | ||
97 | <span class="filename">{{ filename }}</span> | ||
98 | <span class="glyphicon glyphicon-remove" (click)="removeFile()"></span> | ||
99 | </div> | ||
100 | </div> | ||
101 | |||
102 | <div *ngIf="fileError" class="alert alert-danger"> | ||
103 | {{ fileError }} | ||
104 | </div> | ||
105 | |||
106 | <div class="form-group"> | ||
107 | <label for="description">Description</label> | ||
108 | <textarea | ||
109 | id="description" class="form-control" placeholder="Description..." | ||
110 | formControlName="description" | ||
111 | > | ||
112 | </textarea> | ||
113 | <div *ngIf="formErrors.description" class="alert alert-danger"> | ||
114 | {{ formErrors.description }} | ||
115 | </div> | ||
116 | </div> | ||
117 | |||
118 | <div class="progress"> | ||
119 | <progressbar [value]="uploader.progress" max="100"></progressbar> | ||
120 | </div> | ||
121 | |||
122 | <div class="form-group"> | ||
123 | <input | ||
124 | type="button" value="Upload" class="btn btn-default form-control" | ||
125 | (click)="upload()" | ||
126 | > | ||
127 | </div> | ||
128 | </form> | ||
diff --git a/client/src/app/videos/video-add/video-add.component.scss b/client/src/app/videos/video-add/video-add.component.scss deleted file mode 100644 index 11ee3297e..000000000 --- a/client/src/app/videos/video-add/video-add.component.scss +++ /dev/null | |||
@@ -1,57 +0,0 @@ | |||
1 | .btn-file { | ||
2 | position: relative; | ||
3 | overflow: hidden; | ||
4 | display: block; | ||
5 | } | ||
6 | |||
7 | .btn-file input[type=file] { | ||
8 | position: absolute; | ||
9 | top: 0; | ||
10 | right: 0; | ||
11 | min-width: 100%; | ||
12 | min-height: 100%; | ||
13 | font-size: 100px; | ||
14 | text-align: right; | ||
15 | filter: alpha(opacity=0); | ||
16 | opacity: 0; | ||
17 | outline: none; | ||
18 | background: white; | ||
19 | cursor: inherit; | ||
20 | display: block; | ||
21 | } | ||
22 | |||
23 | .name_file { | ||
24 | display: inline-block; | ||
25 | margin-left: 10px; | ||
26 | } | ||
27 | |||
28 | .form-group { | ||
29 | margin-bottom: 10px; | ||
30 | } | ||
31 | |||
32 | div.tags { | ||
33 | height: 40px; | ||
34 | font-size: 20px; | ||
35 | margin-top: 20px; | ||
36 | |||
37 | .tag { | ||
38 | margin-right: 10px; | ||
39 | |||
40 | .remove { | ||
41 | cursor: pointer; | ||
42 | } | ||
43 | } | ||
44 | } | ||
45 | |||
46 | div.file-to-upload { | ||
47 | height: 40px; | ||
48 | |||
49 | .glyphicon-remove { | ||
50 | cursor: pointer; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | .little-information { | ||
55 | font-size: 0.8em; | ||
56 | font-style: italic; | ||
57 | } | ||
diff --git a/client/src/app/videos/video-add/video-add.component.ts b/client/src/app/videos/video-add/video-add.component.ts deleted file mode 100644 index da556f48d..000000000 --- a/client/src/app/videos/video-add/video-add.component.ts +++ /dev/null | |||
@@ -1,230 +0,0 @@ | |||
1 | import { Component, ElementRef, OnInit } from '@angular/core'; | ||
2 | import { FormBuilder, FormGroup } from '@angular/forms'; | ||
3 | import { Router } from '@angular/router'; | ||
4 | |||
5 | import { FileUploader } from 'ng2-file-upload/ng2-file-upload'; | ||
6 | import { NotificationsService } from 'angular2-notifications'; | ||
7 | |||
8 | import { AuthService } from '../../core'; | ||
9 | import { | ||
10 | FormReactive, | ||
11 | VIDEO_NAME, | ||
12 | VIDEO_CATEGORY, | ||
13 | VIDEO_LICENCE, | ||
14 | VIDEO_LANGUAGE, | ||
15 | VIDEO_DESCRIPTION, | ||
16 | VIDEO_TAGS | ||
17 | } from '../../shared'; | ||
18 | import { VideoService } from '../shared'; | ||
19 | |||
20 | @Component({ | ||
21 | selector: 'my-videos-add', | ||
22 | styleUrls: [ './video-add.component.scss' ], | ||
23 | templateUrl: './video-add.component.html' | ||
24 | }) | ||
25 | |||
26 | export class VideoAddComponent extends FormReactive implements OnInit { | ||
27 | tags: string[] = []; | ||
28 | uploader: FileUploader; | ||
29 | videoCategories = []; | ||
30 | videoLicences = []; | ||
31 | videoLanguages = []; | ||
32 | |||
33 | error: string = null; | ||
34 | form: FormGroup; | ||
35 | formErrors = { | ||
36 | name: '', | ||
37 | category: '', | ||
38 | licence: '', | ||
39 | language: '', | ||
40 | description: '', | ||
41 | currentTag: '' | ||
42 | }; | ||
43 | validationMessages = { | ||
44 | name: VIDEO_NAME.MESSAGES, | ||
45 | category: VIDEO_CATEGORY.MESSAGES, | ||
46 | licence: VIDEO_LICENCE.MESSAGES, | ||
47 | language: VIDEO_LANGUAGE.MESSAGES, | ||
48 | description: VIDEO_DESCRIPTION.MESSAGES, | ||
49 | currentTag: VIDEO_TAGS.MESSAGES | ||
50 | }; | ||
51 | |||
52 | // Special error messages | ||
53 | tagsError = ''; | ||
54 | fileError = ''; | ||
55 | |||
56 | constructor( | ||
57 | private authService: AuthService, | ||
58 | private elementRef: ElementRef, | ||
59 | private formBuilder: FormBuilder, | ||
60 | private router: Router, | ||
61 | private notificationsService: NotificationsService, | ||
62 | private videoService: VideoService | ||
63 | ) { | ||
64 | super(); | ||
65 | } | ||
66 | |||
67 | get filename() { | ||
68 | if (this.uploader.queue.length === 0) { | ||
69 | return null; | ||
70 | } | ||
71 | |||
72 | return this.uploader.queue[0].file.name; | ||
73 | } | ||
74 | |||
75 | buildForm() { | ||
76 | this.form = this.formBuilder.group({ | ||
77 | name: [ '', VIDEO_NAME.VALIDATORS ], | ||
78 | nsfw: [ false ], | ||
79 | category: [ '', VIDEO_CATEGORY.VALIDATORS ], | ||
80 | licence: [ '', VIDEO_LICENCE.VALIDATORS ], | ||
81 | language: [ '', VIDEO_LANGUAGE.VALIDATORS ], | ||
82 | description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], | ||
83 | currentTag: [ '', VIDEO_TAGS.VALIDATORS ] | ||
84 | }); | ||
85 | |||
86 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)); | ||
87 | } | ||
88 | |||
89 | ngOnInit() { | ||
90 | this.videoCategories = this.videoService.videoCategories; | ||
91 | this.videoLicences = this.videoService.videoLicences; | ||
92 | this.videoLanguages = this.videoService.videoLanguages; | ||
93 | |||
94 | this.uploader = new FileUploader({ | ||
95 | authToken: this.authService.getRequestHeaderValue(), | ||
96 | queueLimit: 1, | ||
97 | url: '/api/v1/videos', | ||
98 | removeAfterUpload: true | ||
99 | }); | ||
100 | |||
101 | this.uploader.onBuildItemForm = (item, form) => { | ||
102 | const name = this.form.value['name']; | ||
103 | const nsfw = this.form.value['nsfw']; | ||
104 | const category = this.form.value['category']; | ||
105 | const licence = this.form.value['licence']; | ||
106 | const language = this.form.value['language']; | ||
107 | const description = this.form.value['description']; | ||
108 | |||
109 | form.append('name', name); | ||
110 | form.append('category', category); | ||
111 | form.append('nsfw', nsfw); | ||
112 | form.append('licence', licence); | ||
113 | |||
114 | // Language is optional | ||
115 | if (language) { | ||
116 | form.append('language', language); | ||
117 | } | ||
118 | |||
119 | form.append('description', description); | ||
120 | |||
121 | for (let i = 0; i < this.tags.length; i++) { | ||
122 | form.append(`tags[${i}]`, this.tags[i]); | ||
123 | } | ||
124 | }; | ||
125 | |||
126 | this.buildForm(); | ||
127 | } | ||
128 | |||
129 | checkForm() { | ||
130 | this.forceCheck(); | ||
131 | |||
132 | if (this.filename === null) { | ||
133 | this.fileError = 'You did not add a file.'; | ||
134 | } | ||
135 | |||
136 | return this.form.valid === true && this.tagsError === '' && this.fileError === ''; | ||
137 | } | ||
138 | |||
139 | fileChanged() { | ||
140 | this.fileError = ''; | ||
141 | } | ||
142 | |||
143 | onTagKeyPress(event: KeyboardEvent) { | ||
144 | // Enter press | ||
145 | if (event.keyCode === 13) { | ||
146 | this.addTagIfPossible(); | ||
147 | } | ||
148 | } | ||
149 | |||
150 | removeFile() { | ||
151 | this.uploader.clearQueue(); | ||
152 | } | ||
153 | |||
154 | removeTag(tag: string) { | ||
155 | this.tags.splice(this.tags.indexOf(tag), 1); | ||
156 | this.form.get('currentTag').enable(); | ||
157 | } | ||
158 | |||
159 | upload() { | ||
160 | // Maybe the user forgot to press "enter" when he filled the field | ||
161 | this.addTagIfPossible(); | ||
162 | |||
163 | if (this.checkForm() === false) { | ||
164 | return; | ||
165 | } | ||
166 | |||
167 | const item = this.uploader.queue[0]; | ||
168 | // TODO: wait for https://github.com/valor-software/ng2-file-upload/pull/242 | ||
169 | item.alias = 'videofile'; | ||
170 | |||
171 | // FIXME: remove | ||
172 | // Run detection change for progress bar | ||
173 | const interval = setInterval(() => { ; }, 250); | ||
174 | |||
175 | item.onSuccess = () => { | ||
176 | clearInterval(interval); | ||
177 | |||
178 | console.log('Video uploaded.'); | ||
179 | this.notificationsService.success('Success', 'Video uploaded.'); | ||
180 | |||
181 | |||
182 | // Print all the videos once it's finished | ||
183 | this.router.navigate(['/videos/list']); | ||
184 | }; | ||
185 | |||
186 | item.onError = (response: string, status: number) => { | ||
187 | clearInterval(interval); | ||
188 | |||
189 | // We need to handle manually these cases beceause we use the FileUpload component | ||
190 | if (status === 400) { | ||
191 | this.error = response; | ||
192 | } else if (status === 401) { | ||
193 | this.error = 'Access token was expired, refreshing token...'; | ||
194 | this.authService.refreshAccessToken().subscribe( | ||
195 | () => { | ||
196 | // Update the uploader request header | ||
197 | this.uploader.authToken = this.authService.getRequestHeaderValue(); | ||
198 | this.error += ' access token refreshed. Please retry your request.'; | ||
199 | } | ||
200 | ); | ||
201 | } else { | ||
202 | this.error = 'Unknow error'; | ||
203 | console.error(this.error); | ||
204 | } | ||
205 | }; | ||
206 | |||
207 | this.uploader.uploadAll(); | ||
208 | } | ||
209 | |||
210 | private addTagIfPossible() { | ||
211 | const currentTag = this.form.value['currentTag']; | ||
212 | if (currentTag === undefined) return; | ||
213 | |||
214 | // Check if the tag is valid and does not already exist | ||
215 | if ( | ||
216 | currentTag.length >= 2 && | ||
217 | this.form.controls['currentTag'].valid && | ||
218 | this.tags.indexOf(currentTag) === -1 | ||
219 | ) { | ||
220 | this.tags.push(currentTag); | ||
221 | this.form.patchValue({ currentTag: '' }); | ||
222 | |||
223 | if (this.tags.length >= 3) { | ||
224 | this.form.get('currentTag').disable(); | ||
225 | } | ||
226 | |||
227 | this.tagsError = ''; | ||
228 | } | ||
229 | } | ||
230 | } | ||