[ADF-2306] DocumentList should let configure the includeFields request to the se… (#3109)

* DocumentList should let configure the includeFields request to the server

* fix test

* fix test after rebase

* fix permissions

* travis_wait dist
This commit is contained in:
Eugenio Romano 2018-03-22 09:27:12 +00:00 committed by GitHub
parent 99e694ef98
commit e8e2af7d6b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 136 additions and 41 deletions

View File

@ -68,7 +68,7 @@ jobs:
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
script: ./scripts/test-dist.sh
script: travis_wait 30 ./scripts/test-dist.sh
- stage: Check 2.0.0 Project Update
script: ./scripts/test-e2e-bc.sh
- stage: Check ADF exports

View File

@ -70,6 +70,7 @@
},
"COLUMNS": {
"DISPLAY_NAME": "Display name",
"IS_LOCKED": "Lock",
"TAG": "Tag",
"CREATED_BY": "Created by",
"CREATED_ON": "Created on",

View File

@ -189,6 +189,7 @@
[multiselect]="multiselect"
[display]="displayMode"
[node]="nodeResult"
[includeFields]="includeFields"
(error)="onNavigationError($event)"
(success)="resetError()"
(ready)="emitReadyEvent($event)"
@ -240,6 +241,15 @@
</ng-template>
</data-column>
-->
<data-column
class="desktop-only"
title="{{'DOCUMENT_LIST.COLUMNS.IS_LOCKED' | translate}}"
key="isLocked">
<ng-template let-entry="$implicit">
<mat-icon *ngIf="entry.data.getValue(entry.row, entry.col)">lock</mat-icon>
<mat-icon *ngIf="!entry.data.getValue(entry.row, entry.col)">lock_open</mat-icon>
</ng-template>
</data-column>
<data-column
title="{{'DOCUMENT_LIST.COLUMNS.CREATED_BY' | translate}}"
key="createdByUser.displayName"

View File

@ -58,6 +58,7 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy {
showViewer = false;
showVersions = false;
displayMode = DisplayMode.List;
includeFields = ['isLocked'];
baseShareUrl = this.appConfig.get<string>('ecmHost') + '/preview/s/';

View File

@ -82,6 +82,7 @@ Displays the documents from a repository.
| maxItems | `number` | | Default value is stored into user preference settings |
| skipCount | `number` | `0` | Number of elements to skip over for pagination purposes |
| enableInfiniteScrolling | `boolean` | `false` | Set document list to work in infinite scrolling mode |
| includeFields | `string[]` | `[]` | Include additional information about the node in the server request.for example: association, isLink, isLocked and others. |
### Events

View File

@ -124,7 +124,8 @@ describe('DocumentList', () => {
it('should call action\'s handler with node', () => {
let node = new FileNode();
let action = new ContentActionModel();
action.handler = () => { };
action.handler = () => {
};
spyOn(action, 'handler').and.stub();
@ -136,7 +137,8 @@ describe('DocumentList', () => {
it('should call action\'s handler with node and permission', () => {
let node = new FileNode();
let action = new ContentActionModel();
action.handler = () => { };
action.handler = () => {
};
action.permission = 'fake-permission';
spyOn(action, 'handler').and.stub();
@ -148,7 +150,8 @@ describe('DocumentList', () => {
it('should call action\'s execute with node if it is defined', () => {
let node = new FileNode();
let action = new ContentActionModel();
action.execute = () => { };
action.execute = () => {
};
spyOn(action, 'execute').and.stub();
documentList.executeContentAction(node, action);
@ -161,7 +164,8 @@ describe('DocumentList', () => {
let node = new FileNode();
let action = new ContentActionModel();
action.handler = () => deleteObservable;
action.execute = () => { };
action.execute = () => {
};
spyOn(action, 'execute').and.stub();
documentList.executeContentAction(node, action);
@ -1395,4 +1399,18 @@ describe('DocumentList', () => {
documentList.loadFolderByNodeId('-favorites-');
expect(documentList.skipCount).toBe(0, 'skipCount is reset');
});
it('should add includeFields in the server request when present', () => {
documentList.currentFolderId = 'fake-id';
documentList.includeFields = ['test-include'];
spyOn(documentListService, 'getFolder');
documentList.ngOnChanges({ rowFilter: new SimpleChange(null, <RowFilter> {}, true) });
expect(documentListService.getFolder).toHaveBeenCalledWith(null, {
maxItems: 25,
skipCount: 0,
rootFolderId: 'fake-id'
}, ['test-include']);
});
});

View File

@ -27,7 +27,12 @@ import {
PaginationQueryParams,
PermissionsEnum
} from '@alfresco/adf-core';
import { AlfrescoApiService, AppConfigService, DataColumnListComponent, UserPreferencesService } from '@alfresco/adf-core';
import {
AlfrescoApiService,
AppConfigService,
DataColumnListComponent,
UserPreferencesService
} from '@alfresco/adf-core';
import {
AfterContentInit, Component, ContentChild, ElementRef, EventEmitter, HostListener, Input, NgZone,
OnChanges, OnDestroy, OnInit, Output, SimpleChanges, TemplateRef, ViewChild, ViewEncapsulation
@ -73,6 +78,10 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
@ContentChild(DataColumnListComponent) columnList: DataColumnListComponent;
/** Include additional information about the node in the server request.for example: association, isLink, isLocked and others. */
@Input()
includeFields: string[];
/** Change the display mode of the table. Can be "list" or "gallery". */
@Input()
display: string = DisplayMode.List;
@ -539,7 +548,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.loadRecent(merge);
} else {
this.documentListService
.getFolderNode(nodeId)
.getFolderNode(nodeId, this.includeFields)
.then(node => {
this.folderNode = node;
this.currentFolderId = node.id;
@ -566,7 +575,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
maxItems: maxItems,
skipCount: skipCount,
rootFolderId: id
})
}, this.includeFields)
.subscribe(
val => {
this.data.loadPage(<NodePaging> val, merge);
@ -976,7 +985,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
.then(result => result.list.entries.map(node => node.entry.id));
} else if (nodeId) {
return this.documentListService.getFolderNode(nodeId)
return this.documentListService.getFolderNode(nodeId, this.includeFields)
.then(node => [node.id]);
}

View File

@ -28,6 +28,7 @@ declare let jasmine: any;
describe('DocumentListService', () => {
let service: DocumentListService;
let alfrescoApiService: AlfrescoApiService;
let fakeEntryNode = {
'entry': {
@ -92,7 +93,7 @@ describe('DocumentListService', () => {
beforeEach(() => {
let contentService = new ContentService(null, null, null, null);
let alfrescoApiService = new AlfrescoApiService(new AppConfigService(null), new StorageService());
alfrescoApiService = new AlfrescoApiService(new AppConfigService(null), new StorageService());
service = new DocumentListService(null, contentService, alfrescoApiService, null, null);
jasmine.Ajax.install();
});
@ -157,6 +158,53 @@ describe('DocumentListService', () => {
});
});
it('should add the includeTypes in the request Node Children if required', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeChildren');
service.getFolder('/fake-root/fake-name', {}, ['isLocked']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('-root-', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions', 'isLocked'],
relativePath: '/fake-root/fake-name'
});
});
it('should not add the includeTypes in the request Node Children if is duplicated', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeChildren');
service.getFolder('/fake-root/fake-name', {}, ['allowableOperations']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('-root-', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions'],
relativePath: '/fake-root/fake-name'
});
});
it('should add the includeTypes in the request getFolderNode if required', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeInfo');
service.getFolderNode('test-id', ['isLocked']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('test-id', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions', 'isLocked']
});
});
it('should not add the includeTypes in the request getFolderNode if is duplicated', () => {
let spyGetNodeInfo = spyOn(alfrescoApiService.getInstance().nodes, 'getNodeInfo');
service.getFolderNode('test-id', ['allowableOperations']);
expect(spyGetNodeInfo).toHaveBeenCalledWith('test-id', {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions']
}
);
});
it('should delete the folder', () => {
service.deleteNode('fake-id').subscribe(
res => {
@ -189,4 +237,4 @@ describe('DocumentListService', () => {
jasmine.Ajax.requests.mostRecent().respondWith({ status: 200, contentType: 'json' });
});
});
})

View File

@ -41,16 +41,19 @@ export class DocumentListService {
private thumbnailService: ThumbnailService) {
}
private getNodesPromise(folder: string, opts?: any): Promise<NodePaging> {
private getNodesPromise(folder: string, opts?: any, includeFields: string[] = []): Promise<NodePaging> {
let rootNodeId = DocumentListService.ROOT_ID;
if (opts && opts.rootFolderId) {
rootNodeId = opts.rootFolderId;
}
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
let params: any = {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions']
include: includeFieldsRequest
};
if (folder) {
@ -114,8 +117,8 @@ export class DocumentListService {
* @param folder Path to folder.
* @param opts Options.
*/
getFolder(folder: string, opts?: any): Observable<NodePaging> {
return Observable.fromPromise(this.getNodesPromise(folder, opts))
getFolder(folder: string, opts?: any, includeFields: string[] = []): Observable<NodePaging> {
return Observable.fromPromise(this.getNodesPromise(folder, opts, includeFields))
.map(res => <NodePaging> res)
.catch(err => this.handleError(err));
}
@ -124,10 +127,14 @@ export class DocumentListService {
* Gets a folder node via its node ID.
* @param nodeId ID of the folder node
*/
getFolderNode(nodeId: string): Promise<MinimalNodeEntryEntity> {
getFolderNode(nodeId: string, includeFields: string[] = []): Promise<MinimalNodeEntryEntity> {
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
let opts: any = {
includeSource: true,
include: ['path', 'properties', 'allowableOperations', 'permissions']
include: includeFieldsRequest
};
let nodes: any = this.apiService.getInstance().nodes;