From a685e25ca05f08ad1b3f7fbaccc8744727bd8d27 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 9 Oct 2017 14:28:44 +0200 Subject: Try to optimize frontend --- client/src/app/videos/video-edit/index.ts | 2 - .../app/videos/video-edit/video-add.component.html | 121 --------------- .../app/videos/video-edit/video-add.component.ts | 165 --------------------- .../videos/video-edit/video-edit.component.scss | 56 ------- .../videos/video-edit/video-update.component.html | 92 ------------ .../videos/video-edit/video-update.component.ts | 134 ----------------- 6 files changed, 570 deletions(-) delete mode 100644 client/src/app/videos/video-edit/index.ts delete mode 100644 client/src/app/videos/video-edit/video-add.component.html delete mode 100644 client/src/app/videos/video-edit/video-add.component.ts delete mode 100644 client/src/app/videos/video-edit/video-edit.component.scss delete mode 100644 client/src/app/videos/video-edit/video-update.component.html delete mode 100644 client/src/app/videos/video-edit/video-update.component.ts (limited to 'client/src/app/videos/video-edit') diff --git a/client/src/app/videos/video-edit/index.ts b/client/src/app/videos/video-edit/index.ts deleted file mode 100644 index 3b4a9cb87..000000000 --- a/client/src/app/videos/video-edit/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './video-add.component' -export * from './video-update.component' diff --git a/client/src/app/videos/video-edit/video-add.component.html b/client/src/app/videos/video-edit/video-add.component.html deleted file mode 100644 index 698152ff9..000000000 --- a/client/src/app/videos/video-edit/video-add.component.html +++ /dev/null @@ -1,121 +0,0 @@ -
-
- -

Upload a video

- -
{{ error }}
- -
-
- - -
- {{ formErrors.name }} -
-
- -
- - -
- -
- - - -
- {{ formErrors.category }} -
-
- -
- - - -
- {{ formErrors.licence }} -
-
- -
- - - -
- {{ formErrors.language }} -
-
- -
- (press enter to add the tag) - -
- -
- -
- Select the video... - - -
-
- -
-
- {{ filename }} - -
-
- -
- {{ formErrors.videofile }} -
- -
- - -
- {{ formErrors.description }} -
-
- -
- - - - Server is processing the video - - -
- -
- -
-
-
-
diff --git a/client/src/app/videos/video-edit/video-add.component.ts b/client/src/app/videos/video-edit/video-add.component.ts deleted file mode 100644 index 21311b184..000000000 --- a/client/src/app/videos/video-edit/video-add.component.ts +++ /dev/null @@ -1,165 +0,0 @@ -import { Component, OnInit, ViewChild } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' -import { Router } from '@angular/router' - -import { NotificationsService } from 'angular2-notifications' - -import { - FormReactive, - VIDEO_NAME, - VIDEO_CATEGORY, - VIDEO_LICENCE, - VIDEO_LANGUAGE, - VIDEO_DESCRIPTION, - VIDEO_TAGS -} from '../../shared' -import { VideoService } from '../shared' -import { VideoCreate } from '../../../../../shared' -import { HttpEventType, HttpResponse } from '@angular/common/http' -import { VIDEO_FILE } from '../../shared/forms/form-validators/video' - -@Component({ - selector: 'my-videos-add', - styleUrls: [ './video-edit.component.scss' ], - templateUrl: './video-add.component.html' -}) - -export class VideoAddComponent extends FormReactive implements OnInit { - @ViewChild('videofileInput') videofileInput - - progressPercent = 0 - tags: string[] = [] - videoCategories = [] - videoLicences = [] - videoLanguages = [] - - tagValidators = VIDEO_TAGS.VALIDATORS - tagValidatorsMessages = VIDEO_TAGS.MESSAGES - - error: string - form: FormGroup - formErrors = { - name: '', - category: '', - licence: '', - language: '', - description: '', - videofile: '' - } - validationMessages = { - name: VIDEO_NAME.MESSAGES, - category: VIDEO_CATEGORY.MESSAGES, - licence: VIDEO_LICENCE.MESSAGES, - language: VIDEO_LANGUAGE.MESSAGES, - description: VIDEO_DESCRIPTION.MESSAGES, - videofile: VIDEO_FILE.MESSAGES - } - - constructor ( - private formBuilder: FormBuilder, - private router: Router, - private notificationsService: NotificationsService, - private videoService: VideoService - ) { - super() - } - - get filename () { - return this.form.value['videofile'] - } - - buildForm () { - this.form = this.formBuilder.group({ - name: [ '', VIDEO_NAME.VALIDATORS ], - nsfw: [ false ], - category: [ '', VIDEO_CATEGORY.VALIDATORS ], - licence: [ '', VIDEO_LICENCE.VALIDATORS ], - language: [ '', VIDEO_LANGUAGE.VALIDATORS ], - description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], - videofile: [ '', VIDEO_FILE.VALIDATORS ], - tags: [ '' ] - }) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.videoCategories = this.videoService.videoCategories - this.videoLicences = this.videoService.videoLicences - this.videoLanguages = this.videoService.videoLanguages - - this.buildForm() - } - - // The goal is to keep reactive form validation (required field) - // https://stackoverflow.com/a/44238894 - fileChange ($event) { - this.form.controls['videofile'].setValue($event.target.files[0].name) - } - - removeFile () { - this.videofileInput.nativeElement.value = '' - this.form.controls['videofile'].setValue('') - } - - checkForm () { - this.forceCheck() - - return this.form.valid - } - - upload () { - if (this.checkForm() === false) { - return - } - - const formValue: VideoCreate = this.form.value - - const name = formValue.name - const nsfw = formValue.nsfw - const category = formValue.category - const licence = formValue.licence - const language = formValue.language - const description = formValue.description - const tags = formValue.tags - const videofile = this.videofileInput.nativeElement.files[0] - - const formData = new FormData() - formData.append('name', name) - formData.append('category', '' + category) - formData.append('nsfw', '' + nsfw) - formData.append('licence', '' + licence) - formData.append('videofile', videofile) - - // Language is optional - if (language) { - formData.append('language', '' + language) - } - - formData.append('description', description) - - for (let i = 0; i < tags.length; i++) { - formData.append(`tags[${i}]`, tags[i]) - } - - this.videoService.uploadVideo(formData).subscribe( - event => { - if (event.type === HttpEventType.UploadProgress) { - this.progressPercent = Math.round(100 * event.loaded / event.total) - } else if (event instanceof HttpResponse) { - console.log('Video uploaded.') - this.notificationsService.success('Success', 'Video uploaded.') - - // Display all the videos once it's finished - this.router.navigate([ '/videos/list' ]) - } - }, - - err => { - // Reset progress - this.progressPercent = 0 - this.error = err.message - } - ) - } -} diff --git a/client/src/app/videos/video-edit/video-edit.component.scss b/client/src/app/videos/video-edit/video-edit.component.scss deleted file mode 100644 index 9ee0c520c..000000000 --- a/client/src/app/videos/video-edit/video-edit.component.scss +++ /dev/null @@ -1,56 +0,0 @@ -.btn-file { - position: relative; - overflow: hidden; - display: block; -} - -.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; -} - -.form-group { - margin-bottom: 10px; -} - -div.tags { - height: 40px; - font-size: 20px; - margin-top: 20px; - - .tag { - margin-right: 10px; - - .remove { - cursor: pointer; - } - } -} - -div.file-to-upload { - height: 40px; - - .glyphicon-remove { - cursor: pointer; - } -} - -.little-information { - font-size: 0.8em; - font-style: italic; -} - -.label-tags { - margin-bottom: 0; -} diff --git a/client/src/app/videos/video-edit/video-update.component.html b/client/src/app/videos/video-edit/video-update.component.html deleted file mode 100644 index 7f4faf21b..000000000 --- a/client/src/app/videos/video-edit/video-update.component.html +++ /dev/null @@ -1,92 +0,0 @@ -
-
- -

Update {{ video?.name }}

- -
{{ error }}
- -
-
- - -
- {{ formErrors.name }} -
-
- -
- - -
- -
- - - -
- {{ formErrors.category }} -
-
- -
- - - -
- {{ formErrors.licence }} -
-
- -
- - - -
- {{ formErrors.language }} -
-
- -
- (press enter to add the tag) - -
- -
- - -
- {{ formErrors.description }} -
-
- -
- -
-
-
-
diff --git a/client/src/app/videos/video-edit/video-update.component.ts b/client/src/app/videos/video-edit/video-update.component.ts deleted file mode 100644 index 141ed3522..000000000 --- a/client/src/app/videos/video-edit/video-update.component.ts +++ /dev/null @@ -1,134 +0,0 @@ -import { Component, ElementRef, OnInit } from '@angular/core' -import { FormBuilder, FormGroup } from '@angular/forms' -import { ActivatedRoute, Router } from '@angular/router' - -import { NotificationsService } from 'angular2-notifications' - -import { AuthService } from '../../core' -import { - FormReactive, - VIDEO_NAME, - VIDEO_CATEGORY, - VIDEO_LICENCE, - VIDEO_LANGUAGE, - VIDEO_DESCRIPTION, - VIDEO_TAGS -} from '../../shared' -import { Video, VideoService } from '../shared' - -@Component({ - selector: 'my-videos-update', - styleUrls: [ './video-edit.component.scss' ], - templateUrl: './video-update.component.html' -}) - -export class VideoUpdateComponent extends FormReactive implements OnInit { - tags: string[] = [] - videoCategories = [] - videoLicences = [] - videoLanguages = [] - video: Video - - tagValidators = VIDEO_TAGS.VALIDATORS - tagValidatorsMessages = VIDEO_TAGS.MESSAGES - - error: string = null - form: FormGroup - formErrors = { - name: '', - category: '', - licence: '', - language: '', - description: '' - } - validationMessages = { - name: VIDEO_NAME.MESSAGES, - category: VIDEO_CATEGORY.MESSAGES, - licence: VIDEO_LICENCE.MESSAGES, - language: VIDEO_LANGUAGE.MESSAGES, - description: VIDEO_DESCRIPTION.MESSAGES - } - - fileError = '' - - constructor ( - private authService: AuthService, - private elementRef: ElementRef, - private formBuilder: FormBuilder, - private route: ActivatedRoute, - private router: Router, - private notificationsService: NotificationsService, - private videoService: VideoService - ) { - super() - } - - buildForm () { - this.form = this.formBuilder.group({ - name: [ '', VIDEO_NAME.VALIDATORS ], - nsfw: [ false ], - category: [ '', VIDEO_CATEGORY.VALIDATORS ], - licence: [ '', VIDEO_LICENCE.VALIDATORS ], - language: [ '', VIDEO_LANGUAGE.VALIDATORS ], - description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], - tags: [ '' ] - }) - - this.form.valueChanges.subscribe(data => this.onValueChanged(data)) - } - - ngOnInit () { - this.buildForm() - - this.videoCategories = this.videoService.videoCategories - this.videoLicences = this.videoService.videoLicences - this.videoLanguages = this.videoService.videoLanguages - - const uuid: string = this.route.snapshot.params['uuid'] - this.videoService.getVideo(uuid) - .subscribe( - video => { - this.video = video - - this.hydrateFormFromVideo() - }, - - err => { - console.error(err) - this.error = 'Cannot fetch video.' - } - ) - } - - checkForm () { - this.forceCheck() - - return this.form.valid - } - - update () { - if (this.checkForm() === false) { - return - } - - this.video.patch(this.form.value) - - this.videoService.updateVideo(this.video) - .subscribe( - () => { - this.notificationsService.success('Success', 'Video updated.') - this.router.navigate([ '/videos/watch', this.video.uuid ]) - }, - - err => { - this.error = 'Cannot update the video.' - console.error(err) - } - ) - - } - - private hydrateFormFromVideo () { - this.form.patchValue(this.video.toJSON()) - } -} -- cgit v1.2.3