]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/video/video-actions-dropdown.component.ts
Remove deprecated NgbTabsetModule module
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / video / video-actions-dropdown.component.ts
index 90bdf7df8f0b271aa97eee4ca507acbe577bbbfb..67c4d6fbce31812216c95b00619f95aa48253682 100644 (file)
@@ -1,8 +1,7 @@
 import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
 import { I18n } from '@ngx-translate/i18n-polyfill'
 import { DropdownAction, DropdownButtonSize, DropdownDirection } from '@app/shared/buttons/action-dropdown.component'
-import { AuthService, ConfirmService, Notifier, ServerService } from '@app/core'
-import { BlocklistService } from '@app/shared/blocklist'
+import { AuthService, ConfirmService, Notifier } from '@app/core'
 import { Video } from '@app/shared/video/video.model'
 import { VideoService } from '@app/shared/video/video.service'
 import { VideoDetails } from '@app/shared/video/video-details.model'
@@ -13,6 +12,8 @@ import { VideoReportComponent } from '@app/shared/video/modals/video-report.comp
 import { VideoBlacklistComponent } from '@app/shared/video/modals/video-blacklist.component'
 import { VideoBlacklistService } from '@app/shared/video-blacklist'
 import { ScreenService } from '@app/shared/misc/screen.service'
+import { VideoCaption } from '@shared/models'
+import { RedundancyService } from '@app/shared/video/redundancy.service'
 
 export type VideoActionsDisplayType = {
   playlist?: boolean
@@ -21,6 +22,7 @@ export type VideoActionsDisplayType = {
   blacklist?: boolean
   delete?: boolean
   report?: boolean
+  duplicate?: boolean
 }
 
 @Component({
@@ -37,6 +39,7 @@ export class VideoActionsDropdownComponent implements OnChanges {
   @ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent
 
   @Input() video: Video | VideoDetails
+  @Input() videoCaptions: VideoCaption[] = []
 
   @Input() displayOptions: VideoActionsDisplayType = {
     playlist: false,
@@ -44,9 +47,10 @@ export class VideoActionsDropdownComponent implements OnChanges {
     update: true,
     blacklist: true,
     delete: true,
-    report: true
+    report: true,
+    duplicate: true
   }
-  @Input() placement: string = 'left'
+  @Input() placement = 'left'
 
   @Input() label: string
 
@@ -57,6 +61,7 @@ export class VideoActionsDropdownComponent implements OnChanges {
   @Output() videoRemoved = new EventEmitter()
   @Output() videoUnblacklisted = new EventEmitter()
   @Output() videoBlacklisted = new EventEmitter()
+  @Output() modalOpened = new EventEmitter()
 
   videoActions: DropdownAction<{ video: Video }>[][] = []
 
@@ -67,10 +72,9 @@ export class VideoActionsDropdownComponent implements OnChanges {
     private notifier: Notifier,
     private confirmService: ConfirmService,
     private videoBlacklistService: VideoBlacklistService,
-    private serverService: ServerService,
     private screenService: ScreenService,
     private videoService: VideoService,
-    private blocklistService: BlocklistService,
+    private redundancyService: RedundancyService,
     private i18n: I18n
   ) { }
 
@@ -79,6 +83,11 @@ export class VideoActionsDropdownComponent implements OnChanges {
   }
 
   ngOnChanges () {
+    if (this.loaded) {
+      this.loaded = false
+      this.playlistAdd.reload()
+    }
+
     this.buildActions()
   }
 
@@ -97,14 +106,20 @@ export class VideoActionsDropdownComponent implements OnChanges {
   /* Show modals */
 
   showDownloadModal () {
-    this.videoDownloadModal.show(this.video as VideoDetails)
+    this.modalOpened.emit()
+
+    this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions)
   }
 
   showReportModal () {
+    this.modalOpened.emit()
+
     this.videoReportModal.show()
   }
 
   showBlacklistModal () {
+    this.modalOpened.emit()
+
     this.videoBlacklistModal.show()
   }
 
@@ -126,6 +141,14 @@ export class VideoActionsDropdownComponent implements OnChanges {
     return this.video.isUnblacklistableBy(this.user)
   }
 
+  isVideoDownloadable () {
+    return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled
+  }
+
+  canVideoBeDuplicated () {
+    return this.video.canBeDuplicatedBy(this.user)
+  }
+
   /* Action handlers */
 
   async unblacklistVideo () {
@@ -151,6 +174,8 @@ export class VideoActionsDropdownComponent implements OnChanges {
   }
 
   async removeVideo () {
+    this.modalOpened.emit()
+
     const res = await this.confirmService.confirm(this.i18n('Do you really want to delete this video?'), this.i18n('Delete'))
     if (res === false) return
 
@@ -166,6 +191,18 @@ export class VideoActionsDropdownComponent implements OnChanges {
         )
   }
 
+  duplicateVideo () {
+    this.redundancyService.addVideoRedundancy(this.video)
+      .subscribe(
+        () => {
+          const message = this.i18n('This video will be duplicated by your instance.')
+          this.notifier.success(message)
+        },
+
+        err => this.notifier.error(err.message)
+      )
+  }
+
   onVideoBlacklisted () {
     this.videoBlacklisted.emit()
   }
@@ -179,59 +216,61 @@ export class VideoActionsDropdownComponent implements OnChanges {
   }
 
   private buildActions () {
-    this.videoActions = []
-
-    if (this.authService.isLoggedIn()) {
-      this.videoActions.push([
+    this.videoActions = [
+      [
         {
           label: this.i18n('Save to playlist'),
           handler: () => this.playlistDropdown.toggle(),
-          isDisplayed: () => this.displayOptions.playlist,
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
           iconName: 'playlist-add'
         }
-      ])
-
-      this.videoActions.push([
+      ],
+      [
         {
           label: this.i18n('Download'),
           handler: () => this.showDownloadModal(),
-          isDisplayed: () => this.displayOptions.download,
+          isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
           iconName: 'download'
         },
         {
           label: this.i18n('Update'),
           linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
           iconName: 'edit',
-          isDisplayed: () => this.displayOptions.update && this.isVideoUpdatable()
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
         },
         {
           label: this.i18n('Blacklist'),
           handler: () => this.showBlacklistModal(),
           iconName: 'no',
-          isDisplayed: () => this.displayOptions.blacklist && this.isVideoBlacklistable()
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlacklistable()
         },
         {
           label: this.i18n('Unblacklist'),
           handler: () => this.unblacklistVideo(),
           iconName: 'undo',
-          isDisplayed: () => this.displayOptions.blacklist && this.isVideoUnblacklistable()
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblacklistable()
+        },
+        {
+          label: this.i18n('Duplicate (redundancy)'),
+          handler: () => this.duplicateVideo(),
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(),
+          iconName: 'cloud-download'
         },
         {
           label: this.i18n('Delete'),
           handler: () => this.removeVideo(),
-          isDisplayed: () => this.displayOptions.delete && this.isVideoRemovable(),
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
           iconName: 'delete'
         }
-      ])
-
-      this.videoActions.push([
+      ],
+      [
         {
           label: this.i18n('Report'),
           handler: () => this.showReportModal(),
-          isDisplayed: () => this.displayOptions.report,
+          isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
           iconName: 'alert'
         }
-      ])
-    }
+      ]
+    ]
   }
 }