Add ability to set a public to private in client
authorChocobozzz <me@florianbigard.com>
Fri, 7 Jun 2019 12:50:27 +0000 (14:50 +0200)
committerChocobozzz <me@florianbigard.com>
Fri, 7 Jun 2019 13:01:55 +0000 (15:01 +0200)
12 files changed:
client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-create.component.ts
client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.ts
client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-update.component.ts
client/src/app/videos/+video-edit/shared/video-edit.component.ts
client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html
client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts
client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html
client/src/app/videos/+video-edit/video-add-components/video-send.ts
client/src/app/videos/+video-edit/video-add-components/video-upload.component.html
client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
client/src/app/videos/+video-edit/video-update.component.html
client/src/app/videos/+video-edit/video-update.component.ts

index 87a10961f4b9466c0f969f26e6fea7ac3a45a62e..8aed8b5135cc7f0d329e0542f8106674a0ed1565 100644 (file)
@@ -7,7 +7,6 @@ import { FormValidatorService } from '@app/shared/forms/form-validators/form-val
 import { VideoPlaylistValidatorsService } from '@app/shared'
 import { VideoPlaylistCreate } from '@shared/models/videos/playlist/video-playlist-create.model'
 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
-import { VideoConstant } from '@shared/models'
 import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model'
 import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
 
@@ -18,7 +17,6 @@ import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
 })
 export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylistEdit implements OnInit {
   error: string
-  videoPlaylistPrivacies: VideoConstant<VideoPlaylistPrivacy>[] = []
 
   constructor (
     protected formValidatorService: FormValidatorService,
@@ -47,6 +45,7 @@ export class MyAccountVideoPlaylistCreateComponent extends MyAccountVideoPlaylis
     })
 
     populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
+      .catch(err => console.error('Cannot populate user video channels.', err))
 
     this.serverService.videoPlaylistPrivaciesLoaded.subscribe(
       () => {
index 81dd9a75fe40d759f24a5276ed896e3e9ec8bc49..e9418878630ea0a458983b780489326dfa0dd4ff 100644 (file)
@@ -1,10 +1,12 @@
 import { FormReactive } from '@app/shared'
 import { VideoPlaylist } from '@shared/models/videos/playlist/video-playlist.model'
+import { VideoConstant, VideoPlaylistPrivacy } from '@shared/models'
 
 export abstract class MyAccountVideoPlaylistEdit extends FormReactive {
   // Declare it here to avoid errors in create template
   videoPlaylistToUpdate: VideoPlaylist
   userVideoChannels: { id: number, label: string }[] = []
+  videoPlaylistPrivacies: VideoConstant<VideoPlaylistPrivacy>[] = []
 
   abstract isCreation (): boolean
   abstract getFormButtonTitle (): string
index 4887fdfb4f5d1bf10b329c7a4471a721bcba901b..917ad725844cfcd45f72ea0bf29b89d1775074a2 100644 (file)
@@ -9,9 +9,8 @@ import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
 import { VideoPlaylistService } from '@app/shared/video-playlist/video-playlist.service'
 import { VideoPlaylistValidatorsService } from '@app/shared'
 import { VideoPlaylistUpdate } from '@shared/models/videos/playlist/video-playlist-update.model'
-import { VideoConstant } from '@shared/models'
-import { VideoPlaylistPrivacy } from '@shared/models/videos/playlist/video-playlist-privacy.model'
 import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
+import { delayWhen, map, switchMap } from 'rxjs/operators'
 
 @Component({
   selector: 'my-account-video-playlist-update',
@@ -21,7 +20,6 @@ import { VideoPlaylist } from '@app/shared/video-playlist/video-playlist.model'
 export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylistEdit implements OnInit, OnDestroy {
   error: string
   videoPlaylistToUpdate: VideoPlaylist
-  videoPlaylistPrivacies: VideoConstant<VideoPlaylistPrivacy>[] = []
 
   private paramsSub: Subscription
 
@@ -53,31 +51,24 @@ export class MyAccountVideoPlaylistUpdateComponent extends MyAccountVideoPlaylis
     })
 
     populateAsyncUserVideoChannels(this.authService, this.userVideoChannels)
-
-    this.paramsSub = this.route.params.subscribe(routeParams => {
-      const videoPlaylistId = routeParams['videoPlaylistId']
-
-      this.videoPlaylistService.getVideoPlaylist(videoPlaylistId).subscribe(
-        videoPlaylistToUpdate => {
-          this.videoPlaylistToUpdate = videoPlaylistToUpdate
-
-          this.hydrateFormFromPlaylist()
-
-          this.serverService.videoPlaylistPrivaciesLoaded.subscribe(
-            () => {
-              this.videoPlaylistPrivacies = this.serverService.getVideoPlaylistPrivacies()
-                .filter(p => {
-                  // If the playlist is not private, we cannot put it in private anymore
-                  return this.videoPlaylistToUpdate.privacy.id === VideoPlaylistPrivacy.PRIVATE ||
-                    p.id !== VideoPlaylistPrivacy.PRIVATE
-                })
-            }
-          )
-        },
-
-        err => this.error = err.message
-      )
-    })
+      .catch(err => console.error('Cannot populate user video channels.', err))
+
+    this.paramsSub = this.route.params
+                         .pipe(
+                           map(routeParams => routeParams['videoPlaylistId']),
+                           switchMap(videoPlaylistId => this.videoPlaylistService.getVideoPlaylist(videoPlaylistId)),
+                           delayWhen(() => this.serverService.videoPlaylistPrivaciesLoaded)
+                         )
+                         .subscribe(
+                           videoPlaylistToUpdate => {
+                             this.videoPlaylistPrivacies = this.serverService.getVideoPlaylistPrivacies()
+                             this.videoPlaylistToUpdate = videoPlaylistToUpdate
+
+                             this.hydrateFormFromPlaylist()
+                           },
+
+                           err => this.error = err.message
+                         )
   }
 
   ngOnDestroy () {
index 95d397b528701593abebdcc1d35ee8d21a34f1f0..a2776b73dacbc2b4875203a3db8d9527bfa0f079 100644 (file)
@@ -13,6 +13,7 @@ import { VideoCaptionAddModalComponent } from '@app/videos/+video-edit/shared/vi
 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
 import { removeElementFromArray } from '@app/shared/misc/utils'
 import { VideoConstant, VideoPrivacy } from '../../../../../../shared'
+import { VideoService } from '@app/shared/video/video.service'
 
 @Component({
   selector: 'my-video-edit',
@@ -23,7 +24,6 @@ export class VideoEditComponent implements OnInit, OnDestroy {
   @Input() form: FormGroup
   @Input() formErrors: { [ id: string ]: string } = {}
   @Input() validationMessages: FormReactiveValidationMessages = {}
-  @Input() videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   @Input() userVideoChannels: { id: number, label: string, support: string }[] = []
   @Input() schedulePublicationPossible = true
   @Input() videoCaptions: (VideoCaptionEdit & { captionPath?: string })[] = []
@@ -34,6 +34,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
   // So that it can be accessed in the template
   readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
 
+  videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   videoCategories: VideoConstant<number>[] = []
   videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
@@ -58,6 +59,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
     private formValidatorService: FormValidatorService,
     private videoValidatorsService: VideoValidatorsService,
     private videoCaptionService: VideoCaptionService,
+    private videoService: VideoService,
     private route: ActivatedRoute,
     private router: Router,
     private notifier: Notifier,
@@ -132,6 +134,9 @@ export class VideoEditComponent implements OnInit, OnDestroy {
     this.videoLicences = this.serverService.getVideoLicences()
     this.videoLanguages = this.serverService.getVideoLanguages()
 
+    const privacies = this.serverService.getVideoPrivacies()
+    this.videoPrivacies = this.videoService.explainedPrivacyLabels(privacies)
+
     this.initialVideoCaptions = this.videoCaptions.map(c => c.language.id)
 
     this.ngZone.runOutsideAngular(() => {
index 537d7ffa2b36a47139c74358102f7a54df484385..7a495fea5997d400ff8e7ec86738e6d68f44d26e 100644 (file)
@@ -58,7 +58,7 @@
 <form [hidden]="!hasImportedVideo" novalidate [formGroup]="form">
   <my-video-edit
     [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false"
-    [validationMessages]="validationMessages" [videoPrivacies]="explainedVideoPrivacies" [userVideoChannels]="userVideoChannels"
+    [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
   ></my-video-edit>
 
   <div class="submit-container">
index d2e9f6cfe2a24cee2468a7c60179a9868e3ef7d9..ed9cb5840803ca3345b68f196fb5c176715eaf1d 100644 (file)
@@ -100,7 +100,6 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca
           previewUrl: null
         }))
 
-        this.explainedVideoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
 
         this.hydrateFormFromVideo()
       },
index 984b9d590314420c86756112b6b3921f7f225b72..e4f19faa866ca4a618ee6994d83f9bf55d26c557 100644 (file)
@@ -51,7 +51,7 @@
 <form [hidden]="!hasImportedVideo" novalidate [formGroup]="form">
   <my-video-edit
     [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions" [schedulePublicationPossible]="false"
-    [validationMessages]="validationMessages" [videoPrivacies]="explainedVideoPrivacies" [userVideoChannels]="userVideoChannels"
+    [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
   ></my-video-edit>
 
   <div class="submit-container">
index 8401caeec51b8a6c7608c60d0930f5970d451fe9..580c123a029a59cc10a857545a441b9c60cdc28c 100644 (file)
@@ -14,7 +14,6 @@ import { CanComponentDeactivateResult } from '@app/shared/guards/can-deactivate-
 export abstract class VideoSend extends FormReactive implements OnInit {
   userVideoChannels: { id: number, label: string, support: string }[] = []
   videoPrivacies: VideoConstant<VideoPrivacy>[] = []
-  explainedVideoPrivacies: VideoConstant<VideoPrivacy>[] = []
   videoCaptions: VideoCaptionEdit[] = []
 
   firstStepPrivacyId = 0
index 3247a2bd6c381a03a44847c8c0f7724de5659829..0f904affbb8cde071cf2d91ce3c85c5685464a6d 100644 (file)
@@ -71,7 +71,7 @@
 <form [hidden]="!isUploadingVideo" novalidate [formGroup]="form">
   <my-video-edit
     [form]="form" [formErrors]="formErrors" [videoCaptions]="videoCaptions"
-    [validationMessages]="validationMessages" [videoPrivacies]="explainedVideoPrivacies" [userVideoChannels]="userVideoChannels"
+    [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
     [waitTranscodingEnabled]="waitTranscodingEnabled"
   ></my-video-edit>
 
index 73de25c59484a89a179d8e62c30c114666acb7da..69fa13a2f3280d4916ab54a2b75984ba559eda20 100644 (file)
@@ -188,8 +188,6 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
       previewfile: this.previewfileUpload
     })
 
-    this.explainedVideoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
-
     this.videoUploadObservable = this.videoService.uploadVideo(formData).subscribe(
       event => {
         if (event.type === HttpEventType.UploadProgress) {
index b5cab7ed5d2b7d9feac788e4fe87e5313cbc89f7..aa148311f8d3b89283cf9a0d2c8e48981eb6b0ff 100644 (file)
@@ -7,7 +7,7 @@
 
     <my-video-edit
       [form]="form" [formErrors]="formErrors" [schedulePublicationPossible]="schedulePublicationPossible"
-      [validationMessages]="validationMessages" [videoPrivacies]="explainedVideoPrivacies" [userVideoChannels]="userVideoChannels"
+      [validationMessages]="validationMessages" [userVideoChannels]="userVideoChannels"
       [videoCaptions]="videoCaptions" [waitTranscodingEnabled]="waitTranscodingEnabled"
     ></my-video-edit>
 
index 10f797d028bbeda17828b7dccffdb127d2d5cb09..e990ceb137c460e145a6da96bba47db19fbb9dd4 100644 (file)
@@ -3,7 +3,6 @@ import { Component, HostListener, OnInit } from '@angular/core'
 import { ActivatedRoute, Router } from '@angular/router'
 import { LoadingBarService } from '@ngx-loading-bar/core'
 import { Notifier } from '@app/core'
-import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
 import { ServerService } from '../../core'
 import { FormReactive } from '../../shared'
 import { VideoEdit } from '../../shared/video/video-edit.model'
@@ -23,8 +22,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   video: VideoEdit
 
   isUpdatingVideo = false
-  videoPrivacies: VideoConstant<VideoPrivacy>[] = []
-  explainedVideoPrivacies: VideoConstant<VideoPrivacy>[] = []
   userVideoChannels: { id: number, label: string, support: string }[] = []
   schedulePublicationPossible = false
   videoCaptions: VideoCaptionEdit[] = []
@@ -49,9 +46,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   ngOnInit () {
     this.buildForm({})
 
-    this.serverService.videoPrivaciesLoaded
-        .subscribe(() => this.videoPrivacies = this.serverService.getVideoPrivacies())
-
     this.route.data
         .pipe(map(data => data.videoData))
         .subscribe(({ video, videoChannels, videoCaptions }) => {
@@ -59,15 +53,6 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
           this.userVideoChannels = videoChannels
           this.videoCaptions = videoCaptions
 
-          // We cannot set private a video that was not private
-          if (this.video.privacy !== VideoPrivacy.PRIVATE) {
-            this.videoPrivacies = this.videoPrivacies.filter(p => p.id !== VideoPrivacy.PRIVATE)
-          } else { // We can schedule video publication only if it it is private
-            this.schedulePublicationPossible = this.video.privacy === VideoPrivacy.PRIVATE
-          }
-
-          this.explainedVideoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
-
           const videoFiles = (video as VideoDetails).files
           if (videoFiles.length > 1) { // Already transcoded
             this.waitTranscodingEnabled = false