aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/video-abuse
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-09-14 11:57:49 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-09-14 11:57:49 +0200
commitd592e0a9b2931c7c9cbedb27fb8efc9aaacad9bb (patch)
tree549b14b842de296efed846a11b3681efe08cfa9e /client/src/app/shared/video-abuse
parent91f6f169b1110eeae6ebf5c387f4204b0d07703c (diff)
downloadPeerTube-d592e0a9b2931c7c9cbedb27fb8efc9aaacad9bb.tar.gz
PeerTube-d592e0a9b2931c7c9cbedb27fb8efc9aaacad9bb.tar.zst
PeerTube-d592e0a9b2931c7c9cbedb27fb8efc9aaacad9bb.zip
Move to HttpClient and PrimeNG data table
Diffstat (limited to 'client/src/app/shared/video-abuse')
-rw-r--r--client/src/app/shared/video-abuse/video-abuse.service.ts41
1 files changed, 26 insertions, 15 deletions
diff --git a/client/src/app/shared/video-abuse/video-abuse.service.ts b/client/src/app/shared/video-abuse/video-abuse.service.ts
index 636a02084..984581114 100644
--- a/client/src/app/shared/video-abuse/video-abuse.service.ts
+++ b/client/src/app/shared/video-abuse/video-abuse.service.ts
@@ -1,42 +1,53 @@
1import { Injectable } from '@angular/core' 1import { Injectable } from '@angular/core'
2import { Http } from '@angular/http' 2import { HttpClient, HttpParams } from '@angular/common/http'
3import { Observable } from 'rxjs/Observable'
4import 'rxjs/add/operator/catch' 3import 'rxjs/add/operator/catch'
5import 'rxjs/add/operator/map' 4import 'rxjs/add/operator/map'
5import { Observable } from 'rxjs/Observable'
6
7import { SortMeta } from 'primeng/primeng'
6 8
7import { AuthService } from '../core' 9import { AuthService } from '../core'
8import { AuthHttp } from '../auth' 10import { RestExtractor, RestPagination, RestService } from '../rest'
9import { RestDataSource, RestExtractor, ResultList } from '../rest' 11import { Utils } from '../utils'
10import { VideoAbuse } from '../../../../../shared' 12import { ResultList, VideoAbuse } from '../../../../../shared'
11 13
12@Injectable() 14@Injectable()
13export class VideoAbuseService { 15export class VideoAbuseService {
14 private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/' 16 private static BASE_VIDEO_ABUSE_URL = API_URL + '/api/v1/videos/'
15 17
16 constructor ( 18 constructor (
17 private authHttp: AuthHttp, 19 private authHttp: HttpClient,
20 private restService: RestService,
18 private restExtractor: RestExtractor 21 private restExtractor: RestExtractor
19 ) {} 22 ) {}
20 23
21 getDataSource () { 24 getVideoAbuses (pagination: RestPagination, sort: SortMeta): Observable<ResultList<VideoAbuse>> {
22 return new RestDataSource(this.authHttp, VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse') 25 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + 'abuse'
26
27 let params = new HttpParams()
28 params = this.restService.addRestGetParams(params, pagination, sort)
29
30 return this.authHttp.get<ResultList<VideoAbuse>>(url, { params })
31 .map(res => this.restExtractor.convertResultListDateToHuman(res))
32 .map(res => this.restExtractor.applyToResultListData(res, this.formatVideoAbuse.bind(this)))
33 .catch(res => this.restExtractor.handleError(res))
23 } 34 }
24 35
25 reportVideo (id: number, reason: string) { 36 reportVideo (id: number, reason: string) {
37 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
26 const body = { 38 const body = {
27 reason 39 reason
28 } 40 }
29 const url = VideoAbuseService.BASE_VIDEO_ABUSE_URL + id + '/abuse'
30 41
31 return this.authHttp.post(url, body) 42 return this.authHttp.post(url, body)
32 .map(this.restExtractor.extractDataBool) 43 .map(this.restExtractor.extractDataBool)
33 .catch((res) => this.restExtractor.handleError(res)) 44 .catch(res => this.restExtractor.handleError(res))
34 } 45 }
35 46
36 private extractVideoAbuses (result: ResultList) { 47 private formatVideoAbuse (videoAbuse: VideoAbuse) {
37 const videoAbuses: VideoAbuse[] = result.data 48 return Object.assign(videoAbuse, {
38 const totalVideoAbuses = result.total 49 createdAt: Utils.dateToHuman(videoAbuse.createdAt)
39 50 })
40 return { videoAbuses, totalVideoAbuses }
41 } 51 }
52
42} 53}