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