mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-08 02:24:11 +00:00
44239: more pagination fixes
This commit is contained in:
@@ -2,5 +2,5 @@
|
|||||||
<h2>{{'home.top-level-communities.head' | translate}}</h2>
|
<h2>{{'home.top-level-communities.head' | translate}}</h2>
|
||||||
<p class="lead">{{'home.top-level-communities.help' | translate}}</p>
|
<p class="lead">{{'home.top-level-communities.help' | translate}}</p>
|
||||||
<ds-object-list [config]="config" [sortConfig]="sortConfig"
|
<ds-object-list [config]="config" [sortConfig]="sortConfig"
|
||||||
[objects]="topLevelCommunities" [hideGear]="false"></ds-object-list>
|
[objects]="topLevelCommunities" [hideGear]="false" (paginationChange)="updatePage()"></ds-object-list>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -13,16 +13,12 @@ import { ActivatedRoute } from '@angular/router';
|
|||||||
templateUrl: './top-level-community-list.component.html',
|
templateUrl: './top-level-community-list.component.html',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush
|
changeDetection: ChangeDetectionStrategy.OnPush
|
||||||
})
|
})
|
||||||
export class TopLevelCommunityListComponent implements OnInit {
|
export class TopLevelCommunityListComponent {
|
||||||
topLevelCommunities: RemoteData<Community[]>;
|
topLevelCommunities: RemoteData<Community[]>;
|
||||||
config: PaginationComponentOptions;
|
config: PaginationComponentOptions;
|
||||||
sortConfig: SortOptions;
|
sortConfig: SortOptions;
|
||||||
private sub;
|
|
||||||
|
|
||||||
constructor(
|
constructor(private cds: CommunityDataService) {
|
||||||
private cds: CommunityDataService,
|
|
||||||
private route: ActivatedRoute
|
|
||||||
) {
|
|
||||||
this.config = new PaginationComponentOptions();
|
this.config = new PaginationComponentOptions();
|
||||||
this.config.id = 'top-level-pagination';
|
this.config.id = 'top-level-pagination';
|
||||||
this.config.pageSizeOptions = [4];
|
this.config.pageSizeOptions = [4];
|
||||||
@@ -31,19 +27,19 @@ export class TopLevelCommunityListComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
this.updatePage({
|
||||||
this.sub = this.route
|
page: 1,
|
||||||
.queryParams
|
pageSize: this.config.pageSize,
|
||||||
.subscribe((params) => {
|
sortField: this.sortConfig.field,
|
||||||
this.topLevelCommunities = this.cds.findAll({
|
direction: this.sortConfig.direction
|
||||||
currentPage: params.page,
|
});
|
||||||
elementsPerPage: params.pageSize,
|
|
||||||
sort: { field: params.sortField, direction: params.sortDirection }
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy() {
|
updatePage(data) {
|
||||||
this.sub.unsubscribe();
|
this.topLevelCommunities = this.cds.findAll({
|
||||||
|
currentPage: data.page,
|
||||||
|
elementsPerPage: data.pageSize,
|
||||||
|
sort: { field: data.sortField, direction: data.sortDirection }
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -325,27 +325,27 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
* The page size to validate
|
* The page size to validate
|
||||||
*/
|
*/
|
||||||
private validateParams(page: any, pageSize: any, sortDirection: any, sortField: any) {
|
private validateParams(page: any, pageSize: any, sortDirection: any, sortField: any) {
|
||||||
|
const originalPageInfo = {
|
||||||
|
id: this.id,
|
||||||
|
page: page,
|
||||||
|
pageSize: pageSize,
|
||||||
|
sortDirection: sortDirection,
|
||||||
|
sortField: sortField
|
||||||
|
};
|
||||||
// tslint:disable-next-line:triple-equals
|
// tslint:disable-next-line:triple-equals
|
||||||
const newPage = validatePage();
|
const filteredPageInfo = {
|
||||||
const newSize = validateSize();
|
id: this.id,
|
||||||
|
page: this.validatePage(page),
|
||||||
|
pageSize: this.validatePageSize(pageSize),
|
||||||
|
sortDirection: sortDirection,
|
||||||
|
sortField: sortField
|
||||||
|
};
|
||||||
|
|
||||||
this.currentPage = page
|
// let filteredPageSize = this.pageSizeOptions.find((x) => x === pageSize);
|
||||||
} else {
|
if (JSON.stringify(originalPageInfo) !== JSON.stringify(filteredPageInfo)) {
|
||||||
this.currentPage = this.paginationOptions.currentPage;
|
// filteredPageSize = (filteredPageSize) ? filteredPageSize : this.pageSize;
|
||||||
}
|
|
||||||
|
|
||||||
let filteredPageSize = this.pageSizeOptions.find((x) => x == pageSize);
|
|
||||||
if (!isNumeric(page) || !filteredPageSize) {
|
|
||||||
const filteredPage = isNumeric(page) ? page : this.currentPage;
|
|
||||||
filteredPageSize = (filteredPageSize) ? filteredPageSize : this.pageSize;
|
|
||||||
this.router.navigate([], {
|
this.router.navigate([], {
|
||||||
queryParams: {
|
queryParams: filteredPageInfo
|
||||||
pageId: this.id,
|
|
||||||
page: filteredPage,
|
|
||||||
pageSize: filteredPageSize,
|
|
||||||
sortDirection: sortDirection,
|
|
||||||
sortField: sortField
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
let hasChanged = false;
|
let hasChanged = false;
|
||||||
@@ -386,6 +386,23 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private validatePage(page: any): string {
|
||||||
|
let result = this.currentPage
|
||||||
|
if (isNumeric(page)) {
|
||||||
|
result = page;
|
||||||
|
}
|
||||||
|
return result + '';
|
||||||
|
}
|
||||||
|
|
||||||
|
private validatePageSize(pageSize: any): string {
|
||||||
|
const filteredPageSize = this.pageSizeOptions.find((x) => x === pageSize);
|
||||||
|
let result = this.pageSize
|
||||||
|
if (filteredPageSize) {
|
||||||
|
result = pageSize;
|
||||||
|
}
|
||||||
|
return result + '';
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ensure options passed contains the required properties.
|
* Ensure options passed contains the required properties.
|
||||||
*
|
*
|
||||||
@@ -409,4 +426,5 @@ export class PaginationComponent implements OnDestroy, OnInit {
|
|||||||
get shouldShowBottomPager(): boolean {
|
get shouldShowBottomPager(): boolean {
|
||||||
return this.hasMultiplePages || !this.hidePagerWhenSinglePage
|
return this.hasMultiplePages || !this.hidePagerWhenSinglePage
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user