mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-17 23:13:04 +00:00
44024: collection page pagination fix
This commit is contained in:
@@ -32,13 +32,10 @@
|
|||||||
</ds-comcol-page-content>
|
</ds-comcol-page-content>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
<br>
|
||||||
<div *ngIf="itemData.hasSucceeded | async">
|
<div *ngIf="(itemData.hasSucceeded | async)">
|
||||||
<h2>{{'collection.page.browse.recent.head' | translate}}</h2>
|
<h2>{{'collection.page.browse.recent.head' | translate}}</h2>
|
||||||
<ds-object-list [config]="config" [sortConfig]="sortConfig"
|
<ds-object-list [config]="paginationConfig" [sortConfig]="sortConfig"
|
||||||
[objects]="itemData" [hideGear]="false"
|
[objects]="itemData" [hideGear]="false"
|
||||||
(pageChange)="onPageChange($event)"
|
(paginationChange)="updatePage($event)"></ds-object-list>
|
||||||
(pageSizeChange)="onPageSizeChange($event)"
|
|
||||||
(sortDirectionChange)="onSortDirectionChange($event)"
|
|
||||||
(sortFieldChange)="onSortDirectionChange($event)"></ds-object-list>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -14,75 +14,81 @@ import { ItemDataService } from '../core/data/item-data.service';
|
|||||||
import { Item } from '../core/shared/item.model';
|
import { Item } from '../core/shared/item.model';
|
||||||
import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model';
|
import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model';
|
||||||
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
|
||||||
import { hasValue, isUndefined } from '../shared/empty.util';
|
import { hasValue, isNotEmpty, isUndefined } from '../shared/empty.util';
|
||||||
import { PageInfo } from '../core/shared/page-info.model';
|
import { PageInfo } from '../core/shared/page-info.model';
|
||||||
|
import { Observable } from 'rxjs/Observable';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'ds-collection-page',
|
selector: 'ds-collection-page',
|
||||||
styleUrls: ['./collection-page.component.scss'],
|
styleUrls: ['./collection-page.component.scss'],
|
||||||
templateUrl: './collection-page.component.html',
|
templateUrl: './collection-page.component.html',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush
|
|
||||||
})
|
})
|
||||||
export class CollectionPageComponent implements OnInit, OnDestroy {
|
export class CollectionPageComponent implements OnInit, OnDestroy {
|
||||||
collectionData: RemoteData<Collection>;
|
collectionData: RemoteData<Collection>;
|
||||||
itemData: RemoteData<Item[]>;
|
itemData: RemoteData<Item[]>;
|
||||||
logoData: RemoteData<Bitstream>;
|
logoData: RemoteData<Bitstream>;
|
||||||
config: PaginationComponentOptions;
|
paginationConfig: PaginationComponentOptions;
|
||||||
sortConfig: SortOptions;
|
sortConfig: SortOptions;
|
||||||
private subs: Subscription[] = [];
|
private subs: Subscription[] = [];
|
||||||
private collectionId: string;
|
private collectionId: string;
|
||||||
private pageInfoState: PageInfo;
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
private collectionDataService: CollectionDataService,
|
|
||||||
private itemDataService: ItemDataService,
|
|
||||||
private ref: ChangeDetectorRef,
|
|
||||||
private route: ActivatedRoute
|
|
||||||
) {
|
|
||||||
|
|
||||||
|
constructor(private collectionDataService: CollectionDataService,
|
||||||
|
private itemDataService: ItemDataService,
|
||||||
|
private route: ActivatedRoute) {
|
||||||
|
this.paginationConfig = new PaginationComponentOptions();
|
||||||
|
this.paginationConfig.id = 'collection-page-pagination';
|
||||||
|
this.paginationConfig.pageSizeOptions = [4];
|
||||||
|
this.paginationConfig.pageSize = 4;
|
||||||
|
this.paginationConfig.currentPage = 1;
|
||||||
|
this.sortConfig = new SortOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.subs.push(this.route.params.map((params: Params) => params.id)
|
this.subs.push(
|
||||||
.subscribe((id: string) => {
|
Observable.combineLatest(
|
||||||
this.collectionId = id;
|
this.route.params,
|
||||||
this.collectionData = this.collectionDataService.findById(this.collectionId);
|
this.route.queryParams,
|
||||||
this.subs.push(this.collectionData.payload.subscribe((collection) => this.logoData = collection.logo));
|
(params, queryParams,) => {
|
||||||
|
return Object.assign({}, params, queryParams);
|
||||||
|
})
|
||||||
|
.subscribe((params) => {
|
||||||
|
this.collectionId = params.id;
|
||||||
|
this.collectionData = this.collectionDataService.findById(this.collectionId);
|
||||||
|
this.subs.push(this.collectionData.payload.subscribe((collection) => this.logoData = collection.logo));
|
||||||
|
|
||||||
this.config = new PaginationComponentOptions();
|
const page = +params.page || this.paginationConfig.currentPage;
|
||||||
this.config.id = 'collection-browse';
|
const pageSize = +params.pageSize || this.paginationConfig.pageSize;
|
||||||
this.config.pageSizeOptions = [4];
|
const sortDirection = +params.page || this.sortConfig.direction;
|
||||||
this.config.pageSize = 4;
|
const pagination = Object.assign({},
|
||||||
this.sortConfig = new SortOptions();
|
this.paginationConfig,
|
||||||
|
{ currentPage: page, pageSize: pageSize }
|
||||||
|
);
|
||||||
|
const sort = Object.assign({},
|
||||||
|
this.sortConfig,
|
||||||
|
{ direction: sortDirection, field: params.sortField }
|
||||||
|
);
|
||||||
|
this.updatePage({
|
||||||
|
pagination: pagination,
|
||||||
|
sort: sort
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
this.updateResults();
|
}
|
||||||
}));
|
|
||||||
|
|
||||||
|
updatePage(searchOptions) {
|
||||||
|
this.itemData = this.itemDataService.findAll({
|
||||||
|
scopeID: this.collectionId,
|
||||||
|
currentPage: searchOptions.pagination.currentPage,
|
||||||
|
elementsPerPage: searchOptions.pagination.pageSize,
|
||||||
|
sort: searchOptions.sort
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
|
this.subs.filter((sub) => hasValue(sub)).forEach((sub) => sub.unsubscribe());
|
||||||
}
|
}
|
||||||
|
|
||||||
onPaginationChange(field: string): void {
|
isNotEmpty(object: any) {
|
||||||
this.sortConfig = new SortOptions(field, this.sortConfig.direction);
|
return isNotEmpty(object);
|
||||||
this.updateResults();
|
|
||||||
}
|
|
||||||
|
|
||||||
updateResults() {
|
|
||||||
this.itemData = null;
|
|
||||||
this.ref.markForCheck();
|
|
||||||
this.itemData = this.itemDataService.findAll({
|
|
||||||
scopeID: this.collectionId,
|
|
||||||
currentPage: this.config.currentPage,
|
|
||||||
elementsPerPage: this.config.pageSize,
|
|
||||||
sort: this.sortConfig
|
|
||||||
});
|
|
||||||
this.subs.push(this.itemData.pageInfo.subscribe((pageInfo) => {
|
|
||||||
if (isUndefined(this.pageInfoState) || this.pageInfoState !== pageInfo) {
|
|
||||||
this.pageInfoState = pageInfo;
|
|
||||||
this.ref.detectChanges();
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -11,8 +11,8 @@ import { ActivatedRoute } from '@angular/router';
|
|||||||
selector: 'ds-top-level-community-list',
|
selector: 'ds-top-level-community-list',
|
||||||
styleUrls: ['./top-level-community-list.component.scss'],
|
styleUrls: ['./top-level-community-list.component.scss'],
|
||||||
templateUrl: './top-level-community-list.component.html',
|
templateUrl: './top-level-community-list.component.html',
|
||||||
changeDetection: ChangeDetectionStrategy.OnPush
|
|
||||||
})
|
})
|
||||||
|
|
||||||
export class TopLevelCommunityListComponent {
|
export class TopLevelCommunityListComponent {
|
||||||
topLevelCommunities: RemoteData<Community[]>;
|
topLevelCommunities: RemoteData<Community[]>;
|
||||||
config: PaginationComponentOptions;
|
config: PaginationComponentOptions;
|
||||||
@@ -23,10 +23,11 @@ export class TopLevelCommunityListComponent {
|
|||||||
this.config.id = 'top-level-pagination';
|
this.config.id = 'top-level-pagination';
|
||||||
this.config.pageSizeOptions = [4];
|
this.config.pageSizeOptions = [4];
|
||||||
this.config.pageSize = 4;
|
this.config.pageSize = 4;
|
||||||
|
this.config.currentPage = 1;
|
||||||
this.sortConfig = new SortOptions();
|
this.sortConfig = new SortOptions();
|
||||||
|
|
||||||
this.updatePage({
|
this.updatePage({
|
||||||
page: 1,
|
page: this.config.currentPage,
|
||||||
pageSize: this.config.pageSize,
|
pageSize: this.config.pageSize,
|
||||||
sortField: this.sortConfig.field,
|
sortField: this.sortConfig.field,
|
||||||
direction: this.sortConfig.direction
|
direction: this.sortConfig.direction
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { Component, Input, OnInit } from '@angular/core';
|
import { Component, Input, OnDestroy, OnInit } from '@angular/core';
|
||||||
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
import { DSpaceObject } from '../../core/shared/dspace-object.model';
|
||||||
import { Router } from '@angular/router';
|
import { Router } from '@angular/router';
|
||||||
import { isNotEmpty, hasValue, isEmpty } from '../empty.util';
|
import { isNotEmpty, hasValue, isEmpty } from '../empty.util';
|
||||||
@@ -15,13 +15,14 @@ import { Observable } from 'rxjs/Observable';
|
|||||||
styleUrls: ['./search-form.component.scss'],
|
styleUrls: ['./search-form.component.scss'],
|
||||||
templateUrl: './search-form.component.html',
|
templateUrl: './search-form.component.html',
|
||||||
})
|
})
|
||||||
export class SearchFormComponent implements OnInit {
|
export class SearchFormComponent implements OnInit, OnDestroy {
|
||||||
@Input() query: string;
|
@Input() query: string;
|
||||||
selectedId = '';
|
selectedId = '';
|
||||||
// Optional existing search parameters
|
// Optional existing search parameters
|
||||||
@Input() currentParams: {};
|
@Input() currentParams: {};
|
||||||
@Input() scopes: Observable<DSpaceObject[]>;
|
@Input() scopes: Observable<DSpaceObject[]>;
|
||||||
scopeOptions: string[] = [];
|
scopeOptions: string[] = [];
|
||||||
|
sub;
|
||||||
|
|
||||||
@Input()
|
@Input()
|
||||||
set scope(dso: DSpaceObject) {
|
set scope(dso: DSpaceObject) {
|
||||||
@@ -32,6 +33,7 @@ export class SearchFormComponent implements OnInit {
|
|||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
if (this.scopes) {
|
if (this.scopes) {
|
||||||
|
this.sub =
|
||||||
this.scopes
|
this.scopes
|
||||||
.filter((scopes: DSpaceObject[]) => isEmpty(scopes))
|
.filter((scopes: DSpaceObject[]) => isEmpty(scopes))
|
||||||
.subscribe((scopes: DSpaceObject[]) => {
|
.subscribe((scopes: DSpaceObject[]) => {
|
||||||
@@ -50,7 +52,6 @@ export class SearchFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateSearch(data: any) {
|
updateSearch(data: any) {
|
||||||
|
|
||||||
this.router.navigate(['/search'], {
|
this.router.navigate(['/search'], {
|
||||||
queryParams: Object.assign({}, this.currentParams,
|
queryParams: Object.assign({}, this.currentParams,
|
||||||
{
|
{
|
||||||
@@ -73,4 +74,10 @@ export class SearchFormComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
return id1 === id2;
|
return id1 === id2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnDestroy(): void {
|
||||||
|
if (this.sub) {
|
||||||
|
this.sub.unsubscribe();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user