diff options
Diffstat (limited to 'client/src/app/videos')
3 files changed, 39 insertions, 3 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' |
18 | import { VideoEdit } from '../../../shared/video/video-edit.model' | 18 | import { VideoEdit } from '../../../shared/video/video-edit.model' |
19 | import { 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 | } |
diff --git a/client/src/app/videos/+video-edit/video-add.component.ts b/client/src/app/videos/+video-edit/video-add.component.ts index 032504cea..997f033b7 100644 --- a/client/src/app/videos/+video-edit/video-add.component.ts +++ b/client/src/app/videos/+video-edit/video-add.component.ts | |||
@@ -42,7 +42,7 @@ export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy | |||
42 | formErrors: { [ id: string ]: string } = {} | 42 | formErrors: { [ id: string ]: string } = {} |
43 | validationMessages: ValidatorMessage = {} | 43 | validationMessages: ValidatorMessage = {} |
44 | 44 | ||
45 | userVideoChannels = [] | 45 | userVideoChannels: { id: number, label: string, support: string }[] = [] |
46 | userVideoQuotaUsed = 0 | 46 | userVideoQuotaUsed = 0 |
47 | videoPrivacies = [] | 47 | videoPrivacies = [] |
48 | firstStepPrivacyId = 0 | 48 | firstStepPrivacyId = 0 |
diff --git a/client/src/app/videos/+video-edit/video-update.component.ts b/client/src/app/videos/+video-edit/video-update.component.ts index 339da1bf4..310285f92 100644 --- a/client/src/app/videos/+video-edit/video-update.component.ts +++ b/client/src/app/videos/+video-edit/video-update.component.ts | |||
@@ -66,7 +66,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit { | |||
66 | .listAccountVideoChannels(video.account) | 66 | .listAccountVideoChannels(video.account) |
67 | .pipe( | 67 | .pipe( |
68 | map(result => result.data), | 68 | map(result => result.data), |
69 | map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName }))), | 69 | map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support }))), |
70 | map(videoChannels => ({ video, videoChannels })) | 70 | map(videoChannels => ({ video, videoChannels })) |
71 | ) | 71 | ) |
72 | }) | 72 | }) |