+
`
})
class TestComponent {
selection = [];
- done = jasmine.createSpy('done');
+ @ViewChild(NodeDeleteDirective)
+ deleteDirective;
+
+ onDelete = jasmine.createSpy('onDelete');
}
@Component({
template: `
-
+ (delete)="onDelete($event)">
`
})
class TestWithPermissionsComponent {
selection = [];
- done = jasmine.createSpy('done');
+ @ViewChild(NodeDeleteDirective)
+ deleteDirective;
+
+ onDelete = jasmine.createSpy('onDelete');
}
@Component({
@@ -53,18 +58,21 @@ class TestWithPermissionsComponent {
+ (delete)="onDelete($event)">
`
})
class TestDeletePermanentComponent {
selection = [];
+ @ViewChild(NodeDeleteDirective)
+ deleteDirective;
+
permanent = true;
- done = jasmine.createSpy('done');
+ onDelete = jasmine.createSpy('onDelete');
}
-describe('NodeDeleteDirective', () => {
+describe('NodeleteDirective', () => {
let fixture: ComponentFixture
;
let fixtureWithPermissions: ComponentFixture;
let fixtureWithPermanentComponent: ComponentFixture;
@@ -75,7 +83,6 @@ describe('NodeDeleteDirective', () => {
let componentWithPermissions: TestWithPermissionsComponent;
let componentWithPermanentDelete: TestDeletePermanentComponent;
let alfrescoApi: AlfrescoApiService;
- let notification: NotificationService;
let nodeApi;
beforeEach(async(() => {
@@ -103,54 +110,60 @@ describe('NodeDeleteDirective', () => {
alfrescoApi = TestBed.get(AlfrescoApiService);
nodeApi = alfrescoApi.getInstance().nodes;
- notification = TestBed.get(NotificationService);
});
}));
describe('Delete', () => {
- beforeEach(() => {
- spyOn(notification, 'openSnackMessage');
- });
it('should do nothing if selection is empty', () => {
spyOn(nodeApi, 'deleteNode');
component.selection = [];
fixture.detectChanges();
- element.triggerEventHandler('click', null);
+ element.nativeElement.click();
expect(nodeApi.deleteNode).not.toHaveBeenCalled();
});
- it('should process node successfully', fakeAsync(() => {
+ it('should process node successfully', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = [{ entry: { id: '1', name: 'name1' } }];
+ component.deleteDirective.delete.subscribe((message) => {
+ expect(message).toBe(
+ 'CORE.DELETE_NODE.SINGULAR'
+ );
+ done();
+ });
+
fixture.detectChanges();
- element.triggerEventHandler('click', null);
- tick();
- expect(notification.openSnackMessage).toHaveBeenCalledWith(
- 'CORE.DELETE_NODE.SINGULAR'
- );
- }));
+ fixture.whenStable().then(() => {
+ element.nativeElement.click();
+ });
+ });
- it('should notify failed node deletion', fakeAsync(() => {
+ it('should notify failed node deletion', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.reject('error'));
component.selection = [{ entry: { id: '1', name: 'name1' } }];
+ component.deleteDirective.delete.subscribe((message) => {
+ expect(message).toBe(
+ 'CORE.DELETE_NODE.ERROR_SINGULAR'
+ );
+ done();
+ });
+
fixture.detectChanges();
- element.triggerEventHandler('click', null);
- tick();
- expect(notification.openSnackMessage).toHaveBeenCalledWith(
- 'CORE.DELETE_NODE.ERROR_SINGULAR'
- );
- }));
+ fixture.whenStable().then(() => {
+ element.nativeElement.click();
+ });
+ });
- it('should notify nodes deletion', fakeAsync(() => {
+ it('should notify nodes deletion', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = [
@@ -158,16 +171,21 @@ describe('NodeDeleteDirective', () => {
{ entry: { id: '2', name: 'name2' } }
];
+ component.deleteDirective.delete.subscribe((message) => {
+ expect(message).toBe(
+ 'CORE.DELETE_NODE.PLURAL'
+ );
+ done();
+ });
+
fixture.detectChanges();
- element.triggerEventHandler('click', null);
- tick();
- expect(notification.openSnackMessage).toHaveBeenCalledWith(
- 'CORE.DELETE_NODE.PLURAL'
- );
- }));
+ fixture.whenStable().then(() => {
+ element.nativeElement.click();
+ });
+ });
- it('should notify failed nodes deletion', fakeAsync(() => {
+ it('should notify failed nodes deletion', (done) => {
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.reject('error'));
component.selection = [
@@ -175,16 +193,21 @@ describe('NodeDeleteDirective', () => {
{ entry: { id: '2', name: 'name2' } }
];
+ component.deleteDirective.delete.subscribe((message) => {
+ expect(message).toBe(
+ 'CORE.DELETE_NODE.ERROR_PLURAL'
+ );
+ done();
+ });
+
fixture.detectChanges();
- element.triggerEventHandler('click', null);
- tick();
- expect(notification.openSnackMessage).toHaveBeenCalledWith(
- 'CORE.DELETE_NODE.ERROR_PLURAL'
- );
- }));
+ fixture.whenStable().then(() => {
+ element.nativeElement.click();
+ });
+ });
- it('should notify partial deletion when only one node is successful', fakeAsync(() => {
+ it('should notify partial deletion when only one node is successful', (done) => {
spyOn(nodeApi, 'deleteNode').and.callFake((id) => {
if (id === '1') {
return Promise.reject('error');
@@ -198,16 +221,21 @@ describe('NodeDeleteDirective', () => {
{ entry: { id: '2', name: 'name2' } }
];
+ component.deleteDirective.delete.subscribe((message) => {
+ expect(message).toBe(
+ 'CORE.DELETE_NODE.PARTIAL_SINGULAR'
+ );
+ done();
+ });
+
fixture.detectChanges();
- element.triggerEventHandler('click', null);
- tick();
- expect(notification.openSnackMessage).toHaveBeenCalledWith(
- 'CORE.DELETE_NODE.PARTIAL_SINGULAR'
- );
- }));
+ fixture.whenStable().then(() => {
+ element.nativeElement.click();
+ });
+ });
- it('should notify partial deletion when some nodes are successful', fakeAsync(() => {
+ it('should notify partial deletion when some nodes are successful', (done) => {
spyOn(nodeApi, 'deleteNode').and.callFake((id) => {
if (id === '1') {
return Promise.reject(null);
@@ -228,26 +256,31 @@ describe('NodeDeleteDirective', () => {
{ entry: { id: '3', name: 'name3' } }
];
- fixture.detectChanges();
- element.triggerEventHandler('click', null);
- tick();
+ component.deleteDirective.delete.subscribe((message) => {
+ expect(message).toBe(
+ 'CORE.DELETE_NODE.PARTIAL_PLURAL'
+ );
+ done();
+ });
- expect(notification.openSnackMessage).toHaveBeenCalledWith(
- 'CORE.DELETE_NODE.PARTIAL_PLURAL'
- );
- }));
+ fixture.detectChanges();
+
+ fixture.whenStable().then(() => {
+ element.nativeElement.click();
+ });
+ });
it('should emit event when delete is done', fakeAsync(() => {
- component.done.calls.reset();
+ component.onDelete.calls.reset();
spyOn(nodeApi, 'deleteNode').and.returnValue(Promise.resolve());
component.selection = [{ entry: { id: '1', name: 'name1' } }];
fixture.detectChanges();
- element.triggerEventHandler('click', null);
+ element.nativeElement.click();
tick();
- expect(component.done).toHaveBeenCalled();
+ expect(component.onDelete).toHaveBeenCalled();
}));
it('should disable the button if no node are selected', fakeAsync(() => {
@@ -303,12 +336,12 @@ describe('NodeDeleteDirective', () => {
fixtureWithPermanentComponent.detectChanges();
componentWithPermanentDelete.selection = [
- { entry: { id: '1', name: 'name1'}
+ { entry: { id: '1', name: 'name1' }
];
fixtureWithPermanentComponent.detectChanges();
- elementWithPermanentDelete.triggerEventHandler('click', null);
+ elementWithPermanentDelete.nativeElement.click();
tick();
expect(deleteApi).toHaveBeenCalledWith('1', { permanent: true });
@@ -325,7 +358,7 @@ describe('NodeDeleteDirective', () => {
fixtureWithPermanentComponent.detectChanges();
- elementWithPermanentDelete.triggerEventHandler('click', null);
+ elementWithPermanentDelete.nativeElement.click();
tick();
expect(deleteApi).toHaveBeenCalledWith('1');
diff --git a/lib/core/directives/node-delete.directive.ts b/lib/core/directives/node-delete.directive.ts
index 4497a05be3..deb497ea13 100644
--- a/lib/core/directives/node-delete.directive.ts
+++ b/lib/core/directives/node-delete.directive.ts
@@ -21,7 +21,6 @@ import { Directive, ElementRef, EventEmitter, HostListener, Input, OnChanges, Ou
import { MinimalNodeEntity, MinimalNodeEntryEntity, DeletedNodeEntity, DeletedNodeMinimalEntry } from 'alfresco-js-api';
import { Observable } from 'rxjs/Observable';
import { AlfrescoApiService } from '../services/alfresco-api.service';
-import { NotificationService } from '../services/notification.service';
import { TranslationService } from '../services/translation.service';
import 'rxjs/add/observable/fromPromise';
import 'rxjs/observable/forkJoin';
@@ -70,8 +69,7 @@ export class NodeDeleteDirective implements OnChanges {
this.process(this.selection);
}
- constructor(private notification: NotificationService,
- private alfrescoApiService: AlfrescoApiService,
+ constructor(private alfrescoApiService: AlfrescoApiService,
private translation: TranslationService,
private elementRef: ElementRef) {
}
@@ -99,11 +97,7 @@ export class NodeDeleteDirective implements OnChanges {
.subscribe((data: ProcessedNodeData[]) => {
const processedItems: ProcessStatus = this.processStatus(data);
- this.notify(processedItems);
-
- if (processedItems.someSucceeded) {
- this.delete.emit();
- }
+ this.delete.emit(this.getMessage(processedItems));
});
}
}
@@ -174,27 +168,23 @@ export class NodeDeleteDirective implements OnChanges {
);
}
- private notify(status) {
- this.getMessage(status).subscribe((message) => this.notification.openSnackMessage(message));
- }
-
- private getMessage(status): Observable {
+ private getMessage(status): string {
if (status.allFailed && !status.oneFailed) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.DELETE_NODE.ERROR_PLURAL',
{ number: status.failed.length }
);
}
if (status.allSucceeded && !status.oneSucceeded) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.DELETE_NODE.PLURAL',
{ number: status.success.length }
);
}
if (status.someFailed && status.someSucceeded && !status.oneSucceeded) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.DELETE_NODE.PARTIAL_PLURAL',
{
success: status.success.length,
@@ -204,7 +194,7 @@ export class NodeDeleteDirective implements OnChanges {
}
if (status.someFailed && status.oneSucceeded) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.DELETE_NODE.PARTIAL_SINGULAR',
{
success: status.success.length,
@@ -214,14 +204,14 @@ export class NodeDeleteDirective implements OnChanges {
}
if (status.oneFailed && !status.someSucceeded) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.DELETE_NODE.ERROR_SINGULAR',
{ name: status.failed[0].entry.name }
);
}
if (status.oneSucceeded && !status.someFailed) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.DELETE_NODE.SINGULAR',
{ name: status.success[0].entry.name }
);
diff --git a/lib/core/directives/node-restore.directive.spec.ts b/lib/core/directives/node-restore.directive.spec.ts
index 9948f9af35..5e1ce11482 100644
--- a/lib/core/directives/node-restore.directive.spec.ts
+++ b/lib/core/directives/node-restore.directive.spec.ts
@@ -76,7 +76,7 @@ describe('NodeRestoreDirective', () => {
}));
beforeEach(() => {
- spyOn(translation, 'get').and.returnValue(Observable.of('message'));
+ spyOn(translation, 'instant').and.returnValue('message');
});
it('should not restore when selection is empty', () => {
@@ -201,7 +201,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
- expect(translation.get).toHaveBeenCalledWith(
+ expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.PARTIAL_PLURAL',
{ number: 2 }
);
@@ -221,7 +221,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
- expect(translation.get).toHaveBeenCalledWith(
+ expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.NODE_EXISTS',
{ name: 'name1' }
);
@@ -241,7 +241,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
- expect(translation.get).toHaveBeenCalledWith(
+ expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.GENERIC',
{ name: 'name1' }
);
@@ -261,7 +261,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
- expect(translation.get).toHaveBeenCalledWith(
+ expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.LOCATION_MISSING',
{ name: 'name1' }
);
@@ -288,7 +288,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
- expect(translation.get).toHaveBeenCalledWith(
+ expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.PLURAL'
);
}));
@@ -305,7 +305,7 @@ describe('NodeRestoreDirective', () => {
element.triggerEventHandler('click', null);
tick();
- expect(translation.get).toHaveBeenCalledWith(
+ expect(translation.instant).toHaveBeenCalledWith(
'CORE.RESTORE_NODE.SINGULAR',
{ name: 'name1' }
);
diff --git a/lib/core/directives/node-restore.directive.ts b/lib/core/directives/node-restore.directive.ts
index 55a9eabc0d..435a04008e 100644
--- a/lib/core/directives/node-restore.directive.ts
+++ b/lib/core/directives/node-restore.directive.ts
@@ -51,16 +51,14 @@ export class NodeRestoreDirective {
this.recover(this.selection);
}
- constructor(
- private alfrescoApiService: AlfrescoApiService,
- private translation: TranslationService,
- private router: Router,
- private notification: NotificationService
- ) {
+ constructor(private alfrescoApiService: AlfrescoApiService,
+ private translation: TranslationService,
+ private router: Router,
+ private notification: NotificationService) {
this.restoreProcessStatus = this.processStatus();
}
- private recover(selection: any) {
+ private recover(selection: any) {
if (!selection.length) {
return;
}
@@ -109,7 +107,7 @@ export class NodeRestoreDirective {
private getDeletedNodes(): Observable {
const promise = this.alfrescoApiService.getInstance()
- .core.nodesApi.getDeletedNodes({ include: [ 'path' ] });
+ .core.nodesApi.getDeletedNodes({ include: ['path'] });
return Observable.from(promise);
}
@@ -138,10 +136,10 @@ export class NodeRestoreDirective {
private navigateLocation(path: PathInfoEntity) {
const parent = path.elements[path.elements.length - 1];
- this.router.navigate([ this.location, parent.id ]);
+ this.router.navigate([this.location, parent.id]);
}
- private diff(selection , list, fromList = true): any {
+ private diff(selection, list, fromList = true): any {
const ids = selection.map(item => item.entry.id);
return list.filter(item => {
@@ -195,11 +193,11 @@ export class NodeRestoreDirective {
);
}
- private getRestoreMessage(): Observable {
+ private getRestoreMessage(): string {
const { restoreProcessStatus: status } = this;
if (status.someFailed && !status.oneFailed) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.RESTORE_NODE.PARTIAL_PLURAL',
{
number: status.fail.length
@@ -209,14 +207,14 @@ export class NodeRestoreDirective {
if (status.oneFailed && status.fail[0].statusCode) {
if (status.fail[0].statusCode === 409) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.RESTORE_NODE.NODE_EXISTS',
{
name: status.fail[0].entry.name
}
);
} else {
- return this.translation.get(
+ return this.translation.instant(
'CORE.RESTORE_NODE.GENERIC',
{
name: status.fail[0].entry.name
@@ -226,7 +224,7 @@ export class NodeRestoreDirective {
}
if (status.oneFailed && !status.fail[0].statusCode) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.RESTORE_NODE.LOCATION_MISSING',
{
name: status.fail[0].entry.name
@@ -235,11 +233,11 @@ export class NodeRestoreDirective {
}
if (status.allSucceeded && !status.oneSucceeded) {
- return this.translation.get('CORE.RESTORE_NODE.PLURAL');
+ return this.translation.instant('CORE.RESTORE_NODE.PLURAL');
}
if (status.allSucceeded && status.oneSucceeded) {
- return this.translation.get(
+ return this.translation.instant(
'CORE.RESTORE_NODE.SINGULAR',
{
name: status.success[0].entry.name
@@ -251,17 +249,13 @@ export class NodeRestoreDirective {
private restoreNotification(): void {
const status = Object.assign({}, this.restoreProcessStatus);
- Observable.zip(
- this.getRestoreMessage(),
- this.translation.get('CORE.RESTORE_NODE.VIEW')
- ).subscribe((messages) => {
- const [ message, actionLabel ] = messages;
- const action = (status.oneSucceeded && !status.someFailed) ? actionLabel : '';
+ let message = this.getRestoreMessage();
- this.notification.openSnackMessageAction(message, action)
- .onAction()
- .subscribe(() => this.navigateLocation(status.success[0].entry.path));
- });
+ const action = (status.oneSucceeded && !status.someFailed) ? this.translation.instant('CORE.RESTORE_NODE.VIEW') : '';
+
+ this.notification.openSnackMessageAction(message, action)
+ .onAction()
+ .subscribe(() => this.navigateLocation(status.success[0].entry.path));
}
private refresh(): void {
diff --git a/lib/process-services/app-list/select-apps-dialog-component.ts b/lib/process-services/app-list/select-apps-dialog-component.ts
index 953de62b17..d190998503 100644
--- a/lib/process-services/app-list/select-apps-dialog-component.ts
+++ b/lib/process-services/app-list/select-apps-dialog-component.ts
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-import { AppsProcessService, NotificationService, TranslationService } from '@alfresco/adf-core';
+import { AppsProcessService } from '@alfresco/adf-core';
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material';
@@ -30,8 +30,6 @@ export class SelectAppsDialogComponent {
selectedProcess: any;
constructor(private appsProcessService: AppsProcessService,
- private translateService: TranslationService,
- private notificationService: NotificationService,
public dialogRef: MatDialogRef,
@Inject(MAT_DIALOG_DATA) public data: any) {
@@ -40,14 +38,8 @@ export class SelectAppsDialogComponent {
this.processApps = apps.filter((currentApp) => {
return currentApp.id;
});
- },
- (err) => {
- this.translateService.get('TAG.MESSAGES.EXIST').subscribe((error) => {
- this.notificationService.openSnackMessage(error, 4000);
- });
}
);
-
}
onStart(): void {