Fix pagination issues

This commit is contained in:
Giuseppe Digilio
2017-07-28 20:19:54 +02:00
parent 713d00f96d
commit aa6afea6e2
7 changed files with 142 additions and 62 deletions

View File

@@ -1,6 +1,6 @@
import {
ChangeDetectionStrategy, ChangeDetectorRef, Component, OnDestroy,
OnInit
ChangeDetectionStrategy, ChangeDetectorRef, Component, DoCheck, OnChanges, OnDestroy,
OnInit, SimpleChanges
} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
@@ -16,6 +16,8 @@ import { Item } from '../core/shared/item.model';
import { SortOptions, SortDirection } from '../core/cache/models/sort-options.model';
import { PaginationComponentOptions } from '../shared/pagination/pagination-component-options.model';
import { hasValue } from '../shared/empty.util';
import { PageInfo } from '../core/shared/page-info.model';
import { isUndefined } from 'util';
@Component({
selector: 'ds-collection-page',
@@ -23,7 +25,7 @@ import { hasValue } from '../shared/empty.util';
templateUrl: './collection-page.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class CollectionPageComponent implements OnInit, OnDestroy {
export class CollectionPageComponent implements OnChanges, OnInit, OnDestroy {
collectionData: RemoteData<Collection>;
itemData: RemoteData<Item[]>;
logoData: RemoteData<Bitstream>;
@@ -31,6 +33,7 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
sortConfig: SortOptions;
private subs: Subscription[] = [];
private collectionId: string;
private pageInfoState: PageInfo;
constructor(
private collectionDataService: CollectionDataService,
@@ -41,6 +44,10 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
}
ngOnChanges(changes: SimpleChanges) {
console.log(changes);
}
ngOnInit(): void {
this.subs.push(this.route.params.map((params: Params) => params.id)
.subscribe((id: string) => {
@@ -84,13 +91,20 @@ export class CollectionPageComponent implements OnInit, OnDestroy {
}
updateResults() {
this.itemData = undefined;
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.ref.detectChanges();
this.itemData.pageInfo.subscribe((pageInfo) => {
if (isUndefined(this.pageInfoState) || this.pageInfoState !== pageInfo) {
this.pageInfoState = pageInfo;
this.ref.detectChanges();
}
});
}
}