aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/+videos
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
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')
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.html15
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.scss3
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.ts51
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.html1
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.html1
-rw-r--r--client/src/app/+videos/+video-edit/video-add-components/video-upload.component.html1
-rw-r--r--client/src/app/+videos/+video-edit/video-update.component.html3
-rw-r--r--client/src/app/+videos/+video-edit/video-update.component.ts8
8 files changed, 75 insertions, 8 deletions
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.html b/client/src/app/+videos/+video-edit/shared/video-edit.component.html
index ae3413e79..842997b20 100644
--- a/client/src/app/+videos/+video-edit/shared/video-edit.component.html
+++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.html
@@ -265,6 +265,21 @@
265 </ng-template> 265 </ng-template>
266 </ng-container> 266 </ng-container>
267 267
268 <ng-container ngbNavItem *ngIf="pluginFields.length !== 0">
269 <a ngbNavLink i18n>Plugin settings</a>
270
271 <ng-template ngbNavContent>
272 <div class="row plugin-settings">
273
274 <div class="col-md-12 col-xl-8">
275 <div *ngFor="let pluginSetting of pluginFields" class="form-group">
276 <my-dynamic-form-field [form]="pluginDataFormGroup" [formErrors]="formErrors" [setting]="pluginSetting.commonOptions"></my-dynamic-form-field>
277 </div>
278 </div>
279
280 </div>
281 </ng-template>
282 </ng-container>
268 </div> 283 </div>
269 284
270 <div [ngbNavOutlet]="nav"></div> 285 <div [ngbNavOutlet]="nav"></div>
diff --git a/client/src/app/+videos/+video-edit/shared/video-edit.component.scss b/client/src/app/+videos/+video-edit/shared/video-edit.component.scss
index 9caf009c5..3082a4f72 100644
--- a/client/src/app/+videos/+video-edit/shared/video-edit.component.scss
+++ b/client/src/app/+videos/+video-edit/shared/video-edit.component.scss
@@ -7,7 +7,8 @@
7@import 'variables'; 7@import 'variables';
8@import 'mixins'; 8@import 'mixins';
9 9
10label { 10label,
11my-dynamic-form-field ::ng-deep label {
11 font-weight: $font-regular; 12 font-weight: $font-regular;
12 font-size: 100%; 13 font-size: 100%;
13} 14}
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' ]
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.html b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.html
index 825cb6df4..785514c76 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.html
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-torrent.component.html
@@ -58,6 +58,7 @@
58 <my-video-edit 58 <my-video-edit
59 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false" 59 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false"
60 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels" 60 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
61 type="import-torrent"
61 ></my-video-edit> 62 ></my-video-edit>
62 63
63 <div class="submit-container"> 64 <div class="submit-container">
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.html b/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.html
index 2107dc9d0..3e4eb5fbc 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.html
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-import-url.component.html
@@ -54,6 +54,7 @@
54 <my-video-edit 54 <my-video-edit
55 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false" 55 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false"
56 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels" 56 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
57 type="import-url"
57 ></my-video-edit> 58 ></my-video-edit>
58 59
59 <div class="submit-container"> 60 <div class="submit-container">
diff --git a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.html b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.html
index ed697c25b..677fa1197 100644
--- a/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.html
+++ b/client/src/app/+videos/+video-edit/video-add-components/video-upload.component.html
@@ -69,6 +69,7 @@
69 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" 69 [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions"
70 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels" 70 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
71 [waitTranscodingEnabled]="waitTranscodingEnabled" 71 [waitTranscodingEnabled]="waitTranscodingEnabled"
72 type="upload"
72 ></my-video-edit> 73 ></my-video-edit>
73 74
74 <div class="submit-container"> 75 <div class="submit-container">
diff --git a/client/src/app/+videos/+video-edit/video-update.component.html b/client/src/app/+videos/+video-edit/video-update.component.html
index 6c1239395..b37596399 100644
--- a/client/src/app/+videos/+video-edit/video-update.component.html
+++ b/client/src/app/+videos/+video-edit/video-update.component.html
@@ -10,11 +10,12 @@
10 [form]="form" [formErrors]="formErrors" [schedulePublicationPossible]="schedulePublicationPossible" 10 [form]="form" [formErrors]="formErrors" [schedulePublicationPossible]="schedulePublicationPossible"
11 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels" 11 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
12 [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="waitTranscodingEnabled" 12 [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="waitTranscodingEnabled"
13 type="update" (pluginFieldsAdded)="hydratePluginFieldsFromVideo()"
13 ></my-video-edit> 14 ></my-video-edit>
14 15
15 <div class="submit-container"> 16 <div class="submit-container">
16 <my-button className="orange-button" i18n-label label="Update" icon="circle-tick" 17 <my-button className="orange-button" i18n-label label="Update" icon="circle-tick"
17 (click)="update()" (keydown.enter)="update()" 18 (click)="update()" (keydown.enter)="update()"
18 [disabled]="!form.valid || isUpdatingVideo === true" 19 [disabled]="!form.valid || isUpdatingVideo === true"
19 ></my-button> 20 ></my-button>
20 </div> 21 </div>
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 2e1d0f89d..20438a2d3 100644
--- a/client/src/app/+videos/+video-edit/video-update.component.ts
+++ b/client/src/app/+videos/+video-edit/video-update.component.ts
@@ -126,6 +126,14 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
126 ) 126 )
127 } 127 }
128 128
129 hydratePluginFieldsFromVideo () {
130 if (!this.video.pluginData) return
131
132 this.form.patchValue({
133 pluginData: this.video.pluginData
134 })
135 }
136
129 private hydrateFormFromVideo () { 137 private hydrateFormFromVideo () {
130 this.form.patchValue(this.video.toFormPatch()) 138 this.form.patchValue(this.video.toFormPatch())
131 139