From e33f64d19920eb900e5d45726af7fdeaa3f93b1f Mon Sep 17 00:00:00 2001 From: crusader Date: Fri, 25 May 2018 11:52:02 +0900 Subject: [PATCH] ing --- src/model/commons/Page.ts | 87 ++++++++++++++++++++++++++++++++++----- 1 file changed, 77 insertions(+), 10 deletions(-) diff --git a/src/model/commons/Page.ts b/src/model/commons/Page.ts index 5f97fa8..1ac8bed 100644 --- a/src/model/commons/Page.ts +++ b/src/model/commons/Page.ts @@ -1,11 +1,78 @@ -export interface Page { - content: any; - first: boolean; - last: boolean; - number: number; - numberOfElements: number; - size: number; - sort: any; - totalElements: number; - totalPages: number; +// export interface Page { +// content: any; +// first: boolean; +// last: boolean; +// number: number; +// numberOfElements: number; +// size: number; +// sort: any; +// totalElements: number; +// totalPages: number; +// } + +export class Pageable { + page: number; + size: number; + + public getPageSize(): number { + return this.size; + } + + public getPageNumber(): number { + return this.page; + } + + public getOffset(): number { + return this.page * this.size; + } } + +export class Page { + content: T[]; + pageable: Pageable; + total: number; + + public getNumber(): number { + return this.pageable == null ? 0 : this.pageable.getPageNumber(); + } + + public getSize(): number { + return this.pageable == null ? 0 : this.pageable.getPageSize(); + } + + public getTotalPages(): number { + return this.getSize() == 0 ? 0 : Math.ceil(this.total / this.getSize()); + } + + public getNumberOfElements(): number { + return this.content.length; + } + + public getTotalElements(): number { + return this.total; + } + + public hasPreviousPage(): boolean { + return this.getNumber() > 0; + } + + public isFirstPage(): boolean { + return !this.hasPreviousPage(); + } + + public hasNextPage(): boolean { + return ((this.getNumber() + 1) * this.getSize()) < this.total; + } + + public isLastPage(): boolean { + return !this.hasNextPage(); + } + + public getContent(): T[] { + return this.content; + } + + public hasContent(): boolean { + return null !== this.content && 0 < this.content.length; + } +} \ No newline at end of file