diff options
Diffstat (limited to 'client/src/app/shared/shared-video-comment/video-comment.service.ts')
-rw-r--r-- | client/src/app/shared/shared-video-comment/video-comment.service.ts | 45 |
1 files changed, 44 insertions, 1 deletions
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' | |||
2 | import { catchError, map } from 'rxjs/operators' | 2 | import { catchError, map } from 'rxjs/operators' |
3 | import { HttpClient, HttpParams } from '@angular/common/http' | 3 | import { HttpClient, HttpParams } from '@angular/common/http' |
4 | import { Injectable } from '@angular/core' | 4 | import { Injectable } from '@angular/core' |
5 | import { ComponentPaginationLight, RestExtractor, RestService } from '@app/core' | 5 | import { ComponentPaginationLight, RestExtractor, RestPagination, RestService } from '@app/core' |
6 | import { objectLineFeedToHtml } from '@app/helpers' | 6 | import { objectLineFeedToHtml } from '@app/helpers' |
7 | import { | 7 | import { |
8 | FeedFormat, | 8 | FeedFormat, |
9 | ResultList, | 9 | ResultList, |
10 | VideoComment as VideoCommentServerModel, | 10 | VideoComment as VideoCommentServerModel, |
11 | VideoCommentAdmin, | ||
11 | VideoCommentCreate, | 12 | VideoCommentCreate, |
12 | VideoCommentThreadTree as VideoCommentThreadTreeServerModel | 13 | VideoCommentThreadTree as VideoCommentThreadTreeServerModel |
13 | } from '@shared/models' | 14 | } from '@shared/models' |
14 | import { environment } from '../../../environments/environment' | 15 | import { environment } from '../../../environments/environment' |
15 | import { VideoCommentThreadTree } from './video-comment-thread-tree.model' | 16 | import { VideoCommentThreadTree } from './video-comment-thread-tree.model' |
16 | import { VideoComment } from './video-comment.model' | 17 | import { VideoComment } from './video-comment.model' |
18 | import { SortMeta } from 'primeng/api' | ||
17 | 19 | ||
18 | @Injectable() | 20 | @Injectable() |
19 | export class VideoCommentService { | 21 | export class VideoCommentService { |
@@ -48,6 +50,27 @@ export class VideoCommentService { | |||
48 | ) | 50 | ) |
49 | } | 51 | } |
50 | 52 | ||
53 | getAdminVideoComments (options: { | ||
54 | pagination: RestPagination, | ||
55 | sort: SortMeta, | ||
56 | search?: string | ||
57 | }): Observable<ResultList<VideoCommentAdmin>> { | ||
58 | const { pagination, sort, search } = options | ||
59 | const url = VideoCommentService.BASE_VIDEO_URL + '/comments' | ||
60 | |||
61 | let params = new HttpParams() | ||
62 | params = this.restService.addRestGetParams(params, pagination, sort) | ||
63 | |||
64 | if (search) { | ||
65 | params = this.buildParamsFromSearch(search, params) | ||
66 | } | ||
67 | |||
68 | return this.authHttp.get<ResultList<VideoCommentAdmin>>(url, { params }) | ||
69 | .pipe( | ||
70 | catchError(res => this.restExtractor.handleError(res)) | ||
71 | ) | ||
72 | } | ||
73 | |||
51 | getVideoCommentThreads (parameters: { | 74 | getVideoCommentThreads (parameters: { |
52 | videoId: number | string, | 75 | videoId: number | string, |
53 | componentPagination: ComponentPaginationLight, | 76 | componentPagination: ComponentPaginationLight, |
@@ -146,4 +169,24 @@ export class VideoCommentService { | |||
146 | 169 | ||
147 | return tree as VideoCommentThreadTree | 170 | return tree as VideoCommentThreadTree |
148 | } | 171 | } |
172 | |||
173 | private buildParamsFromSearch (search: string, params: HttpParams) { | ||
174 | const filters = this.restService.parseQueryStringFilter(search, { | ||
175 | state: { | ||
176 | prefix: 'local:', | ||
177 | isBoolean: true, | ||
178 | handler: v => { | ||
179 | if (v === 'true') return v | ||
180 | if (v === 'false') return v | ||
181 | |||
182 | return undefined | ||
183 | } | ||
184 | }, | ||
185 | |||
186 | searchAccount: { prefix: 'account:' }, | ||
187 | searchVideo: { prefix: 'video:' } | ||
188 | }) | ||
189 | |||
190 | return this.restService.addObjectParams(params, filters) | ||
191 | } | ||
149 | } | 192 | } |