]>
Commit | Line | Data |
---|---|---|
5baee5fc | 1 | import { SortMeta } from 'primeng/api' |
5ed46c1b | 2 | import { switchMap } from 'rxjs/operators' |
66357162 C |
3 | import { buildVideoLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' |
4 | import { environment } from 'src/environments/environment' | |
67ed6552 | 5 | import { AfterViewInit, Component, OnInit } from '@angular/core' |
66357162 | 6 | import { DomSanitizer } from '@angular/platform-browser' |
67ed6552 C |
7 | import { ActivatedRoute, Params, Router } from '@angular/router' |
8 | import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core' | |
1fd61899 | 9 | import { AdvancedInputFilter } from '@app/shared/shared-forms' |
67ed6552 C |
10 | import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' |
11 | import { VideoBlockService } from '@app/shared/shared-moderation' | |
67ed6552 | 12 | import { VideoBlacklist, VideoBlacklistType } from '@shared/models' |
5baee5fc RK |
13 | |
14 | @Component({ | |
15 | selector: 'my-video-block-list', | |
16 | templateUrl: './video-block-list.component.html', | |
4504f09f | 17 | styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ] |
5baee5fc | 18 | }) |
8b381422 | 19 | export class VideoBlockListComponent extends RestTable implements OnInit, AfterViewInit { |
71ab65d0 | 20 | blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = [] |
5baee5fc RK |
21 | totalRecords = 0 |
22 | sort: SortMeta = { field: 'createdAt', order: -1 } | |
23 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | |
3487330d | 24 | blocklistTypeFilter: VideoBlacklistType = undefined |
5baee5fc | 25 | |
3487330d | 26 | videoBlocklistActions: DropdownAction<VideoBlacklist>[][] = [] |
5baee5fc | 27 | |
1fd61899 C |
28 | inputFilters: AdvancedInputFilter[] = [ |
29 | { | |
30 | queryParams: { 'search': 'type:auto' }, | |
31 | label: $localize`Automatic blocks` | |
32 | }, | |
33 | { | |
34 | queryParams: { 'search': 'type:manual' }, | |
35 | label: $localize`Manual blocks` | |
36 | } | |
37 | ] | |
38 | ||
5baee5fc | 39 | constructor ( |
5ed46c1b C |
40 | protected route: ActivatedRoute, |
41 | protected router: Router, | |
5baee5fc RK |
42 | private notifier: Notifier, |
43 | private serverService: ServerService, | |
44 | private confirmService: ConfirmService, | |
45 | private videoBlocklistService: VideoBlockService, | |
46 | private markdownRenderer: MarkdownService, | |
71ab65d0 | 47 | private sanitizer: DomSanitizer, |
5ed46c1b C |
48 | private videoService: VideoService |
49 | ) { | |
5baee5fc RK |
50 | super() |
51 | ||
52 | this.videoBlocklistActions = [ | |
53 | [ | |
54 | { | |
66357162 | 55 | label: $localize`Internal actions`, |
4ee63ec6 RK |
56 | isHeader: true, |
57 | isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED | |
5baee5fc RK |
58 | }, |
59 | { | |
66357162 | 60 | label: $localize`Switch video block to manual`, |
5baee5fc RK |
61 | handler: videoBlock => { |
62 | this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe( | |
63 | switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true)) | |
64 | ).subscribe( | |
65 | () => { | |
66357162 | 66 | this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`) |
5baee5fc RK |
67 | this.loadData() |
68 | }, | |
8b381422 | 69 | |
5baee5fc RK |
70 | err => this.notifier.error(err.message) |
71 | ) | |
4ee63ec6 RK |
72 | }, |
73 | isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED | |
5baee5fc RK |
74 | } |
75 | ], | |
76 | [ | |
77 | { | |
66357162 | 78 | label: $localize`Actions for the video`, |
8b381422 | 79 | isHeader: true |
5baee5fc RK |
80 | }, |
81 | { | |
66357162 | 82 | label: $localize`Unblock`, |
5baee5fc RK |
83 | handler: videoBlock => this.unblockVideo(videoBlock) |
84 | }, | |
85 | ||
86 | { | |
66357162 | 87 | label: $localize`Delete`, |
5baee5fc RK |
88 | handler: async videoBlock => { |
89 | const res = await this.confirmService.confirm( | |
66357162 C |
90 | $localize`Do you really want to delete this video?`, |
91 | $localize`Delete` | |
5baee5fc RK |
92 | ) |
93 | if (res === false) return | |
94 | ||
95 | this.videoService.removeVideo(videoBlock.video.id) | |
96 | .subscribe( | |
97 | () => { | |
66357162 | 98 | this.notifier.success($localize`Video deleted.`) |
5baee5fc RK |
99 | }, |
100 | ||
101 | err => this.notifier.error(err.message) | |
102 | ) | |
103 | } | |
104 | } | |
105 | ] | |
106 | ] | |
107 | } | |
108 | ||
109 | ngOnInit () { | |
110 | this.serverService.getConfig() | |
111 | .subscribe(config => { | |
112 | // don't filter if auto-blacklist is not enabled as this will be the only list | |
113 | if (config.autoBlacklist.videos.ofUsers.enabled) { | |
3487330d | 114 | this.blocklistTypeFilter = VideoBlacklistType.MANUAL |
5baee5fc RK |
115 | } |
116 | }) | |
117 | ||
118 | this.initialize() | |
5ed46c1b | 119 | this.listenToSearchChange() |
5baee5fc RK |
120 | } |
121 | ||
122 | ngAfterViewInit () { | |
3f6441e0 | 123 | if (this.search) this.setTableFilter(this.search, false) |
5baee5fc RK |
124 | } |
125 | ||
5baee5fc RK |
126 | getIdentifier () { |
127 | return 'VideoBlockListComponent' | |
128 | } | |
129 | ||
3487330d | 130 | getVideoUrl (videoBlock: VideoBlacklist) { |
5baee5fc RK |
131 | return Video.buildClientUrl(videoBlock.video.uuid) |
132 | } | |
133 | ||
5baee5fc RK |
134 | toHtml (text: string) { |
135 | return this.markdownRenderer.textMarkdownToHTML(text) | |
136 | } | |
137 | ||
3487330d | 138 | async unblockVideo (entry: VideoBlacklist) { |
66357162 | 139 | const confirmMessage = $localize`Do you really want to unblock this video? It will be available again in the videos list.` |
5baee5fc | 140 | |
66357162 | 141 | const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`) |
5baee5fc RK |
142 | if (res === false) return |
143 | ||
144 | this.videoBlocklistService.unblockVideo(entry.video.id).subscribe( | |
145 | () => { | |
66357162 | 146 | this.notifier.success($localize`Video ${entry.video.name} unblocked.`) |
5baee5fc RK |
147 | this.loadData() |
148 | }, | |
149 | ||
150 | err => this.notifier.error(err.message) | |
151 | ) | |
152 | } | |
153 | ||
71ab65d0 | 154 | getVideoEmbed (entry: VideoBlacklist) { |
951b582f | 155 | return buildVideoOrPlaylistEmbed( |
71ab65d0 | 156 | buildVideoLink({ |
5beb89f2 | 157 | baseUrl: `${environment.originServerUrl}/videos/embed/${entry.video.uuid}`, |
71ab65d0 RK |
158 | title: false, |
159 | warningTitle: false | |
4097c6d6 TP |
160 | }), |
161 | entry.video.name | |
71ab65d0 RK |
162 | ) |
163 | } | |
164 | ||
5baee5fc RK |
165 | protected loadData () { |
166 | this.videoBlocklistService.listBlocks({ | |
167 | pagination: this.pagination, | |
168 | sort: this.sort, | |
8b381422 | 169 | search: this.search |
5baee5fc RK |
170 | }) |
171 | .subscribe( | |
172 | async resultList => { | |
173 | this.totalRecords = resultList.total | |
174 | ||
175 | this.blocklist = resultList.data | |
176 | ||
177 | for (const element of this.blocklist) { | |
71ab65d0 RK |
178 | Object.assign(element, { |
179 | reasonHtml: await this.toHtml(element.reason), | |
180 | embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element)) | |
181 | }) | |
5baee5fc RK |
182 | } |
183 | }, | |
184 | ||
185 | err => this.notifier.error(err.message) | |
186 | ) | |
187 | } | |
188 | } |