[ADF-3912] Improved folder retrieving for DL (#4423)

* [ADF-3912] added abstract class for document-list component to be provided

* [ADF-3912] - created abstract class for document-list service

* [ADF-3912] - fixing and removing the custom resource from document-list

* [ADF-3912] added interface for document list service

* [ADF-3912] added interface for loadFolderById for DL component

* [ADF-3912] fixed missing return type

* [ADF-3912] removed comment

* [ADF-3912] fixed PR comments

* [ADF-3912] fixed wrong import

* [ADF-3912] fixed unit test failing

* [ADF-3912] removed unused method

* [ADF-3912] fixed lint problems
This commit is contained in:
Vito
2019-03-27 13:10:59 +00:00
committed by Eugenio Romano
parent 3b1c4923b2
commit a2823eeb99
14 changed files with 256 additions and 166 deletions

View File

@@ -866,9 +866,9 @@ describe('DocumentList', () => {
it('should display folder content from loadFolderByNodeId on reload if currentFolderId defined', () => {
documentList.currentFolderId = 'id-folder';
spyOn(documentList, 'loadFolderByNodeId').and.stub();
spyOn(documentList, 'loadFolder').and.stub();
documentList.reload();
expect(documentList.loadFolderByNodeId).toHaveBeenCalled();
expect(documentList.loadFolder).toHaveBeenCalled();
});
it('should require node to resolve context menu actions', () => {
@@ -1050,8 +1050,8 @@ describe('DocumentList', () => {
disposableError.unsubscribe();
done();
});
documentList.loadFolderByNodeId('123');
documentList.currentFolderId = '123';
documentList.loadFolder();
});
it('should emit folderChange event when a folder node is clicked', (done) => {
@@ -1075,7 +1075,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('123');
documentList.currentFolderId = '123';
documentList.loadFolder();
});
it('should reset noPermission upon reload', () => {
@@ -1135,7 +1136,8 @@ describe('DocumentList', () => {
it('should fetch trashcan', () => {
spyOn(apiService.nodesApi, 'getDeletedNodes').and.returnValue(Promise.resolve(null));
documentList.loadFolderByNodeId('-trashcan-');
documentList.currentFolderId = '-trashcan-';
documentList.loadFolder();
expect(apiService.nodesApi.getDeletedNodes).toHaveBeenCalled();
});
@@ -1148,14 +1150,16 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-trashcan-');
documentList.currentFolderId = '-trashcan-';
documentList.loadFolder();
});
it('should fetch shared links', () => {
const sharedlinksApi = apiService.getInstance().core.sharedlinksApi;
spyOn(sharedlinksApi, 'findSharedLinks').and.returnValue(Promise.resolve(null));
documentList.loadFolderByNodeId('-sharedlinks-');
documentList.currentFolderId = '-sharedlinks-';
documentList.loadFolder();
expect(sharedlinksApi.findSharedLinks).toHaveBeenCalled();
});
@@ -1169,13 +1173,15 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-sharedlinks-');
documentList.currentFolderId = '-sharedlinks-';
documentList.loadFolder();
});
it('should fetch sites', () => {
const sitesApi = apiService.getInstance().core.sitesApi;
documentList.loadFolderByNodeId('-sites-');
documentList.currentFolderId = '-sites-';
documentList.loadFolder();
expect(sitesApi.getSites).toHaveBeenCalled();
});
@@ -1188,7 +1194,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-sites-');
documentList.currentFolderId = '-sites-';
documentList.loadFolder();
});
it('should assure that sites have name property set', (done) => {
@@ -1201,7 +1208,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-sites-');
documentList.currentFolderId = '-sites-';
documentList.loadFolder();
});
it('should assure that sites have name property set correctly', (done) => {
@@ -1214,14 +1222,16 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-sites-');
documentList.currentFolderId = '-sites-';
documentList.loadFolder();
});
it('should fetch user membership sites', () => {
const peopleApi = apiService.getInstance().core.peopleApi;
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
documentList.loadFolderByNodeId('-mysites-');
documentList.currentFolderId = '-mysites-';
documentList.loadFolder();
expect(peopleApi.listSiteMembershipsForPerson).toHaveBeenCalled();
});
@@ -1235,7 +1245,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-mysites-');
documentList.currentFolderId = '-mysites-';
documentList.loadFolder();
});
it('should assure that user membership sites have name property set', (done) => {
@@ -1243,7 +1254,8 @@ describe('DocumentList', () => {
const peopleApi = apiService.getInstance().core.peopleApi;
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
documentList.loadFolderByNodeId('-mysites-');
documentList.currentFolderId = '-mysites-';
documentList.loadFolder();
expect(peopleApi.listSiteMembershipsForPerson).toHaveBeenCalled();
const disposableReady = documentList.ready.subscribe((page) => {
@@ -1259,7 +1271,8 @@ describe('DocumentList', () => {
const peopleApi = apiService.getInstance().core.peopleApi;
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
documentList.loadFolderByNodeId('-mysites-');
documentList.currentFolderId = '-mysites-';
documentList.loadFolder();
expect(peopleApi.listSiteMembershipsForPerson).toHaveBeenCalled();
const disposableReady = documentList.ready.subscribe((page) => {
@@ -1274,7 +1287,8 @@ describe('DocumentList', () => {
const favoritesApi = apiService.getInstance().core.favoritesApi;
spyFavorite.and.returnValue(Promise.resolve(null));
documentList.loadFolderByNodeId('-favorites-');
documentList.currentFolderId = '-favorites-';
documentList.loadFolder();
expect(favoritesApi.getFavorites).toHaveBeenCalled();
});
@@ -1287,7 +1301,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-favorites-');
documentList.currentFolderId = '-favorites-';
documentList.loadFolder();
});
it('should fetch recent', () => {
@@ -1295,7 +1310,8 @@ describe('DocumentList', () => {
const getPersonSpy = spyOn(apiService.peopleApi, 'getPerson').and.returnValue(Promise.resolve(person));
documentList.loadFolderByNodeId('-recent-');
documentList.currentFolderId = '-recent-';
documentList.loadFolder();
expect(getPersonSpy).toHaveBeenCalledWith('-me-');
});
@@ -1309,7 +1325,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-recent-');
documentList.currentFolderId = '-recent-';
documentList.loadFolder();
});
it('should emit error when fetch recent fails on search call', (done) => {
@@ -1321,7 +1338,8 @@ describe('DocumentList', () => {
done();
});
documentList.loadFolderByNodeId('-recent-');
documentList.currentFolderId = '-recent-';
documentList.loadFolder();
});
it('should have correct currentFolderId on loading folder by node id', () => {
@@ -1330,7 +1348,8 @@ describe('DocumentList', () => {
const peopleApi = apiService.getInstance().core.peopleApi;
spyOn(peopleApi, 'listSiteMembershipsForPerson').and.returnValue(Promise.resolve(fakeGetSiteMembership));
documentList.loadFolderByNodeId('-mysites-');
documentList.currentFolderId = '-mysites-';
documentList.loadFolder();
expect(documentList.currentFolderId).toBe('-mysites-');
});

View File

@@ -53,12 +53,11 @@ import { ShareDataTableAdapter } from './../data/share-datatable-adapter';
import { presetsDefaultModel } from '../models/preset.model';
import { ContentActionModel } from './../models/content-action.model';
import { PermissionStyleModel } from './../models/permissions-style.model';
import { DocumentListService } from './../services/document-list.service';
import { NodeEntityEvent, NodeEntryEvent } from './node.event';
import { CustomResourcesService } from './../services/custom-resources.service';
import { NavigableComponentInterface } from '../../breadcrumb/navigable-component.interface';
import { RowFilter } from '../data/row-filter.model';
import { Observable } from 'rxjs/index';
import { DocumentListService } from '../services/document-list.service';
import { DocumentLoaderNode } from '../models/document-folder.model';
@Component({
selector: 'adf-document-list',
@@ -323,7 +322,6 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
private elementRef: ElementRef,
private appConfig: AppConfigService,
private userPreferencesService: UserPreferencesService,
private customResourcesService: CustomResourcesService,
private contentService: ContentService,
private thumbnailService: ThumbnailService,
private alfrescoApiService: AlfrescoApiService,
@@ -378,7 +376,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
ngOnInit() {
this.rowMenuCache = {};
this.loadLayoutPresets();
this.data = new ShareDataTableAdapter(this.documentListService, this.thumbnailService, this.contentService, null, this.getDefaultSorting(), this.sortingMode);
this.data = new ShareDataTableAdapter(this.thumbnailService, this.contentService, null, this.getDefaultSorting(), this.sortingMode);
this.data.thumbnails = this.thumbnails;
this.data.permissionsStyle = this.permissionsStyle;
@@ -416,7 +414,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
}
if (!this.data) {
this.data = new ShareDataTableAdapter(this.documentListService, this.thumbnailService, this.contentService, schema, this.getDefaultSorting(), this.sortingMode);
this.data = new ShareDataTableAdapter(this.thumbnailService, this.contentService, schema, this.getDefaultSorting(), this.sortingMode);
} else if (schema && schema.length > 0) {
this.data.setColumns(schema);
}
@@ -627,45 +625,20 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte
this.setupDefaultColumns(this._currentFolderId);
}
this.loadFolderByNodeId(this._currentFolderId);
}
loadFolderByNodeId(nodeId: string) {
if (this.customResourcesService.isCustomSource(nodeId)) {
this.updateCustomSourceData(nodeId);
this.customResourcesService.loadFolderByNodeId(nodeId, this._pagination, this.includeFields)
.subscribe((nodePaging: NodePaging) => {
this.onPageLoaded(nodePaging);
}, (err) => {
this.error.emit(err);
});
} else {
this.documentListService.getFolder(null, {
maxItems: this._pagination.maxItems,
skipCount: this._pagination.skipCount,
rootFolderId: nodeId,
where: this.where
}, this.includeFields)
.subscribe((nodePaging: NodePaging) => {
this.getSourceNodeWithPath(nodeId).subscribe((nodeEntry: NodeEntry) => {
this.onPageLoaded(nodePaging);
});
}, (err) => {
this.handleError(err);
});
if (this.documentListService.isCustomSourceService(this._currentFolderId)) {
this.updateCustomSourceData(this._currentFolderId);
}
}
getSourceNodeWithPath(nodeId: string): Observable<NodeEntry> {
const getSourceObservable = this.documentListService.getFolderNode(nodeId, this.includeFields);
getSourceObservable.subscribe((nodeEntry: NodeEntry) => {
this.folderNode = nodeEntry.entry;
this.$folderNode.next(this.folderNode);
});
return getSourceObservable;
this.documentListService.loadFolderByNodeId(this._currentFolderId, this._pagination, this.includeFields, this.where)
.subscribe((documentNode: DocumentLoaderNode) => {
if (documentNode.currentNode) {
this.folderNode = documentNode.currentNode.entry;
this.$folderNode.next(documentNode.currentNode.entry);
}
this.onPageLoaded(documentNode.children);
}, (err) => {
this.handleError(err);
});
}
resetSelection() {