]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/+admin/overview/videos/video-list.component.ts
Add ability to filter by file type
[github/Chocobozzz/PeerTube.git] / client / src / app / +admin / overview / videos / video-list.component.ts
CommitLineData
33f6dce1 1import { SortMeta } from 'primeng/api'
61f85385 2import { finalize } from 'rxjs/operators'
33f6dce1
C
3import { Component, OnInit } from '@angular/core'
4import { ActivatedRoute, Router } from '@angular/router'
5import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core'
33f6dce1 6import { AdvancedInputFilter } from '@app/shared/shared-forms'
61f85385 7import { DropdownAction, Video, VideoService } from '@app/shared/shared-main'
33f6dce1 8import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature'
61f85385 9import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models'
05ac4ac7 10import { VideoAdminService } from './video-admin.service'
33f6dce1
C
11
12@Component({
13 selector: 'my-video-list',
14 templateUrl: './video-list.component.html',
15 styleUrls: [ './video-list.component.scss' ]
16})
17export class VideoListComponent extends RestTable implements OnInit {
18 videos: Video[] = []
19
20 totalRecords = 0
7e7d8e48 21 sort: SortMeta = { field: 'publishedAt', order: -1 }
33f6dce1
C
22 pagination: RestPagination = { count: this.rowsPerPage, start: 0 }
23
24 bulkVideoActions: DropdownAction<Video[]>[][] = []
25
26 selectedVideos: Video[] = []
27
231ff4af 28 inputFilters: AdvancedInputFilter[]
33f6dce1
C
29
30 videoActionsOptions: VideoActionsDisplayType = {
31 playlist: false,
32 download: false,
33 update: true,
34 blacklist: true,
35 delete: true,
36 report: false,
37 duplicate: true,
38 mute: true,
39 liveInfo: false
40 }
41
231ff4af 42 loading = true
61f85385 43
33f6dce1
C
44 constructor (
45 protected route: ActivatedRoute,
46 protected router: Router,
47 private confirmService: ConfirmService,
48 private auth: AuthService,
49 private notifier: Notifier,
05ac4ac7
C
50 private videoService: VideoService,
51 private videoAdminService: VideoAdminService
33f6dce1
C
52 ) {
53 super()
54 }
55
56 get authUser () {
57 return this.auth.getUser()
58 }
59
60 ngOnInit () {
61 this.initialize()
62
05ac4ac7 63 this.inputFilters = this.videoAdminService.buildAdminInputFilter()
231ff4af 64
33f6dce1
C
65 this.bulkVideoActions = [
66 [
67 {
68 label: $localize`Delete`,
69 handler: videos => this.removeVideos(videos),
70 isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO)
71 }
72 ]
73 ]
74 }
75
76 getIdentifier () {
77 return 'VideoListComponent'
78 }
79
80 isInSelectionMode () {
81 return this.selectedVideos.length !== 0
82 }
83
84 onVideoRemoved () {
85 this.reloadData()
86 }
87
d324756e
C
88 getPrivacyBadgeClass (video: Video) {
89 if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-blue'
2760b454
C
90
91 return 'badge-yellow'
92 }
93
d324756e
C
94 isUnpublished (video: Video) {
95 return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED
2760b454
C
96 }
97
98 isAccountBlocked (video: Video) {
99 return video.blockedOwner
100 }
101
102 isServerBlocked (video: Video) {
103 return video.blockedServer
104 }
105
106 isVideoBlocked (video: Video) {
107 return video.blacklisted
108 }
109
d324756e
C
110 isImport (video: Video) {
111 return video.state.id === VideoState.TO_IMPORT
112 }
113
3c10840f 114 isHLS (video: Video) {
d5d9c5b7
C
115 const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS)
116 if (!p) return false
117
118 return p.files.length !== 0
3c10840f
C
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
61f85385
C
138 this.loading = true
139
05ac4ac7 140 this.videoAdminService.getAdminVideos({
33f6dce1
C
141 pagination: this.pagination,
142 sort: this.sort,
143 search: this.search
61f85385
C
144 }).pipe(finalize(() => this.loading = false))
145 .subscribe({
146 next: resultList => {
147 this.videos = resultList.data
148 this.totalRecords = resultList.total
149 },
150
151 error: err => this.notifier.error(err.message)
152 })
33f6dce1
C
153 }
154
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
159
160 this.videoService.removeVideo(videos.map(v => v.id))
161 .subscribe({
162 next: () => {
163 this.notifier.success($localize`${videos.length} videos deleted.`)
164 this.reloadData()
165 },
166
167 error: err => this.notifier.error(err.message)
168 })
169 }
170}