]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - client/src/app/shared/rest/rest.service.ts
Merge branch 'release/2.1.0' into develop
[github/Chocobozzz/PeerTube.git] / client / src / app / shared / rest / rest.service.ts
index f7838ba06a51e899a7cf784af2369f098da801a3..5bd2b5e43a732443517bf49867b966526fbaae64 100644 (file)
@@ -1,6 +1,7 @@
 import { Injectable } from '@angular/core'
 import { HttpParams } from '@angular/common/http'
-import { SortMeta } from 'primeng/primeng'
+import { SortMeta } from 'primeng/api'
+import { ComponentPagination, ComponentPaginationLight } from './component-pagination.model'
 
 import { RestPagination } from './rest-pagination'
 
@@ -31,4 +32,25 @@ export class RestService {
     return newParams
   }
 
+  addObjectParams (params: HttpParams, object: { [ name: string ]: any }) {
+    for (const name of Object.keys(object)) {
+      const value = object[name]
+      if (!value) continue
+
+      if (Array.isArray(value) && value.length !== 0) {
+        for (const v of value) params = params.append(name, v)
+      } else {
+        params = params.append(name, value)
+      }
+    }
+
+    return params
+  }
+
+  componentPaginationToRestPagination (componentPagination: ComponentPaginationLight): RestPagination {
+    const start: number = (componentPagination.currentPage - 1) * componentPagination.itemsPerPage
+    const count: number = componentPagination.itemsPerPage
+
+    return { start, count }
+  }
 }