From c26ee586b20e907c99f3b6f3f33405f91fd82c13 Mon Sep 17 00:00:00 2001 From: Sinan997 Date: Tue, 1 Aug 2023 12:01:08 +0300 Subject: [PATCH] setting total count on service. (find a better way) --- .../core/src/lib/services/list.service.ts | 29 +++++++++++++------ .../lib/components/users/users.component.ts | 4 +-- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/npm/ng-packs/packages/core/src/lib/services/list.service.ts b/npm/ng-packs/packages/core/src/lib/services/list.service.ts index 00eed90933..9395f87d5a 100644 --- a/npm/ng-packs/packages/core/src/lib/services/list.service.ts +++ b/npm/ng-packs/packages/core/src/lib/services/list.service.ts @@ -52,6 +52,17 @@ export class ListService implements return this._page; } + private _totalCount = 0 + set totalCount(value: number) { + if (value === this._totalCount) return; + + this._totalCount = value; + this.get(); + } + get totalCount(): number { + return this._totalCount; + } + private _sortKey = ''; set sortKey(value: string) { this._sortKey = value; @@ -121,15 +132,15 @@ export class ListService implements } private resetPageWhenUnchanged() { - console.log('this.page',this._page); - console.log('this._maxResultCount',this._maxResultCount); - console.log('this._skipCount',this._skipCount); - const skipCount = this._page * this._maxResultCount; - console.log({skipCount}); - this._skipCount = skipCount; - console.log('this.page',this._page); - console.log('this._maxResultCount',this._maxResultCount); - console.log('this._skipCount',this._skipCount); + const skipCount = this._page * this._maxResultCount; // 10 + if(skipCount === this._totalCount){ + if(this.page > 0){ + this.page = this.page - 1; + } + }else{ + this._skipCount = skipCount; + } + } private next() { diff --git a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts index 5dcd3be238..447a2a4d92 100644 --- a/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts +++ b/npm/ng-packs/packages/identity/src/lib/components/users/users.component.ts @@ -185,8 +185,8 @@ export class UsersComponent implements OnInit { private hookToQuery() { this.list.hookToQuery(query => this.service.getList(query)).subscribe(res => { - (this.data = res) - console.log(this.data); + this.data = res; + this.list.totalCount = res.totalCount }); }