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