[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

@ -9,7 +9,7 @@ addons:
before_script:
- "sudo chown root /opt/google/chrome/chrome-sandbox"
- "sudo chmod 4755 /opt/google/chrome/chrome-sandbox"
before_install:
- export CHROME_BIN=chromium-browser
- export DISPLAY=:99.0
@ -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);
@ -985,7 +989,7 @@ describe('DocumentList', () => {
documentList.noPermission = true;
fixture.detectChanges();
documentList.ngOnChanges({ node: new SimpleChange(null, {list: {entities: {}}}, true) });
documentList.ngOnChanges({ node: new SimpleChange(null, { list: { entities: {} } }, true) });
expect(documentList.data.loadPage).toHaveBeenCalled();
expect(documentList.noPermission).toBeFalsy();
@ -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,18 +575,18 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
maxItems: maxItems,
skipCount: skipCount,
rootFolderId: id
})
}, this.includeFields)
.subscribe(
val => {
this.data.loadPage(<NodePaging> val, merge);
this.loading = false;
this.infiniteLoading = false;
this.onDataReady(val);
resolve(true);
},
error => {
reject(error);
});
val => {
this.data.loadPage(<NodePaging> val, merge);
this.loading = false;
this.infiniteLoading = false;
this.onDataReady(val);
resolve(true);
},
error => {
reject(error);
});
});
}
@ -640,13 +649,13 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.apiService.sitesApi.getSites(options)
.then((page: NodePaging) => {
page.list.entries.map(
({entry}: any) => {
({ entry }: any) => {
entry.name = entry.name || entry.title;
return {entry};
return { entry };
}
);
this.onPageLoaded(page, merge);
})
})
.catch(error => this.error.emit(error));
}
@ -664,7 +673,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
let page: NodePaging = {
list: {
entries: result.list.entries
.map(({entry: {site}}: any) => {
.map(({ entry: { site } }: any) => {
site.allowableOperations = site.allowableOperations ? site.allowableOperations : [this.CREATE_PERMISSION];
site.name = site.name || site.title;
return {
@ -976,8 +985,8 @@ 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)
.then(node => [ node.id ]);
return this.documentListService.getFolderNode(nodeId, this.includeFields)
.then(node => [node.id]);
}
return new Promise((resolve) => {

View File

@ -28,6 +28,7 @@ declare let jasmine: any;
describe('DocumentListService', () => {
let service: DocumentListService;
let alfrescoApiService: AlfrescoApiService;
let fakeEntryNode = {
'entry': {
@ -35,9 +36,9 @@ describe('DocumentListService', () => {
'createdAt': '2016-12-06T15:58:32.408+0000',
'isFolder': true,
'isFile': false,
'createdByUser': {'id': 'admin', 'displayName': 'Administrator'},
'createdByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'modifiedAt': '2016-12-06T15:58:32.408+0000',
'modifiedByUser': {'id': 'admin', 'displayName': 'Administrator'},
'modifiedByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'name': 'fake-name',
'id': '2214733d-a920-4dbe-af95-4230345fae82',
'nodeType': 'cm:folder',
@ -58,7 +59,7 @@ describe('DocumentListService', () => {
let fakeFolder = {
'list': {
'pagination': {'count': 1, 'hasMoreItems': false, 'totalItems': 1, 'skipCount': 0, 'maxItems': 20},
'pagination': { 'count': 1, 'hasMoreItems': false, 'totalItems': 1, 'skipCount': 0, 'maxItems': 20 },
'entries': [{
'entry': {
'createdAt': '2016-12-06T13:03:14.880+0000',
@ -68,19 +69,19 @@ describe('DocumentListService', () => {
'elements': [{
'id': 'ed7ab80e-b398-4bed-b38d-139ae4cc592a',
'name': 'Company Home'
}, {'id': '99e1368f-e816-47fc-a8bf-3b358feaf31e', 'name': 'Sites'}, {
}, { 'id': '99e1368f-e816-47fc-a8bf-3b358feaf31e', 'name': 'Sites' }, {
'id': 'b4cff62a-664d-4d45-9302-98723eac1319',
'name': 'swsdp'
}, {
'id': '8f2105b4-daaf-4874-9e8a-2152569d109b',
'name': 'documentLibrary'
}, {'id': '17fa78d2-4d6b-4a46-876b-4b0ea07f7f32', 'name': 'empty'}]
}, { 'id': '17fa78d2-4d6b-4a46-876b-4b0ea07f7f32', 'name': 'empty' }]
},
'isFolder': true,
'isFile': false,
'createdByUser': {'id': 'admin', 'displayName': 'Administrator'},
'createdByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'modifiedAt': '2016-12-06T13:03:14.880+0000',
'modifiedByUser': {'id': 'admin', 'displayName': 'Administrator'},
'modifiedByUser': { 'id': 'admin', 'displayName': 'Administrator' },
'name': 'fake-name',
'id': 'aac546f6-1525-46ff-bf6b-51cb85f3cda7',
'nodeType': 'cm:folder',
@ -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;