From 0f8d00e3144060270d7fe603865fccaf18649c47 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 13 Nov 2020 16:38:23 +0100 Subject: Implement video comment list in admin --- .../shared-video-comment/video-comment.model.ts | 52 +++++++++++++++++++++- .../shared-video-comment/video-comment.service.ts | 45 ++++++++++++++++++- 2 files changed, 95 insertions(+), 2 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-video-comment/video-comment.model.ts b/client/src/app/shared/shared-video-comment/video-comment.model.ts index e85443196..1589091e5 100644 --- a/client/src/app/shared/shared-video-comment/video-comment.model.ts +++ b/client/src/app/shared/shared-video-comment/video-comment.model.ts @@ -1,6 +1,6 @@ import { getAbsoluteAPIUrl } from '@app/helpers' import { Actor } from '@app/shared/shared-main' -import { Account as AccountInterface, VideoComment as VideoCommentServerModel } from '@shared/models' +import { Account as AccountInterface, VideoComment as VideoCommentServerModel, VideoCommentAdmin as VideoCommentAdminServerModel } from '@shared/models' export class VideoComment implements VideoCommentServerModel { id: number @@ -46,3 +46,53 @@ export class VideoComment implements VideoCommentServerModel { } } } + +export class VideoCommentAdmin implements VideoCommentAdminServerModel { + id: number + url: string + text: string + textHtml: string + + threadId: number + inReplyToCommentId: number + + createdAt: Date | string + updatedAt: Date | string + + account: AccountInterface + + video: { + id: number + uuid: string + name: string + } + + by: string + accountAvatarUrl: string + + constructor (hash: VideoCommentAdminServerModel, textHtml: string) { + this.id = hash.id + this.url = hash.url + this.text = hash.text + this.textHtml = textHtml + + this.threadId = hash.threadId + this.inReplyToCommentId = hash.inReplyToCommentId + + this.createdAt = new Date(hash.createdAt.toString()) + this.updatedAt = new Date(hash.updatedAt.toString()) + + this.video = { + id: hash.video.id, + uuid: hash.video.uuid, + name: hash.video.name + } + + this.account = hash.account + + if (this.account) { + this.by = Actor.CREATE_BY_STRING(this.account.name, this.account.host) + this.accountAvatarUrl = Actor.GET_ACTOR_AVATAR_URL(this.account) + } + } +} diff --git a/client/src/app/shared/shared-video-comment/video-comment.service.ts b/client/src/app/shared/shared-video-comment/video-comment.service.ts index 81c65aa38..e318e069d 100644 --- a/client/src/app/shared/shared-video-comment/video-comment.service.ts +++ b/client/src/app/shared/shared-video-comment/video-comment.service.ts @@ -2,18 +2,20 @@ import { Observable } from 'rxjs' import { catchError, map } from 'rxjs/operators' import { HttpClient, HttpParams } from '@angular/common/http' import { Injectable } from '@angular/core' -import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' +import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' import { objectLineFeedToHtml } from '@app/helpers' import { FeedFormat, ResultList, VideoComment as VideoCommentServerModel, + VideoCommentAdmin, VideoCommentCreate, VideoCommentThreadTree as VideoCommentThreadTreeServerModel } from '@shared/models' import { environment } from '../../../environments/environment' import { VideoCommentThreadTree } from './video-comment-thread-tree.model' import { VideoComment } from './video-comment.model' +import { SortMeta } from 'primeng/api' @Injectable() export class VideoCommentService { @@ -48,6 +50,27 @@ export class VideoCommentService { ) } + getAdminVideoComments (options: { + pagination: RestPagination, + sort: SortMeta, + search?: string + }): Observable> { + const { pagination, sort, search } = options + const url = VideoCommentService.BASE_VIDEO_URL + '/comments' + + let params = new HttpParams() + params = this.restService.addRestGetParams(params, pagination, sort) + + if (search) { + params = this.buildParamsFromSearch(search, params) + } + + return this.authHttp.get>(url, { params }) + .pipe( + catchError(res => this.restExtractor.handleError(res)) + ) + } + getVideoCommentThreads (parameters: { videoId: number | string, componentPagination: ComponentPaginationLight, @@ -146,4 +169,24 @@ export class VideoCommentService { return tree as VideoCommentThreadTree } + + private buildParamsFromSearch (search: string, params: HttpParams) { + const filters = this.restService.parseQueryStringFilter(search, { + state: { + prefix: 'local:', + isBoolean: true, + handler: v => { + if (v === 'true') return v + if (v === 'false') return v + + return undefined + } + }, + + searchAccount: { prefix: 'account:' }, + searchVideo: { prefix: 'video:' } + }) + + return this.restService.addObjectParams(params, filters) + } } -- cgit v1.2.3 From f1273314593a4a7dc7ec9594ce0c6c3ae8f62b34 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 16 Nov 2020 11:55:17 +0100 Subject: Add admin view to manage comments --- client/src/app/shared/shared-main/feeds/feed.component.html | 2 +- client/src/app/shared/shared-main/feeds/feed.component.scss | 2 +- .../app/shared/shared-video-comment/video-comment.model.ts | 11 +++++++++-- .../app/shared/shared-video-comment/video-comment.service.ts | 7 ++++--- 4 files changed, 15 insertions(+), 7 deletions(-) (limited to 'client/src/app/shared') diff --git a/client/src/app/shared/shared-main/feeds/feed.component.html b/client/src/app/shared/shared-main/feeds/feed.component.html index 13883fd9b..a00011785 100644 --- a/client/src/app/shared/shared-main/feeds/feed.component.html +++ b/client/src/app/shared/shared-main/feeds/feed.component.html @@ -1,4 +1,4 @@ -
+
> { const { pagination, sort, search } = options - const url = VideoCommentService.BASE_VIDEO_URL + '/comments' + const url = VideoCommentService.BASE_VIDEO_URL + 'comments' let params = new HttpParams() params = this.restService.addRestGetParams(params, pagination, sort) @@ -172,7 +173,7 @@ export class VideoCommentService { private buildParamsFromSearch (search: string, params: HttpParams) { const filters = this.restService.parseQueryStringFilter(search, { - state: { + isLocal: { prefix: 'local:', isBoolean: true, handler: v => { -- cgit v1.2.3