]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/videos/video-list.component.ts
Some fixes for admin videos list
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / videos / video-list.component.ts
CommitLineData
33f6dce1
C
1import { SortMeta } from 'primeng/api'
2import { Component, OnInit } from '@angular/core'
3import { ActivatedRoute, Router } from '@angular/router'
4import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
5import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
3c10840f 6import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
33f6dce1
C
7import { AdvancedInputFilter } from '@app/shared/shared-forms'
8import { 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})
15export class VideoListComponent extends RestTable implements OnInit {
16 videos: Video[] = []
17
18 totalRecords = 0
7e7d8e48 19 sort: SortMeta = { field: 'publishedAt', order: -1 }
33f6dce1
C
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 {
2760b454
C
31 queryParams: { search: 'isLocal:false' },
32 label: $localize`Remote videos`
33 },
34 {
35 queryParams: { search: 'isLocal:true' },
36 label: $localize`Local videos`
33f6dce1
C
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
2760b454
C
95 getPrivacyBadgeClass (privacy: VideoPrivacy) {
96 if (privacy === VideoPrivacy.PUBLIC) return 'badge-blue'
97
98 return 'badge-yellow'
99 }
100
101 isUnpublished (state: VideoState) {
7e7d8e48 102 return state !== VideoState.LIVE_ENDED && state !== VideoState.PUBLISHED
2760b454
C
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
3c10840f
C
117 isHLS (video: Video) {
118 return video.streamingPlaylists.some(p => p.type === VideoStreamingPlaylistType.HLS)
119 }
120
121 isWebTorrent (video: Video) {
122 return video.files.length !== 0
123 }
124
125 getFilesSize (video: Video) {
126 let files = video.files
127
128 if (this.isHLS(video)) {
129 files = files.concat(video.streamingPlaylists[0].files)
130 }
131
132 return files.reduce((p, f) => p += f.size, 0)
133 }
134
33f6dce1
C
135 protected reloadData () {
136 this.selectedVideos = []
137
138 this.videoService.getAdminVideos({
139 pagination: this.pagination,
140 sort: this.sort,
141 search: this.search
142 }).subscribe({
143 next: resultList => {
144 this.videos = resultList.data
145 this.totalRecords = resultList.total
146 },
147
148 error: err => this.notifier.error(err.message)
149 })
150 }
151
152 private async removeVideos (videos: Video[]) {
153 const message = $localize`Are you sure you want to delete these ${videos.length} videos?`
154 const res = await this.confirmService.confirm(message, $localize`Delete`)
155 if (res === false) return
156
157 this.videoService.removeVideo(videos.map(v => v.id))
158 .subscribe({
159 next: () => {
160 this.notifier.success($localize`${videos.length} videos deleted.`)
161 this.reloadData()
162 },
163
164 error: err => this.notifier.error(err.message)
165 })
166 }
167}