]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - client/src/app/+admin/overview/videos/video-list.component.ts
Deprecate filter video query
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / videos / video-list.component.ts
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'
9
10 @Component({
11 selector: 'my-video-list',
12 templateUrl: './video-list.component.html',
13 styleUrls: [ './video-list.component.scss' ]
14 })
15 export class VideoListComponent extends RestTable implements OnInit {
16 videos: Video[] = []
17
18 totalRecords = 0
19 sort: SortMeta = { field: 'publishedAt', order: 1 }
20 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
21
22 bulkVideoActions: DropdownAction<Video[]>[][] = []
23
24 selectedVideos: Video[] = []
25
26 inputFilters: AdvancedInputFilter[] = [
27 {
28 title: $localize`Advanced filters`,
29 children: [
30 {
31 queryParams: { search: 'isLocal:false' },
32 label: $localize`Remote videos`
33 },
34 {
35 queryParams: { search: 'isLocal:true' },
36 label: $localize`Local videos`
37 }
38 ]
39 }
40 ]
41
42 videoActionsOptions: VideoActionsDisplayType = {
43 playlist: false,
44 download: false,
45 update: true,
46 blacklist: true,
47 delete: true,
48 report: false,
49 duplicate: true,
50 mute: true,
51 liveInfo: false
52 }
53
54 constructor (
55 protected route: ActivatedRoute,
56 protected router: Router,
57 private confirmService: ConfirmService,
58 private auth: AuthService,
59 private notifier: Notifier,
60 private videoService: VideoService
61 ) {
62 super()
63 }
64
65 get authUser () {
66 return this.auth.getUser()
67 }
68
69 ngOnInit () {
70 this.initialize()
71
72 this.bulkVideoActions = [
73 [
74 {
75 label: $localize`Delete`,
76 handler: videos => this.removeVideos(videos),
77 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
78 }
79 ]
80 ]
81 }
82
83 getIdentifier () {
84 return 'VideoListComponent'
85 }
86
87 isInSelectionMode () {
88 return this.selectedVideos.length !== 0
89 }
90
91 onVideoRemoved () {
92 this.reloadData()
93 }
94
95 getPrivacyBadgeClass (privacy: VideoPrivacy) {
96 if (privacy === VideoPrivacy.PUBLIC) return 'badge-blue'
97
98 return 'badge-yellow'
99 }
100
101 isUnpublished (state: VideoState) {
102 return state !== VideoState.PUBLISHED
103 }
104
105 isAccountBlocked (video: Video) {
106 return video.blockedOwner
107 }
108
109 isServerBlocked (video: Video) {
110 return video.blockedServer
111 }
112
113 isVideoBlocked (video: Video) {
114 return video.blacklisted
115 }
116
117 protected reloadData () {
118 this.selectedVideos = []
119
120 this.videoService.getAdminVideos({
121 pagination: this.pagination,
122 sort: this.sort,
123 search: this.search
124 }).subscribe({
125 next: resultList => {
126 this.videos = resultList.data
127 this.totalRecords = resultList.total
128 },
129
130 error: err => this.notifier.error(err.message)
131 })
132 }
133
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
138
139 this.videoService.removeVideo(videos.map(v => v.id))
140 .subscribe({
141 next: () => {
142 this.notifier.success($localize`${videos.length} videos deleted.`)
143 this.reloadData()
144 },
145
146 error: err => this.notifier.error(err.message)
147 })
148 }
149 }