diff options
Diffstat (limited to 'client/src/app/shared/rest/rest-data-source.ts')
-rw-r--r-- | client/src/app/shared/rest/rest-data-source.ts | 60 |
1 files changed, 30 insertions, 30 deletions
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 @@ | |||
1 | import { Http, RequestOptionsArgs, URLSearchParams, } from '@angular/http'; | 1 | import { Http, RequestOptionsArgs, URLSearchParams, Response } from '@angular/http' |
2 | 2 | ||
3 | import { ServerDataSource } from 'ng2-smart-table'; | 3 | import { ServerDataSource } from 'ng2-smart-table' |
4 | 4 | ||
5 | export class RestDataSource extends ServerDataSource { | 5 | export 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 | } |