-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'
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
blacklist?: boolean
delete?: boolean
report?: boolean
+ duplicate?: boolean
}
@Component({
@ViewChild('videoBlacklistModal') videoBlacklistModal: VideoBlacklistComponent
@Input() video: Video | VideoDetails
+ @Input() videoCaptions: VideoCaption[] = []
@Input() displayOptions: VideoActionsDisplayType = {
playlist: false,
update: true,
blacklist: true,
delete: true,
- report: true
+ report: true,
+ duplicate: true
}
@Input() placement = 'left'
@Output() videoRemoved = new EventEmitter()
@Output() videoUnblacklisted = new EventEmitter()
@Output() videoBlacklisted = new EventEmitter()
+ @Output() modalOpened = new EventEmitter()
videoActions: DropdownAction<{ video: Video }>[][] = []
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
) { }
/* 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()
}
return this.video && this.video instanceof VideoDetails && this.video.downloadEnabled
}
+ canVideoBeDuplicated () {
+ return this.video.canBeDuplicatedBy(this.user)
+ }
+
/* Action handlers */
async unblacklistVideo () {
}
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
)
}
+ 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()
}
iconName: 'undo',
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblacklistable()
},
+ {
+ 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(),