]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Video support field inherits channel support field
authorChocobozzz <me@florianbigard.com>
Fri, 25 May 2018 16:32:53 +0000 (18:32 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 25 May 2018 16:32:53 +0000 (18:32 +0200)
client/src/app/+my-account/my-account-video-channels/my-account-video-channel-edit.component.html
client/src/app/shared/forms/markdown-textarea.component.scss
client/src/app/shared/misc/utils.ts
client/src/app/videos/+video-edit/shared/video-edit.component.ts
client/src/app/videos/+video-edit/video-add.component.ts
client/src/app/videos/+video-edit/video-update.component.ts

index d5fb6262a874f49eab43bdc555c459ee1fd55707..10d408d55be9f7fe36f625bbf89ec89d4098d9f8 100644 (file)
 
   <div class="form-group">
     <label for="support">Support</label>
-    <my-help helpType="markdownEnhanced" preHtml="Short text to tell people how they can support your channel (membership platform...)."></my-help>
+    <my-help
+      helpType="markdownEnhanced" preHtml="Short text to tell people how they can support your channel (membership platform...).<br /><br />
+When you will upload a video in this channel, the video support field will be automatically filled by this text."
+    ></my-help>
     <my-markdown-textarea
         id="support" formControlName="support" textareaWidth="500px" [previewColumn]="true" markdownType="enhanced"
         [classes]="{ 'input-error': formErrors['support'] }"
index 9c92a67d90f0946c3ed2c75ae61eb185f3234200..118b38b9116355410f1b32c71b51a00eb319cefb 100644 (file)
@@ -13,6 +13,7 @@
   .previews {
     max-height: 150px;
     overflow-y: auto;
+    flex-grow: 1;
   }
 
   /deep/ {
index 727e339350d6717266a8a424451a488fa88a5d6e..11933e90b48c218494718f7b37706a032a7ccc03 100644 (file)
@@ -17,7 +17,7 @@ function getParameterByName (name: string, url: string) {
   return decodeURIComponent(results[2].replace(/\+/g, ' '))
 }
 
-function populateAsyncUserVideoChannels (authService: AuthService, channel: any[]) {
+function populateAsyncUserVideoChannels (authService: AuthService, channel: { id: number, label: string, support: string }[]) {
   return new Promise(res => {
     authService.userInformationLoaded
       .subscribe(
@@ -28,7 +28,7 @@ function populateAsyncUserVideoChannels (authService: AuthService, channel: any[
           const videoChannels = user.videoChannels
           if (Array.isArray(videoChannels) === false) return
 
-          videoChannels.forEach(c => channel.push({ id: c.id, label: c.displayName }))
+          videoChannels.forEach(c => channel.push({ id: c.id, label: c.displayName, support: c.support }))
 
           return res()
         }
index d4567e26c9db71a2900f05c04ef80a20278be689..ccfae5fcc00424a77900161ebf6836d169681695 100644 (file)
@@ -16,6 +16,7 @@ import {
   VIDEO_TAGS
 } from '../../../shared/forms/form-validators/video'
 import { VideoEdit } from '../../../shared/video/video-edit.model'
+import { map } from 'rxjs/operators'
 
 @Component({
   selector: 'my-video-edit',
@@ -28,7 +29,7 @@ export class VideoEditComponent implements OnInit {
   @Input() formErrors: { [ id: string ]: string } = {}
   @Input() validationMessages: ValidatorMessage = {}
   @Input() videoPrivacies = []
-  @Input() userVideoChannels = []
+  @Input() userVideoChannels: { id: number, label: string, support: string }[] = []
 
   videoCategories = []
   videoLicences = []
@@ -84,6 +85,37 @@ export class VideoEditComponent implements OnInit {
     this.form.addControl('thumbnailfile', new FormControl(''))
     this.form.addControl('previewfile', new FormControl(''))
     this.form.addControl('support', new FormControl('', VIDEO_SUPPORT.VALIDATORS))
+
+    // We will update the "support" field depending on the channel
+    this.form.controls['channelId']
+      .valueChanges
+      .pipe(map(res => parseInt(res.toString(), 10)))
+      .subscribe(
+        newChannelId => {
+          const oldChannelId = parseInt(this.form.value['channelId'], 10)
+          const currentSupport = this.form.value['support']
+
+          // Not initialized yet
+          if (isNaN(newChannelId)) return
+          const newChannel = this.userVideoChannels.find(c => c.id === newChannelId)
+
+          // First time we set the channel?
+          if (isNaN(oldChannelId)) return this.updateSupportField(newChannel.support)
+          const oldChannel = this.userVideoChannels.find(c => c.id === oldChannelId)
+
+          if (!newChannel || !oldChannel) {
+            console.error('Cannot find new or old channel.')
+            return
+          }
+
+          // If the current support text is not the same than the old channel, the user updated it.
+          // We don't want the user to lose his text, so stop here
+          if (currentSupport && currentSupport !== oldChannel.support) return
+
+          // Update the support text with our new channel
+          this.updateSupportField(newChannel.support)
+        }
+      )
   }
 
   ngOnInit () {
@@ -93,4 +125,8 @@ export class VideoEditComponent implements OnInit {
     this.videoLicences = this.serverService.getVideoLicences()
     this.videoLanguages = this.serverService.getVideoLanguages()
   }
+
+  private updateSupportField (support: string) {
+    return this.form.patchValue({ support: support || '' })
+  }
 }
index 032504cea2aaea3d3972d0c9e3bd08bc7d309f09..997f033b75faa3b9a38078008fc8a629f9a746fc 100644 (file)
@@ -42,7 +42,7 @@ export class VideoAddComponent extends FormReactive implements OnInit, OnDestroy
   formErrors: { [ id: string ]: string } = {}
   validationMessages: ValidatorMessage = {}
 
-  userVideoChannels = []
+  userVideoChannels: { id: number, label: string, support: string }[] = []
   userVideoQuotaUsed = 0
   videoPrivacies = []
   firstStepPrivacyId = 0
index 339da1bf472fe41823dce633ee49319a430cfce0..310285f923caac1723e62c95cfd73cee1180c068 100644 (file)
@@ -66,7 +66,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
                        .listAccountVideoChannels(video.account)
                        .pipe(
                          map(result => result.data),
-                         map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName }))),
+                         map(videoChannels => videoChannels.map(c => ({ id: c.id, label: c.displayName, support: c.support }))),
                          map(videoChannels => ({ video, videoChannels }))
                        )
           })