1 import { SortMeta } from 'primeng/api'
2 import { Component, OnInit } from '@angular/core'
3 import { ActivatedRoute, Router } from '@angular/router'
4 import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
5 import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
6 import { UserRight, VideoPrivacy, VideoState } from '@shared/models'
7 import { AdvancedInputFilter } from '@app/shared/shared-forms'
8 import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
11 selector: 'my-video-list',
12 templateUrl: './video-list.component.html',
13 styleUrls: [ './video-list.component.scss' ]
15 export class VideoListComponent extends RestTable implements OnInit {
19 sort: SortMeta = { field: 'publishedAt', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
22 bulkVideoActions: DropdownAction<Video[]>[][] = []
24 selectedVideos: Video[] = []
26 inputFilters: AdvancedInputFilter[] = [
28 title: $localize`Advanced filters`,
31 queryParams: { search: 'isLocal:false' },
32 label: $localize`Remote videos`
35 queryParams: { search: 'isLocal:true' },
36 label: $localize`Local videos`
42 videoActionsOptions: VideoActionsDisplayType = {
55 protected route: ActivatedRoute,
56 protected router: Router,
57 private confirmService: ConfirmService,
58 private auth: AuthService,
59 private notifier: Notifier,
60 private videoService: VideoService
66 return this.auth.getUser()
72 this.bulkVideoActions = [
75 label: $localize`Delete`,
76 handler: videos => this.removeVideos(videos),
77 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
84 return 'VideoListComponent'
87 isInSelectionMode () {
88 return this.selectedVideos.length !== 0
95 getPrivacyBadgeClass (privacy: VideoPrivacy) {
96 if (privacy === VideoPrivacy.PUBLIC) return 'badge-blue'
101 isUnpublished (state: VideoState) {
102 return state !== VideoState.PUBLISHED
105 isAccountBlocked (video: Video) {
106 return video.blockedOwner
109 isServerBlocked (video: Video) {
110 return video.blockedServer
113 isVideoBlocked (video: Video) {
114 return video.blacklisted
117 protected reloadData () {
118 this.selectedVideos = []
120 this.videoService.getAdminVideos({
121 pagination: this.pagination,
125 next: resultList => {
126 this.videos = resultList.data
127 this.totalRecords = resultList.total
130 error: err => this.notifier.error(err.message)
134 private async removeVideos (videos: Video[]) {
135 const message = $localize`Are you sure you want to delete these ${videos.length} videos?`
136 const res = await this.confirmService.confirm(message, $localize`Delete`)
137 if (res === false) return
139 this.videoService.removeVideo(videos.map(v => v.id))
142 this.notifier.success($localize`${videos.length} videos deleted.`)
146 error: err => this.notifier.error(err.message)