aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/videos/+video-edit/shared/video-edit.component.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2018-05-25 18:32:53 +0200
committerChocobozzz <me@florianbigard.com>2018-05-25 18:32:53 +0200
commit74af5145f210e7e23d40b22c9ee3d968723d2595 (patch)
treed8910eeb89d75e36ecd5fd4f6090ec643d13a099 /client/src/app/videos/+video-edit/shared/video-edit.component.ts
parent407eab9c954a99fa8b65c637e4b1a37920fd849e (diff)
downloadPeerTube-74af5145f210e7e23d40b22c9ee3d968723d2595.tar.gz
PeerTube-74af5145f210e7e23d40b22c9ee3d968723d2595.tar.zst
PeerTube-74af5145f210e7e23d40b22c9ee3d968723d2595.zip
Video support field inherits channel support field
Diffstat (limited to 'client/src/app/videos/+video-edit/shared/video-edit.component.ts')
-rw-r--r--client/src/app/videos/+video-edit/shared/video-edit.component.ts38
1 files changed, 37 insertions, 1 deletions
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 d4567e26c..ccfae5fcc 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
@@ -16,6 +16,7 @@ import {
16 VIDEO_TAGS 16 VIDEO_TAGS
17} from '../../../shared/forms/form-validators/video' 17} from '../../../shared/forms/form-validators/video'
18import { VideoEdit } from '../../../shared/video/video-edit.model' 18import { VideoEdit } from '../../../shared/video/video-edit.model'
19import { map } from 'rxjs/operators'
19 20
20@Component({ 21@Component({
21 selector: 'my-video-edit', 22 selector: 'my-video-edit',
@@ -28,7 +29,7 @@ export class VideoEditComponent implements OnInit {
28 @Input() formErrors: { [ id: string ]: string } = {} 29 @Input() formErrors: { [ id: string ]: string } = {}
29 @Input() validationMessages: ValidatorMessage = {} 30 @Input() validationMessages: ValidatorMessage = {}
30 @Input() videoPrivacies = [] 31 @Input() videoPrivacies = []
31 @Input() userVideoChannels = [] 32 @Input() userVideoChannels: { id: number, label: string, support: string }[] = []
32 33
33 videoCategories = [] 34 videoCategories = []
34 videoLicences = [] 35 videoLicences = []
@@ -84,6 +85,37 @@ export class VideoEditComponent implements OnInit {
84 this.form.addControl('thumbnailfile', new FormControl('')) 85 this.form.addControl('thumbnailfile', new FormControl(''))
85 this.form.addControl('previewfile', new FormControl('')) 86 this.form.addControl('previewfile', new FormControl(''))
86 this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS)) 87 this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS))
88
89 // We will update the "support" field depending on the channel
90 this.form.controls['channelId']
91 .valueChanges
92 .pipe(map(res => parseInt(res.toString(), 10)))
93 .subscribe(
94 newChannelId => {
95 const oldChannelId = parseInt(this.form.value['channelId'], 10)
96 const currentSupport = this.form.value['support']
97
98 // Not initialized yet
99 if (isNaN(newChannelId)) return
100 const newChannel = this.userVideoChannels.find(c => c.id === newChannelId)
101
102 // First time we set the channel?
103 if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support)
104 const oldChannel = this.userVideoChannels.find(c => c.id === oldChannelId)
105
106 if (!newChannel || !oldChannel) {
107 console.error('Cannot find new or old channel.')
108 return
109 }
110
111 // If the current support text is not the same than the old channel, the user updated it.
112 // We don't want the user to lose his text, so stop here
113 if (currentSupport && currentSupport !== oldChannel.support) return
114
115 // Update the support text with our new channel
116 this.updateSupportField(newChannel.support)
117 }
118 )
87 } 119 }
88 120
89 ngOnInit () { 121 ngOnInit () {
@@ -93,4 +125,8 @@ export class VideoEditComponent implements OnInit {
93 this.videoLicences = this.serverService.getVideoLicences() 125 this.videoLicences = this.serverService.getVideoLicences()
94 this.videoLanguages = this.serverService.getVideoLanguages() 126 this.videoLanguages = this.serverService.getVideoLanguages()
95 } 127 }
128
129 private updateSupportField (support: string) {
130 return this.form.patchValue({ support: support || '' })
131 }
96} 132}