mirror of https://github.com/Chocobozzz/PeerTube
Add playlist channel validator when playlist is public
parent
c5e4e36d2a
commit
978c9d497b
|
@ -35,13 +35,17 @@ export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylis
|
||||||
|
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
this.buildForm({
|
this.buildForm({
|
||||||
'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME,
|
displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME,
|
||||||
privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY,
|
privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY,
|
||||||
description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION,
|
description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION,
|
||||||
videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID,
|
videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID,
|
||||||
thumbnailfile: null
|
thumbnailfile: null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.form.get('privacy').valueChanges.subscribe(privacy => {
|
||||||
|
this.videoPlaylistValidatorsService.setChannelValidator(this.form.get('videoChannelId'), privacy)
|
||||||
|
})
|
||||||
|
|
||||||
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
|
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
|
||||||
|
|
||||||
this.serverService.videoPlaylistPrivaciesLoaded.subscribe(
|
this.serverService.videoPlaylistPrivaciesLoaded.subscribe(
|
||||||
|
@ -60,7 +64,7 @@ export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylis
|
||||||
|
|
||||||
const body = this.form.value
|
const body = this.form.value
|
||||||
const videoPlaylistCreate: VideoPlaylistCreate = {
|
const videoPlaylistCreate: VideoPlaylistCreate = {
|
||||||
displayName: body['display-name'],
|
displayName: body.displayName,
|
||||||
privacy: body.privacy,
|
privacy: body.privacy,
|
||||||
description: body.description || null,
|
description: body.description || null,
|
||||||
videoChannelId: body.videoChannelId || null,
|
videoChannelId: body.videoChannelId || null,
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 col-xl-6">
|
<div class="col-md-12 col-xl-6">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label i18n for="display-name">Display name</label>
|
<label i18n for="displayName">Display name</label>
|
||||||
<input
|
<input
|
||||||
type="text" id="display-name"
|
type="text" id="displayName"
|
||||||
formControlName="display-name" [ngClass]="{ 'input-error': formErrors['display-name'] }"
|
formControlName="displayName" [ngClass]="{ 'input-error': formErrors['displayName'] }"
|
||||||
>
|
>
|
||||||
<div *ngIf="formErrors['display-name']" class="form-error">
|
<div *ngIf="formErrors['displayName']" class="form-error">
|
||||||
{{ formErrors['display-name'] }}
|
{{ formErrors['displayName'] }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -50,6 +50,10 @@
|
||||||
<option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
|
<option *ngFor="let channel of userVideoChannels" [value]="channel.id">{{ channel.label }}</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div *ngIf="formErrors['videoChannelId']" class="form-error">
|
||||||
|
{{ formErrors['videoChannelId'] }}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
|
|
|
@ -41,13 +41,17 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis
|
||||||
|
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
this.buildForm({
|
this.buildForm({
|
||||||
'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME,
|
displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME,
|
||||||
privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY,
|
privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY,
|
||||||
description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION,
|
description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION,
|
||||||
videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID,
|
videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID,
|
||||||
thumbnailfile: null
|
thumbnailfile: null
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.form.get('privacy').valueChanges.subscribe(privacy => {
|
||||||
|
this.videoPlaylistValidatorsService.setChannelValidator(this.form.get('videoChannelId'), privacy)
|
||||||
|
})
|
||||||
|
|
||||||
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
|
populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
|
||||||
|
|
||||||
this.paramsSub = this.route.params.subscribe(routeParams => {
|
this.paramsSub = this.route.params.subscribe(routeParams => {
|
||||||
|
@ -85,8 +89,8 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis
|
||||||
|
|
||||||
const body = this.form.value
|
const body = this.form.value
|
||||||
const videoPlaylistUpdate: VideoPlaylistUpdate = {
|
const videoPlaylistUpdate: VideoPlaylistUpdate = {
|
||||||
displayName: body['display-name'],
|
displayName: body.displayName,
|
||||||
privacy: body['privacy'],
|
privacy: body.privacy,
|
||||||
description: body.description || null,
|
description: body.description || null,
|
||||||
videoChannelId: body.videoChannelId || null,
|
videoChannelId: body.videoChannelId || null,
|
||||||
thumbnailfile: body.thumbnailfile || undefined
|
thumbnailfile: body.thumbnailfile || undefined
|
||||||
|
@ -115,7 +119,7 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis
|
||||||
|
|
||||||
private hydrateFormFromPlaylist () {
|
private hydrateFormFromPlaylist () {
|
||||||
this.form.patchValue({
|
this.form.patchValue({
|
||||||
'display-name': this.videoPlaylistToUpdate.displayName,
|
displayName: this.videoPlaylistToUpdate.displayName,
|
||||||
privacy: this.videoPlaylistToUpdate.privacy.id,
|
privacy: this.videoPlaylistToUpdate.privacy.id,
|
||||||
description: this.videoPlaylistToUpdate.description,
|
description: this.videoPlaylistToUpdate.description,
|
||||||
videoChannelId: this.videoPlaylistToUpdate.videoChannel ? this.videoPlaylistToUpdate.videoChannel.id : null
|
videoChannelId: this.videoPlaylistToUpdate.videoChannel ? this.videoPlaylistToUpdate.videoChannel.id : null
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
import { I18n } from '@ngx-translate/i18n-polyfill'
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||||
import { Validators } from '@angular/forms'
|
import { AbstractControl, FormControl, Validators } from '@angular/forms'
|
||||||
import { Injectable } from '@angular/core'
|
import { Injectable } from '@angular/core'
|
||||||
import { BuildFormValidator } from '@app/shared'
|
import { BuildFormValidator } from '@app/shared'
|
||||||
|
import { VideoPlaylistPrivacy } from '@shared/models'
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class VideoPlaylistValidatorsService {
|
export class VideoPlaylistValidatorsService {
|
||||||
|
@ -46,7 +47,20 @@ export class VideoPlaylistValidatorsService {
|
||||||
|
|
||||||
this.VIDEO_PLAYLIST_CHANNEL_ID = {
|
this.VIDEO_PLAYLIST_CHANNEL_ID = {
|
||||||
VALIDATORS: [ ],
|
VALIDATORS: [ ],
|
||||||
MESSAGES: { }
|
MESSAGES: {
|
||||||
|
'required': this.i18n('The channel is required when the playlist is public.')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setChannelValidator (channelControl: AbstractControl, privacy: VideoPlaylistPrivacy) {
|
||||||
|
if (privacy.toString() === VideoPlaylistPrivacy.PUBLIC.toString()) {
|
||||||
|
channelControl.setValidators([ Validators.required ])
|
||||||
|
} else {
|
||||||
|
channelControl.setValidators(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
channelControl.markAsDirty()
|
||||||
|
channelControl.updateValueAndValidity()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,13 +60,13 @@
|
||||||
|
|
||||||
<form class="new-playlist-block dropdown-item" *ngIf="isNewPlaylistBlockOpened" (ngSubmit)="createPlaylist()" [formGroup]="form">
|
<form class="new-playlist-block dropdown-item" *ngIf="isNewPlaylistBlockOpened" (ngSubmit)="createPlaylist()" [formGroup]="form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label i18n for="display-name">Display name</label>
|
<label i18n for="displayName">Display name</label>
|
||||||
<input
|
<input
|
||||||
type="text" id="display-name"
|
type="text" id="displayName"
|
||||||
formControlName="display-name" [ngClass]="{ 'input-error': formErrors['display-name'] }"
|
formControlName="displayName" [ngClass]="{ 'input-error': formErrors['displayName'] }"
|
||||||
>
|
>
|
||||||
<div *ngIf="formErrors['display-name']" class="form-error">
|
<div *ngIf="formErrors['displayName']" class="form-error">
|
||||||
{{ formErrors['display-name'] }}
|
{{ formErrors['displayName'] }}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { forkJoin } from 'rxjs'
|
||||||
import { Video, VideoPlaylistCreate, VideoPlaylistElementCreate, VideoPlaylistPrivacy } from '@shared/models'
|
import { Video, VideoPlaylistCreate, VideoPlaylistElementCreate, VideoPlaylistPrivacy } from '@shared/models'
|
||||||
import { FormReactive, FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/forms'
|
import { FormReactive, FormValidatorService, VideoPlaylistValidatorsService } from '@app/shared/forms'
|
||||||
import { I18n } from '@ngx-translate/i18n-polyfill'
|
import { I18n } from '@ngx-translate/i18n-polyfill'
|
||||||
import { secondsToTime, timeToInt } from '../../../assets/player/utils'
|
import { secondsToTime } from '../../../assets/player/utils'
|
||||||
|
|
||||||
type PlaylistSummary = {
|
type PlaylistSummary = {
|
||||||
id: number
|
id: number
|
||||||
|
@ -54,7 +54,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
|
||||||
this.resetOptions(true)
|
this.resetOptions(true)
|
||||||
|
|
||||||
this.buildForm({
|
this.buildForm({
|
||||||
'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME
|
displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME
|
||||||
})
|
})
|
||||||
|
|
||||||
forkJoin([
|
forkJoin([
|
||||||
|
@ -105,7 +105,7 @@ export class VideoAddToPlaylistComponent extends FormReactive implements OnInit
|
||||||
}
|
}
|
||||||
|
|
||||||
createPlaylist () {
|
createPlaylist () {
|
||||||
const displayName = this.form.value[ 'display-name' ]
|
const displayName = this.form.value[ 'displayName' ]
|
||||||
|
|
||||||
const videoPlaylistCreate: VideoPlaylistCreate = {
|
const videoPlaylistCreate: VideoPlaylistCreate = {
|
||||||
displayName,
|
displayName,
|
||||||
|
|
Loading…
Reference in New Issue