[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

@@ -16,26 +16,28 @@
*/
import {
AlfrescoApiService, AuthenticationService, ContentService, LogService, ThumbnailService
AlfrescoApiService, ContentService, LogService, PaginationModel
} from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { NodeEntry, NodePaging } from '@alfresco/js-api';
import { Observable, from, throwError } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { DocumentLoaderNode } from '../models/document-folder.model';
import { Observable, from, throwError, forkJoin } from 'rxjs';
import { catchError, map } from 'rxjs/operators';
import { DocumentListLoader } from '../interfaces/document-list-loader.interface';
import { CustomResourcesService } from './custom-resources.service';
@Injectable({
providedIn: 'root'
})
export class DocumentListService {
export class DocumentListService implements DocumentListLoader {
static ROOT_ID = '-root-';
constructor(authService: AuthenticationService,
private contentService: ContentService,
constructor(private contentService: ContentService,
private apiService: AlfrescoApiService,
private logService: LogService,
private thumbnailService: ThumbnailService) {
private customResourcesService: CustomResourcesService) {
}
/**
@@ -155,30 +157,31 @@ export class DocumentListService {
);
}
/**
* Get thumbnail URL for the given document node.
* @param node Node to get URL for.
* @returns Thumbnail URL string
*/
getDocumentThumbnailUrl(node: NodeEntry): string {
return this.thumbnailService.getDocumentThumbnailUrl(node);
isCustomSourceService(nodeId): boolean {
return this.customResourcesService.isCustomSource(nodeId);
}
/**
* Gets the icon that represents a MIME type.
* @param mimeType MIME type to get the icon for
* @returns Path to the icon file
*/
getMimeTypeIcon(mimeType: string): string {
return this.thumbnailService.getMimeTypeIcon(mimeType);
loadFolderByNodeId(nodeId: string, pagination: PaginationModel, includeFields: string[], where?: string): Observable<DocumentLoaderNode> {
if (this.customResourcesService.isCustomSource(nodeId)) {
return this.customResourcesService.loadFolderByNodeId(nodeId, pagination, includeFields).pipe(
map((result: any) => new DocumentLoaderNode(null, result))
);
} else {
return this.retrieveDocumentNode(nodeId, pagination, includeFields, where);
}
}
/**
* Gets a default icon for MIME types with no specific icon.
* @returns Path to the icon file
*/
getDefaultMimeTypeIcon(): string {
return this.thumbnailService.getDefaultMimeTypeIcon();
private retrieveDocumentNode(nodeId: string, pagination: PaginationModel, includeFields: string[], where?: string): Observable<DocumentLoaderNode> {
return forkJoin(
this.getFolderNode(nodeId, includeFields),
this.getFolder(null, {
maxItems: pagination.maxItems,
skipCount: pagination.skipCount,
rootFolderId: nodeId,
where: where
}, includeFields)).pipe(
map((results) => new DocumentLoaderNode(results[0], results[1]))
);
}
private handleError(error: any) {