]>
Commit | Line | Data |
---|---|---|
33f6dce1 C |
1 | import { SortMeta } from 'primeng/api' |
2 | import { Component, OnInit } from '@angular/core' | |
3 | import { ActivatedRoute, Router } from '@angular/router' | |
4 | import { AuthService, ConfirmService, Notifier, RestPagination, RestTable } from '@app/core' | |
5 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' | |
6 | import { UserRight } from '@shared/models' | |
7 | import { AdvancedInputFilter } from '@app/shared/shared-forms' | |
8 | import { VideoActionsDisplayType } from '@app/shared/shared-video-miniature' | |
9 | ||
10 | @Component({ | |
11 | selector: 'my-video-list', | |
12 | templateUrl: './video-list.component.html', | |
13 | styleUrls: [ './video-list.component.scss' ] | |
14 | }) | |
15 | export class VideoListComponent extends RestTable implements OnInit { | |
16 | videos: Video[] = [] | |
17 | ||
18 | totalRecords = 0 | |
19 | sort: SortMeta = { field: 'publishedAt', order: 1 } | |
20 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
21 | ||
22 | bulkVideoActions: DropdownAction<Video[]>[][] = [] | |
23 | ||
24 | selectedVideos: Video[] = [] | |
25 | ||
26 | inputFilters: AdvancedInputFilter[] = [ | |
27 | { | |
28 | title: $localize`Advanced filters`, | |
29 | children: [ | |
30 | { | |
31 | queryParams: { search: 'local:true' }, | |
32 | label: $localize`Only local videos` | |
33 | } | |
34 | ] | |
35 | } | |
36 | ] | |
37 | ||
38 | videoActionsOptions: VideoActionsDisplayType = { | |
39 | playlist: false, | |
40 | download: false, | |
41 | update: true, | |
42 | blacklist: true, | |
43 | delete: true, | |
44 | report: false, | |
45 | duplicate: true, | |
46 | mute: true, | |
47 | liveInfo: false | |
48 | } | |
49 | ||
50 | constructor ( | |
51 | protected route: ActivatedRoute, | |
52 | protected router: Router, | |
53 | private confirmService: ConfirmService, | |
54 | private auth: AuthService, | |
55 | private notifier: Notifier, | |
56 | private videoService: VideoService | |
57 | ) { | |
58 | super() | |
59 | } | |
60 | ||
61 | get authUser () { | |
62 | return this.auth.getUser() | |
63 | } | |
64 | ||
65 | ngOnInit () { | |
66 | this.initialize() | |
67 | ||
68 | this.bulkVideoActions = [ | |
69 | [ | |
70 | { | |
71 | label: $localize`Delete`, | |
72 | handler: videos => this.removeVideos(videos), | |
73 | isDisplayed: () => this.authUser.hasRight(UserRight.REMOVE_ANY_VIDEO) | |
74 | } | |
75 | ] | |
76 | ] | |
77 | } | |
78 | ||
79 | getIdentifier () { | |
80 | return 'VideoListComponent' | |
81 | } | |
82 | ||
83 | isInSelectionMode () { | |
84 | return this.selectedVideos.length !== 0 | |
85 | } | |
86 | ||
87 | onVideoRemoved () { | |
88 | this.reloadData() | |
89 | } | |
90 | ||
91 | protected reloadData () { | |
92 | this.selectedVideos = [] | |
93 | ||
94 | this.videoService.getAdminVideos({ | |
95 | pagination: this.pagination, | |
96 | sort: this.sort, | |
97 | search: this.search | |
98 | }).subscribe({ | |
99 | next: resultList => { | |
100 | this.videos = resultList.data | |
101 | this.totalRecords = resultList.total | |
102 | }, | |
103 | ||
104 | error: err => this.notifier.error(err.message) | |
105 | }) | |
106 | } | |
107 | ||
108 | private async removeVideos (videos: Video[]) { | |
109 | const message = $localize`Are you sure you want to delete these ${videos.length} videos?` | |
110 | const res = await this.confirmService.confirm(message, $localize`Delete`) | |
111 | if (res === false) return | |
112 | ||
113 | this.videoService.removeVideo(videos.map(v => v.id)) | |
114 | .subscribe({ | |
115 | next: () => { | |
116 | this.notifier.success($localize`${videos.length} videos deleted.`) | |
117 | this.reloadData() | |
118 | }, | |
119 | ||
120 | error: err => this.notifier.error(err.message) | |
121 | }) | |
122 | } | |
123 | } |