76654: PaginationService

This commit is contained in:
Yana De Pauw
2021-02-05 15:47:07 +01:00
parent 11b6b3c929
commit fab226912f
49 changed files with 826 additions and 826 deletions

View File

@@ -1,5 +1,5 @@
import { Component, OnInit } from '@angular/core';
import { BehaviorSubject, combineLatest as observableCombineLatest, Observable, zip } from 'rxjs';
import { combineLatest as observableCombineLatest, Observable, zip } from 'rxjs';
import { RemoteData } from '../../../core/data/remote-data';
import { PaginatedList } from '../../../core/data/paginated-list.model';
import { PaginationComponentOptions } from '../../../shared/pagination/pagination-component-options.model';
@@ -12,6 +12,7 @@ import { NotificationsService } from '../../../shared/notifications/notification
import { Router } from '@angular/router';
import { TranslateService } from '@ngx-translate/core';
import { NoContent } from '../../../core/shared/NoContent.model';
import { PaginationService } from '../../../core/pagination/pagination.service';
/**
* This component renders a list of bitstream formats
@@ -30,7 +31,7 @@ export class BitstreamFormatsComponent implements OnInit {
/**
* A BehaviourSubject that keeps track of the pageState used to update the currently displayed bitstreamFormats
*/
pageState: BehaviorSubject<string>;
// pageState: BehaviorSubject<string>;
/**
* The current pagination configuration for the page used by the FindAll method
@@ -45,14 +46,16 @@ export class BitstreamFormatsComponent implements OnInit {
* Currently simply renders all bitstream formats
*/
pageConfig: PaginationComponentOptions = Object.assign(new PaginationComponentOptions(), {
id: 'registry-bitstreamformats-pagination',
id: 'rbp',
pageSize: 20
});
constructor(private notificationsService: NotificationsService,
private router: Router,
private translateService: TranslateService,
private bitstreamFormatService: BitstreamFormatDataService) {
private bitstreamFormatService: BitstreamFormatDataService,
private paginationService: PaginationService,
) {
}
/**
@@ -80,10 +83,8 @@ export class BitstreamFormatsComponent implements OnInit {
this.deselectAll();
this.router.navigate([], {
queryParams: Object.assign({}, { page: 1 }),
queryParamsHandling: 'merge'
}); });
this.paginationService.resetPage(this.pageConfig.id);
});
}
);
}
@@ -141,31 +142,12 @@ export class BitstreamFormatsComponent implements OnInit {
});
}
/**
* When the page is changed, make sure to update the list of bitstreams to match the new page
* @param event The page change event
*/
onPageChange(event) {
this.config = Object.assign(new FindListOptions(), this.config, {
currentPage: event,
});
this.pageConfig.currentPage = event;
this.pageState.next('pageChange');
}
ngOnInit(): void {
this.pageState = new BehaviorSubject('init');
this.bitstreamFormats = this.pageState.pipe(
switchMap(() => {
return this.updateFormats()
;
}));
}
/**
* Finds all formats based on the current config
*/
private updateFormats() {
return this.bitstreamFormatService.findAll(this.config);
this.bitstreamFormats = this.paginationService.getFindListOptions(this.pageConfig.id, this.config).pipe(
switchMap((findListOptions: FindListOptions) => {
return this.bitstreamFormatService.findAll(findListOptions);
})
);
}
}