From 11ac88de40215783835cf6e6259ff0f6cee258dd Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 23 Jan 2017 22:16:48 +0100 Subject: Client: add basic support to report video abuses --- .../src/app/shared/forms/form-validators/index.ts | 2 +- .../shared/forms/form-validators/video-abuse.ts | 10 +++++ .../shared/forms/form-validators/video-report.ts | 10 ----- client/src/app/shared/index.ts | 1 + client/src/app/shared/shared.module.ts | 4 +- client/src/app/shared/video-abuse/index.ts | 2 + .../app/shared/video-abuse/video-abuse.model.ts | 8 ++++ .../app/shared/video-abuse/video-abuse.service.ts | 44 ++++++++++++++++++++++ 8 files changed, 69 insertions(+), 12 deletions(-) create mode 100644 client/src/app/shared/forms/form-validators/video-abuse.ts delete mode 100644 client/src/app/shared/forms/form-validators/video-report.ts create mode 100644 client/src/app/shared/video-abuse/index.ts create mode 100644 client/src/app/shared/video-abuse/video-abuse.model.ts create mode 100644 client/src/app/shared/video-abuse/video-abuse.service.ts (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/forms/form-validators/index.ts b/client/src/app/shared/forms/form-validators/index.ts index 119b5d9bf..ab7c2df31 100644 --- a/client/src/app/shared/forms/form-validators/index.ts +++ b/client/src/app/shared/forms/form-validators/index.ts @@ -1,4 +1,4 @@ export * from './host.validator'; export * from './user'; -export * from './video-report'; +export * from './video-abuse'; export * from './video'; diff --git a/client/src/app/shared/forms/form-validators/video-abuse.ts b/client/src/app/shared/forms/form-validators/video-abuse.ts new file mode 100644 index 000000000..94a29a3b7 --- /dev/null +++ b/client/src/app/shared/forms/form-validators/video-abuse.ts @@ -0,0 +1,10 @@ +import { Validators } from '@angular/forms'; + +export const VIDEO_ABUSE_REASON = { + VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], + MESSAGES: { + 'required': 'Report reason name is required.', + 'minlength': 'Report reson must be at least 2 characters long.', + 'maxlength': 'Report reson cannot be more than 300 characters long.' + } +}; diff --git a/client/src/app/shared/forms/form-validators/video-report.ts b/client/src/app/shared/forms/form-validators/video-report.ts deleted file mode 100644 index 036ee1721..000000000 --- a/client/src/app/shared/forms/form-validators/video-report.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { Validators } from '@angular/forms'; - -export const VIDEO_REPORT_REASON = { - VALIDATORS: [ Validators.required, Validators.minLength(2), Validators.maxLength(300) ], - MESSAGES: { - 'required': 'Report reason name is required.', - 'minlength': 'Report reson must be at least 2 characters long.', - 'maxlength': 'Report reson cannot be more than 300 characters long.' - } -}; diff --git a/client/src/app/shared/index.ts b/client/src/app/shared/index.ts index 52a647b83..7876e6f14 100644 --- a/client/src/app/shared/index.ts +++ b/client/src/app/shared/index.ts @@ -3,4 +3,5 @@ export * from './forms'; export * from './rest'; export * from './search'; export * from './users'; +export * from './video-abuse'; export * from './shared.module'; diff --git a/client/src/app/shared/shared.module.ts b/client/src/app/shared/shared.module.ts index 748c5d520..7b2386d6c 100644 --- a/client/src/app/shared/shared.module.ts +++ b/client/src/app/shared/shared.module.ts @@ -14,6 +14,7 @@ import { FileUploadModule } from 'ng2-file-upload/ng2-file-upload'; import { AUTH_HTTP_PROVIDERS } from './auth'; import { RestExtractor, RestService } from './rest'; import { SearchComponent, SearchService } from './search'; +import { VideoAbuseService } from './video-abuse'; @NgModule({ imports: [ @@ -57,7 +58,8 @@ import { SearchComponent, SearchService } from './search'; AUTH_HTTP_PROVIDERS, RestExtractor, RestService, - SearchService + SearchService, + VideoAbuseService ] }) export class SharedModule { } diff --git a/client/src/app/shared/video-abuse/index.ts b/client/src/app/shared/video-abuse/index.ts new file mode 100644 index 000000000..563533ba5 --- /dev/null +++ b/client/src/app/shared/video-abuse/index.ts @@ -0,0 +1,2 @@ +export * from './video-abuse.service'; +export * from './video-abuse.model'; diff --git a/client/src/app/shared/video-abuse/video-abuse.model.ts b/client/src/app/shared/video-abuse/video-abuse.model.ts new file mode 100644 index 000000000..bb0373027 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse.model.ts @@ -0,0 +1,8 @@ +export interface VideoAbuse { + id: string; + reason: string; + reporterPodHost: string; + reporterUsername: string; + videoId: string; + createdAt: Date; +} diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts new file mode 100644 index 000000000..2750a41c7 --- /dev/null +++ b/client/src/app/shared/video-abuse/video-abuse.service.ts @@ -0,0 +1,44 @@ +import { Injectable } from '@angular/core'; +import { Http } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import 'rxjs/add/operator/catch'; +import 'rxjs/add/operator/map'; + +import { AuthService } from '../core'; +import { AuthHttp } from '../auth'; +import { RestExtractor, ResultList } from '../rest'; +import { VideoAbuse } from './video-abuse.model'; + +@Injectable() +export class VideoAbuseService { + private static BASE_VIDEO_ABUSE_URL = '/api/v1/videos/'; + + constructor( + private authHttp: AuthHttp, + private restExtractor: RestExtractor + ) {} + + getVideoAbuses() { + return this.authHttp.get(VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') + .map(this.restExtractor.extractDataList) + .map(this.extractVideoAbuses) + } + + reportVideo(id: string, reason: string) { + const body = { + reason + }; + const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'; + + return this.authHttp.post(url, body) + .map(this.restExtractor.extractDataBool) + .catch((res) => this.restExtractor.handleError(res)); + } + + private extractVideoAbuses(result: ResultList) { + const videoAbuses: VideoAbuse[] = result.data; + const totalVideoAbuses = result.total; + + return { videoAbuses, totalVideoAbuses }; + } +} -- cgit v1.2.3