1
0
Fork 0
peertube/client/src/app/shared/shared-video-miniature/video-actions-dropdown.comp...

428 lines
13 KiB
TypeScript
Raw Normal View History

import { Component, EventEmitter, Input, OnChanges, Output, ViewChild } from '@angular/core'
2022-02-11 09:51:33 +00:00
import { AuthService, ConfirmService, Notifier, ScreenService, ServerService } from '@app/core'
import { BlocklistService, VideoBlockComponent, VideoBlockService, VideoReportComponent } from '@app/shared/shared-moderation'
2019-04-05 08:52:27 +00:00
import { NgbDropdown } from '@ng-bootstrap/ng-bootstrap'
import { VideoCaption } from '@shared/models'
import {
Actor,
DropdownAction,
DropdownButtonSize,
DropdownDirection,
RedundancyService,
Video,
VideoDetails,
VideoService
} from '../shared-main'
2020-11-05 09:56:23 +00:00
import { LiveStreamInformationComponent } from '../shared-video-live'
2020-06-23 12:10:17 +00:00
import { VideoAddToPlaylistComponent } from '../shared-video-playlist'
import { VideoDownloadComponent } from './video-download.component'
2019-04-05 08:52:27 +00:00
export type VideoActionsDisplayType = {
playlist?: boolean
download?: boolean
update?: boolean
blacklist?: boolean
delete?: boolean
report?: boolean
2020-01-10 09:11:28 +00:00
duplicate?: boolean
mute?: boolean
2020-11-05 09:56:23 +00:00
liveInfo?: boolean
removeFiles?: boolean
2021-11-18 13:35:08 +00:00
transcoding?: boolean
2022-03-22 15:58:49 +00:00
studio?: boolean
2022-04-05 12:03:52 +00:00
stats?: boolean
2019-04-05 08:52:27 +00:00
}
@Component({
selector: 'my-video-actions-dropdown',
templateUrl: './video-actions-dropdown.component.html',
styleUrls: [ './video-actions-dropdown.component.scss' ]
})
export class VideoActionsDropdownComponent implements OnChanges {
2020-02-07 09:00:34 +00:00
@ViewChild('playlistDropdown') playlistDropdown: NgbDropdown
@ViewChild('playlistAdd') playlistAdd: VideoAddToPlaylistComponent
2019-04-05 08:52:27 +00:00
2020-02-07 09:00:34 +00:00
@ViewChild('videoDownloadModal') videoDownloadModal: VideoDownloadComponent
@ViewChild('videoReportModal') videoReportModal: VideoReportComponent
@ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
2020-11-05 09:56:23 +00:00
@ViewChild('liveStreamInformationModal') liveStreamInformationModal: LiveStreamInformationComponent
2019-04-05 08:52:27 +00:00
@Input() video: Video | VideoDetails
@Input() videoCaptions: VideoCaption[] = []
2019-04-05 08:52:27 +00:00
@Input() displayOptions: VideoActionsDisplayType = {
playlist: false,
download: true,
update: true,
blacklist: true,
delete: true,
2020-01-10 09:11:28 +00:00
report: true,
duplicate: true,
2020-11-05 09:56:23 +00:00
mute: true,
2021-11-18 13:35:08 +00:00
liveInfo: false,
removeFiles: false,
2022-02-11 09:51:33 +00:00
transcoding: false,
2022-04-05 12:03:52 +00:00
studio: true,
stats: true
2019-04-05 08:52:27 +00:00
}
@Input() placement = 'left'
2022-04-05 12:03:52 +00:00
@Input() moreActions: DropdownAction<{ video: Video }>[][] = []
2019-04-05 08:52:27 +00:00
@Input() label: string
@Input() buttonStyled = false
@Input() buttonSize: DropdownButtonSize = 'normal'
@Input() buttonDirection: DropdownDirection = 'vertical'
@Output() videoFilesRemoved = new EventEmitter()
2019-04-05 08:52:27 +00:00
@Output() videoRemoved = new EventEmitter()
@Output() videoUnblocked = new EventEmitter()
@Output() videoBlocked = new EventEmitter()
@Output() videoAccountMuted = new EventEmitter()
2021-11-18 13:35:08 +00:00
@Output() transcodingCreated = new EventEmitter()
2019-12-05 08:21:09 +00:00
@Output() modalOpened = new EventEmitter()
2019-04-05 08:52:27 +00:00
videoActions: DropdownAction<{ video: Video }>[][] = []
private loaded = false
constructor (
private authService: AuthService,
private notifier: Notifier,
private confirmService: ConfirmService,
private blocklistService: BlocklistService,
private videoBlocklistService: VideoBlockService,
2019-04-05 08:52:27 +00:00
private screenService: ScreenService,
private videoService: VideoService,
2022-02-11 09:51:33 +00:00
private redundancyService: RedundancyService,
private serverService: ServerService
2019-04-05 08:52:27 +00:00
) { }
get user () {
return this.authService.getUser()
}
ngOnChanges () {
if (this.loaded) {
this.loaded = false
if (this.playlistAdd) this.playlistAdd.reload()
}
2019-04-05 08:52:27 +00:00
this.buildActions()
}
isUserLoggedIn () {
return this.authService.isLoggedIn()
}
loadDropdownInformation () {
if (!this.isUserLoggedIn() || this.loaded === true) return
this.loaded = true
if (this.displayOptions.playlist) this.playlistAdd.load()
}
/* Show modals */
showDownloadModal () {
2019-12-05 08:21:09 +00:00
this.modalOpened.emit()
this.videoDownloadModal.show(this.video as VideoDetails, this.videoCaptions)
2019-04-05 08:52:27 +00:00
}
showReportModal () {
2019-12-05 08:21:09 +00:00
this.modalOpened.emit()
2019-04-05 08:52:27 +00:00
this.videoReportModal.show()
}
showBlockModal () {
2019-12-05 08:21:09 +00:00
this.modalOpened.emit()
2021-11-17 10:18:49 +00:00
this.videoBlockModal.show([ this.video ])
2019-04-05 08:52:27 +00:00
}
2020-11-05 09:56:23 +00:00
showLiveInfoModal (video: Video) {
this.modalOpened.emit()
this.liveStreamInformationModal.show(video)
}
2019-04-05 08:52:27 +00:00
/* Actions checker */
isVideoUpdatable () {
return this.video.isUpdatableBy(this.user)
}
2022-02-11 09:51:33 +00:00
isVideoEditable () {
2022-03-22 15:58:49 +00:00
return this.video.isEditableBy(this.user, this.serverService.getHTMLConfig().videoStudio.enabled)
2022-02-11 09:51:33 +00:00
}
2022-04-05 12:03:52 +00:00
isVideoStatsAvailable () {
return this.video.canSeeStats(this.user)
}
2019-04-05 08:52:27 +00:00
isVideoRemovable () {
return this.video.isRemovableBy(this.user)
}
isVideoBlockable () {
return this.video.isBlockableBy(this.user)
2019-04-05 08:52:27 +00:00
}
isVideoUnblockable () {
return this.video.isUnblockableBy(this.user)
2019-04-05 08:52:27 +00:00
}
2020-11-05 09:56:23 +00:00
isVideoLiveInfoAvailable () {
return this.video.isLiveInfoAvailableBy(this.user)
}
isVideoDownloadable () {
return this.video &&
this.video.isLive !== true &&
this.video instanceof VideoDetails &&
this.video.downloadEnabled
}
2020-01-10 09:11:28 +00:00
canVideoBeDuplicated () {
return !this.video.isLive && this.video.canBeDuplicatedBy(this.user)
2020-01-10 09:11:28 +00:00
}
isVideoAccountMutable () {
return this.video.account.id !== this.user.account.id
}
canRemoveVideoFiles () {
2021-11-18 13:35:08 +00:00
return this.video.canRemoveFiles(this.user)
}
canRunTranscoding () {
return this.video.canRunTranscoding(this.user)
}
2019-04-05 08:52:27 +00:00
/* Action handlers */
async unblockVideo () {
2021-11-15 08:12:15 +00:00
const confirmMessage = $localize`Do you really want to unblock ${this.video.name}? It will be available again in the videos list.`
2019-04-05 08:52:27 +00:00
2021-11-15 08:12:15 +00:00
const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock ${this.video.name}`)
2019-04-05 08:52:27 +00:00
if (res === false) return
this.videoBlocklistService.unblockVideo(this.video.id)
2021-08-17 09:27:47 +00:00
.subscribe({
next: () => {
this.notifier.success($localize`Video ${this.video.name} unblocked.`)
2019-04-05 08:52:27 +00:00
this.video.blacklisted = false
this.video.blacklistedReason = null
2019-04-05 08:52:27 +00:00
this.videoUnblocked.emit()
},
2019-04-05 08:52:27 +00:00
2021-08-17 09:27:47 +00:00
error: err => this.notifier.error(err.message)
})
2019-04-05 08:52:27 +00:00
}
async removeVideo () {
2019-12-05 08:21:09 +00:00
this.modalOpened.emit()
2021-11-15 08:12:15 +00:00
let message = $localize`Do you really want to delete ${this.video.name}?`
2020-10-28 09:49:20 +00:00
if (this.video.isLive) {
message += ' ' + $localize`The live stream will be automatically terminated and replays won't be saved.`
2020-10-28 09:49:20 +00:00
}
2021-11-15 08:12:15 +00:00
const res = await this.confirmService.confirm(message, $localize`Delete ${this.video.name}`)
2019-04-05 08:52:27 +00:00
if (res === false) return
this.videoService.removeVideo(this.video.id)
2021-08-17 09:27:47 +00:00
.subscribe({
next: () => {
this.notifier.success($localize`Video ${this.video.name} deleted.`)
2019-04-05 08:52:27 +00:00
this.videoRemoved.emit()
},
2021-08-17 09:27:47 +00:00
error: err => this.notifier.error(err.message)
})
2019-04-05 08:52:27 +00:00
}
2020-01-10 09:11:28 +00:00
duplicateVideo () {
this.redundancyService.addVideoRedundancy(this.video)
2021-08-17 09:27:47 +00:00
.subscribe({
next: () => {
2021-11-15 08:12:15 +00:00
const message = $localize`${this.video.name} will be duplicated by your instance.`
this.notifier.success(message)
},
2020-01-10 09:11:28 +00:00
2021-08-17 09:27:47 +00:00
error: err => this.notifier.error(err.message)
})
}
muteVideoAccount () {
const params = { nameWithHost: Actor.CREATE_BY_STRING(this.video.account.name, this.video.account.host) }
this.blocklistService.blockAccountByUser(params)
2021-08-17 09:27:47 +00:00
.subscribe({
next: () => {
this.notifier.success($localize`Account ${params.nameWithHost} muted.`)
this.videoAccountMuted.emit()
},
2021-08-17 09:27:47 +00:00
error: err => this.notifier.error(err.message)
})
2020-01-10 09:11:28 +00:00
}
async removeVideoFiles (video: Video, type: 'hls' | 'webtorrent') {
const confirmMessage = $localize`Do you really want to remove "${this.video.name}" files?`
const res = await this.confirmService.confirm(confirmMessage, $localize`Remove "${this.video.name}" files`)
if (res === false) return
this.videoService.removeVideoFiles([ video.id ], type)
.subscribe({
next: () => {
this.notifier.success($localize`Removed files of ${video.name}.`)
this.videoFilesRemoved.emit()
},
error: err => this.notifier.error(err.message)
})
}
2021-11-18 13:35:08 +00:00
runTranscoding (video: Video, type: 'hls' | 'webtorrent') {
this.videoService.runTranscoding([ video.id ], type)
.subscribe({
next: () => {
this.notifier.success($localize`Transcoding jobs created for ${video.name}.`)
this.transcodingCreated.emit()
},
error: err => this.notifier.error(err.message)
})
}
onVideoBlocked () {
this.videoBlocked.emit()
2019-04-05 08:52:27 +00:00
}
getPlaylistDropdownPlacement () {
if (this.screenService.isInSmallView()) {
return 'bottom-right'
}
return 'bottom-left bottom-right'
}
private buildActions () {
2019-06-07 09:08:56 +00:00
this.videoActions = [
[
2019-04-05 08:52:27 +00:00
{
label: $localize`Save to playlist`,
2019-04-05 08:52:27 +00:00
handler: () => this.playlistDropdown.toggle(),
2019-06-07 09:08:56 +00:00
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.playlist,
2019-04-05 08:52:27 +00:00
iconName: 'playlist-add'
}
2019-06-07 09:08:56 +00:00
],
[ // actions regarding the video
2019-04-05 08:52:27 +00:00
{
label: $localize`Download`,
2019-04-05 08:52:27 +00:00
handler: () => this.showDownloadModal(),
isDisplayed: () => this.displayOptions.download && this.isVideoDownloadable(),
2019-04-05 08:52:27 +00:00
iconName: 'download'
},
2020-11-05 09:56:23 +00:00
{
label: $localize`Display live information`,
handler: ({ video }) => this.showLiveInfoModal(video),
isDisplayed: () => this.displayOptions.liveInfo && this.isVideoLiveInfoAvailable(),
2020-11-05 09:56:23 +00:00
iconName: 'live'
},
2019-04-05 08:52:27 +00:00
{
label: $localize`Update`,
2019-04-05 08:52:27 +00:00
linkBuilder: ({ video }) => [ '/videos/update', video.uuid ],
iconName: 'edit',
2019-06-07 09:08:56 +00:00
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.update && this.isVideoUpdatable()
2019-04-05 08:52:27 +00:00
},
2022-02-11 09:51:33 +00:00
{
2022-03-22 15:58:49 +00:00
label: $localize`Studio`,
linkBuilder: ({ video }) => [ '/studio/edit', video.uuid ],
2022-02-11 09:51:33 +00:00
iconName: 'film',
2022-03-22 15:58:49 +00:00
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.studio && this.isVideoEditable()
2022-02-11 09:51:33 +00:00
},
2022-04-05 12:03:52 +00:00
{
label: $localize`Stats`,
linkBuilder: ({ video }) => [ '/stats/videos', video.uuid ],
iconName: 'stats',
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.stats && this.isVideoStatsAvailable()
},
2019-04-05 08:52:27 +00:00
{
label: $localize`Block`,
handler: () => this.showBlockModal(),
2019-04-05 08:52:27 +00:00
iconName: 'no',
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoBlockable()
2019-04-05 08:52:27 +00:00
},
{
label: $localize`Unblock`,
handler: () => this.unblockVideo(),
2019-04-05 08:52:27 +00:00
iconName: 'undo',
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.blacklist && this.isVideoUnblockable()
2019-04-05 08:52:27 +00:00
},
2020-01-10 09:11:28 +00:00
{
label: $localize`Mirror`,
2020-01-10 09:11:28 +00:00
handler: () => this.duplicateVideo(),
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.duplicate && this.canVideoBeDuplicated(),
iconName: 'cloud-download'
},
2019-04-05 08:52:27 +00:00
{
label: $localize`Delete`,
2019-04-05 08:52:27 +00:00
handler: () => this.removeVideo(),
2019-06-07 09:08:56 +00:00
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.delete && this.isVideoRemovable(),
2019-04-05 08:52:27 +00:00
iconName: 'delete'
},
2019-04-05 08:52:27 +00:00
{
label: $localize`Report`,
2019-04-05 08:52:27 +00:00
handler: () => this.showReportModal(),
2019-06-07 09:08:56 +00:00
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.report,
iconName: 'flag'
2019-04-05 08:52:27 +00:00
}
],
[
2021-11-18 13:35:08 +00:00
{
label: $localize`Run HLS transcoding`,
handler: ({ video }) => this.runTranscoding(video, 'hls'),
isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
iconName: 'cog'
},
{
label: $localize`Run WebTorrent transcoding`,
handler: ({ video }) => this.runTranscoding(video, 'webtorrent'),
isDisplayed: () => this.displayOptions.transcoding && this.canRunTranscoding(),
iconName: 'cog'
},
{
label: $localize`Delete HLS files`,
handler: ({ video }) => this.removeVideoFiles(video, 'hls'),
isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
iconName: 'delete'
},
{
label: $localize`Delete WebTorrent files`,
handler: ({ video }) => this.removeVideoFiles(video, 'webtorrent'),
isDisplayed: () => this.displayOptions.removeFiles && this.canRemoveVideoFiles(),
iconName: 'delete'
}
],
[ // actions regarding the account/its server
{
label: $localize`Mute account`,
handler: () => this.muteVideoAccount(),
isDisplayed: () => this.authService.isLoggedIn() && this.displayOptions.mute && this.isVideoAccountMutable(),
iconName: 'no'
}
2019-06-07 09:08:56 +00:00
]
]
2022-04-05 12:03:52 +00:00
this.videoActions = this.videoActions.concat(this.moreActions)
2019-04-05 08:52:27 +00:00
}
}