X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2F%2Badmin%2Fmoderation%2Fvideo-block-list%2Fvideo-block-list.component.ts;h=8d67e9beb42b8c08b91f3e8ef506b2fe86dd1dad;hb=de61544582726713c965d3369902f4a464f72e20;hp=aa6b5d0a9c185e360681db870052a0ff5daf8695;hpb=5beb89f223539f1e415a976ff104f772526b4d20;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts index aa6b5d0a9..8d67e9beb 100644 --- a/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts +++ b/client/src/app/+admin/moderation/video-block-list/video-block-list.component.ts @@ -1,13 +1,14 @@ import { SortMeta } from 'primeng/api' import { switchMap } from 'rxjs/operators' -import { buildVideoLink, buildVideoOrPlaylistEmbed } from 'src/assets/player/utils' import { environment } from 'src/environments/environment' -import { AfterViewInit, Component, OnInit } from '@angular/core' -import { DomSanitizer } from '@angular/platform-browser' -import { ActivatedRoute, Params, Router } from '@angular/router' +import { Component, OnInit } from '@angular/core' +import { ActivatedRoute, Router } from '@angular/router' import { ConfirmService, MarkdownService, Notifier, RestPagination, RestTable, ServerService } from '@app/core' -import { DropdownAction, Video, VideoService } from '@app/shared/shared-main' +import { AdvancedInputFilter } from '@app/shared/shared-forms' +import { DropdownAction, VideoService } from '@app/shared/shared-main' import { VideoBlockService } from '@app/shared/shared-moderation' +import { buildVideoOrPlaylistEmbed } from '@root-helpers/video' +import { buildVideoEmbedLink, decorateVideoLink } from '@shared/core-utils' import { VideoBlacklist, VideoBlacklistType } from '@shared/models' @Component({ @@ -15,8 +16,8 @@ import { VideoBlacklist, VideoBlacklistType } from '@shared/models' templateUrl: './video-block-list.component.html', styleUrls: [ '../../../shared/shared-moderation/moderation.scss', './video-block-list.component.scss' ] }) -export class VideoBlockListComponent extends RestTable implements OnInit, AfterViewInit { - blocklist: (VideoBlacklist & { reasonHtml?: string, embedHtml?: string })[] = [] +export class VideoBlockListComponent extends RestTable implements OnInit { + blocklist: (VideoBlacklist & { reasonHtml?: string })[] = [] totalRecords = 0 sort: SortMeta = { field: 'createdAt', order: -1 } pagination: RestPagination = { count: this.rowsPerPage, start: 0 } @@ -24,6 +25,22 @@ export class VideoBlockListComponent extends RestTable implements OnInit, AfterV videoBlocklistActions: DropdownAction[][] = [] + inputFilters: AdvancedInputFilter[] = [ + { + title: $localize`Advanced filters`, + children: [ + { + value: 'type:auto', + label: $localize`Automatic blocks` + }, + { + value: 'type:manual', + label: $localize`Manual blocks` + } + ] + } + ] + constructor ( protected route: ActivatedRoute, protected router: Router, @@ -32,7 +49,6 @@ export class VideoBlockListComponent extends RestTable implements OnInit, AfterV private confirmService: ConfirmService, private videoBlocklistService: VideoBlockService, private markdownRenderer: MarkdownService, - private sanitizer: DomSanitizer, private videoService: VideoService ) { super() @@ -48,15 +64,15 @@ export class VideoBlockListComponent extends RestTable implements OnInit, AfterV label: $localize`Switch video block to manual`, handler: videoBlock => { this.videoBlocklistService.unblockVideo(videoBlock.video.id).pipe( - switchMap(_ => this.videoBlocklistService.blockVideo(videoBlock.video.id, undefined, true)) - ).subscribe( - () => { + switchMap(_ => this.videoBlocklistService.blockVideo([ { videoId: videoBlock.video.id, unfederate: true } ])) + ).subscribe({ + next: () => { this.notifier.success($localize`Video ${videoBlock.video.name} switched to manual block.`) - this.loadData() + this.reloadData() }, - err => this.notifier.error(err.message) - ) + error: err => this.notifier.error(err.message) + }) }, isDisplayed: videoBlock => videoBlock.type === VideoBlacklistType.AUTO_BEFORE_PUBLISHED } @@ -81,13 +97,11 @@ export class VideoBlockListComponent extends RestTable implements OnInit, AfterV if (res === false) return this.videoService.removeVideo(videoBlock.video.id) - .subscribe( - () => { - this.notifier.success($localize`Video deleted.`) - }, + .subscribe({ + next: () => this.notifier.success($localize`Video deleted.`), - err => this.notifier.error(err.message) - ) + error: err => this.notifier.error(err.message) + }) } } ] @@ -95,49 +109,20 @@ export class VideoBlockListComponent extends RestTable implements OnInit, AfterV } ngOnInit () { - this.serverService.getConfig() - .subscribe(config => { - // don't filter if auto-blacklist is not enabled as this will be the only list - if (config.autoBlacklist.videos.ofUsers.enabled) { - this.blocklistTypeFilter = VideoBlacklistType.MANUAL - } - }) - - this.initialize() - this.listenToSearchChange() - } - - ngAfterViewInit () { - if (this.search) this.setTableFilter(this.search) - } - - /* Table filter functions */ - onBlockSearch (event: Event) { - this.onSearch(event) - this.setQueryParams((event.target as HTMLInputElement).value) - } + const serverConfig = this.serverService.getHTMLConfig() - setQueryParams (search: string) { - const queryParams: Params = {} - if (search) Object.assign(queryParams, { search }) - this.router.navigate([ '/admin/moderation/video-blocks/list' ], { queryParams }) - } + // Don't filter if auto-blacklist is not enabled as this will be the only list + if (serverConfig.autoBlacklist.videos.ofUsers.enabled) { + this.blocklistTypeFilter = VideoBlacklistType.MANUAL + } - resetTableFilter () { - this.setTableFilter('') - this.setQueryParams('') - this.resetSearch() + this.initialize() } - /* END Table filter functions */ getIdentifier () { return 'VideoBlockListComponent' } - getVideoUrl (videoBlock: VideoBlacklist) { - return Video.buildClientUrl(videoBlock.video.uuid) - } - toHtml (text: string) { return this.markdownRenderer.textMarkdownToHTML(text) } @@ -148,47 +133,49 @@ export class VideoBlockListComponent extends RestTable implements OnInit, AfterV const res = await this.confirmService.confirm(confirmMessage, $localize`Unblock`) if (res === false) return - this.videoBlocklistService.unblockVideo(entry.video.id).subscribe( - () => { - this.notifier.success($localize`Video ${entry.video.name} unblocked.`) - this.loadData() - }, + this.videoBlocklistService.unblockVideo(entry.video.id) + .subscribe({ + next: () => { + this.notifier.success($localize`Video ${entry.video.name} unblocked.`) + this.reloadData() + }, - err => this.notifier.error(err.message) - ) + error: err => this.notifier.error(err.message) + }) } getVideoEmbed (entry: VideoBlacklist) { - return buildVideoOrPlaylistEmbed( - buildVideoLink({ - baseUrl: `${environment.originServerUrl}/videos/embed/${entry.video.uuid}`, + return buildVideoOrPlaylistEmbed({ + embedUrl: decorateVideoLink({ + url: buildVideoEmbedLink(entry.video, environment.originServerUrl), + title: false, warningTitle: false - }) - ) + }), + embedTitle: entry.video.name + }) } - protected loadData () { + protected reloadData () { this.videoBlocklistService.listBlocks({ pagination: this.pagination, sort: this.sort, search: this.search }) - .subscribe( - async resultList => { + .subscribe({ + next: async resultList => { this.totalRecords = resultList.total this.blocklist = resultList.data for (const element of this.blocklist) { Object.assign(element, { - reasonHtml: await this.toHtml(element.reason), - embedHtml: this.sanitizer.bypassSecurityTrustHtml(this.getVideoEmbed(element)) + reasonHtml: await this.toHtml(element.reason) }) } }, - err => this.notifier.error(err.message) - ) + error: err => this.notifier.error(err.message) + }) } }