aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos/+video-edit/shared/video-edit.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2020-08-20 16:18:16 +0200
committerChocobozzz <chocobozzz@cpy.re>2020-08-21 15:39:51 +0200
commit7294aab0c879ef96c0fde15c389a2c4c1463d3c7 (patch)
treebad1176720ee04266eba5470e9956e3a7871e349 /client/src/app/+videos/+video-edit/shared/video-edit.component.ts
parentf95628636b6ccdf3eae2449ca718e075b072f678 (diff)
downloadPeerTube-7294aab0c879ef96c0fde15c389a2c4c1463d3c7.tar.gz
PeerTube-7294aab0c879ef96c0fde15c389a2c4c1463d3c7.tar.zst
PeerTube-7294aab0c879ef96c0fde15c389a2c4c1463d3c7.zip
Add ability to set custom field to video form
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.ts51
1 files changed, 45 insertions, 6 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 92d06aa12..f04111e69 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,8 +1,8 @@
1import { forkJoin } from 'rxjs' 1import { forkJoin } from 'rxjs'
2import { map } from 'rxjs/operators' 2import { map } from 'rxjs/operators'
3import { Component, Input, NgZone, OnDestroy, OnInit, ViewChild } from '@angular/core' 3import { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
4import { FormArray, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms' 4import { FormArray, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms'
5import { ServerService } from '@app/core' 5import { HooksService, PluginService, ServerService } from '@app/core'
6import { removeElementFromArray } from '@app/helpers' 6import { removeElementFromArray } from '@app/helpers'
7import { 7import {
8 VIDEO_CATEGORY_VALIDATOR, 8 VIDEO_CATEGORY_VALIDATOR,
@@ -21,6 +21,7 @@ import { FormReactiveValidationMessages, FormValidatorService, SelectChannelItem
21import { InstanceService } from '@app/shared/shared-instance' 21import { InstanceService } from '@app/shared/shared-instance'
22import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main' 22import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main'
23import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models' 23import { ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models'
24import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model'
24import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service' 25import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service'
25import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component' 26import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component'
26 27
@@ -39,9 +40,12 @@ export class VideoEditComponent implements OnInit, OnDestroy {
39 @Input() schedulePublicationPossible = true 40 @Input() schedulePublicationPossible = true
40 @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = [] 41 @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = []
41 @Input() waitTranscodingEnabled = true 42 @Input() waitTranscodingEnabled = true
43 @Input() type: 'import-url' | 'import-torrent' | 'upload' | 'update'
42 44
43 @ViewChild('videoCaptionAddModal', { static: true }) videoCaptionAddModal: VideoCaptionAddModalComponent 45 @ViewChild('videoCaptionAddModal', { static: true }) videoCaptionAddModal: VideoCaptionAddModalComponent
44 46
47 @Output() pluginFieldsAdded = new EventEmitter<void>()
48
45 // So that it can be accessed in the template 49 // So that it can be accessed in the template
46 readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY 50 readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
47 51
@@ -53,6 +57,8 @@ export class VideoEditComponent implements OnInit, OnDestroy {
53 tagValidators: ValidatorFn[] 57 tagValidators: ValidatorFn[]
54 tagValidatorsMessages: { [ name: string ]: string } 58 tagValidatorsMessages: { [ name: string ]: string }
55 59
60 pluginDataFormGroup: FormGroup
61
56 schedulePublicationEnabled = false 62 schedulePublicationEnabled = false
57 63
58 calendarLocale: any = {} 64 calendarLocale: any = {}
@@ -64,6 +70,11 @@ export class VideoEditComponent implements OnInit, OnDestroy {
64 70
65 serverConfig: ServerConfig 71 serverConfig: ServerConfig
66 72
73 pluginFields: {
74 commonOptions: RegisterClientFormFieldOptions
75 videoFormOptions: RegisterClientVideoFieldOptions
76 }[] = []
77
67 private schedulerInterval: any 78 private schedulerInterval: any
68 private firstPatchDone = false 79 private firstPatchDone = false
69 private initialVideoCaptions: string[] = [] 80 private initialVideoCaptions: string[] = []
@@ -72,9 +83,11 @@ export class VideoEditComponent implements OnInit, OnDestroy {
72 private formValidatorService: FormValidatorService, 83 private formValidatorService: FormValidatorService,
73 private videoService: VideoService, 84 private videoService: VideoService,
74 private serverService: ServerService, 85 private serverService: ServerService,
86 private pluginService: PluginService,
75 private instanceService: InstanceService, 87 private instanceService: InstanceService,
76 private i18nPrimengCalendarService: I18nPrimengCalendarService, 88 private i18nPrimengCalendarService: I18nPrimengCalendarService,
77 private ngZone: NgZone 89 private ngZone: NgZone,
90 private hooks: HooksService
78 ) { 91 ) {
79 this.calendarLocale = this.i18nPrimengCalendarService.getCalendarLocale() 92 this.calendarLocale = this.i18nPrimengCalendarService.getCalendarLocale()
80 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone() 93 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone()
@@ -136,19 +149,26 @@ export class VideoEditComponent implements OnInit, OnDestroy {
136 ngOnInit () { 149 ngOnInit () {
137 this.updateForm() 150 this.updateForm()
138 151
152 this.pluginService.ensurePluginsAreLoaded('video-edit')
153 .then(() => this.updatePluginFields())
154
139 this.serverService.getVideoCategories() 155 this.serverService.getVideoCategories()
140 .subscribe(res => this.videoCategories = res) 156 .subscribe(res => this.videoCategories = res)
157
141 this.serverService.getVideoLicences() 158 this.serverService.getVideoLicences()
142 .subscribe(res => this.videoLicences = res) 159 .subscribe(res => this.videoLicences = res)
160
143 forkJoin([ 161 forkJoin([
144 this.instanceService.getAbout(), 162 this.instanceService.getAbout(),
145 this.serverService.getVideoLanguages() 163 this.serverService.getVideoLanguages()
146 ]).pipe(map(([ about, languages ]) => ({ about, languages }))) 164 ]).pipe(map(([ about, languages ]) => ({ about, languages })))
147 .subscribe(res => { 165 .subscribe(res => {
148 this.videoLanguages = res.languages 166 this.videoLanguages = res.languages
149 .map(l => res.about.instance.languages.includes(l.id) 167 .map(l => {
150 ? { ...l, group: $localize`Instance languages`, groupOrder: 0 } 168 return res.about.instance.languages.includes(l.id)
151 : { ...l, group: $localize`All languages`, groupOrder: 1 }) 169 ? { ...l, group: $localize`Instance languages`, groupOrder: 0 }
170 : { ...l, group: $localize`All languages`, groupOrder: 1 }
171 })
152 .sort((a, b) => a.groupOrder - b.groupOrder) 172 .sort((a, b) => a.groupOrder - b.groupOrder)
153 }) 173 })
154 174
@@ -173,6 +193,8 @@ export class VideoEditComponent implements OnInit, OnDestroy {
173 this.ngZone.runOutsideAngular(() => { 193 this.ngZone.runOutsideAngular(() => {
174 this.schedulerInterval = setInterval(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute 194 this.schedulerInterval = setInterval(() => this.minScheduledDate = new Date(), 1000 * 60) // Update every minute
175 }) 195 })
196
197 this.hooks.runAction('action:video-edit.init', 'video-edit', { type: this.type })
176 } 198 }
177 199
178 ngOnDestroy () { 200 ngOnDestroy () {
@@ -223,6 +245,23 @@ export class VideoEditComponent implements OnInit, OnDestroy {
223 }) 245 })
224 } 246 }
225 247
248 private updatePluginFields () {
249 this.pluginFields = this.pluginService.getRegisteredVideoFormFields(this.type)
250
251 if (this.pluginFields.length === 0) return
252
253 const obj: any = {}
254
255 for (const setting of this.pluginFields) {
256 obj[setting.commonOptions.name] = new FormControl(setting.commonOptions.default)
257 }
258
259 this.pluginDataFormGroup = new FormGroup(obj)
260 this.form.addControl('pluginData', this.pluginDataFormGroup)
261
262 this.pluginFieldsAdded.emit()
263 }
264
226 private trackPrivacyChange () { 265 private trackPrivacyChange () {
227 // We will update the schedule input and the wait transcoding checkbox validators 266 // We will update the schedule input and the wait transcoding checkbox validators
228 this.form.controls[ 'privacy' ] 267 this.form.controls[ 'privacy' ]