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
) { }
}
ngOnChanges () {
+ if (this.loaded) {
+ this.loaded = false
+ this.playlistAdd.reload()
+ }
+
this.buildActions()
}
/* 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.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 () {
}
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()
}
}
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('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'
}
- ])
- }
+ ]
+ ]
}
}