1 import { SortMeta } from 'primeng/api'
2 import { finalize } from 'rxjs/operators'
3 import { Component, OnInit } 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 { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
9 import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
10 import { VideoAdminService } from './video-admin.service'
13 selector: 'my-video-list',
14 templateUrl: './video-list.component.html',
15 styleUrls: [ './video-list.component.scss' ]
17 export class VideoListComponent extends RestTable implements OnInit {
21 sort: SortMeta = { field: 'publishedAt', order: -1 }
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
24 bulkVideoActions: DropdownAction<Video[]>[][] = []
26 selectedVideos: Video[] = []
28 inputFilters: AdvancedInputFilter[]
30 videoActionsOptions: VideoActionsDisplayType = {
45 protected route: ActivatedRoute,
46 protected router: Router,
47 private confirmService: ConfirmService,
48 private auth: AuthService,
49 private notifier: Notifier,
50 private videoService: VideoService,
51 private videoAdminService: VideoAdminService
57 return this.auth.getUser()
63 this.inputFilters = this.videoAdminService.buildAdminInputFilter()
65 this.bulkVideoActions = [
68 label: $localize`Delete`,
69 handler: videos => this.removeVideos(videos),
70 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
77 return 'VideoListComponent'
80 isInSelectionMode () {
81 return this.selectedVideos.length !== 0
88 getPrivacyBadgeClass (video: Video) {
89 if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-green'
94 isUnpublished (video: Video) {
95 return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED
98 isAccountBlocked (video: Video) {
99 return video.blockedOwner
102 isServerBlocked (video: Video) {
103 return video.blockedServer
106 isVideoBlocked (video: Video) {
107 return video.blacklisted
110 isImport (video: Video) {
111 return video.state.id === VideoState.TO_IMPORT
114 isHLS (video: Video) {
115 const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
118 return p.files.length !== 0
121 isWebTorrent (video: Video) {
122 return video.files.length !== 0
125 getFilesSize (video: Video) {
126 let files = video.files
128 if (this.isHLS(video)) {
129 files = files.concat(video.streamingPlaylists[0].files)
132 return files.reduce((p, f) => p += f.size, 0)
135 protected reloadData () {
136 this.selectedVideos = []
140 this.videoAdminService.getAdminVideos({
141 pagination: this.pagination,
144 }).pipe(finalize(() => this.loading = false))
146 next: resultList => {
147 this.videos = resultList.data
148 this.totalRecords = resultList.total
151 error: err => this.notifier.error(err.message)
155 private async removeVideos (videos: Video[]) {
156 const message = $localize`Are you sure you want to delete these ${videos.length} videos?`
157 const res = await this.confirmService.confirm(message, $localize`Delete`)
158 if (res === false) return
160 this.videoService.removeVideo(videos.map(v => v.id))
163 this.notifier.success($localize`${videos.length} videos deleted.`)
167 error: err => this.notifier.error(err.message)