Eugenio Romano 07c247ca11 [ADF-2500] fix trashcan bug plus refactoring documentlist (#3136)
* [ADF-2500] The full content of Trashcan is not displayed.

fix pagination problem and add tests

* refactor code

* custom resources services

* move custom resources in separate service part 2

* move custom resources in separate service part 3

* move isCustomResources in custom resources

* move getCorrispondinNodeIds in custom services

* reorganize code

* add pagination interface

* remove permissions check document list and use the common cs method
remove the merge option and move it in the paginator

* make infinte scrolling always use the target

* restore loading infinite page

* fix license header

* fix type problems

* breadcrumb test service

* fix test

* export CustomResourcesService

* fix test pagination

* fix content ndoe test

* remove timeout content node selector test

* fix after rebase

* ripristinate observalbe in search service

* fix wrong type return stub document list test

* fix search service

* fix test document list

* move handle error in common method

* restore observable in search control

* Update search-control.component.spec.ts

* fix after rebase

* add import switchmap

* core import in karma conf

* missing commas

* fix mocks

* fix mock searchquerybody

* search test fix
2018-04-09 10:31:43 +01:00

192 lines
6.8 KiB
TypeScript

/*!
* @license
* Copyright 2016 Alfresco Software, Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import {
AlfrescoApiService, AuthenticationService, ContentService, LogService,
PermissionsEnum, ThumbnailService
} from '@alfresco/adf-core';
import { Injectable } from '@angular/core';
import { Response } from '@angular/http';
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from 'alfresco-js-api';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/throw';
@Injectable()
export class DocumentListService {
static ROOT_ID = '-root-';
constructor(authService: AuthenticationService,
private contentService: ContentService,
private apiService: AlfrescoApiService,
private logService: LogService,
private thumbnailService: ThumbnailService) {
}
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: includeFieldsRequest
};
if (folder) {
params.relativePath = folder;
}
if (opts) {
if (opts.maxItems) {
params.maxItems = opts.maxItems;
}
if (opts.skipCount) {
params.skipCount = opts.skipCount;
}
}
return this.apiService.getInstance().nodes.getNodeChildren(rootNodeId, params);
}
/**
* Deletes a node.
* @param nodeId ID of the node to delete
* @returns Empty response when the operation is complete
*/
deleteNode(nodeId: string): Observable<any> {
return Observable.fromPromise(this.apiService.getInstance().nodes.deleteNode(nodeId));
}
/**
* Copy a node to destination node
*
* @param nodeId The id of the node to be copied
* @param targetParentId The id of the folder where the node will be copied
* @returns NodeEntry for the copied node
*/
copyNode(nodeId: string, targetParentId: string) {
return Observable.fromPromise(this.apiService.getInstance().nodes.copyNode(nodeId, { targetParentId }))
.catch(err => this.handleError(err));
}
/**
* Move a node to destination node
*
* @param nodeId The id of the node to be moved
* @param targetParentId The id of the folder where the node will be moved
* @returns NodeEntry for the moved node
*/
moveNode(nodeId: string, targetParentId: string) {
return Observable.fromPromise(this.apiService.getInstance().nodes.moveNode(nodeId, { targetParentId }))
.catch(err => this.handleError(err));
}
/**
* Create a new folder in the path.
* @param name Folder name
* @param parentId Parent folder ID
* @returns Details of the created folder node
*/
createFolder(name: string, parentId: string): Observable<MinimalNodeEntity> {
return Observable.fromPromise(this.apiService.getInstance().nodes.createFolder(name, '/', parentId))
.catch(err => this.handleError(err));
}
/**
* Gets the folder node with the specified relative name path below the root node.
* @param folder Path to folder.
* @param opts Options.
* @param includeFields Extra information to include (available options are "aspectNames", "isLink" and "association")
* @returns Details of the folder
*/
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));
}
/**
* Gets a folder node via its node ID.
* @param nodeId ID of the folder node
* @param includeFields Extra information to include (available options are "aspectNames", "isLink" and "association")
* @returns Details of the folder
*/
getFolderNode(nodeId: string, includeFields: string[] = []): Observable<MinimalNodeEntryEntity> {
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', ...includeFields]
.filter((element, index, array) => index === array.indexOf(element));
let opts: any = {
includeSource: true,
include: includeFieldsRequest
};
return Observable.fromPromise(this.apiService.getInstance().nodes.getNodeInfo(nodeId, opts));
}
/**
* Get thumbnail URL for the given document node.
* @param node Node to get URL for.
* @returns Thumbnail URL string
*/
getDocumentThumbnailUrl(node: MinimalNodeEntity): string {
return this.thumbnailService.getDocumentThumbnailUrl(node);
}
/**
* 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);
}
/**
* Gets a default icon for MIME types with no specific icon.
* @returns Path to the icon file
*/
getDefaultMimeTypeIcon(): string {
return this.thumbnailService.getDefaultMimeTypeIcon();
}
/**
* @Deprecated 2.3.0 use the one in the content service
* Checks if a node has the specified permission.
* @param node Target node
* @param permission Permission level to query
* @returns True if the node has the permission, false otherwise
*/
hasPermission(node: any, permission: PermissionsEnum | string): boolean {
return this.contentService.hasPermission(node, permission);
}
private handleError(error: Response) {
// in a real world app, we may send the error to some remote logging infrastructure
// instead of just logging it to the console
this.logService.error(error);
return Observable.throw(error || 'Server error');
}
}