import { map } from 'rxjs/operators'
import { SelectChannelItem } from 'src/types/select-options-item.model'
import { ChangeDetectorRef, Component, EventEmitter, Input, NgZone, OnDestroy, OnInit, Output, ViewChild } from '@angular/core'
-import { AbstractControl, FormArray, FormControl, FormGroup, ValidationErrors, Validators } from '@angular/forms'
+import { AbstractControl, FormArray, FormControl, FormGroup, Validators } from '@angular/forms'
import { HooksService, PluginService, ServerService } from '@app/core'
import { removeElementFromArray } from '@app/helpers'
import { BuildFormValidator } from '@app/shared/form-validators'
@Input() videoToUpdate: VideoDetails
@Input() userVideoChannels: SelectChannelItem[] = []
- @Input() schedulePublicationPossible = true
+ @Input() forbidScheduledPublication = true
@Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = []
.subscribe(privacies => {
this.videoPrivacies = this.videoService.explainedPrivacyLabels(privacies).videoPrivacies
- if (this.schedulePublicationPossible) {
- this.videoPrivacies.push({
- id: this.SPECIAL_SCHEDULED_PRIVACY,
- label: $localize`Scheduled`,
- description: $localize`Hide the video until a specific date`
- })
- }
+ // Can't schedule publication if private privacy is not available (could be deleted by a plugin)
+ const hasPrivatePrivacy = this.videoPrivacies.some(p => p.id === VideoPrivacy.PRIVATE)
+ if (this.forbidScheduledPublication || !hasPrivatePrivacy) return
+
+ this.videoPrivacies.push({
+ id: this.SPECIAL_SCHEDULED_PRIVACY,
+ label: $localize`Scheduled`,
+ description: $localize`Hide the video until a specific date`
+ })
})
this.initialVideoCaptions = this.videoCaptions.map(c => c.language.id)
for (const setting of this.pluginFields) {
await this.pluginService.translateSetting(setting.pluginInfo.plugin.npmName, setting.commonOptions)
- const validator = (control: AbstractControl): ValidationErrors | null => {
+ const validator = async (control: AbstractControl) => {
if (!setting.commonOptions.error) return null
- const error = setting.commonOptions.error({ formValues: this.form.value, value: control.value })
+ const error = await setting.commonOptions.error({ formValues: this.form.value, value: control.value })
return error?.error ? { [setting.commonOptions.name]: error.text } : null
}
const name = setting.commonOptions.name
pluginObj[name] = {
- VALIDATORS: [ validator ],
+ ASYNC_VALIDATORS: [ validator ],
+ VALIDATORS: [],
MESSAGES: {}
}
this.cd.detectChanges()
this.pluginFieldsAdded.emit()
+
+ // Plugins may need other control values to calculate potential errors
+ this.form.valueChanges.subscribe(() => this.formValidatorService.updateTreeValidity(this.pluginDataFormGroup))
}
private trackPrivacyChange () {