UNPKG

@c8y/client

Version:

Client application programming interface to access the Cumulocity IoT-Platform REST services.

64 lines 2.21 kB
import { __awaiter } from "tslib"; /** * Paging allows you to query the next and previous data chunks * in a convenient way. You can also go to a specific page or just read * page information about the current data chunk. * Note that page numbers are generated by backend * and may be used as offset rather than a continuous range of positive numbers * (e.g. in case of users with restricted permissions). */ export class Paging { constructor(service, statistics, filter) { this.filter = filter; this.service = service; this.currentPage = statistics.currentPage; this.nextPage = statistics.nextPage; this.prevPage = statistics.prevPage; this.pageSize = statistics.pageSize; this.totalPages = statistics.totalPages; this.totalElements = statistics.totalElements; } /** * Gets the next page of available data from the server. * @param filter */ next() { return __awaiter(this, arguments, void 0, function* (filter = {}) { return this.list(this.getFilter(filter, this.nextPage)); }); } /** * Gets the previous page of available data from server. * @param filter */ prev() { return __awaiter(this, arguments, void 0, function* (filter = {}) { return this.list(this.getFilter(filter, this.prevPage)); }); } /** * Method used by next(), prev() and goto() to call the service.list method. * It is public so it can be overriden in special cases (like children objects * in inventory). * @param filter */ list() { return __awaiter(this, arguments, void 0, function* (filter = {}) { return this.service.list(filter); }); } /** * Goes to the page that you define as page parameter. * @param page * @param filter */ goto(page_1) { return __awaiter(this, arguments, void 0, function* (page, filter = {}) { return this.list(this.getFilter(filter, page)); }); } getFilter(filter, page) { return Object.assign(filter, this.filter, { currentPage: page }); } } //# sourceMappingURL=Paging.js.map