From d592e0a9b2931c7c9cbedb27fb8efc9aaacad9bb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 14 Sep 2017 11:57:49 +0200 Subject: Move to HttpClient and PrimeNG data table --- client/src/app/shared/rest/rest.service.ts | 31 ++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'client/src/app/shared/rest/rest.service.ts') diff --git a/client/src/app/shared/rest/rest.service.ts b/client/src/app/shared/rest/rest.service.ts index 43dc20b34..f7838ba06 100644 --- a/client/src/app/shared/rest/rest.service.ts +++ b/client/src/app/shared/rest/rest.service.ts @@ -1,27 +1,34 @@ import { Injectable } from '@angular/core' -import { URLSearchParams } from '@angular/http' +import { HttpParams } from '@angular/common/http' +import { SortMeta } from 'primeng/primeng' import { RestPagination } from './rest-pagination' @Injectable() export class RestService { - buildRestGetParams (pagination?: RestPagination, sort?: string) { - const params = new URLSearchParams() + addRestGetParams (params: HttpParams, pagination?: RestPagination, sort?: SortMeta | string) { + let newParams = params - if (pagination) { - const start: number = (pagination.currentPage - 1) * pagination.itemsPerPage - const count: number = pagination.itemsPerPage - - params.set('start', start.toString()) - params.set('count', count.toString()) + if (pagination !== undefined) { + newParams = newParams.set('start', pagination.start.toString()) + .set('count', pagination.count.toString()) } - if (sort) { - params.set('sort', sort) + if (sort !== undefined) { + let sortString = '' + + if (typeof sort === 'string') { + sortString = sort + } else { + const sortPrefix = sort.order === 1 ? '' : '-' + sortString = sortPrefix + sort.field + } + + newParams = newParams.set('sort', sortString) } - return params + return newParams } } -- cgit v1.2.3