]>
Commit | Line | Data |
---|---|---|
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 | import { VideoAdminService } from './video-admin.service' | |
11 | ||
12 | @Component({ | |
13 | selector: 'my-video-list', | |
14 | templateUrl: './video-list.component.html', | |
15 | styleUrls: [ './video-list.component.scss' ] | |
16 | }) | |
17 | export class VideoListComponent extends RestTable implements OnInit { | |
18 | videos: Video[] = [] | |
19 | ||
20 | totalRecords = 0 | |
21 | sort: SortMeta = { field: 'publishedAt', order: -1 } | |
22 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
23 | ||
24 | bulkVideoActions: DropdownAction<Video[]>[][] = [] | |
25 | ||
26 | selectedVideos: Video[] = [] | |
27 | ||
28 | inputFilters: AdvancedInputFilter[] | |
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 | ||
42 | loading = true | |
43 | ||
44 | constructor ( | |
45 | protected route: ActivatedRoute, | |
46 | protected router: Router, | |
47 | private confirmService: ConfirmService, | |
48 | private auth: AuthService, | |
49 | private notifier: Notifier, | |
50 | private videoService: VideoService, | |
51 | private videoAdminService: VideoAdminService | |
52 | ) { | |
53 | super() | |
54 | } | |
55 | ||
56 | get authUser () { | |
57 | return this.auth.getUser() | |
58 | } | |
59 | ||
60 | ngOnInit () { | |
61 | this.initialize() | |
62 | ||
63 | this.inputFilters = this.videoAdminService.buildAdminInputFilter() | |
64 | ||
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 | ||
88 | getPrivacyBadgeClass (video: Video) { | |
89 | if (video.privacy.id === VideoPrivacy.PUBLIC) return 'badge-blue' | |
90 | ||
91 | return 'badge-yellow' | |
92 | } | |
93 | ||
94 | isUnpublished (video: Video) { | |
95 | return video.state.id !== VideoState.LIVE_ENDED && video.state.id !== VideoState.PUBLISHED | |
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 | ||
110 | isImport (video: Video) { | |
111 | return video.state.id === VideoState.TO_IMPORT | |
112 | } | |
113 | ||
114 | isHLS (video: Video) { | |
115 | const p = video.streamingPlaylists.find(p => p.type === VideoStreamingPlaylistType.HLS) | |
116 | if (!p) return false | |
117 | ||
118 | return p.files.length !== 0 | |
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 | ||
135 | protected reloadData () { | |
136 | this.selectedVideos = [] | |
137 | ||
138 | this.loading = true | |
139 | ||
140 | this.videoAdminService.getAdminVideos({ | |
141 | pagination: this.pagination, | |
142 | sort: this.sort, | |
143 | search: this.search | |
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 | }) | |
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 | } |