X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fshared%2Fvideo%2Fvideo-actions-dropdown.component.ts;h=1f57636108f82594a1370e2dbecbf5db105338c9;hb=0c4bacbff53bc732f5a2677d62a6ead7752e2405;hp=df799499e371d13651f9d383f34345538cbbc529;hpb=73b3aa6429dfb2e31628fa09a479dce318289d7d;p=oweals%2Fpeertube.git diff --git a/client/src/app/shared/video/video-actions-dropdown.component.ts b/client/src/app/shared/video/video-actions-dropdown.component.ts index df799499e..1f5763610 100644 --- a/client/src/app/shared/video/video-actions-dropdown.component.ts +++ b/client/src/app/shared/video/video-actions-dropdown.component.ts @@ -1,8 +1,7 @@ -import { AfterViewInit, Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core' +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' @@ -10,9 +9,11 @@ import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap' import { VideoAddToPlaylistComponent } from '@app/shared/video-playlist/video-add-to-playlist.component' import { VideoDownloadComponent } from '@app/shared/video/modals/video-download.component' import { VideoReportComponent } from '@app/shared/video/modals/video-report.component' -import { VideoBlacklistComponent } from '@app/shared/video/modals/video-blacklist.component' -import { VideoBlacklistService } from '@app/shared/video-blacklist' +import { VideoBlockComponent } from '@app/shared/video/modals/video-block.component' +import { VideoBlockService } from '@app/shared/video-block' 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({ @@ -34,9 +36,10 @@ export class VideoActionsDropdownComponent implements OnChanges { @ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent @ViewChild('videoReportModal') videoReportModal: VideoReportComponent - @ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent + @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent @Input() video: Video | VideoDetails + @Input() videoCaptions: VideoCaption[] = [] @Input() displayOptions: VideoActionsDisplayType = { playlist: false, @@ -44,7 +47,8 @@ export class VideoActionsDropdownComponent implements OnChanges { update: true, blacklist: true, delete: true, - report: true + report: true, + duplicate: true } @Input() placement = 'left' @@ -55,8 +59,9 @@ export class VideoActionsDropdownComponent implements OnChanges { @Input() buttonDirection: DropdownDirection = 'vertical' @Output() videoRemoved = new EventEmitter() - @Output() videoUnblacklisted = new EventEmitter() - @Output() videoBlacklisted = new EventEmitter() + @Output() videoUnblocked = new EventEmitter() + @Output() videoBlocked = new EventEmitter() + @Output() modalOpened = new EventEmitter() videoActions: DropdownAction<{ video: Video }>[][] = [] @@ -66,11 +71,10 @@ export class VideoActionsDropdownComponent implements OnChanges { private authService: AuthService, private notifier: Notifier, private confirmService: ConfirmService, - private videoBlacklistService: VideoBlacklistService, - private serverService: ServerService, + private videoBlocklistService: VideoBlockService, private screenService: ScreenService, private videoService: VideoService, - private blocklistService: BlocklistService, + private redundancyService: RedundancyService, private i18n: I18n ) { } @@ -81,7 +85,7 @@ export class VideoActionsDropdownComponent implements OnChanges { ngOnChanges () { if (this.loaded) { this.loaded = false - this.playlistAdd.unload() + this.playlistAdd.reload() } this.buildActions() @@ -102,15 +106,21 @@ 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.videoBlacklistModal.show() + showBlockModal () { + this.modalOpened.emit() + + this.videoBlockModal.show() } /* Actions checker */ @@ -123,36 +133,40 @@ export class VideoActionsDropdownComponent implements OnChanges { return this.video.isRemovableBy(this.user) } - isVideoBlacklistable () { - return this.video.isBlackistableBy(this.user) + isVideoBlockable () { + return this.video.isBlockableBy(this.user) } - isVideoUnblacklistable () { - return this.video.isUnblacklistableBy(this.user) + isVideoUnblockable () { + return this.video.isUnblockableBy(this.user) } isVideoDownloadable () { return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled } + canVideoBeDuplicated () { + return this.video.canBeDuplicatedBy(this.user) + } + /* Action handlers */ - async unblacklistVideo () { + async unblockVideo () { const confirmMessage = this.i18n( - 'Do you really want to remove this video from the blacklist? It will be available again in the videos list.' + 'Do you really want to unblock this video? It will be available again in the videos list.' ) - const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblacklist')) + const res = await this.confirmService.confirm(confirmMessage, this.i18n('Unblock')) if (res === false) return - this.videoBlacklistService.removeVideoFromBlacklist(this.video.id).subscribe( + this.videoBlocklistService.unblockVideo(this.video.id).subscribe( () => { - this.notifier.success(this.i18n('Video {{name}} removed from the blacklist.', { name: this.video.name })) + this.notifier.success(this.i18n('Video {{name}} unblocked.', { name: this.video.name })) this.video.blacklisted = false - this.video.blacklistedReason = null + this.video.blockedReason = null - this.videoUnblacklisted.emit() + this.videoUnblocked.emit() }, err => this.notifier.error(err.message) @@ -160,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 @@ -175,8 +191,20 @@ export class VideoActionsDropdownComponent implements OnChanges { ) } - onVideoBlacklisted () { - this.videoBlacklisted.emit() + 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) + ) + } + + onVideoBlocked () { + this.videoBlocked.emit() } getPlaylistDropdownPlacement () { @@ -188,19 +216,16 @@ 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(), @@ -211,36 +236,41 @@ export class VideoActionsDropdownComponent implements OnChanges { 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(), + label: this.i18n('Block'), + handler: () => this.showBlockModal(), iconName: 'no', - isDisplayed: () => this.displayOptions.blacklist && this.isVideoBlacklistable() + isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable() }, { - label: this.i18n('Unblacklist'), - handler: () => this.unblacklistVideo(), + label: this.i18n('Unblock'), + handler: () => this.unblockVideo(), iconName: 'undo', - isDisplayed: () => this.displayOptions.blacklist && this.isVideoUnblacklistable() + isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable() + }, + { + label: this.i18n('Mirror'), + 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' } - ]) - } + ] + ] } }