diff options
Diffstat (limited to 'client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts')
-rw-r--r-- | client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts index 83d194d52..f54e3dccd 100644 --- a/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts +++ b/client/src/app/+admin/moderation/video-abuse-list/video-abuse-list.component.ts | |||
@@ -16,9 +16,23 @@ import { getAbsoluteAPIUrl } from '@app/shared/misc/utils' | |||
16 | import { DomSanitizer } from '@angular/platform-browser' | 16 | import { DomSanitizer } from '@angular/platform-browser' |
17 | import { BlocklistService } from '@app/shared/blocklist' | 17 | import { BlocklistService } from '@app/shared/blocklist' |
18 | import { VideoService } from '@app/shared/video/video.service' | 18 | import { VideoService } from '@app/shared/video/video.service' |
19 | import { ActivatedRoute } from '@angular/router' | 19 | import { ActivatedRoute, Params, Router } from '@angular/router' |
20 | import { filter } from 'rxjs/operators' | 20 | import { filter } from 'rxjs/operators' |
21 | 21 | ||
22 | export type ProcessedVideoAbuse = VideoAbuse & { | ||
23 | moderationCommentHtml?: string, | ||
24 | reasonHtml?: string | ||
25 | embedHtml?: string | ||
26 | updatedAt?: Date | ||
27 | // override bare server-side definitions with rich client-side definitions | ||
28 | reporterAccount: Account | ||
29 | video: VideoAbuse['video'] & { | ||
30 | channel: VideoAbuse['video']['channel'] & { | ||
31 | ownerAccount: Account | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
22 | @Component({ | 36 | @Component({ |
23 | selector: 'my-video-abuse-list', | 37 | selector: 'my-video-abuse-list', |
24 | templateUrl: './video-abuse-list.component.html', | 38 | templateUrl: './video-abuse-list.component.html', |
@@ -27,7 +41,7 @@ import { filter } from 'rxjs/operators' | |||
27 | export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit { | 41 | export class VideoAbuseListComponent extends RestTable implements OnInit, AfterViewInit { |
28 | @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent | 42 | @ViewChild('moderationCommentModal', { static: true }) moderationCommentModal: ModerationCommentModalComponent |
29 | 43 | ||
30 | videoAbuses: (VideoAbuse & { moderationCommentHtml?: string, reasonHtml?: string })[] = [] | 44 | videoAbuses: ProcessedVideoAbuse[] = [] |
31 | totalRecords = 0 | 45 | totalRecords = 0 |
32 | sort: SortMeta = { field: 'createdAt', order: 1 } | 46 | sort: SortMeta = { field: 'createdAt', order: 1 } |
33 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } | 47 | pagination: RestPagination = { count: this.rowsPerPage, start: 0 } |
@@ -44,7 +58,8 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV | |||
44 | private i18n: I18n, | 58 | private i18n: I18n, |
45 | private markdownRenderer: MarkdownService, | 59 | private markdownRenderer: MarkdownService, |
46 | private sanitizer: DomSanitizer, | 60 | private sanitizer: DomSanitizer, |
47 | private route: ActivatedRoute | 61 | private route: ActivatedRoute, |
62 | private router: Router | ||
48 | ) { | 63 | ) { |
49 | super() | 64 | super() |
50 | 65 | ||
@@ -212,15 +227,24 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV | |||
212 | this.loadData() | 227 | this.loadData() |
213 | } | 228 | } |
214 | 229 | ||
215 | createByString (account: Account) { | 230 | /* Table filter functions */ |
216 | return Account.CREATE_BY_STRING(account.name, account.host) | 231 | onAbuseSearch (event: Event) { |
232 | this.onSearch(event) | ||
233 | this.setQueryParams((event.target as HTMLInputElement).value) | ||
234 | } | ||
235 | |||
236 | setQueryParams (search: string) { | ||
237 | const queryParams: Params = {} | ||
238 | if (search) Object.assign(queryParams, { search }) | ||
239 | this.router.navigate([ '/admin/moderation/video-abuses/list' ], { queryParams }) | ||
217 | } | 240 | } |
218 | 241 | ||
219 | setTableFilter (filter: string) { | 242 | resetTableFilter () { |
220 | // FIXME: cannot use ViewChild, so create a component for the filter input | 243 | this.setTableFilter('') |
221 | const filterInput = document.getElementById('table-filter') as HTMLInputElement | 244 | this.setQueryParams('') |
222 | if (filterInput) filterInput.value = filter | 245 | this.resetSearch() |
223 | } | 246 | } |
247 | /* END Table filter functions */ | ||
224 | 248 | ||
225 | isVideoAbuseAccepted (videoAbuse: VideoAbuse) { | 249 | isVideoAbuseAccepted (videoAbuse: VideoAbuse) { |
226 | return videoAbuse.state.id === VideoAbuseState.ACCEPTED | 250 | return videoAbuse.state.id === VideoAbuseState.ACCEPTED |
@@ -279,17 +303,20 @@ export class VideoAbuseListComponent extends RestTable implements OnInit, AfterV | |||
279 | }).subscribe( | 303 | }).subscribe( |
280 | async resultList => { | 304 | async resultList => { |
281 | this.totalRecords = resultList.total | 305 | this.totalRecords = resultList.total |
306 | this.videoAbuses = [] | ||
282 | 307 | ||
283 | this.videoAbuses = resultList.data | 308 | for (const abuse of resultList.data) { |
284 | |||
285 | for (const abuse of this.videoAbuses) { | ||
286 | Object.assign(abuse, { | 309 | Object.assign(abuse, { |
287 | reasonHtml: await this.toHtml(abuse.reason), | 310 | reasonHtml: await this.toHtml(abuse.reason), |
288 | moderationCommentHtml: await this.toHtml(abuse.moderationComment), | 311 | moderationCommentHtml: await this.toHtml(abuse.moderationComment), |
289 | embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)), | 312 | embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(abuse)), |
290 | reporterAccount: new Account(abuse.reporterAccount) | 313 | reporterAccount: new Account(abuse.reporterAccount) |
291 | }) | 314 | }) |
315 | |||
316 | if (abuse.video.channel?.ownerAccount) abuse.video.channel.ownerAccount = new Account(abuse.video.channel.ownerAccount) | ||
292 | if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt | 317 | if (abuse.updatedAt === abuse.createdAt) delete abuse.updatedAt |
318 | |||
319 | this.videoAbuses.push(abuse as ProcessedVideoAbuse) | ||
293 | } | 320 | } |
294 | 321 | ||
295 | }, | 322 | }, |