Create Folder directive enhancement: custom nodeType (#3214)

This commit is contained in:
Popovics András
2018-04-19 13:03:38 +01:00
committed by Eugenio Romano
parent 0ff0573401
commit deb09e4d5f
7 changed files with 138 additions and 72 deletions

View File

@@ -33,6 +33,7 @@ Creates folders.
| -- | -- | -- | -- |
| adf-create-folder | `string` | DEFAULT_FOLDER_PARENT_ID | Parent folder where the new folder will be located after creation. |
| title | `string` | null | The title of the opened dialog. |
| nodeType | `string` | 'cm:folder' | The type of the node to be created. |
### Events

View File

@@ -299,7 +299,30 @@ describe('FolderDialogComponent', () => {
properties: {
'cm:title': 'folder-name-update',
'cm:description': 'folder-description-update'
},
nodeType: 'cm:folder'
}
);
});
it('should submit updated values if form is valid (with custom nodeType)', () => {
spyOn(nodesApi, 'createFolder').and.returnValue(Observable.of({}));
component.form.controls['name'].setValue('folder-name-update');
component.form.controls['description'].setValue('folder-description-update');
component.nodeType = 'cm:sushi';
component.submit();
expect(nodesApi.createFolder).toHaveBeenCalledWith(
'parentNodeId',
{
name: 'folder-name-update',
properties: {
'cm:title': 'folder-name-update',
'cm:description': 'folder-description-update'
},
nodeType: 'cm:sushi'
}
);
});

View File

@@ -47,6 +47,7 @@ export class FolderDialogComponent implements OnInit {
editTitle = 'CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE';
createTitle = 'CORE.FOLDER_DIALOG.CREATE_FOLDER_TITLE';
nodeType = 'cm:folder';
constructor(
private formBuilder: FormBuilder,
@@ -60,6 +61,7 @@ export class FolderDialogComponent implements OnInit {
if (data) {
this.editTitle = data.editTitle || this.editTitle;
this.createTitle = data.createTitle || this.createTitle;
this.nodeType = data.nodeType || this.nodeType;
}
}
@@ -116,8 +118,8 @@ export class FolderDialogComponent implements OnInit {
}
private create(): Observable<MinimalNodeEntryEntity> {
const { name, properties, nodesApi, data: { parentNodeId} } = this;
return nodesApi.createFolder(parentNodeId, { name, properties });
const { name, properties, nodeType, nodesApi, data: { parentNodeId} } = this;
return nodesApi.createFolder(parentNodeId, { name, properties, nodeType });
}
private edit(): Observable<MinimalNodeEntryEntity> {

View File

@@ -31,9 +31,15 @@ import { Subject } from 'rxjs/Subject';
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
@Component({
template: '<div [adf-create-folder]="parentNode" (success)="success($event)" title="create-title"></div>'
template: `
<div
[adf-create-folder]="parentNode"
(success)="success($event)"
title="create-title"
[nodeType]="'cm:my-litte-pony'">
</div>`
})
class TestComponent {
class Test1Component {
parentNode = '';
public successParameter: MinimalNodeEntryEntity = null;
@@ -42,20 +48,25 @@ class TestComponent {
}
}
@Component({
template: `<div [adf-create-folder]="parentNode"></div>`
})
class Test2Component {
parentNode = '';
public successParameter: MinimalNodeEntryEntity = null;
}
describe('FolderCreateDirective', () => {
let fixture: ComponentFixture<TestComponent>;
let fixture: ComponentFixture<Test1Component | Test2Component>;
let element;
let node: any;
let dialog: MatDialog;
let contentService: ContentService;
let dialogRefMock;
const event = {
type: 'click',
preventDefault: () => null
};
const event = { type: 'click', preventDefault: () => null };
beforeEach(() => {
beforeEach(async(() => {
TestBed.configureTestingModule({
imports: [
HttpClientModule,
@@ -71,22 +82,16 @@ describe('FolderCreateDirective', () => {
})
],
declarations: [
TestComponent,
Test1Component,
Test2Component,
FolderDialogComponent,
FolderCreateDirective
],
providers: [
ContentService
]
});
TestBed.compileComponents();
fixture = TestBed.createComponent(TestComponent);
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
dialog = TestBed.get(MatDialog);
contentService = TestBed.get(ContentService);
});
}).compileComponents();
}));
beforeEach(() => {
node = { entry: { id: 'nodeId' } };
@@ -98,7 +103,15 @@ describe('FolderCreateDirective', () => {
success: new Subject<MinimalNodeEntryEntity>()
}
};
});
describe('With overrides', () => {
beforeEach(() => {
fixture = TestBed.createComponent(Test1Component);
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
dialog = TestBed.get(MatDialog);
contentService = TestBed.get(ContentService);
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
});
@@ -142,16 +155,43 @@ describe('FolderCreateDirective', () => {
});
}));
it('should open the dialog with the proper title', async(() => {
it('should open the dialog with the proper title and nodeType', async(() => {
fixture.detectChanges();
element.triggerEventHandler('click', event);
expect(dialog.open).toHaveBeenCalledWith(jasmine.any(Function), {
data: {
parentNodeId: jasmine.any(String),
createTitle: 'create-title'
createTitle: 'create-title',
nodeType: 'cm:my-litte-pony'
},
width: jasmine.any(String)
});
}));
});
describe('Without overrides', () => {
beforeEach(() => {
fixture = TestBed.createComponent(Test2Component);
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
dialog = TestBed.get(MatDialog);
contentService = TestBed.get(ContentService);
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
});
it('should open the dialog with the default title and nodeType', async(() => {
fixture.detectChanges();
element.triggerEventHandler('click', event);
expect(dialog.open).toHaveBeenCalledWith(jasmine.any(Function), {
data: {
parentNodeId: jasmine.any(String),
createTitle: null,
nodeType: 'cm:folder'
},
width: jasmine.any(String)
});
}));
});
});

View File

@@ -38,6 +38,9 @@ export class FolderCreateDirective {
@Input()
title: string = null;
@Input()
nodeType = 'cm:folder';
/** Emitted when the create folder give error for example a folder with same name already exist */
@Output()
error: EventEmitter<any> = new EventEmitter<any>();
@@ -58,13 +61,10 @@ export class FolderCreateDirective {
private get dialogConfig(): MatDialogConfig {
const { DIALOG_WIDTH: width } = FolderCreateDirective;
const { parentNodeId } = this;
const { parentNodeId, title: createTitle, nodeType } = this;
return {
data: {
parentNodeId,
createTitle: this.title
},
data: { parentNodeId, createTitle, nodeType },
width: `${width}px`
};
}

View File

@@ -17,7 +17,7 @@
/* tslint:disable:no-input-rename */
import { Component} from '@angular/core';
import { Component } from '@angular/core';
@Component({
selector: 'adf-no-permission-template',

View File

@@ -24,7 +24,7 @@ import { PermissionListComponent } from './components/permission-list/permission
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
import { InheritPermissionDirective } from './components/inherited-button.directive';
import { NodePermissionService } from './services/node-permission.service';
import { NoPermissionTemplateComponent } from "./components/permission-list/no-permission.component";
import { NoPermissionTemplateComponent } from './components/permission-list/no-permission.component';
@NgModule({
imports: [