From: Chocobozzz Date: Fri, 7 Jun 2019 12:50:27 +0000 (+0200) Subject: Add ability to set a public to private in client X-Git-Tag: v1.4.0-rc.1~183 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=851f5daa1eec66e1faa3c45238ec9ab91be05b00;p=oweals%2Fpeertube.git Add ability to set a public to private in 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 87a10961f..8aed8b513 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 @@ -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[] = [] 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( () => { diff --git a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.ts b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.ts index 81dd9a75f..e94188786 100644 --- a/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.ts +++ b/client/src/app/+my-account/my-account-video-playlists/my-account-video-playlist-edit.ts @@ -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[] = [] abstract isCreation (): boolean abstract getFormButtonTitle (): string 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 4887fdfb4..917ad7258 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 @@ -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[] = [] 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 () { 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 95d397b52..a2776b73d 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 @@ -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[] = [] @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[] = [] videoCategories: VideoConstant[] = [] videoLicences: VideoConstant[] = [] videoLanguages: VideoConstant[] = [] @@ -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(() => { diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html index 537d7ffa2..7a495fea5 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html +++ b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.html @@ -58,7 +58,7 @@
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts index d2e9f6cfe..ed9cb5840 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-import-torrent.component.ts @@ -100,7 +100,6 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca previewUrl: null })) - this.explainedVideoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies) this.hydrateFormFromVideo() }, diff --git a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html index 984b9d590..e4f19faa8 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html +++ b/client/src/app/videos/+video-edit/video-add-components/video-import-url.component.html @@ -51,7 +51,7 @@
diff --git a/client/src/app/videos/+video-edit/video-add-components/video-send.ts b/client/src/app/videos/+video-edit/video-add-components/video-send.ts index 8401caeec..580c123a0 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-send.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-send.ts @@ -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[] = [] - explainedVideoPrivacies: VideoConstant[] = [] videoCaptions: VideoCaptionEdit[] = [] firstStepPrivacyId = 0 diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html index 3247a2bd6..0f904affb 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html +++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.html @@ -71,7 +71,7 @@ diff --git a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts index 73de25c59..69fa13a2f 100644 --- a/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts +++ b/client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts @@ -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) { diff --git a/client/src/app/videos/+video-edit/video-update.component.html b/client/src/app/videos/+video-edit/video-update.component.html index b5cab7ed5..aa148311f 100644 --- a/client/src/app/videos/+video-edit/video-update.component.html +++ b/client/src/app/videos/+video-edit/video-update.component.html @@ -7,7 +7,7 @@ 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 10f797d02..e990ceb13 100644 --- a/client/src/app/videos/+video-edit/video-update.component.ts +++ b/client/src/app/videos/+video-edit/video-update.component.ts @@ -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[] = [] - explainedVideoPrivacies: VideoConstant[] = [] 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