From 0f319334065fae8756fe7c7eec333000474d07ba Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 22 Apr 2021 14:25:32 +0200 Subject: Add ability to hide plugin form fields --- .../shared/i18n-primeng-calendar.service.ts | 5 ---- .../+video-edit/shared/video-edit.component.html | 2 +- .../+video-edit/shared/video-edit.component.ts | 32 +++++++++++++++------- .../+video-edit/video-update.component.html | 2 +- client/src/standalone/videos/embed.ts | 1 + 5 files changed, 25 insertions(+), 17 deletions(-) (limited to 'client') 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' @Injectable() export class I18nPrimengCalendarService { - private readonly calendarLocale: any = {} constructor (private config: PrimeNGConfig) { this.config.setTranslation({ @@ -73,10 +72,6 @@ export class I18nPrimengCalendarService { }) } - getCalendarLocale () { - return this.calendarLocale - } - getTimezone () { const gmt = new Date().toString().match(/([A-Z]+[\+-][0-9]+)/)[1] 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 @@
-
+
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' import { map } from 'rxjs/operators' import { SelectChannelItem } from 'src/types/select-options-item.model' import { Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core' -import { FormArray, FormControl, FormGroup, ValidatorFn, Validators } from '@angular/forms' +import { FormArray, FormControl, FormGroup, Validators } from '@angular/forms' import { HooksService, PluginService, ServerService } from '@app/core' import { removeElementFromArray } from '@app/helpers' import { @@ -21,13 +21,17 @@ import { import { FormReactiveValidationMessages, FormValidatorService } from '@app/shared/shared-forms' import { InstanceService } from '@app/shared/shared-instance' import { VideoCaptionEdit, VideoEdit, VideoService } from '@app/shared/shared-main' -import { LiveVideo, ServerConfig, VideoConstant, VideoPrivacy } from '@shared/models' +import { LiveVideo, ServerConfig, VideoConstant, VideoDetails, VideoPrivacy } from '@shared/models' import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model' import { I18nPrimengCalendarService } from './i18n-primeng-calendar.service' import { VideoCaptionAddModalComponent } from './video-caption-add-modal.component' import { VideoEditType } from './video-edit.type' type VideoLanguages = VideoConstant & { group?: string } +type PluginField = { + commonOptions: RegisterClientFormFieldOptions + videoFormOptions: RegisterClientVideoFieldOptions +} @Component({ selector: 'my-video-edit', @@ -38,9 +42,14 @@ export class VideoEditComponent implements OnInit, OnDestroy { @Input() form: FormGroup @Input() formErrors: { [ id: string ]: string } = {} @Input() validationMessages: FormReactiveValidationMessages = {} + + @Input() videoToUpdate: VideoDetails + @Input() userVideoChannels: SelectChannelItem[] = [] @Input() schedulePublicationPossible = true + @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = [] + @Input() waitTranscodingEnabled = true @Input() type: VideoEditType @Input() liveVideo: LiveVideo @@ -57,9 +66,6 @@ export class VideoEditComponent implements OnInit, OnDestroy { videoLicences: VideoConstant[] = [] videoLanguages: VideoLanguages[] = [] - tagValidators: ValidatorFn[] - tagValidatorsMessages: { [ name: string ]: string } - pluginDataFormGroup: FormGroup schedulePublicationEnabled = false @@ -73,10 +79,7 @@ export class VideoEditComponent implements OnInit, OnDestroy { serverConfig: ServerConfig - pluginFields: { - commonOptions: RegisterClientFormFieldOptions - videoFormOptions: RegisterClientVideoFieldOptions - }[] = [] + pluginFields: PluginField[] = [] private schedulerInterval: any private firstPatchDone = false @@ -92,7 +95,6 @@ export class VideoEditComponent implements OnInit, OnDestroy { private ngZone: NgZone, private hooks: HooksService ) { - this.calendarLocale = this.i18nPrimengCalendarService.getCalendarLocale() this.calendarTimezone = this.i18nPrimengCalendarService.getTimezone() this.calendarDateFormat = this.i18nPrimengCalendarService.getDateFormat() } @@ -251,6 +253,16 @@ export class VideoEditComponent implements OnInit, OnDestroy { return this.form.value['permanentLive'] === true } + isPluginFieldHidden (pluginField: PluginField) { + if (typeof pluginField.commonOptions.hidden !== 'function') return false + + return pluginField.commonOptions.hidden({ + formValues: this.form.value, + videoToUpdate: this.videoToUpdate, + liveVideo: this.liveVideo + }) + } + private sortVideoCaptions () { this.videoCaptions.sort((v1, v2) => { 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 @@ [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels" [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="isWaitTranscodingEnabled()" type="update" (pluginFieldsAdded)="hydratePluginFieldsFromVideo()" - [liveVideo]="liveVideo" + [liveVideo]="liveVideo" [videoToUpdate]="videoDetails" >
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 { getSettings: unimplemented, isLoggedIn: unimplemented, + getAuthHeader: unimplemented, notifier: { info: unimplemented, -- cgit v1.2.3