[ACA-3672] - added server order for document -list (#5899)

* [ACA-3672] - added sorting server side for document-list

* [ACA-3672] - added and fixed unit tests for backend order

* [ACA-3672] - fixed failing test

* [ACA-3672] - regenerated doc and renamed variable

Co-authored-by: Vito Albano <vitoalbano@Vitos-MacBook-Pro.local>
This commit is contained in:
Vito
2020-07-23 14:04:05 +01:00
committed by GitHub
parent a5972e753a
commit 30c5c58d40
57 changed files with 132 additions and 81 deletions

View File

@@ -121,7 +121,8 @@ describe('Breadcrumb', () => {
expect(documentListService.loadFolderByNodeId).toHaveBeenCalledWith(node.id,
documentListComponent.DEFAULT_PAGINATION,
documentListComponent.includeFields,
documentListComponent.where);
documentListComponent.where,
documentListComponent.orderBy);
});
it('should build the path based on the document list node', () => {

View File

@@ -144,7 +144,7 @@ describe('DropdownBreadcrumb', () => {
fixture.whenStable().then(() => {
clickOnTheFirstOption();
expect(documentListService.loadFolderByNodeId).toHaveBeenCalledWith('1', documentList.DEFAULT_PAGINATION, undefined, undefined);
expect(documentListService.loadFolderByNodeId).toHaveBeenCalledWith('1', documentList.DEFAULT_PAGINATION, undefined, undefined, ['name ASC']);
done();
});
});

View File

@@ -13,7 +13,7 @@
[noPermission]="noPermission"
[showHeader]="showHeader"
[rowMenuCacheEnabled]="false"
[stickyHeader]="stickyHeader"
[stickyHeader]="stickyHeader"
[allowFiltering]="allowFiltering"
(showRowContextMenu)="onShowRowContextMenu($event)"
(showRowActionsMenu)="onShowRowActionsMenu($event)"
@@ -22,6 +22,7 @@
(rowDblClick)="onNodeDblClick($event.value?.node)"
(row-select)="onNodeSelect($event.detail)"
(row-unselect)="onNodeUnselect($event.detail)"
(sorting-changed)="onSortingChanged($event)"
[class.adf-datatable-gallery-thumbnails]="data.thumbnails">
<adf-header-filter-template>

View File

@@ -1451,6 +1451,7 @@ describe('DocumentList', () => {
where: undefined,
maxItems: 25,
skipCount: 0,
orderBy: [ 'name ASC' ],
rootFolderId: 'fake-id'
}, ['test-include']);
});
@@ -1466,6 +1467,24 @@ describe('DocumentList', () => {
where: '(isFolder=true)',
maxItems: 25,
skipCount: 0,
orderBy: [ 'name ASC' ],
rootFolderId: 'fake-id'
}, ['test-include']);
});
it('should add orderBy in the server request', () => {
documentList.includeFields = ['test-include'];
documentList.orderBy = ['size DESC'];
documentList.currentFolderId = 'fake-id';
documentList.where = null;
fixture.detectChanges();
expect(documentListService.getFolder).toHaveBeenCalledWith(null, {
maxItems: 25,
skipCount: 0,
where: undefined,
orderBy: ['size DESC'],
rootFolderId: 'fake-id'
}, ['test-include']);
});
@@ -1483,6 +1502,7 @@ describe('DocumentList', () => {
expect(documentListService.getFolder).toHaveBeenCalledWith(null, {
maxItems: 25,
skipCount: 0,
orderBy: [ 'name ASC' ],
rootFolderId: 'folder-id',
where: undefined
}, undefined);

View File

@@ -191,7 +191,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
* before delivering it.
*/
@Input()
sortingMode = 'client';
sortingMode = 'server';
/** The inline style to apply to every row. See
* the Angular NgStyle
@@ -314,6 +314,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
selection = new Array<NodeEntry>();
$folderNode: Subject<Node> = new Subject<Node>();
allowFiltering: boolean = true;
orderBy: string[] = ['name ASC'];
// @deprecated 3.0.0
folderNode: Node;
@@ -639,7 +640,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.updateCustomSourceData(this._currentFolderId);
}
this.documentListService.loadFolderByNodeId(this._currentFolderId, this._pagination, this.includeFields, this.where)
this.documentListService.loadFolderByNodeId(this._currentFolderId, this._pagination, this.includeFields, this.where, this.orderBy)
.subscribe((documentNode: DocumentLoaderNode) => {
if (documentNode.currentNode) {
this.folderNode = documentNode.currentNode.entry;
@@ -665,6 +666,11 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
}
onSortingChanged(event: CustomEvent) {
this.orderBy = [''.concat(event.detail.key, ' ' , event.detail.direction)];
this.reload();
}
/**
* Creates a set of predefined columns.
*/

View File

@@ -110,6 +110,9 @@ export class DocumentListService implements DocumentListLoader {
if (opts.where) {
params.where = opts.where;
}
if (opts.orderBy) {
params.orderBy = opts.orderBy;
}
}
return from(this.apiService.getInstance().nodes.getNodeChildren(rootNodeId, params)).pipe(
@@ -169,22 +172,23 @@ export class DocumentListService implements DocumentListLoader {
* @param where Optionally filter the list
* @returns Details of the folder
*/
loadFolderByNodeId(nodeId: string, pagination: PaginationModel, includeFields: string[], where?: string): Observable<DocumentLoaderNode> {
loadFolderByNodeId(nodeId: string, pagination: PaginationModel, includeFields: string[], where?: string, orderBy?: string[]): Observable<DocumentLoaderNode> {
if (this.customResourcesService.isCustomSource(nodeId)) {
return this.customResourcesService.loadFolderByNodeId(nodeId, pagination, includeFields, where).pipe(
map((result: any) => new DocumentLoaderNode(null, result))
);
} else {
return this.retrieveDocumentNode(nodeId, pagination, includeFields, where);
return this.retrieveDocumentNode(nodeId, pagination, includeFields, where, orderBy);
}
}
private retrieveDocumentNode(nodeId: string, pagination: PaginationModel, includeFields: string[], where?: string): Observable<DocumentLoaderNode> {
private retrieveDocumentNode(nodeId: string, pagination: PaginationModel, includeFields: string[], where?: string, orderBy?: string[]): Observable<DocumentLoaderNode> {
return forkJoin(
this.getFolderNode(nodeId, includeFields),
this.getFolder(null, {
maxItems: pagination.maxItems,
skipCount: pagination.skipCount,
orderBy: orderBy,
rootFolderId: nodeId,
where: where
}, includeFields)).pipe(