]>
Commit | Line | Data |
---|---|---|
33f6dce1 | 1 | import { SortMeta } from 'primeng/api' |
61f85385 | 2 | import { finalize } from 'rxjs/operators' |
33f6dce1 C |
3 | import { Component, OnInit } from '@angular/core' |
4 | import { ActivatedRoute, Router } from '@angular/router' | |
5 | import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | |
33f6dce1 | 6 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
61f85385 | 7 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' |
33f6dce1 | 8 | import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature' |
61f85385 | 9 | import { UserRight, VideoPrivacy, VideoState, VideoStreamingPlaylistType } from '@shared/models' |
05ac4ac7 | 10 | import { 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 | }) | |
17 | export 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 | ||
2760b454 C |
88 | getPrivacyBadgeClass (privacy: VideoPrivacy) { |
89 | if (privacy === VideoPrivacy.PUBLIC) return 'badge-blue' | |
90 | ||
91 | return 'badge-yellow' | |
92 | } | |
93 | ||
94 | isUnpublished (state: VideoState) { | |
7e7d8e48 | 95 | return state !== VideoState.LIVE_ENDED && state !== 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 | ||
3c10840f C |
110 | isHLS (video: Video) { |
111 | return video.streamingPlaylists.some(p => p.type === VideoStreamingPlaylistType.HLS) | |
112 | } | |
113 | ||
114 | isWebTorrent (video: Video) { | |
115 | return video.files.length !== 0 | |
116 | } | |
117 | ||
118 | getFilesSize (video: Video) { | |
119 | let files = video.files | |
120 | ||
121 | if (this.isHLS(video)) { | |
122 | files = files.concat(video.streamingPlaylists[0].files) | |
123 | } | |
124 | ||
125 | return files.reduce((p, f) => p += f.size, 0) | |
126 | } | |
127 | ||
33f6dce1 C |
128 | protected reloadData () { |
129 | this.selectedVideos = [] | |
130 | ||
61f85385 C |
131 | this.loading = true |
132 | ||
05ac4ac7 | 133 | this.videoAdminService.getAdminVideos({ |
33f6dce1 C |
134 | pagination: this.pagination, |
135 | sort: this.sort, | |
136 | search: this.search | |
61f85385 C |
137 | }).pipe(finalize(() => this.loading = false)) |
138 | .subscribe({ | |
139 | next: resultList => { | |
140 | this.videos = resultList.data | |
141 | this.totalRecords = resultList.total | |
142 | }, | |
143 | ||
144 | error: err => this.notifier.error(err.message) | |
145 | }) | |
33f6dce1 C |
146 | } |
147 | ||
148 | private async removeVideos (videos: Video[]) { | |
149 | const message = $localize`Are you sure you want to delete these ${videos.length} videos?` | |
150 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
151 | if (res === false) return | |
152 | ||
153 | this.videoService.removeVideo(videos.map(v => v.id)) | |
154 | .subscribe({ | |
155 | next: () => { | |
156 | this.notifier.success($localize`${videos.length} videos deleted.`) | |
157 | this.reloadData() | |
158 | }, | |
159 | ||
160 | error: err => this.notifier.error(err.message) | |
161 | }) | |
162 | } | |
163 | } |