diff options
Diffstat (limited to 'client/src/app/videos/+video-edit')
3 files changed, 39 insertions, 63 deletions
diff --git a/client/src/app/videos/+video-edit/shared/video-edit.component.ts b/client/src/app/videos/+video-edit/shared/video-edit.component.ts index ccfae5fcc..cd2a26ae3 100644 --- a/client/src/app/videos/+video-edit/shared/video-edit.component.ts +++ b/client/src/app/videos/+video-edit/shared/video-edit.component.ts | |||
@@ -1,7 +1,7 @@ | |||
1 | import { Component, Input, OnInit } from '@angular/core' | 1 | import { Component, Input, OnInit } from '@angular/core' |
2 | import { FormBuilder, FormControl, FormGroup } from '@angular/forms' | 2 | import { FormGroup } from '@angular/forms' |
3 | import { ActivatedRoute, Router } from '@angular/router' | 3 | import { ActivatedRoute, Router } from '@angular/router' |
4 | import { VIDEO_IMAGE, VIDEO_SUPPORT } from '@app/shared' | 4 | import { VIDEO_SUPPORT } from '@app/shared' |
5 | import { NotificationsService } from 'angular2-notifications' | 5 | import { NotificationsService } from 'angular2-notifications' |
6 | import { ServerService } from '../../../core/server' | 6 | import { ServerService } from '../../../core/server' |
7 | import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators' | 7 | import { VIDEO_CHANNEL } from '../../../shared/forms/form-validators' |
@@ -17,6 +17,7 @@ import { | |||
17 | } from '../../../shared/forms/form-validators/video' | 17 | } from '../../../shared/forms/form-validators/video' |
18 | import { VideoEdit } from '../../../shared/video/video-edit.model' | 18 | import { VideoEdit } from '../../../shared/video/video-edit.model' |
19 | import { map } from 'rxjs/operators' | 19 | import { map } from 'rxjs/operators' |
20 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
20 | 21 | ||
21 | @Component({ | 22 | @Component({ |
22 | selector: 'my-video-edit', | 23 | selector: 'my-video-edit', |
@@ -42,7 +43,7 @@ export class VideoEditComponent implements OnInit { | |||
42 | error: string = null | 43 | error: string = null |
43 | 44 | ||
44 | constructor ( | 45 | constructor ( |
45 | private formBuilder: FormBuilder, | 46 | private formValidatorService: FormValidatorService, |
46 | private route: ActivatedRoute, | 47 | private route: ActivatedRoute, |
47 | private router: Router, | 48 | private router: Router, |
48 | private notificationsService: NotificationsService, | 49 | private notificationsService: NotificationsService, |
@@ -50,41 +51,34 @@ export class VideoEditComponent implements OnInit { | |||
50 | ) { } | 51 | ) { } |
51 | 52 | ||
52 | updateForm () { | 53 | updateForm () { |
53 | this.formErrors['name'] = '' | 54 | const defaultValues = { |
54 | this.formErrors['privacy'] = '' | 55 | nsfw: 'false', |
55 | this.formErrors['channelId'] = '' | 56 | commentsEnabled: 'true', |
56 | this.formErrors['category'] = '' | 57 | tags: [] |
57 | this.formErrors['licence'] = '' | 58 | } |
58 | this.formErrors['language'] = '' | 59 | const obj = { |
59 | this.formErrors['description'] = '' | 60 | name: VIDEO_NAME, |
60 | this.formErrors['thumbnailfile'] = '' | 61 | privacy: VIDEO_PRIVACY, |
61 | this.formErrors['previewfile'] = '' | 62 | channelId: VIDEO_CHANNEL, |
62 | this.formErrors['support'] = '' | 63 | nsfw: null, |
63 | 64 | commentsEnabled: null, | |
64 | this.validationMessages['name'] = VIDEO_NAME.MESSAGES | 65 | category: VIDEO_CATEGORY, |
65 | this.validationMessages['privacy'] = VIDEO_PRIVACY.MESSAGES | 66 | licence: VIDEO_LICENCE, |
66 | this.validationMessages['channelId'] = VIDEO_CHANNEL.MESSAGES | 67 | language: VIDEO_LANGUAGE, |
67 | this.validationMessages['category'] = VIDEO_CATEGORY.MESSAGES | 68 | description: VIDEO_DESCRIPTION, |
68 | this.validationMessages['licence'] = VIDEO_LICENCE.MESSAGES | 69 | tags: null, |
69 | this.validationMessages['language'] = VIDEO_LANGUAGE.MESSAGES | 70 | thumbnailfile: null, |
70 | this.validationMessages['description'] = VIDEO_DESCRIPTION.MESSAGES | 71 | previewfile: null, |
71 | this.validationMessages['thumbnailfile'] = VIDEO_IMAGE.MESSAGES | 72 | support: VIDEO_SUPPORT |
72 | this.validationMessages['previewfile'] = VIDEO_IMAGE.MESSAGES | 73 | } |
73 | this.validationMessages['support'] = VIDEO_SUPPORT.MESSAGES | 74 | |
74 | 75 | this.formValidatorService.updateForm( | |
75 | this.form.addControl('name', new FormControl('', VIDEO_NAME.VALIDATORS)) | 76 | this.form, |
76 | this.form.addControl('privacy', new FormControl('', VIDEO_PRIVACY.VALIDATORS)) | 77 | this.formErrors, |
77 | this.form.addControl('channelId', new FormControl('', VIDEO_CHANNEL.VALIDATORS)) | 78 | this.validationMessages, |
78 | this.form.addControl('nsfw', new FormControl(false)) | 79 | obj, |
79 | this.form.addControl('commentsEnabled', new FormControl(true)) | 80 | defaultValues |
80 | this.form.addControl('category', new FormControl('', VIDEO_CATEGORY.VALIDATORS)) | 81 | ) |
81 | this.form.addControl('licence', new FormControl('', VIDEO_LICENCE.VALIDATORS)) | ||
82 | this.form.addControl('language', new FormControl('', VIDEO_LANGUAGE.VALIDATORS)) | ||
83 | this.form.addControl('description', new FormControl('', VIDEO_DESCRIPTION.VALIDATORS)) | ||
84 | this.form.addControl('tags', new FormControl([])) | ||
85 | this.form.addControl('thumbnailfile', new FormControl('')) | ||
86 | this.form.addControl('previewfile', new FormControl('')) | ||
87 | this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS)) | ||
88 | 82 | ||
89 | // We will update the "support" field depending on the channel | 83 | // We will update the "support" field depending on the channel |
90 | this.form.controls['channelId'] | 84 | this.form.controls['channelId'] |
@@ -98,6 +92,7 @@ export class VideoEditComponent implements OnInit { | |||
98 | // Not initialized yet | 92 | // Not initialized yet |
99 | if (isNaN(newChannelId)) return | 93 | if (isNaN(newChannelId)) return |
100 | const newChannel = this.userVideoChannels.find(c => c.id === newChannelId) | 94 | const newChannel = this.userVideoChannels.find(c => c.id === newChannelId) |
95 | if (!newChannel) return | ||
101 | 96 | ||
102 | // First time we set the channel? | 97 | // First time we set the channel? |
103 | if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support) | 98 | if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support) |
diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts index a615fd92c..332f757d7 100644 --- a/client/src/app/videos/+video-edit/video-add.component.ts +++ b/client/src/app/videos/+video-edit/video-add.component.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import { HttpEventType, HttpResponse } from '@angular/common/http' | 1 | import { HttpEventType, HttpResponse } from '@angular/common/http' |
2 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' | 2 | import { Component, OnDestroy, OnInit, ViewChild } from '@angular/core' |
3 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
4 | import { Router } from '@angular/router' | 3 | import { Router } from '@angular/router' |
5 | import { UserService } from '@app/shared' | 4 | import { UserService } from '@app/shared' |
6 | import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' | 5 | import { CanComponentDeactivate } from '@app/shared/guards/can-deactivate-guard.service' |
@@ -11,11 +10,11 @@ import { Subscription } from 'rxjs' | |||
11 | import { VideoPrivacy } from '../../../../../shared/models/videos' | 10 | import { VideoPrivacy } from '../../../../../shared/models/videos' |
12 | import { AuthService, ServerService } from '../../core' | 11 | import { AuthService, ServerService } from '../../core' |
13 | import { FormReactive } from '../../shared' | 12 | import { FormReactive } from '../../shared' |
14 | import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message' | ||
15 | import { populateAsyncUserVideoChannels } from '../../shared/misc/utils' | 13 | import { populateAsyncUserVideoChannels } from '../../shared/misc/utils' |
16 | import { VideoEdit } from '../../shared/video/video-edit.model' | 14 | import { VideoEdit } from '../../shared/video/video-edit.model' |
17 | import { VideoService } from '../../shared/video/video.service' | 15 | import { VideoService } from '../../shared/video/video.service' |
18 | import { I18n } from '@ngx-translate/i18n-polyfill' | 16 | import { I18n } from '@ngx-translate/i18n-polyfill' |
17 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
19 | 18 | ||
20 | @Component({ | 19 | @Component({ |
21 | selector: 'my-videos-add', | 20 | selector: 'my-videos-add', |
@@ -39,10 +38,6 @@ export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy | |||
39 | } | 38 | } |
40 | videoFileName: string | 39 | videoFileName: string |
41 | 40 | ||
42 | form: FormGroup | ||
43 | formErrors: { [ id: string ]: string } = {} | ||
44 | validationMessages: ValidatorMessage = {} | ||
45 | |||
46 | userVideoChannels: { id: number, label: string, support: string }[] = [] | 41 | userVideoChannels: { id: number, label: string, support: string }[] = [] |
47 | userVideoQuotaUsed = 0 | 42 | userVideoQuotaUsed = 0 |
48 | videoPrivacies = [] | 43 | videoPrivacies = [] |
@@ -50,7 +45,7 @@ export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy | |||
50 | firstStepChannelId = 0 | 45 | firstStepChannelId = 0 |
51 | 46 | ||
52 | constructor ( | 47 | constructor ( |
53 | private formBuilder: FormBuilder, | 48 | protected formValidatorService: FormValidatorService, |
54 | private router: Router, | 49 | private router: Router, |
55 | private notificationsService: NotificationsService, | 50 | private notificationsService: NotificationsService, |
56 | private authService: AuthService, | 51 | private authService: AuthService, |
@@ -67,13 +62,8 @@ export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy | |||
67 | return this.serverService.getConfig().video.file.extensions.join(',') | 62 | return this.serverService.getConfig().video.file.extensions.join(',') |
68 | } | 63 | } |
69 | 64 | ||
70 | buildForm () { | ||
71 | this.form = this.formBuilder.group({}) | ||
72 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
73 | } | ||
74 | |||
75 | ngOnInit () { | 65 | ngOnInit () { |
76 | this.buildForm() | 66 | this.buildForm({}) |
77 | 67 | ||
78 | populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) | 68 | populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) |
79 | .then(() => this.firstStepChannelId = this.userVideoChannels[0].id) | 69 | .then(() => this.firstStepChannelId = this.userVideoChannels[0].id) |
diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts index e37dd526f..0266164af 100644 --- a/client/src/app/videos/+video-edit/video-update.component.ts +++ b/client/src/app/videos/+video-edit/video-update.component.ts | |||
@@ -1,6 +1,5 @@ | |||
1 | import { map, switchMap } from 'rxjs/operators' | 1 | import { map, switchMap } from 'rxjs/operators' |
2 | import { Component, OnInit } from '@angular/core' | 2 | import { Component, OnInit } from '@angular/core' |
3 | import { FormBuilder, FormGroup } from '@angular/forms' | ||
4 | import { ActivatedRoute, Router } from '@angular/router' | 3 | import { ActivatedRoute, Router } from '@angular/router' |
5 | import { LoadingBarService } from '@ngx-loading-bar/core' | 4 | import { LoadingBarService } from '@ngx-loading-bar/core' |
6 | import { NotificationsService } from 'angular2-notifications' | 5 | import { NotificationsService } from 'angular2-notifications' |
@@ -8,11 +7,11 @@ import { VideoPrivacy } from '../../../../../shared/models/videos' | |||
8 | import { ServerService } from '../../core' | 7 | import { ServerService } from '../../core' |
9 | import { AuthService } from '../../core/auth' | 8 | import { AuthService } from '../../core/auth' |
10 | import { FormReactive } from '../../shared' | 9 | import { FormReactive } from '../../shared' |
11 | import { ValidatorMessage } from '../../shared/forms/form-validators/validator-message' | ||
12 | import { VideoEdit } from '../../shared/video/video-edit.model' | 10 | import { VideoEdit } from '../../shared/video/video-edit.model' |
13 | import { VideoService } from '../../shared/video/video.service' | 11 | import { VideoService } from '../../shared/video/video.service' |
14 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' | 12 | import { VideoChannelService } from '@app/shared/video-channel/video-channel.service' |
15 | import { I18n } from '@ngx-translate/i18n-polyfill' | 13 | import { I18n } from '@ngx-translate/i18n-polyfill' |
14 | import { FormValidatorService } from '@app/shared/forms/form-validators/form-validator.service' | ||
16 | 15 | ||
17 | @Component({ | 16 | @Component({ |
18 | selector: 'my-videos-update', | 17 | selector: 'my-videos-update', |
@@ -23,14 +22,11 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
23 | video: VideoEdit | 22 | video: VideoEdit |
24 | 23 | ||
25 | isUpdatingVideo = false | 24 | isUpdatingVideo = false |
26 | form: FormGroup | ||
27 | formErrors: { [ id: string ]: string } = {} | ||
28 | validationMessages: ValidatorMessage = {} | ||
29 | videoPrivacies = [] | 25 | videoPrivacies = [] |
30 | userVideoChannels = [] | 26 | userVideoChannels = [] |
31 | 27 | ||
32 | constructor ( | 28 | constructor ( |
33 | private formBuilder: FormBuilder, | 29 | protected formValidatorService: FormValidatorService, |
34 | private route: ActivatedRoute, | 30 | private route: ActivatedRoute, |
35 | private router: Router, | 31 | private router: Router, |
36 | private notificationsService: NotificationsService, | 32 | private notificationsService: NotificationsService, |
@@ -44,13 +40,8 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
44 | super() | 40 | super() |
45 | } | 41 | } |
46 | 42 | ||
47 | buildForm () { | ||
48 | this.form = this.formBuilder.group({}) | ||
49 | this.form.valueChanges.subscribe(data => this.onValueChanged(data)) | ||
50 | } | ||
51 | |||
52 | ngOnInit () { | 43 | ngOnInit () { |
53 | this.buildForm() | 44 | this.buildForm({}) |
54 | 45 | ||
55 | this.serverService.videoPrivaciesLoaded | 46 | this.serverService.videoPrivaciesLoaded |
56 | .subscribe(() => this.videoPrivacies = this.serverService.getVideoPrivacies()) | 47 | .subscribe(() => this.videoPrivacies = this.serverService.getVideoPrivacies()) |