From 978c9d497b36e52196eb7e755406571e5d57cbc7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Mar 2019 14:55:10 +0100 Subject: Add playlist channel validator when playlist is public --- .../my-account-video-playlist-create.component.ts | 8 ++++++-- .../my-account-video-playlist-edit.component.html | 14 +++++++++----- .../my-account-video-playlist-update.component.ts | 12 ++++++++---- .../video-playlist-validators.service.ts | 18 ++++++++++++++++-- .../video-add-to-playlist.component.html | 10 +++++----- .../video-playlist/video-add-to-playlist.component.ts | 6 +++--- 6 files changed, 47 insertions(+), 21 deletions(-) (limited to 'client') diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts index 61b61e221..87a10961f 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts @@ -35,13 +35,17 @@ export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylis ngOnInit () { this.buildForm({ - 'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME, + displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME, privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY, description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION, videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID, thumbnailfile: null }) + this.form.get('privacy').valueChanges.subscribe(privacy => { + this.videoPlaylistValidatorsService.setChannelValidator(this.form.get('videoChannelId'), privacy) + }) + populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) this.serverService.videoPlaylistPrivaciesLoaded.subscribe( @@ -60,7 +64,7 @@ export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylis const body = this.form.value const videoPlaylistCreate: VideoPlaylistCreate = { - displayName: body['display-name'], + displayName: body.displayName, privacy: body.privacy, description: body.description || null, videoChannelId: body.videoChannelId || null, diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.component.html b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.component.html index 5d1184218..303fc46f7 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.component.html +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.component.html @@ -6,13 +6,13 @@
- + -
- {{ formErrors['display-name'] }} +
+ {{ formErrors['displayName'] }}
@@ -50,6 +50,10 @@
+ +
+ {{ formErrors['videoChannelId'] }} +
diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts index 167d7dd09..4887fdfb4 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts @@ -41,13 +41,17 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis ngOnInit () { this.buildForm({ - 'display-name': this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME, + displayName: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DISPLAY_NAME, privacy: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_PRIVACY, description: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_DESCRIPTION, videoChannelId: this.videoPlaylistValidatorsService.VIDEO_PLAYLIST_CHANNEL_ID, thumbnailfile: null }) + this.form.get('privacy').valueChanges.subscribe(privacy => { + this.videoPlaylistValidatorsService.setChannelValidator(this.form.get('videoChannelId'), privacy) + }) + populateAsyncUserVideoChannels(this.authService, this.userVideoChannels) this.paramsSub = this.route.params.subscribe(routeParams => { @@ -85,8 +89,8 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis const body = this.form.value const videoPlaylistUpdate: VideoPlaylistUpdate = { - displayName: body['display-name'], - privacy: body['privacy'], + displayName: body.displayName, + privacy: body.privacy, description: body.description || null, videoChannelId: body.videoChannelId || null, thumbnailfile: body.thumbnailfile || undefined @@ -115,7 +119,7 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis private hydrateFormFromPlaylist () { this.form.patchValue({ - 'display-name': this.videoPlaylistToUpdate.displayName, + displayName: this.videoPlaylistToUpdate.displayName, privacy: this.videoPlaylistToUpdate.privacy.id, description: this.videoPlaylistToUpdate.description, videoChannelId: this.videoPlaylistToUpdate.videoChannel ? this.videoPlaylistToUpdate.videoChannel.id : null diff --git a/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts b/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts index 726084b47..a2c9a5368 100644 --- a/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts +++ b/client/src/app/shared/forms/form-validators/video-playlist-validators.service.ts @@ -1,7 +1,8 @@ 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 { BuildFormValidator } from '@app/shared' +import { VideoPlaylistPrivacy } from '@shared/models' @Injectable() export class VideoPlaylistValidatorsService { @@ -46,7 +47,20 @@ export class VideoPlaylistValidatorsService { this.VIDEO_PLAYLIST_CHANNEL_ID = { 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() } } diff --git a/client/src/app/shared/video-playlist/video-add-to-playlist.component.html b/client/src/app/shared/video-playlist/video-add-to-playlist.component.html index f85e50d6d..19b326206 100644 --- a/client/src/app/shared/video-playlist/video-add-to-playlist.component.html +++ b/client/src/app/shared/video-playlist/video-add-to-playlist.component.html @@ -60,13 +60,13 @@