Skip to content

Commit

Permalink
#: Modify PaginationModel
Browse files Browse the repository at this point in the history
  • Loading branch information
zdu-strong committed Jan 18, 2025
1 parent c72bdfa commit 9538360
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 15 deletions.
33 changes: 28 additions & 5 deletions capacitor/src/model/PaginationMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,49 @@ export class PaginationModel<T> {
pageNum: number,
pageSize: number,
stream: linq.IEnumerable<T>
);

constructor(otherPaginationModel: any);

constructor(
pageNum?: number,
pageSize?: number,
stream?: linq.IEnumerable<T>
) {
makeAutoObservable(this);
if (pageNum < 1) {
if (typeof pageNum === "object" && typeof pageSize === "undefined" && typeof stream === "undefined") {
const otherPaginationModel = pageNum as any;
this.pageNum = otherPaginationModel.pageNum;
this.pageSize = otherPaginationModel.pageSize;
this.totalRecord = otherPaginationModel.totalRecord;
this.totalPage = otherPaginationModel.totalPage;
this.list = otherPaginationModel.list;
if (!(typeof this.pageNum === "number" && typeof this.pageSize === "number" && typeof this.totalRecord === "number" && typeof this.totalPage === "number" && typeof this.list === "object" && this.list instanceof Array)) {
throw new Error("Incorrect paging behavior");
}
return;
}
if (!(typeof pageNum === "number" && typeof pageSize === "number" && typeof stream === "object")) {
return;
}
if (pageNum! < 1) {
throw new Error("The page number cannot be less than 1");
}
if (pageSize < 1) {
if (pageSize! < 1) {
throw new Error("The page size cannot be less than 1");
}

if (pageNum !== Math.floor(pageNum)) {
if (pageNum !== Math.floor(pageNum!)) {
throw new Error("The page number must be an integer");
}

if (pageSize !== Math.floor(pageSize!)) {
throw new Error("The page size must be an integer");
}

const totalRecord = stream.count();
const totalRecord = (stream as linq.IEnumerable<T>).count();
const totalPage = Math.floor(mathjs.divide(totalRecord, pageSize)) + mathjs.mod(totalRecord, pageSize) > 0 ? 1 : 0;
const list = stream
const list = (stream as linq.IEnumerable<T>)
.skip(mathjs.multiply(pageNum - 1, pageSize))
.take(pageSize)
.toArray();
Expand Down
33 changes: 28 additions & 5 deletions electron/src/model/PaginationMode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,49 @@ export class PaginationModel<T> {
pageNum: number,
pageSize: number,
stream: linq.IEnumerable<T>
);

constructor(otherPaginationModel: any);

constructor(
pageNum?: number,
pageSize?: number,
stream?: linq.IEnumerable<T>
) {
makeAutoObservable(this);
if (pageNum < 1) {
if (typeof pageNum === "object" && typeof pageSize === "undefined" && typeof stream === "undefined") {
const otherPaginationModel = pageNum as any;
this.pageNum = otherPaginationModel.pageNum;
this.pageSize = otherPaginationModel.pageSize;
this.totalRecord = otherPaginationModel.totalRecord;
this.totalPage = otherPaginationModel.totalPage;
this.list = otherPaginationModel.list;
if (!(typeof this.pageNum === "number" && typeof this.pageSize === "number" && typeof this.totalRecord === "number" && typeof this.totalPage === "number" && typeof this.list === "object" && this.list instanceof Array)) {
throw new Error("Incorrect paging behavior");
}
return;
}
if (!(typeof pageNum === "number" && typeof pageSize === "number" && typeof stream === "object")) {
return;
}
if (pageNum! < 1) {
throw new Error("The page number cannot be less than 1");
}
if (pageSize < 1) {
if (pageSize! < 1) {
throw new Error("The page size cannot be less than 1");
}

if (pageNum !== Math.floor(pageNum)) {
if (pageNum !== Math.floor(pageNum!)) {
throw new Error("The page number must be an integer");
}

if (pageSize !== Math.floor(pageSize!)) {
throw new Error("The page size must be an integer");
}

const totalRecord = stream.count();
const totalRecord = (stream as linq.IEnumerable<T>).count();
const totalPage = Math.floor(mathjs.divide(totalRecord, pageSize)) + mathjs.mod(totalRecord, pageSize) > 0 ? 1 : 0;
const list = stream
const list = (stream as linq.IEnumerable<T>)
.skip(mathjs.multiply(pageNum - 1, pageSize))
.take(pageSize)
.toArray();
Expand Down
33 changes: 28 additions & 5 deletions react/src/model/PaginationModel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,49 @@ export class PaginationModel<T> {
pageNum: number,
pageSize: number,
stream: linq.IEnumerable<T>
);

constructor(otherPaginationModel: any);

constructor(
pageNum?: number,
pageSize?: number,
stream?: linq.IEnumerable<T>
) {
makeAutoObservable(this);
if (pageNum < 1) {
if (typeof pageNum === "object" && typeof pageSize === "undefined" && typeof stream === "undefined") {
const otherPaginationModel = pageNum as any;
this.pageNum = otherPaginationModel.pageNum;
this.pageSize = otherPaginationModel.pageSize;
this.totalRecord = otherPaginationModel.totalRecord;
this.totalPage = otherPaginationModel.totalPage;
this.list = otherPaginationModel.list;
if (!(typeof this.pageNum === "number" && typeof this.pageSize === "number" && typeof this.totalRecord === "number" && typeof this.totalPage === "number" && typeof this.list === "object" && this.list instanceof Array)) {
throw new Error("Incorrect paging behavior");
}
return;
}
if (!(typeof pageNum === "number" && typeof pageSize === "number" && typeof stream === "object")) {
return;
}
if (pageNum! < 1) {
throw new Error("The page number cannot be less than 1");
}
if (pageSize < 1) {
if (pageSize! < 1) {
throw new Error("The page size cannot be less than 1");
}

if (pageNum !== Math.floor(pageNum)) {
if (pageNum !== Math.floor(pageNum!)) {
throw new Error("The page number must be an integer");
}

if (pageSize !== Math.floor(pageSize!)) {
throw new Error("The page size must be an integer");
}

const totalRecord = stream.count();
const totalRecord = (stream as linq.IEnumerable<T>).count();
const totalPage = Math.floor(mathjs.divide(totalRecord, pageSize)) + mathjs.mod(totalRecord, pageSize) > 0 ? 1 : 0;
const list = stream
const list = (stream as linq.IEnumerable<T>)
.skip(mathjs.multiply(pageNum - 1, pageSize))
.take(pageSize)
.toArray();
Expand Down

0 comments on commit 9538360

Please sign in to comment.