From 5baee5fca418487e72ddcd6419d31bca8659b668 Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 2 Jun 2020 20:50:42 +0200 Subject: rename blacklist to block/blocklist, merge block and auto-block views - also replace whitelist with allowlist - add advanced filters for video-block-list view - move icons in video-block-list and video-abuse-list to left side for visibility - add robot icon to depict automated nature of a block in video-block-list resolves #2790 --- client/src/app/shared/video-block/index.ts | 1 + .../app/shared/video-block/video-block.service.ts | 77 ++++++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 client/src/app/shared/video-block/index.ts create mode 100644 client/src/app/shared/video-block/video-block.service.ts (limited to 'client/src/app/shared/video-block') diff --git a/client/src/app/shared/video-block/index.ts b/client/src/app/shared/video-block/index.ts new file mode 100644 index 000000000..a99551a38 --- /dev/null +++ b/client/src/app/shared/video-block/index.ts @@ -0,0 +1 @@ +export * from './video-block.service' diff --git a/client/src/app/shared/video-block/video-block.service.ts b/client/src/app/shared/video-block/video-block.service.ts new file mode 100644 index 000000000..67ca1d85b --- /dev/null +++ b/client/src/app/shared/video-block/video-block.service.ts @@ -0,0 +1,77 @@ +import { catchError, map, concatMap, toArray } from 'rxjs/operators' +import { HttpClient, HttpParams } from '@angular/common/http' +import { Injectable } from '@angular/core' +import { SortMeta } from 'primeng/api' +import { from as observableFrom, Observable } from 'rxjs' +import { VideoBlocklist, VideoBlockType, ResultList } from '../../../../../shared' +import { environment } from '../../../environments/environment' +import { RestExtractor, RestPagination, RestService } from '../rest' + +@Injectable() +export class VideoBlockService { + private static BASE_VIDEOS_URL = environment.apiUrl + '/api/v1/videos/' + + constructor ( + private authHttp: HttpClient, + private restService: RestService, + private restExtractor: RestExtractor + ) {} + + listBlocks (options: { + pagination: RestPagination + sort: SortMeta + search?: string + type?: VideoBlockType + }): Observable> { + const { pagination, sort, search, type } = options + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + if (search) { + const filters = this.restService.parseQueryStringFilter(search, { + type: { + prefix: 'type:', + handler: v => { + if (v === 'manual') return VideoBlockType.MANUAL + if (v === 'auto') return VideoBlockType.AUTO_BEFORE_PUBLISHED + + return undefined + } + } + }) + + params = this.restService.addObjectParams(params, filters) + } + + return this.authHttp.get>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params }) + .pipe( + map(res => this.restExtractor.convertResultListDateToHuman(res)), + catchError(res => this.restExtractor.handleError(res)) + ) + } + + unblockVideo (videoIdArgs: number | number[]) { + const videoIds = Array.isArray(videoIdArgs) ? videoIdArgs : [ videoIdArgs ] + + return observableFrom(videoIds) + .pipe( + concatMap(id => this.authHttp.delete(VideoBlockService.BASE_VIDEOS_URL + id + '/blacklist')), + toArray(), + catchError(err => this.restExtractor.handleError(err)) + ) + } + + blockVideo (videoId: number, reason: string, unfederate: boolean) { + const body = { + unfederate, + reason + } + + return this.authHttp.post(VideoBlockService.BASE_VIDEOS_URL + videoId + '/blacklist', body) + .pipe( + map(this.restExtractor.extractDataBool), + catchError(res => this.restExtractor.handleError(res)) + ) + } +} -- cgit v1.2.3 From 3487330d308166afb542cbacae0475693c0b059e Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 9 Jun 2020 16:07:10 +0200 Subject: preserve original variable names server-side --- client/src/app/shared/video-block/video-block.service.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'client/src/app/shared/video-block') diff --git a/client/src/app/shared/video-block/video-block.service.ts b/client/src/app/shared/video-block/video-block.service.ts index 67ca1d85b..31ccc84ea 100644 --- a/client/src/app/shared/video-block/video-block.service.ts +++ b/client/src/app/shared/video-block/video-block.service.ts @@ -3,7 +3,7 @@ import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' import { SortMeta } from 'primeng/api' import { from as observableFrom, Observable } from 'rxjs' -import { VideoBlocklist, VideoBlockType, ResultList } from '../../../../../shared' +import { VideoBlacklist, VideoBlacklistType, ResultList } from '../../../../../shared' import { environment } from '../../../environments/environment' import { RestExtractor, RestPagination, RestService } from '../rest' @@ -21,8 +21,8 @@ export class VideoBlockService { pagination: RestPagination sort: SortMeta search?: string - type?: VideoBlockType - }): Observable> { + type?: VideoBlacklistType + }): Observable> { const { pagination, sort, search, type } = options let params = new HttpParams() @@ -33,8 +33,8 @@ export class VideoBlockService { type: { prefix: 'type:', handler: v => { - if (v === 'manual') return VideoBlockType.MANUAL - if (v === 'auto') return VideoBlockType.AUTO_BEFORE_PUBLISHED + if (v === 'manual') return VideoBlacklistType.MANUAL + if (v === 'auto') return VideoBlacklistType.AUTO_BEFORE_PUBLISHED return undefined } @@ -44,7 +44,7 @@ export class VideoBlockService { params = this.restService.addObjectParams(params, filters) } - return this.authHttp.get>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params }) + return this.authHttp.get>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params }) .pipe( map(res => this.restExtractor.convertResultListDateToHuman(res)), catchError(res => this.restExtractor.handleError(res)) -- cgit v1.2.3 From e95bede8fe660a38c99e51560caa5dd58a8eb23e Mon Sep 17 00:00:00 2001 From: Rigel Kent Date: Tue, 9 Jun 2020 16:23:16 +0200 Subject: support type as override to search in listBlocks --- client/src/app/shared/video-block/video-block.service.ts | 1 + 1 file changed, 1 insertion(+) (limited to 'client/src/app/shared/video-block') diff --git a/client/src/app/shared/video-block/video-block.service.ts b/client/src/app/shared/video-block/video-block.service.ts index 31ccc84ea..d0673ddba 100644 --- a/client/src/app/shared/video-block/video-block.service.ts +++ b/client/src/app/shared/video-block/video-block.service.ts @@ -43,6 +43,7 @@ export class VideoBlockService { params = this.restService.addObjectParams(params, filters) } + if (type) params = params.append('type', type.toString()) return this.authHttp.get>(VideoBlockService.BASE_VIDEOS_URL + 'blacklist', { params }) .pipe( -- cgit v1.2.3