[ADF-3930] fix infinite pagination (#4275)

* refactoring infinite pagination

* fix lint

* fix import reuqest pagination from core

* fix failing unit test
This commit is contained in:
Eugenio Romano
2019-02-06 14:40:38 +00:00
committed by GitHub
parent 3a9958988a
commit d6b8e85c35
20 changed files with 198 additions and 109 deletions

View File

@@ -143,7 +143,7 @@ export class ContentNodeDialogService {
actionName: action,
currentFolderId: contentEntry.parentId,
imageResolver: this.imageResolver.bind(this),
rowFilter: this.rowFilter.bind(this, contentEntry.id),
where: '(isFolder=true)',
isSelectionValid: this.isCopyMoveSelectionValid.bind(this),
excludeSiteContent: excludeSiteContent || ContentNodeDialogService.nonDocumentSiteContent,
select: select
@@ -186,7 +186,7 @@ export class ContentNodeDialogService {
currentFolderId: contentEntry.id,
imageResolver: this.imageResolver.bind(this),
isSelectionValid: this.hasPermissionOnNodeFolder.bind(this),
rowFilter: this.rowFilter.bind(this, contentEntry.id),
where: '(isFolder=true)',
select: select
};
@@ -232,16 +232,6 @@ export class ContentNodeDialogService {
return null;
}
private rowFilter(currentNodeId: string, row: ShareDataRow): boolean {
const node: Node = row.node.entry;
if (node.id === currentNodeId || node.isFile) {
return false;
} else {
return true;
}
}
private isNodeFile(entry: Node): boolean {
return entry.isFile;
}

View File

@@ -56,7 +56,7 @@
[adf-highlight]="searchTerm"
adf-highlight-selector=".adf-name-location-cell-name"
[showHeader]="false"
[node]="nodes"
[node]="nodePaging"
[maxItems]="pageSize"
[rowFilter]="_rowFilter"
[imageResolver]="imageResolver"
@@ -65,6 +65,7 @@
[contextMenuActions]="false"
[contentActions]="false"
[allowDropFiles]="false"
[where]="where"
(folderChange)="onFolderChange()"
(ready)="onFolderLoaded()"
(node-dblclick)="onNodeDoubleClick($event)"

View File

@@ -517,7 +517,7 @@ describe('ContentNodeSelectorComponent', () => {
it('should clear the search field, nodes and chosenNode when clicking on the X (clear) icon', () => {
component.chosenNode = <Node> {};
component.nodes = {
component.nodePaging = {
list: {
entries: [{ entry: component.chosenNode }]
}
@@ -528,7 +528,7 @@ describe('ContentNodeSelectorComponent', () => {
component.clear();
expect(component.searchTerm).toBe('');
expect(component.nodes).toEqual(null);
expect(component.nodePaging).toEqual(null);
expect(component.chosenNode).toBeNull();
expect(component.showingSearchResults).toBeFalsy();
});

View File

@@ -19,7 +19,7 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ViewEncapsul
import { AlfrescoApiService, HighlightDirective, UserPreferencesService, PaginationModel } from '@alfresco/adf-core';
import { FormControl } from '@angular/forms';
import { Node, NodePaging, Pagination, SiteEntry, SitePaging } from '@alfresco/js-api';
import { DocumentListComponent, PaginationStrategy } from '../document-list/components/document-list.component';
import { DocumentListComponent } from '../document-list/components/document-list.component';
import { RowFilter } from '../document-list/data/row-filter.model';
import { ImageResolver } from '../document-list/data/image-resolver.model';
import { ContentNodeSelectorService } from './content-node-selector.service';
@@ -62,6 +62,13 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
_rowFilter: RowFilter = defaultValidation;
/** Custom where filter function. See the
* [Document List component](document-list.component.md)
* for more information.
*/
@Input()
where: string;
/** Custom row filter function. See the
* [Document List component](document-list.component.md#custom-row-filter)
* for more information.
@@ -125,7 +132,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
@ViewChild(HighlightDirective)
highlighter: HighlightDirective;
nodes: NodePaging | null = null;
nodePaging: NodePaging | null = null;
siteId: null | string;
searchTerm: string = '';
showingSearchResults: boolean = false;
@@ -133,7 +140,6 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
inDialog: boolean = false;
_chosenNode: Node = null;
folderIdToShow: string | null = null;
paginationStrategy: PaginationStrategy = PaginationStrategy.Infinite;
pagination: BehaviorSubject<PaginationModel>;
skipCount: number = 0;
@@ -255,7 +261,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
*/
clearSearch() {
this.searchTerm = '';
this.nodes = null;
this.nodePaging = null;
this.skipCount = 0;
this.chosenNode = null;
this.showingSearchResults = false;
@@ -276,7 +282,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
* Load the first page of a new search result
*/
private startNewSearch(): void {
this.nodes = null;
this.nodePaging = null;
this.skipCount = 0;
this.chosenNode = null;
this.folderIdToShow = null;
@@ -313,14 +319,7 @@ export class ContentNodeSelectorPanelComponent implements OnInit {
this.showingSearchResults = true;
this.loadingSearchResults = false;
// DocumentList hack, since data displaying for preloaded nodes is a little bit messy there
if (!this.nodes) {
this.nodes = nodePaging;
} else {
this.documentList.data.loadPage(nodePaging, true);
}
this.pagination.next(nodePaging.list.pagination);
this.nodePaging = nodePaging;
}
/**

View File

@@ -25,6 +25,7 @@ export interface ContentNodeSelectorComponentData {
dropdownHideMyFiles?: boolean;
dropdownSiteList?: SitePaging;
rowFilter?: any;
where?: string;
imageResolver?: any;
isSelectionValid?: (entry: Node) => boolean;
breadcrumbTransform?: (node) => any;

View File

@@ -13,6 +13,7 @@
[isSelectionValid]="data?.isSelectionValid"
[breadcrumbTransform]="data?.breadcrumbTransform"
[excludeSiteContent]="data?.excludeSiteContent"
[where]="data?.where"
(select)="onSelect($event)">
</adf-content-node-selector-panel>
</mat-dialog-content>
@@ -30,4 +31,4 @@
(click)="onClick()"
data-automation-id="content-node-selector-actions-choose">{{ buttonActionName | translate }}
</button>
</mat-dialog-actions>
</mat-dialog-actions>