aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/rest
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
commitdf98563e2104b82b119c00a3cd83cd0dc1242d25 (patch)
treea9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/shared/rest
parent46757b477c1adb5f98060d15998a3852e18902a6 (diff)
downloadPeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.gz
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.zst
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.zip
Use typescript standard and lint all files
Diffstat (limited to 'client/src/app/shared/rest')
-rw-r--r--client/src/app/shared/rest/index.ts8
-rw-r--r--client/src/app/shared/rest/rest-data-source.ts60
-rw-r--r--client/src/app/shared/rest/rest-extractor.service.ts48
-rw-r--r--client/src/app/shared/rest/rest-pagination.ts8
-rw-r--r--client/src/app/shared/rest/rest.service.ts22
5 files changed, 73 insertions, 73 deletions
diff --git a/client/src/app/shared/rest/index.ts b/client/src/app/shared/rest/index.ts
index 3cb123c3b..e0be155cf 100644
--- a/client/src/app/shared/rest/index.ts
+++ b/client/src/app/shared/rest/index.ts
@@ -1,4 +1,4 @@
1export * from './rest-data-source'; 1export * from './rest-data-source'
2export * from './rest-extractor.service'; 2export * from './rest-extractor.service'
3export * from './rest-pagination'; 3export * from './rest-pagination'
4export * from './rest.service'; 4export * from './rest.service'
diff --git a/client/src/app/shared/rest/rest-data-source.ts b/client/src/app/shared/rest/rest-data-source.ts
index 1def38c73..2ef5d38da 100644
--- a/client/src/app/shared/rest/rest-data-source.ts
+++ b/client/src/app/shared/rest/rest-data-source.ts
@@ -1,51 +1,51 @@
1import { Http, RequestOptionsArgs, URLSearchParams, } from '@angular/http'; 1import { Http, RequestOptionsArgs, URLSearchParams, Response } from '@angular/http'
2 2
3import { ServerDataSource } from 'ng2-smart-table'; 3import { ServerDataSource } from 'ng2-smart-table'
4 4
5export class RestDataSource extends ServerDataSource { 5export class RestDataSource extends ServerDataSource {
6 constructor(http: Http, endpoint: string) { 6 constructor (http: Http, endpoint: string) {
7 const options = { 7 const options = {
8 endPoint: endpoint, 8 endPoint: endpoint,
9 sortFieldKey: 'sort', 9 sortFieldKey: 'sort',
10 dataKey: 'data' 10 dataKey: 'data'
11 }; 11 }
12 12
13 super(http, options); 13 super(http, options)
14 } 14 }
15 15
16 protected extractTotalFromResponse(res) { 16 protected extractTotalFromResponse (res: Response) {
17 const rawData = res.json(); 17 const rawData = res.json()
18 return rawData ? parseInt(rawData.total) : 0; 18 return rawData ? parseInt(rawData.total, 10) : 0
19 } 19 }
20 20
21 protected addSortRequestOptions(requestOptions: RequestOptionsArgs) { 21 protected addSortRequestOptions (requestOptions: RequestOptionsArgs) {
22 let searchParams: URLSearchParams = <URLSearchParams> requestOptions.search; 22 const searchParams = requestOptions.search as URLSearchParams
23 23
24 if (this.sortConf) { 24 if (this.sortConf) {
25 this.sortConf.forEach((fieldConf) => { 25 this.sortConf.forEach((fieldConf) => {
26 const sortPrefix = fieldConf.direction === 'desc' ? '-' : ''; 26 const sortPrefix = fieldConf.direction === 'desc' ? '-' : ''
27 27
28 searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field); 28 searchParams.set(this.conf.sortFieldKey, sortPrefix + fieldConf.field)
29 }); 29 })
30 } 30 }
31 31
32 return requestOptions; 32 return requestOptions
33 } 33 }
34 34
35 protected addPagerRequestOptions(requestOptions: RequestOptionsArgs) { 35 protected addPagerRequestOptions (requestOptions: RequestOptionsArgs) {
36 let searchParams: URLSearchParams = <URLSearchParams> requestOptions.search; 36 const searchParams = requestOptions.search as URLSearchParams
37 37
38 if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) { 38 if (this.pagingConf && this.pagingConf['page'] && this.pagingConf['perPage']) {
39 const perPage = this.pagingConf['perPage']; 39 const perPage = this.pagingConf['perPage']
40 const page = this.pagingConf['page']; 40 const page = this.pagingConf['page']
41 41
42 const start = (page - 1) * perPage; 42 const start = (page - 1) * perPage
43 const count = perPage; 43 const count = perPage
44 44
45 searchParams.set('start', start.toString()); 45 searchParams.set('start', start.toString())
46 searchParams.set('count', count.toString()); 46 searchParams.set('count', count.toString())
47 } 47 }
48 48
49 return requestOptions; 49 return requestOptions
50 } 50 }
51} 51}
diff --git a/client/src/app/shared/rest/rest-extractor.service.ts b/client/src/app/shared/rest/rest-extractor.service.ts
index fcb1598f4..f6a818ec8 100644
--- a/client/src/app/shared/rest/rest-extractor.service.ts
+++ b/client/src/app/shared/rest/rest-extractor.service.ts
@@ -1,52 +1,52 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { Response } from '@angular/http'; 2import { Response } from '@angular/http'
3import { Observable } from 'rxjs/Observable'; 3import { Observable } from 'rxjs/Observable'
4 4
5export interface ResultList { 5export interface ResultList {
6 data: any[]; 6 data: any[]
7 total: number; 7 total: number
8} 8}
9 9
10@Injectable() 10@Injectable()
11export class RestExtractor { 11export class RestExtractor {
12 12
13 constructor () { ; } 13 extractDataBool (res: Response) {
14 14 return true
15 extractDataBool(res: Response) {
16 return true;
17 } 15 }
18 16
19 extractDataList(res: Response) { 17 extractDataList (res: Response) {
20 const body = res.json(); 18 const body = res.json()
21 19
22 const ret: ResultList = { 20 const ret: ResultList = {
23 data: body.data, 21 data: body.data,
24 total: body.total 22 total: body.total
25 }; 23 }
26 24
27 return ret; 25 return ret
28 } 26 }
29 27
30 extractDataGet(res: Response) { 28 extractDataGet (res: Response) {
31 return res.json(); 29 return res.json()
32 } 30 }
33 31
34 handleError(res: Response) { 32 handleError (res: Response) {
35 let text = 'Server error: '; 33 let text = 'Server error: '
36 text += res.text(); 34 text += res.text()
37 let json = ''; 35 let json = ''
38 36
39 try { 37 try {
40 json = res.json(); 38 json = res.json()
41 } catch (err) { ; } 39 } catch (err) {
40 console.error('Cannot get JSON from response.')
41 }
42 42
43 const error = { 43 const error = {
44 json, 44 json,
45 text 45 text
46 }; 46 }
47 47
48 console.error(error); 48 console.error(error)
49 49
50 return Observable.throw(error); 50 return Observable.throw(error)
51 } 51 }
52} 52}
diff --git a/client/src/app/shared/rest/rest-pagination.ts b/client/src/app/shared/rest/rest-pagination.ts
index 0cfa4f468..766e7a9e5 100644
--- a/client/src/app/shared/rest/rest-pagination.ts
+++ b/client/src/app/shared/rest/rest-pagination.ts
@@ -1,5 +1,5 @@
1export interface RestPagination { 1export interface RestPagination {
2 currentPage: number; 2 currentPage: number
3 itemsPerPage: number; 3 itemsPerPage: number
4 totalItems: number; 4 totalItems: number
5}; 5}
diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts
index 16b47e957..43dc20b34 100644
--- a/client/src/app/shared/rest/rest.service.ts
+++ b/client/src/app/shared/rest/rest.service.ts
@@ -1,27 +1,27 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { URLSearchParams } from '@angular/http'; 2import { URLSearchParams } from '@angular/http'
3 3
4import { RestPagination } from './rest-pagination'; 4import { RestPagination } from './rest-pagination'
5 5
6@Injectable() 6@Injectable()
7export class RestService { 7export class RestService {
8 8
9 buildRestGetParams(pagination?: RestPagination, sort?: string) { 9 buildRestGetParams (pagination?: RestPagination, sort?: string) {
10 const params = new URLSearchParams(); 10 const params = new URLSearchParams()
11 11
12 if (pagination) { 12 if (pagination) {
13 const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage; 13 const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage
14 const count: number = pagination.itemsPerPage; 14 const count: number = pagination.itemsPerPage
15 15
16 params.set('start', start.toString()); 16 params.set('start', start.toString())
17 params.set('count', count.toString()); 17 params.set('count', count.toString())
18 } 18 }
19 19
20 if (sort) { 20 if (sort) {
21 params.set('sort', sort); 21 params.set('sort', sort)
22 } 22 }
23 23
24 return params; 24 return params
25 } 25 }
26 26
27} 27}