]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/commitdiff
Better label for video privacies
authorChocobozzz <me@florianbigard.com>
Tue, 4 Sep 2018 14:21:07 +0000 (16:21 +0200)
committerChocobozzz <me@florianbigard.com>
Tue, 4 Sep 2018 15:31:28 +0000 (17:31 +0200)
client/src/app/core/server/server.service.ts
client/src/app/search/search-filters.component.ts
client/src/app/shared/video/video.service.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.ts
client/src/app/videos/+video-edit/video-add-components/video-import-url.component.ts
client/src/app/videos/+video-edit/video-add-components/video-send.ts
client/src/app/videos/+video-edit/video-add-components/video-upload.component.ts
client/src/app/videos/+video-edit/video-update.component.ts

index e7152efa0f8b17afcd352060aa6b715a321fec46..2f1ef1fc23e1f69d4ae7131b1c479209f03f8ed7 100644 (file)
@@ -6,7 +6,7 @@ import { Observable, of, ReplaySubject } from 'rxjs'
 import { getCompleteLocale, ServerConfig } from '../../../../../shared'
 import { About } from '../../../../../shared/models/server/about.model'
 import { environment } from '../../../environments/environment'
-import { VideoConstant } from '../../../../../shared/models/videos'
+import { VideoConstant, VideoPrivacy } from '../../../../../shared/models/videos'
 import { isDefaultLocale, peertubeTranslate } from '../../../../../shared/models/i18n'
 import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils'
 import { sortBy } from '@app/shared/misc/utils'
@@ -82,10 +82,10 @@ export class ServerService {
       }
     }
   }
-  private videoCategories: Array<VideoConstant<string>> = []
-  private videoLicences: Array<VideoConstant<string>> = []
+  private videoCategories: Array<VideoConstant<number>> = []
+  private videoLicences: Array<VideoConstant<number>> = []
   private videoLanguages: Array<VideoConstant<string>> = []
-  private videoPrivacies: Array<VideoConstant<string>> = []
+  private videoPrivacies: Array<VideoConstant<VideoPrivacy>> = []
 
   constructor (
     private http: HttpClient,
@@ -147,7 +147,7 @@ export class ServerService {
 
   private loadVideoAttributeEnum (
     attributeName: 'categories' | 'licences' | 'languages' | 'privacies',
-    hashToPopulate: VideoConstant<string>[],
+    hashToPopulate: VideoConstant<string | number>[],
     notifier: ReplaySubject<boolean>,
     sort = false
   ) {
@@ -164,7 +164,7 @@ export class ServerService {
                   const label = data[ dataKey ]
 
                   hashToPopulate.push({
-                    id: dataKey,
+                    id: attributeName === 'languages' ? dataKey : parseInt(dataKey, 10),
                     label: peertubeTranslate(label, translations)
                   })
                 })
index a40648eb4da80ee7085631aec5e0b700d66dd099..f2f001e3fea46368bf84d283f7c2a8e7b656a827 100644 (file)
@@ -18,8 +18,8 @@ export class SearchFiltersComponent implements OnInit {
 
   @Output() filtered = new EventEmitter<AdvancedSearch>()
 
-  videoCategories: VideoConstant<string>[] = []
-  videoLicences: VideoConstant<string>[] = []
+  videoCategories: VideoConstant<number>[] = []
+  videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
 
   publishedDateRanges: { id: string, label: string }[] = []
index 5c0674e583763c5d13c30ed550cccdb5317f2f55..4a78d70ea740d5a734391e9bd8303f20339b3957 100644 (file)
@@ -4,7 +4,15 @@ import { Injectable } from '@angular/core'
 import { Observable } from 'rxjs'
 import { Video as VideoServerModel, VideoDetails as VideoDetailsServerModel } from '../../../../../shared'
 import { ResultList } from '../../../../../shared/models/result-list.model'
-import { UserVideoRate, UserVideoRateUpdate, VideoFilter, VideoRateType, VideoUpdate } from '../../../../../shared/models/videos'
+import {
+  UserVideoRate,
+  UserVideoRateUpdate,
+  VideoConstant,
+  VideoFilter,
+  VideoPrivacy,
+  VideoRateType,
+  VideoUpdate
+} from '../../../../../shared/models/videos'
 import { FeedFormat } from '../../../../../shared/models/feeds/feed-format.enum'
 import { environment } from '../../../environments/environment'
 import { ComponentPagination } from '../rest/component-pagination.model'
@@ -22,6 +30,7 @@ import { VideoChannelService } from '@app/shared/video-channel/video-channel.ser
 import { ServerService } from '@app/core'
 import { UserSubscriptionService } from '@app/shared/user-subscription'
 import { VideoChannel } from '@app/shared/video-channel/video-channel.model'
+import { I18n } from '@ngx-translate/i18n-polyfill'
 
 export interface VideosProvider {
   getVideos (
@@ -41,7 +50,8 @@ export class VideoService implements VideosProvider {
     private authHttp: HttpClient,
     private restExtractor: RestExtractor,
     private restService: RestService,
-    private serverService: ServerService
+    private serverService: ServerService,
+    private i18n: I18n
   ) {}
 
   getVideoViewUrl (uuid: string) {
@@ -300,6 +310,21 @@ export class VideoService implements VideosProvider {
                )
   }
 
+  explainedPrivacyLabels (privacies: VideoConstant<VideoPrivacy>[]) {
+    const newPrivacies = privacies.slice()
+
+    const privatePrivacy = newPrivacies.find(p => p.id === VideoPrivacy.PRIVATE)
+    if (privatePrivacy) privatePrivacy.label = this.i18n('Only I can see this video')
+
+    const unlistedPrivacy = newPrivacies.find(p => p.id === VideoPrivacy.UNLISTED)
+    if (unlistedPrivacy) unlistedPrivacy.label = this.i18n('Only people with the private link can see this video')
+
+    const publicPrivacy = newPrivacies.find(p => p.id === VideoPrivacy.PUBLIC)
+    if (publicPrivacy) publicPrivacy.label = this.i18n('Anyone can see this video')
+
+    return privacies
+  }
+
   private setVideoRate (id: number, rateType: VideoRateType) {
     const url = VideoService.BASE_VIDEO_URL + id + '/rate'
     const body: UserVideoRateUpdate = {
index b394a13e4932c5fa8125dde7c13e72a826fcbe4f..eb9396d70b0b2f10a6d96093a971f89a046c5cb3 100644 (file)
@@ -12,7 +12,7 @@ import { VideoCaptionService } from '@app/shared/video-caption'
 import { VideoCaptionAddModalComponent } from '@app/videos/+video-edit/shared/video-caption-add-modal.component'
 import { VideoCaptionEdit } from '@app/shared/video-caption/video-caption-edit.model'
 import { removeElementFromArray } from '@app/shared/misc/utils'
-import { VideoConstant } from '../../../../../../shared'
+import { VideoConstant, VideoPrivacy } from '../../../../../../shared'
 
 @Component({
   selector: 'my-video-edit',
@@ -23,7 +23,7 @@ export class VideoEditComponent implements OnInit, OnDestroy {
   @Input() form: FormGroup
   @Input() formErrors: { [ id: string ]: string } = {}
   @Input() validationMessages: FormReactiveValidationMessages = {}
-  @Input() videoPrivacies: { id: number, label: string }[] = []
+  @Input() videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   @Input() userVideoChannels: { id: number, label: string, support: string }[] = []
   @Input() schedulePublicationPossible = true
   @Input() videoCaptions: VideoCaptionEdit[] = []
@@ -33,8 +33,8 @@ export class VideoEditComponent implements OnInit, OnDestroy {
   // So that it can be accessed in the template
   readonly SPECIAL_SCHEDULED_PRIVACY = VideoEdit.SPECIAL_SCHEDULED_PRIVACY
 
-  videoCategories: VideoConstant<string>[] = []
-  videoLicences: VideoConstant<string>[] = []
+  videoCategories: VideoConstant<number>[] = []
+  videoLicences: VideoConstant<number>[] = []
   videoLanguages: VideoConstant<string>[] = []
 
   tagValidators: ValidatorFn[]
index 9623c2bf4f19a65aed8e9641c8f252a3239e3e02..0f7184ff8e82616750fbf6d18dd6eabd5efd2e10 100644 (file)
@@ -95,6 +95,9 @@ export class VideoImportTorrentComponent extends VideoSend implements OnInit, Ca
           thumbnailUrl: null,
           previewUrl: null
         }))
+
+        this.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
+
         this.hydrateFormFromVideo()
       },
 
index 97b402bfe4cebf305a251726f88de9142a970fea..031e557ed688b8dd6bb80c569ec19266a2a86d6e 100644 (file)
@@ -87,6 +87,9 @@ export class VideoImportUrlComponent extends VideoSend implements OnInit, CanCom
           thumbnailUrl: null,
           previewUrl: null
         }))
+
+        this.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
+
         this.hydrateFormFromVideo()
       },
 
index efd182269b96e28a9c8052d35f242fd1e9fafb79..bfe588676741a68fff2bab5e367e1c132df4ec79 100644 (file)
@@ -15,7 +15,7 @@ import { populateAsyncUserVideoChannels } from '@app/shared/misc/utils'
 export abstract class VideoSend extends FormReactive implements OnInit, CanComponentDeactivate {
 
   userVideoChannels: { id: number, label: string, support: string }[] = []
-  videoPrivacies: VideoConstant<string>[] = []
+  videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   videoCaptions: VideoCaptionEdit[] = []
 
   firstStepPrivacyId = 0
index b59fb7335117a0fa8e256309adf4871d3431dabf..f9af1655b8992494501495e57697748606be8067 100644 (file)
@@ -182,6 +182,8 @@ export class VideoUploadComponent extends VideoSend implements OnInit, OnDestroy
       channelId
     })
 
+    this.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
+
     this.videoUploadObservable = this.videoService.uploadVideo(formData).subscribe(
       event => {
         if (event.type === HttpEventType.UploadProgress) {
index 0c60e3439c29433ef445e5162358b49deb6334e5..75b11f46c7bd02c9430eb9538a66ded6eada4cb3 100644 (file)
@@ -24,7 +24,7 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
   video: VideoEdit
 
   isUpdatingVideo = false
-  videoPrivacies: VideoConstant<string>[] = []
+  videoPrivacies: VideoConstant<VideoPrivacy>[] = []
   userVideoChannels: { id: number, label: string, support: string }[] = []
   schedulePublicationPossible = false
   videoCaptions: VideoCaptionEdit[] = []
@@ -62,11 +62,13 @@ export class VideoUpdateComponent extends FormReactive implements OnInit {
 
           // We cannot set private a video that was not private
           if (this.video.privacy !== VideoPrivacy.PRIVATE) {
-            this.videoPrivacies = this.videoPrivacies.filter(p => p.id.toString() !== VideoPrivacy.PRIVATE.toString())
+            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.videoPrivacies = this.videoService.explainedPrivacyLabels(this.videoPrivacies)
+
           // FIXME: Angular does not detect the change inside this subscription, so use the patched setTimeout
           setTimeout(() => this.hydrateFormFromVideo())
         },