Pagination updates

This commit is contained in:
Adina Țeudan 2024-03-18 17:22:45 +02:00
parent 292573f3b3
commit d67798bd60
5 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import { EntitiesService } from './entities.service';
import { Observable } from 'rxjs';
import { map, tap } from 'rxjs/operators';
import { mapEach } from '../../utils';
import { PaginationSettings } from '../../pagination';
interface PaginatedResponse<Interface> {
data: Interface[];
@ -48,6 +49,13 @@ export abstract class PaginatedEntitiesService<
return this._currentConfig;
}
get paginationSettings(): PaginationSettings {
return {
currentPage: this.config.page || 0,
totalPages: Math.ceil(this._currentConfig.totalHits / this._currentConfig.pageSize),
};
}
updateSearchQueryAndReload(value: string): Observable<Class[]> {
return this.loadPage(0, this._currentConfig.pageSize, { [this._searchKey]: value } as SearchOptions);
}

View File

@ -0,0 +1,2 @@
export * from './pagination-settings';
export * from './pagination.component';

View File

@ -0,0 +1,4 @@
export interface PaginationSettings {
currentPage: number;
totalPages: number;
}

View File

@ -20,7 +20,7 @@
<div
id="pagination-next-page-btn"
(click)="selectPage(currentPage + 1)"
[class.disabled]="currentPage === totalPages - 1"
[class.disabled]="currentPage >= totalPages - 1"
class="page"
translate="pagination.next"
></div>

View File

@ -1,6 +1,7 @@
import { ChangeDetectionStrategy, Component, EventEmitter, Input, Output } from '@angular/core';
import { NgForOf } from '@angular/common';
import { TranslateModule } from '@ngx-translate/core';
import { PaginationSettings } from './pagination-settings';
@Component({
selector: 'iqser-pagination',
@ -27,7 +28,7 @@ export class PaginationComponent {
}
@Input()
set settings(value: { currentPage: number; totalPages: number }) {
set settings(value: PaginationSettings) {
this._currentPage = value.currentPage;
this._totalPages = value.totalPages;
this._updatePagesArray();