1 import { SortMeta } from 'primeng/api'
2 import { finalize } from 'rxjs/operators'
3 import { Component, OnInit, ViewChild } from '@angular/core'
4 import { ActivatedRoute, Router } from '@angular/router'
5 import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
6 import { AdvancedInputFilter } from '@app/shared/shared-forms'
7 import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
8 import { VideoBlockComponent, VideoBlockService } from '@app/shared/shared-moderation'
9 import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
10 import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
11 import { VideoAdminService } from './video-admin.service'
14 selector: 'my-video-list',
15 templateUrl: './video-list.component.html',
16 styleUrls: [ './video-list.component.scss' ]
18 export class VideoListComponent extends RestTable implements OnInit {
19 @ViewChild('videoBlockModal') videoBlockModal: VideoBlockComponent
24 sort: SortMeta = { field: 'publishedAt', order: -1 }
25 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
27 bulkVideoActions: DropdownAction<Video[]>[][] = []
29 selectedVideos: Video[] = []
31 inputFilters: AdvancedInputFilter[]
33 videoActionsOptions: VideoActionsDisplayType = {
48 protected route: ActivatedRoute,
49 protected router: Router,
50 private confirmService: ConfirmService,
51 private auth: AuthService,
52 private notifier: Notifier,
53 private videoService: VideoService,
54 private videoAdminService: VideoAdminService,
55 private videoBlockService: VideoBlockService
61 return this.auth.getUser()
67 this.inputFilters = this.videoAdminService.buildAdminInputFilter()
69 this.bulkVideoActions = [
72 label: $localize`Delete`,
73 handler: videos => this.removeVideos(videos),
74 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
77 label: $localize`Block`,
78 handler: videos => this.videoBlockModal.show(videos),
79 isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => !v.blacklisted)
82 label: $localize`Unblock`,
83 handler: videos => this.unblockVideos(videos),
84 isDisplayed: videos => this.authUser.hasRight(UserRight.MANAGE_VIDEO_BLACKLIST) && videos.every(v => v.blacklisted)
91 return 'VideoListComponent'
94 isInSelectionMode () {
95 return this.selectedVideos.length !== 0
102 getPrivacyBadgeClass (video: Video) {
103 if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green'
105 return 'badge-yellow'
108 isUnpublished (video: Video) {
109 return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED
112 isAccountBlocked (video: Video) {
113 return video.blockedOwner
116 isServerBlocked (video: Video) {
117 return video.blockedServer
120 isVideoBlocked (video: Video) {
121 return video.blacklisted
124 isImport (video: Video) {
125 return video.state.id === VideoState.TO_IMPORT
128 isHLS (video: Video) {
129 const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
132 return p.files.length !== 0
135 isWebTorrent (video: Video) {
136 return video.files.length !== 0
139 getFilesSize (video: Video) {
140 let files = video.files
142 if (this.isHLS(video)) {
143 files = files.concat(video.streamingPlaylists[0].files)
146 return files.reduce((p, f) => p += f.size, 0)
153 protected reloadData () {
154 this.selectedVideos = []
158 this.videoAdminService.getAdminVideos({
159 pagination: this.pagination,
162 }).pipe(finalize(() => this.loading = false))
164 next: resultList => {
165 this.videos = resultList.data
166 this.totalRecords = resultList.total
169 error: err => this.notifier.error(err.message)
173 private async removeVideos (videos: Video[]) {
174 const message = $localize`Are you sure you want to delete these ${videos.length} videos?`
175 const res = await this.confirmService.confirm(message, $localize`Delete`)
176 if (res === false) return
178 this.videoService.removeVideo(videos.map(v => v.id))
181 this.notifier.success($localize`Deleted ${videos.length} videos.`)
185 error: err => this.notifier.error(err.message)
189 private unblockVideos (videos: Video[]) {
190 this.videoBlockService.unblockVideo(videos.map(v => v.id))
193 this.notifier.success($localize`Unblocked ${videos.length} videos.`)
197 error: err => this.notifier.error(err.message)