]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - client/src/app/shared/rest/rest.service.ts
Implement header design
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / rest / rest.service.ts
CommitLineData
df98563e 1import { Injectable } from '@angular/core'
d592e0a9 2import { HttpParams } from '@angular/common/http'
3523b64a 3import { SortMeta } from 'primeng/components/common/sortmeta'
de59c48f 4
df98563e 5import { RestPagination } from './rest-pagination'
de59c48f
C
6
7@Injectable()
8export class RestService {
9
d592e0a9
C
10 addRestGetParams (params: HttpParams, pagination?: RestPagination, sort?: SortMeta | string) {
11 let newParams = params
de59c48f 12
d592e0a9
C
13 if (pagination !== undefined) {
14 newParams = newParams.set('start', pagination.start.toString())
15 .set('count', pagination.count.toString())
de59c48f
C
16 }
17
d592e0a9
C
18 if (sort !== undefined) {
19 let sortString = ''
20
21 if (typeof sort === 'string') {
22 sortString = sort
23 } else {
24 const sortPrefix = sort.order === 1 ? '' : '-'
25 sortString = sortPrefix + sort.field
26 }
27
28 newParams = newParams.set('sort', sortString)
de59c48f
C
29 }
30
d592e0a9 31 return newParams
de59c48f
C
32 }
33
34}