mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2645] move the service use in the upload in the right place (#3189)
[ADF-2645] move the service use in the upload in the right place [ADF-2687] No message is displayed when deleting a file/folder from content action [ADF-2714] [demo shell] Not able to download a version of a file * add spaces tslint fix
This commit is contained in:
@@ -63,7 +63,7 @@ describe('ContentAction', () => {
|
||||
beforeEach(() => {
|
||||
contentService = TestBed.get(ContentService);
|
||||
nodeActionsService = new NodeActionsService(null, null, null);
|
||||
documentActions = new DocumentActionsService(nodeActionsService, null);
|
||||
documentActions = new DocumentActionsService(nodeActionsService, null, null);
|
||||
folderActions = new FolderActionsService(nodeActionsService, null, contentService);
|
||||
|
||||
documentList = (TestBed.createComponent(DocumentListComponent).componentInstance as DocumentListComponent);
|
||||
|
@@ -15,7 +15,13 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlfrescoApiServiceMock, AppConfigService, StorageService, ContentService } from '@alfresco/adf-core';
|
||||
import {
|
||||
AlfrescoApiServiceMock,
|
||||
AppConfigService,
|
||||
ContentService,
|
||||
StorageService,
|
||||
TranslationMock
|
||||
} from '@alfresco/adf-core';
|
||||
import { FileNode, FolderNode } from '../../mock';
|
||||
import { ContentActionHandler } from '../models/content-action.model';
|
||||
import { DocumentActionsService } from './document-actions.service';
|
||||
@@ -34,8 +40,7 @@ describe('DocumentActionsService', () => {
|
||||
let alfrescoApiService = new AlfrescoApiServiceMock(new AppConfigService(null), new StorageService());
|
||||
|
||||
documentListService = new DocumentListService(null, contentService, alfrescoApiService, null, null);
|
||||
|
||||
service = new DocumentActionsService(null, null, documentListService, contentService);
|
||||
service = new DocumentActionsService(null, null, new TranslationMock(), documentListService, contentService);
|
||||
});
|
||||
|
||||
it('should register default download action', () => {
|
||||
@@ -47,7 +52,8 @@ describe('DocumentActionsService', () => {
|
||||
});
|
||||
|
||||
it('should register custom action handler', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
let handler: ContentActionHandler = function (obj: any) {
|
||||
};
|
||||
service.setHandler('<key>', handler);
|
||||
expect(service.getHandler('<key>')).toBe(handler);
|
||||
});
|
||||
@@ -57,7 +63,8 @@ describe('DocumentActionsService', () => {
|
||||
});
|
||||
|
||||
it('should be case insensitive for keys', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
let handler: ContentActionHandler = function (obj: any) {
|
||||
};
|
||||
service.setHandler('<key>', handler);
|
||||
expect(service.getHandler('<KEY>')).toBe(handler);
|
||||
});
|
||||
@@ -71,7 +78,7 @@ describe('DocumentActionsService', () => {
|
||||
let file = new FileNode();
|
||||
expect(service.canExecuteAction(file)).toBeTruthy();
|
||||
|
||||
service = new DocumentActionsService(nodeActionsService, null);
|
||||
service = new DocumentActionsService(nodeActionsService, null, null);
|
||||
expect(service.canExecuteAction(file)).toBeFalsy();
|
||||
});
|
||||
|
||||
@@ -82,7 +89,8 @@ describe('DocumentActionsService', () => {
|
||||
});
|
||||
|
||||
it('should set new handler only by key', () => {
|
||||
let handler: ContentActionHandler = function (obj: any) {};
|
||||
let handler: ContentActionHandler = function (obj: any) {
|
||||
};
|
||||
expect(service.setHandler(null, handler)).toBeFalsy();
|
||||
expect(service.setHandler('', handler)).toBeFalsy();
|
||||
expect(service.setHandler('my-handler', handler)).toBeTruthy();
|
||||
@@ -205,8 +213,8 @@ describe('DocumentActionsService', () => {
|
||||
});
|
||||
|
||||
it('should emit success event upon node deletion', (done) => {
|
||||
service.success.subscribe((nodeId) => {
|
||||
expect(nodeId).not.toBeNull();
|
||||
service.success.subscribe((message) => {
|
||||
expect(message).toEqual('CORE.DELETE_NODE.SINGULAR');
|
||||
done();
|
||||
});
|
||||
spyOn(documentListService, 'deleteNode').and.returnValue(Observable.of(true));
|
||||
|
@@ -15,7 +15,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { ContentService } from '@alfresco/adf-core';
|
||||
import { ContentService, TranslationService } from '@alfresco/adf-core';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MinimalNodeEntity } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
@@ -38,6 +38,7 @@ export class DocumentActionsService {
|
||||
|
||||
constructor(private nodeActionsService: NodeActionsService,
|
||||
private contentNodeDialogService: ContentNodeDialogService,
|
||||
private translation: TranslationService,
|
||||
private documentListService?: DocumentListService,
|
||||
private contentService?: ContentService) {
|
||||
this.setupActionHandlers();
|
||||
@@ -111,7 +112,7 @@ export class DocumentActionsService {
|
||||
private prepareHandlers(actionObservable, type: string, action: string, target?: any, permission?: string): void {
|
||||
actionObservable.subscribe(
|
||||
(fileOperationMessage) => {
|
||||
this.success.next(fileOperationMessage);
|
||||
this.success.next(fileOperationMessage);
|
||||
},
|
||||
this.error.next.bind(this.error)
|
||||
);
|
||||
@@ -124,11 +125,19 @@ export class DocumentActionsService {
|
||||
if (this.contentService.hasPermission(node.entry, permission)) {
|
||||
handlerObservable = this.documentListService.deleteNode(node.entry.id);
|
||||
handlerObservable.subscribe(() => {
|
||||
this.success.next(node.entry.id);
|
||||
let message = this.translation.instant('CORE.DELETE_NODE.SINGULAR', { name: node.entry.name });
|
||||
this.success.next(message);
|
||||
}, () => {
|
||||
let message = this.translation.instant('CORE.DELETE_NODE.ERROR_SINGULAR', { name: node.entry.name });
|
||||
this.error.next(message);
|
||||
});
|
||||
return handlerObservable;
|
||||
} else {
|
||||
this.permissionEvent.next(new PermissionModel({type: 'content', action: 'delete', permission: permission}));
|
||||
this.permissionEvent.next(new PermissionModel({
|
||||
type: 'content',
|
||||
action: 'delete',
|
||||
permission: permission
|
||||
}));
|
||||
return Observable.throw(new Error('No permission to delete'));
|
||||
}
|
||||
}
|
||||
|
@@ -21,7 +21,7 @@ import {
|
||||
} from '@alfresco/adf-core';
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodePaging } from 'alfresco-js-api';
|
||||
import { MinimalNodeEntity, MinimalNodeEntryEntity, NodeEntry, NodePaging } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Observable';
|
||||
import 'rxjs/add/observable/throw';
|
||||
|
||||
@@ -127,6 +127,26 @@ export class DocumentListService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a node via its node ID.
|
||||
* @param nodeId
|
||||
* @param includeFields Extra information to include (available options are "aspectNames", "isLink" and "association")
|
||||
* @returns Details of the folder
|
||||
*/
|
||||
getNode(nodeId: string, includeFields: string[] = []): Observable<NodeEntry> {
|
||||
|
||||
let includeFieldsRequest = ['path', 'properties', 'allowableOperations', 'permissions', ...includeFields]
|
||||
.filter((element, index, array) => index === array.indexOf(element));
|
||||
|
||||
let opts: any = {
|
||||
includeSource: true,
|
||||
include: includeFieldsRequest
|
||||
};
|
||||
|
||||
return this.contentService.getNode(nodeId, opts);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated 2.3.0
|
||||
* 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")
|
||||
@@ -144,7 +164,6 @@ export class DocumentListService {
|
||||
|
||||
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.
|
||||
|
Reference in New Issue
Block a user