pagination workarounds (#321)

* pagination workarounds

* update the code
This commit is contained in:
Denys Vuika
2018-04-19 08:17:23 +01:00
committed by Cilibiu Bogdan
parent cb409335b0
commit c4b03e2bb4
2 changed files with 9 additions and 8 deletions

View File

@@ -44,7 +44,6 @@ import { PageComponent } from '../page.component';
}) })
export class FilesComponent extends PageComponent implements OnInit, OnDestroy { export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
private routeData: any = {};
isValidPath = true; isValidPath = true;
private nodePath: PathElement[]; private nodePath: PathElement[];
@@ -77,7 +76,6 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
const { route, contentManagementService, contentService, nodeActionsService, uploadService } = this; const { route, contentManagementService, contentService, nodeActionsService, uploadService } = this;
const { data } = route.snapshot; const { data } = route.snapshot;
this.routeData = data;
this.title = data.i18nTitle; this.title = data.i18nTitle;
route.params.subscribe(({ folderId }: Params) => { route.params.subscribe(({ folderId }: Params) => {
@@ -128,7 +126,7 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
return this.nodesApi.getNode(nodeId); return this.nodesApi.getNode(nodeId);
} }
fetchNodes(parentNodeId?: string, options: any = {}): Observable<NodePaging> { fetchNodes(parentNodeId?: string, options: { maxItems?: number, skipCount?: number } = {}): Observable<NodePaging> {
const defaults = { const defaults = {
include: [ 'isLocked', 'path', 'properties', 'allowableOperations' ] include: [ 'isLocked', 'path', 'properties', 'allowableOperations' ]
}; };
@@ -205,15 +203,17 @@ export class FilesComponent extends PageComponent implements OnInit, OnDestroy {
} }
} }
load(showIndicator: boolean = false, pagination: any = {}) { load(showIndicator: boolean = false, options: { maxItems?: number, skipCount?: number } = {}) {
this.isLoading = showIndicator; this.isLoading = showIndicator;
this.fetchNodes(this.getParentNodeId(), pagination) this.fetchNodes(this.getParentNodeId(), options)
.flatMap((page) => { .flatMap((page) => {
if (this.isCurrentPageEmpty(page) && this.isNotFirstPage(page)) { if (this.isCurrentPageEmpty(page) && this.isNotFirstPage(page)) {
const newSkipCount = pagination.skipCount - pagination.maxItems; const newSkipCount = options.skipCount - options.maxItems;
return this.fetchNodes(this.getParentNodeId(), {skipCount: newSkipCount, maxItems: pagination.maxItems}); return this.fetchNodes(this.getParentNodeId(), {
skipCount: newSkipCount, maxItems: options.maxItems
});
} }
return Observable.of(page); return Observable.of(page);

View File

@@ -64,7 +64,8 @@ export abstract class PageComponent {
onPageLoaded(page: NodePaging) { onPageLoaded(page: NodePaging) {
this.isLoading = false; this.isLoading = false;
this.paging = page; this.paging = page;
this.pagination = page.list.pagination; // TODO: review after ADF-2768 is fixed
this.pagination = this.pagination || page.list.pagination;
this.isEmpty = !(page.list.entries && page.list.entries.length > 0); this.isEmpty = !(page.list.entries && page.list.entries.length > 0);
} }