aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-04-22 14:25:32 +0200
committerChocobozzz <me@florianbigard.com>2021-04-22 14:35:49 +0200
commit0f319334065fae8756fe7c7eec333000474d07ba (patch)
tree2ddc1fa8bdb9307b82cf52c91c86d3ba7a33cf62
parent87e0b71d36ae3d8f098c2be0ab45a29c9f2854b4 (diff)
downloadPeerTube-0f319334065fae8756fe7c7eec333000474d07ba.tar.gz
PeerTube-0f319334065fae8756fe7c7eec333000474d07ba.tar.zst
PeerTube-0f319334065fae8756fe7c7eec333000474d07ba.zip
Add ability to hide plugin form fields
-rw-r--r--client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts5
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.html2
-rw-r--r--client/src/app/+videos/+video-edit/shared/video-edit.component.ts32
-rw-r--r--client/src/app/+videos/+video-edit/video-update.component.html2
-rw-r--r--client/src/standalone/videos/embed.ts1
-rw-r--r--shared/models/plugins/register-client-form-field.model.ts3
-rw-r--r--support/doc/plugins/guide.md8
7 files changed, 35 insertions, 18 deletions
diff --git a/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts b/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts
index 6ef4dbc68..34848b036 100644
--- a/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts
+++ b/client/src/app/+videos/+video-edit/shared/i18n-primeng-calendar.service.ts
@@ -3,7 +3,6 @@ import { PrimeNGConfig } from 'primeng/api'
3 3
4@Injectable() 4@Injectable()
5export class I18nPrimengCalendarService { 5export class I18nPrimengCalendarService {
6 private readonly calendarLocale: any = {}
7 6
8 constructor (private config: PrimeNGConfig) { 7 constructor (private config: PrimeNGConfig) {
9 this.config.setTranslation({ 8 this.config.setTranslation({
@@ -73,10 +72,6 @@ export class I18nPrimengCalendarService {
73 }) 72 })
74 } 73 }
75 74
76 getCalendarLocale () {
77 return this.calendarLocale
78 }
79
80 getTimezone () { 75 getTimezone () {
81 const gmt = new Date().toString().match(/([A-Z]+[\+-][0-9]+)/)[1] 76 const gmt = new Date().toString().match(/([A-Z]+[\+-][0-9]+)/)[1]
82 const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone 77 const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone
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 6208ab69b..6fe52af67 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
@@ -333,7 +333,7 @@
333 <div class="row plugin-settings"> 333 <div class="row plugin-settings">
334 334
335 <div class="col-md-12 col-xl-8"> 335 <div class="col-md-12 col-xl-8">
336 <div *ngFor="let pluginSetting of pluginFields" class="form-group"> 336 <div *ngFor="let pluginSetting of pluginFields" class="form-group" [hidden]="isPluginFieldHidden(pluginSetting)">
337 <my-dynamic-form-field [form]="pluginDataFormGroup" [formErrors]="formErrors" [setting]="pluginSetting.commonOptions"></my-dynamic-form-field> 337 <my-dynamic-form-field [form]="pluginDataFormGroup" [formErrors]="formErrors" [setting]="pluginSetting.commonOptions"></my-dynamic-form-field>
338 </div> 338 </div>
339 </div> 339 </div>
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 f51f52160..34119f7ab 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
@@ -2,7 +2,7 @@ import { 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 { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
5import { FormArray, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms' 5import { FormArray, FormControl, FormGroup, 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 { 8import {
@@ -21,13 +21,17 @@ import {
21import { FormReactiveValidationMessages, FormValidatorService } from '@app/shared/shared-forms' 21import { FormReactiveValidationMessages, FormValidatorService } from '@app/shared/shared-forms'
22import { InstanceService } from '@app/shared/shared-instance' 22import { InstanceService } from '@app/shared/shared-instance'
23import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main' 23import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main'
24import { LiveVideo, ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models' 24import { LiveVideo, ServerConfig, VideoConstant, VideoDetails, VideoPrivacy } from '@shared/models'
25import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model' 25import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model'
26import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service' 26import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service'
27import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component' 27import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component'
28import { VideoEditType } from './video-edit.type' 28import { VideoEditType } from './video-edit.type'
29 29
30type VideoLanguages = VideoConstant<string> & { group?: string } 30type VideoLanguages = VideoConstant<string> & { group?: string }
31type PluginField = {
32 commonOptions: RegisterClientFormFieldOptions
33 videoFormOptions: RegisterClientVideoFieldOptions
34}
31 35
32@Component({ 36@Component({
33 selector: 'my-video-edit', 37 selector: 'my-video-edit',
@@ -38,9 +42,14 @@ export class VideoEditComponent implements OnInit, OnDestroy {
38 @Input() form: FormGroup 42 @Input() form: FormGroup
39 @Input() formErrors: { [ id: string ]: string } = {} 43 @Input() formErrors: { [ id: string ]: string } = {}
40 @Input() validationMessages: FormReactiveValidationMessages = {} 44 @Input() validationMessages: FormReactiveValidationMessages = {}
45
46 @Input() videoToUpdate: VideoDetails
47
41 @Input() userVideoChannels: SelectChannelItem[] = [] 48 @Input() userVideoChannels: SelectChannelItem[] = []
42 @Input() schedulePublicationPossible = true 49 @Input() schedulePublicationPossible = true
50
43 @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = [] 51 @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = []
52
44 @Input() waitTranscodingEnabled = true 53 @Input() waitTranscodingEnabled = true
45 @Input() type: VideoEditType 54 @Input() type: VideoEditType
46 @Input() liveVideo: LiveVideo 55 @Input() liveVideo: LiveVideo
@@ -57,9 +66,6 @@ export class VideoEditComponent implements OnInit, OnDestroy {
57 videoLicences: VideoConstant<number>[] = [] 66 videoLicences: VideoConstant<number>[] = []
58 videoLanguages: VideoLanguages[] = [] 67 videoLanguages: VideoLanguages[] = []
59 68
60 tagValidators: ValidatorFn[]
61 tagValidatorsMessages: { [ name: string ]: string }
62
63 pluginDataFormGroup: FormGroup 69 pluginDataFormGroup: FormGroup
64 70
65 schedulePublicationEnabled = false 71 schedulePublicationEnabled = false
@@ -73,10 +79,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
73 79
74 serverConfig: ServerConfig 80 serverConfig: ServerConfig
75 81
76 pluginFields: { 82 pluginFields: PluginField[] = []
77 commonOptions: RegisterClientFormFieldOptions
78 videoFormOptions: RegisterClientVideoFieldOptions
79 }[] = []
80 83
81 private schedulerInterval: any 84 private schedulerInterval: any
82 private firstPatchDone = false 85 private firstPatchDone = false
@@ -92,7 +95,6 @@ export class VideoEditComponent implements OnInit, OnDestroy {
92 private ngZone: NgZone, 95 private ngZone: NgZone,
93 private hooks: HooksService 96 private hooks: HooksService
94 ) { 97 ) {
95 this.calendarLocale = this.i18nPrimengCalendarService.getCalendarLocale()
96 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone() 98 this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone()
97 this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat() 99 this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat()
98 } 100 }
@@ -251,6 +253,16 @@ export class VideoEditComponent implements OnInit, OnDestroy {
251 return this.form.value['permanentLive'] === true 253 return this.form.value['permanentLive'] === true
252 } 254 }
253 255
256 isPluginFieldHidden (pluginField: PluginField) {
257 if (typeof pluginField.commonOptions.hidden !== 'function') return false
258
259 return pluginField.commonOptions.hidden({
260 formValues: this.form.value,
261 videoToUpdate: this.videoToUpdate,
262 liveVideo: this.liveVideo
263 })
264 }
265
254 private sortVideoCaptions () { 266 private sortVideoCaptions () {
255 this.videoCaptions.sort((v1, v2) => { 267 this.videoCaptions.sort((v1, v2) => {
256 if (v1.language.label < v2.language.label) return -1 268 if (v1.language.label < v2.language.label) return -1
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 41501714f..3ce3e623e 100644
--- a/client/src/app/+videos/+video-edit/video-update.component.html
+++ b/client/src/app/+videos/+video-edit/video-update.component.html
@@ -11,7 +11,7 @@
11 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels" 11 [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
12 [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="isWaitTranscodingEnabled()" 12 [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="isWaitTranscodingEnabled()"
13 type="update" (pluginFieldsAdded)="hydratePluginFieldsFromVideo()" 13 type="update" (pluginFieldsAdded)="hydratePluginFieldsFromVideo()"
14 [liveVideo]="liveVideo" 14 [liveVideo]="liveVideo" [videoToUpdate]="videoDetails"
15 ></my-video-edit> 15 ></my-video-edit>
16 16
17 <div class="submit-container"> 17 <div class="submit-container">
diff --git a/client/src/standalone/videos/embed.ts b/client/src/standalone/videos/embed.ts
index 103014bb0..3a90fdc58 100644
--- a/client/src/standalone/videos/embed.ts
+++ b/client/src/standalone/videos/embed.ts
@@ -777,6 +777,7 @@ export class PeerTubeEmbed {
777 getSettings: unimplemented, 777 getSettings: unimplemented,
778 778
779 isLoggedIn: unimplemented, 779 isLoggedIn: unimplemented,
780 getAuthHeader: unimplemented,
780 781
781 notifier: { 782 notifier: {
782 info: unimplemented, 783 info: unimplemented,
diff --git a/shared/models/plugins/register-client-form-field.model.ts b/shared/models/plugins/register-client-form-field.model.ts
index db61dbc88..2df071337 100644
--- a/shared/models/plugins/register-client-form-field.model.ts
+++ b/shared/models/plugins/register-client-form-field.model.ts
@@ -13,6 +13,9 @@ export type RegisterClientFormFieldOptions = {
13 13
14 // Default setting value 14 // Default setting value
15 default?: string | boolean 15 default?: string | boolean
16
17 // Not supported by plugin setting registration, use registerSettingsScript instead
18 hidden?: (options: any) => boolean
16} 19}
17 20
18export interface RegisterClientVideoFieldOptions { 21export interface RegisterClientVideoFieldOptions {
diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md
index ca951c781..8d85092e7 100644
--- a/support/doc/plugins/guide.md
+++ b/support/doc/plugins/guide.md
@@ -623,7 +623,13 @@ async function register ({ registerVideoField, peertubeHelpers }) {
623 label: 'My added field', 623 label: 'My added field',
624 descriptionHTML: 'Optional description', 624 descriptionHTML: 'Optional description',
625 type: 'input-textarea', 625 type: 'input-textarea',
626 default: '' 626 default: '',
627 // Optional, to hide a field depending on the current form state
628 // liveVideo is in the options object when the user is creating/updating a live
629 // videoToUpdate is in the options object when the user is updating a video
630 hidden: ({ formValues, videoToUpdate, liveVideo }) => {
631 return formValues.pluginData['other-field'] === 'toto'
632 }
627 } 633 }
628 634
629 for (const type of [ 'upload', 'import-url', 'import-torrent', 'update', 'go-live' ]) { 635 for (const type of [ 'upload', 'import-url', 'import-torrent', 'update', 'go-live' ]) {