[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:
Eugenio Romano
2018-04-14 10:39:24 +01:00
committed by GitHub
parent 66d8935624
commit 6cd0e9f5bb
23 changed files with 122 additions and 282 deletions

View File

@@ -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);

View File

@@ -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));

View File

@@ -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'));
}
}

View File

@@ -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.

View File

@@ -20,7 +20,6 @@
"baseUrl" : "./",
"paths": {
"@alfresco/adf-process-services": ["../process-services"],
"@alfresco/adf-content-services": ["../content-services"],
"@alfresco/adf-core": ["../core"],
"@angular/*": ["../node_modules/@angular/*"]
},

View File

@@ -33,13 +33,15 @@ describe('UploadButtonComponent', () => {
};
let fakeFolderNodeWithPermission = {
allowableOperations: [
'create',
'update'
],
isFolder: true,
name: 'Folder Fake Name',
nodeType: 'cm:folder'
entry: {
allowableOperations: [
'create',
'update'
],
isFolder: true,
name: 'Folder Fake Name',
nodeType: 'cm:folder'
}
};
let component: UploadButtonComponent;
@@ -54,6 +56,7 @@ describe('UploadButtonComponent', () => {
],
providers: [
UploadService,
ContentService,
{ provide: TranslationService, useClass: TranslationMock }
]
}).compileComponents();
@@ -98,7 +101,7 @@ describe('UploadButtonComponent', () => {
component.rootFolderId = '-root-';
component.success = null;
spyOn(component, 'getFolderNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
spyOn(contentService, 'getNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
@@ -113,7 +116,7 @@ describe('UploadButtonComponent', () => {
component.rootFolderId = '-my-';
component.success = null;
spyOn(component, 'getFolderNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
spyOn(contentService, 'getNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
uploadService.uploadFilesInTheQueue = jasmine.createSpy('uploadFilesInTheQueue');
@@ -128,7 +131,7 @@ describe('UploadButtonComponent', () => {
component.rootFolderId = '-my-';
spyOn(contentService, 'createFolder').and.returnValue(Observable.of(true));
spyOn(component, 'getFolderNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
spyOn(contentService, 'getNode').and.returnValue(Observable.of(fakeFolderNodeWithPermission));
component.ngOnChanges({ rootFolderId: new SimpleChange(null, component.rootFolderId, true) });
fixture.detectChanges();

View File

@@ -15,29 +15,11 @@
* limitations under the License.
*/
import {
AlfrescoApiService,
EXTENDIBLE_COMPONENT,
FileModel,
FileUtils,
LogService,
NodePermissionSubject,
TranslationService,
UploadService
import { ContentService, EXTENDIBLE_COMPONENT, FileModel, FileUtils,
LogService, NodePermissionSubject, TranslationService, UploadService
} from '@alfresco/adf-core';
import {
Component,
EventEmitter,
forwardRef,
Input,
OnChanges,
OnInit,
Output,
SimpleChanges,
ViewEncapsulation
} from '@angular/core';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
import { Observable } from 'rxjs/Observable';
import { Component, EventEmitter, forwardRef, Input,
OnChanges, OnInit, Output, SimpleChanges, ViewEncapsulation } from '@angular/core';
import { Subject } from 'rxjs/Subject';
import { PermissionModel } from '../../document-list/models/permissions.model';
import 'rxjs/add/observable/throw';
@@ -111,7 +93,7 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
private permissionValue: Subject<boolean> = new Subject<boolean>();
constructor(private uploadService: UploadService,
private apiService: AlfrescoApiService,
private contentService: ContentService,
protected translateService: TranslationService,
protected logService: LogService
) {
@@ -221,31 +203,18 @@ export class UploadButtonComponent extends UploadBase implements OnInit, OnChang
checkPermission() {
if (this.rootFolderId) {
this.getFolderNode(this.rootFolderId).subscribe(
res => this.permissionValue.next(this.hasCreatePermission(res)),
let opts: any = {
includeSource: true,
include: ['allowableOperations']
};
this.contentService.getNode(this.rootFolderId, opts).subscribe(
res => this.permissionValue.next(this.hasCreatePermission(res.entry)),
error => this.error.emit(error)
);
}
}
// TODO: move to ContentService
getFolderNode(nodeId: string): Observable<MinimalNodeEntryEntity> {
let opts: any = {
includeSource: true,
include: ['allowableOperations']
};
return Observable.fromPromise(this.apiService.getInstance().nodes.getNodeInfo(nodeId, opts))
.catch(err => this.handleError(err));
}
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');
}
private hasCreatePermission(node: any): boolean {
if (node && node.allowableOperations) {
return node.allowableOperations.find(permission => permission === 'create') ? true : false;