aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-edit/shared/video-edit.component.ts
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/app/+videos/+video-edit/shared/video-edit.component.ts')
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.ts55
1 files changed, 47 insertions, 8 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 2bec933e9..a03005bcb 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,10 +1,11 @@
1import { forkJoin } from 'rxjs' 1import { forkJoin } from 'rxjs'
2import { map } from 'rxjs/operators' 2import { map } from 'rxjs/operators'
3import { SelectChannelItem } from 'src/types/select-options-item.model' 3import { SelectChannelItem } from 'src/types/select-options-item.model'
4import { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' 4import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
5import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms' 5import { AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms'
6import { HooksService, PluginService, ServerService } from '@app/core' 6import { HooksService, PluginService, ServerService } from '@app/core'
7import { removeElementFromArray } from '@app/helpers' 7import { removeElementFromArray } from '@app/helpers'
8import { BuildFormValidator } from '@app/shared/form-validators'
8import { 9import {
9 VIDEO_CATEGORY_VALIDATOR, 10 VIDEO_CATEGORY_VALIDATOR,
10 VIDEO_CHANNEL_VALIDATOR, 11 VIDEO_CHANNEL_VALIDATOR,
@@ -101,7 +102,8 @@ export class VideoEditComponent implements OnInit, OnDestroy {
101 private instanceService: InstanceService, 102 private instanceService: InstanceService,
102 private i18nPrimengCalendarService: I18nPrimengCalendarService, 103 private i18nPrimengCalendarService: I18nPrimengCalendarService,
103 private ngZone: NgZone, 104 private ngZone: NgZone,
104 private hooks: HooksService 105 private hooks: HooksService,
106 private cd: ChangeDetectorRef
105 ) { 107 ) {
106 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone() 108 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone()
107 this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat() 109 this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat()
@@ -116,7 +118,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
116 licence: this.serverConfig.defaults.publish.licence, 118 licence: this.serverConfig.defaults.publish.licence,
117 tags: [] 119 tags: []
118 } 120 }
119 const obj: any = { 121 const obj: { [ id: string ]: BuildFormValidator } = {
120 name: VIDEO_NAME_VALIDATOR, 122 name: VIDEO_NAME_VALIDATOR,
121 privacy: VIDEO_PRIVACY_VALIDATOR, 123 privacy: VIDEO_PRIVACY_VALIDATOR,
122 channelId: VIDEO_CHANNEL_VALIDATOR, 124 channelId: VIDEO_CHANNEL_VALIDATOR,
@@ -138,7 +140,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
138 saveReplay: null 140 saveReplay: null
139 } 141 }
140 142
141 this.formValidatorService.updateForm( 143 this.formValidatorService.updateFormGroup(
142 this.form, 144 this.form,
143 this.formErrors, 145 this.formErrors,
144 this.validationMessages, 146 this.validationMessages,
@@ -275,6 +277,14 @@ export class VideoEditComponent implements OnInit, OnDestroy {
275 }) 277 })
276 } 278 }
277 279
280 getPluginsFields (tab: 'main' | 'plugin-settings') {
281 return this.pluginFields.filter(p => {
282 const wanted = p.videoFormOptions.tab ?? 'plugin-settings'
283
284 return wanted === tab
285 })
286 }
287
278 private sortVideoCaptions () { 288 private sortVideoCaptions () {
279 this.videoCaptions.sort((v1, v2) => { 289 this.videoCaptions.sort((v1, v2) => {
280 if (v1.language.label < v2.language.label) return -1 290 if (v1.language.label < v2.language.label) return -1
@@ -289,15 +299,44 @@ export class VideoEditComponent implements OnInit, OnDestroy {
289 299
290 if (this.pluginFields.length === 0) return 300 if (this.pluginFields.length === 0) return
291 301
292 const obj: any = {} 302 const pluginObj: { [ id: string ]: BuildFormValidator } = {}
303 const pluginValidationMessages: FormReactiveValidationMessages = {}
304 const pluginFormErrors: any = {}
305 const pluginDefaults: any = {}
293 306
294 for (const setting of this.pluginFields) { 307 for (const setting of this.pluginFields) {
295 obj[setting.commonOptions.name] = new FormControl(setting.commonOptions.default) 308 const validator = (control: AbstractControl): ValidationErrors | null => {
309 if (!setting.commonOptions.error) return null
310
311 const error = setting.commonOptions.error({ formValues: this.form.value, value: control.value })
312
313 return error?.error ? { [setting.commonOptions.name]: error.text } : null
314 }
315
316 const name = setting.commonOptions.name
317
318 pluginObj[name] = {
319 VALIDATORS: [ validator ],
320 MESSAGES: {}
321 }
322
323 pluginDefaults[name] = setting.commonOptions.default
296 } 324 }
297 325
298 this.pluginDataFormGroup = new FormGroup(obj) 326 this.pluginDataFormGroup = new FormGroup({})
327 this.formValidatorService.updateFormGroup(
328 this.pluginDataFormGroup,
329 pluginFormErrors,
330 pluginValidationMessages,
331 pluginObj,
332 pluginDefaults
333 )
334
299 this.form.addControl('pluginData', this.pluginDataFormGroup) 335 this.form.addControl('pluginData', this.pluginDataFormGroup)
336 this.formErrors['pluginData'] = pluginFormErrors
337 this.validationMessages['pluginData'] = pluginValidationMessages
300 338
339 this.cd.detectChanges()
301 this.pluginFieldsAdded.emit() 340 this.pluginFieldsAdded.emit()
302 } 341 }
303 342