mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
Create Folder directive enhancement: custom nodeType (#3214)
This commit is contained in:
committed by
Eugenio Romano
parent
0ff0573401
commit
deb09e4d5f
@@ -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. |
|
| 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. |
|
| title | `string` | null | The title of the opened dialog. |
|
||||||
|
| nodeType | `string` | 'cm:folder' | The type of the node to be created. |
|
||||||
|
|
||||||
### Events
|
### Events
|
||||||
|
|
||||||
|
@@ -299,7 +299,30 @@ describe('FolderDialogComponent', () => {
|
|||||||
properties: {
|
properties: {
|
||||||
'cm:title': 'folder-name-update',
|
'cm:title': 'folder-name-update',
|
||||||
'cm:description': 'folder-description-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'
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
@@ -47,6 +47,7 @@ export class FolderDialogComponent implements OnInit {
|
|||||||
|
|
||||||
editTitle = 'CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE';
|
editTitle = 'CORE.FOLDER_DIALOG.EDIT_FOLDER_TITLE';
|
||||||
createTitle = 'CORE.FOLDER_DIALOG.CREATE_FOLDER_TITLE';
|
createTitle = 'CORE.FOLDER_DIALOG.CREATE_FOLDER_TITLE';
|
||||||
|
nodeType = 'cm:folder';
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
@@ -60,6 +61,7 @@ export class FolderDialogComponent implements OnInit {
|
|||||||
if (data) {
|
if (data) {
|
||||||
this.editTitle = data.editTitle || this.editTitle;
|
this.editTitle = data.editTitle || this.editTitle;
|
||||||
this.createTitle = data.createTitle || this.createTitle;
|
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> {
|
private create(): Observable<MinimalNodeEntryEntity> {
|
||||||
const { name, properties, nodesApi, data: { parentNodeId} } = this;
|
const { name, properties, nodeType, nodesApi, data: { parentNodeId} } = this;
|
||||||
return nodesApi.createFolder(parentNodeId, { name, properties });
|
return nodesApi.createFolder(parentNodeId, { name, properties, nodeType });
|
||||||
}
|
}
|
||||||
|
|
||||||
private edit(): Observable<MinimalNodeEntryEntity> {
|
private edit(): Observable<MinimalNodeEntryEntity> {
|
||||||
|
@@ -31,9 +31,15 @@ import { Subject } from 'rxjs/Subject';
|
|||||||
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
import { MinimalNodeEntryEntity } from 'alfresco-js-api';
|
||||||
|
|
||||||
@Component({
|
@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 = '';
|
parentNode = '';
|
||||||
public successParameter: MinimalNodeEntryEntity = null;
|
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', () => {
|
describe('FolderCreateDirective', () => {
|
||||||
let fixture: ComponentFixture<TestComponent>;
|
let fixture: ComponentFixture<Test1Component | Test2Component>;
|
||||||
let element;
|
let element;
|
||||||
let node: any;
|
let node: any;
|
||||||
let dialog: MatDialog;
|
let dialog: MatDialog;
|
||||||
let contentService: ContentService;
|
let contentService: ContentService;
|
||||||
let dialogRefMock;
|
let dialogRefMock;
|
||||||
|
|
||||||
const event = {
|
const event = { type: 'click', preventDefault: () => null };
|
||||||
type: 'click',
|
|
||||||
preventDefault: () => null
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [
|
imports: [
|
||||||
HttpClientModule,
|
HttpClientModule,
|
||||||
@@ -71,22 +82,16 @@ describe('FolderCreateDirective', () => {
|
|||||||
})
|
})
|
||||||
],
|
],
|
||||||
declarations: [
|
declarations: [
|
||||||
TestComponent,
|
Test1Component,
|
||||||
|
Test2Component,
|
||||||
FolderDialogComponent,
|
FolderDialogComponent,
|
||||||
FolderCreateDirective
|
FolderCreateDirective
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
ContentService
|
ContentService
|
||||||
]
|
]
|
||||||
});
|
}).compileComponents();
|
||||||
|
}));
|
||||||
TestBed.compileComponents();
|
|
||||||
|
|
||||||
fixture = TestBed.createComponent(TestComponent);
|
|
||||||
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
|
|
||||||
dialog = TestBed.get(MatDialog);
|
|
||||||
contentService = TestBed.get(ContentService);
|
|
||||||
});
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
node = { entry: { id: 'nodeId' } };
|
node = { entry: { id: 'nodeId' } };
|
||||||
@@ -98,60 +103,95 @@ describe('FolderCreateDirective', () => {
|
|||||||
success: new Subject<MinimalNodeEntryEntity>()
|
success: new Subject<MinimalNodeEntryEntity>()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
xit('should emit folderCreate event when input value is not undefined', (done) => {
|
describe('With overrides', () => {
|
||||||
spyOn(dialogRefMock, 'afterClosed').and.returnValue(Observable.of(node));
|
|
||||||
spyOn(contentService.folderCreate, 'next');
|
|
||||||
|
|
||||||
contentService.folderCreate.subscribe((val) => {
|
beforeEach(() => {
|
||||||
expect(val).toBe(node);
|
fixture = TestBed.createComponent(Test1Component);
|
||||||
done();
|
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
|
||||||
|
dialog = TestBed.get(MatDialog);
|
||||||
|
contentService = TestBed.get(ContentService);
|
||||||
|
spyOn(dialog, 'open').and.returnValue(dialogRefMock);
|
||||||
});
|
});
|
||||||
|
|
||||||
fixture.detectChanges();
|
xit('should emit folderCreate event when input value is not undefined', (done) => {
|
||||||
|
spyOn(dialogRefMock, 'afterClosed').and.returnValue(Observable.of(node));
|
||||||
|
spyOn(contentService.folderCreate, 'next');
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
contentService.folderCreate.subscribe((val) => {
|
||||||
element.nativeElement.click();
|
expect(val).toBe(node);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
element.nativeElement.click();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not emit folderCreate event when input value is undefined', () => {
|
||||||
|
spyOn(dialogRefMock, 'afterClosed').and.returnValue(Observable.of(null));
|
||||||
|
spyOn(contentService.folderCreate, 'next');
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
element.nativeElement.click();
|
||||||
|
expect(contentService.folderCreate.next).not.toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should emit success event with node if the folder creation was successful', async(() => {
|
||||||
|
const testNode = <MinimalNodeEntryEntity> {};
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
|
element.triggerEventHandler('click', event);
|
||||||
|
dialogRefMock.componentInstance.success.next(testNode);
|
||||||
|
|
||||||
|
fixture.whenStable().then(() => {
|
||||||
|
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
|
||||||
|
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',
|
||||||
|
nodeType: 'cm:my-litte-pony'
|
||||||
|
},
|
||||||
|
width: jasmine.any(String)
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not emit folderCreate event when input value is undefined', () => {
|
describe('Without overrides', () => {
|
||||||
spyOn(dialogRefMock, 'afterClosed').and.returnValue(Observable.of(null));
|
|
||||||
spyOn(contentService.folderCreate, 'next');
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
beforeEach(() => {
|
||||||
|
fixture = TestBed.createComponent(Test2Component);
|
||||||
fixture.whenStable().then(() => {
|
element = fixture.debugElement.query(By.directive(FolderCreateDirective));
|
||||||
element.nativeElement.click();
|
dialog = TestBed.get(MatDialog);
|
||||||
expect(contentService.folderCreate.next).not.toHaveBeenCalled();
|
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)
|
||||||
|
});
|
||||||
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit success event with node if the folder creation was successful', async(() => {
|
|
||||||
const testNode = <MinimalNodeEntryEntity> {};
|
|
||||||
fixture.detectChanges();
|
|
||||||
|
|
||||||
element.triggerEventHandler('click', event);
|
|
||||||
dialogRefMock.componentInstance.success.next(testNode);
|
|
||||||
|
|
||||||
fixture.whenStable().then(() => {
|
|
||||||
expect(fixture.componentInstance.successParameter).toBe(testNode);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should open the dialog with the proper title', async(() => {
|
|
||||||
fixture.detectChanges();
|
|
||||||
element.triggerEventHandler('click', event);
|
|
||||||
|
|
||||||
expect(dialog.open).toHaveBeenCalledWith(jasmine.any(Function), {
|
|
||||||
data: {
|
|
||||||
parentNodeId: jasmine.any(String),
|
|
||||||
createTitle: 'create-title'
|
|
||||||
},
|
|
||||||
width: jasmine.any(String)
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
});
|
||||||
|
@@ -38,6 +38,9 @@ export class FolderCreateDirective {
|
|||||||
@Input()
|
@Input()
|
||||||
title: string = null;
|
title: string = null;
|
||||||
|
|
||||||
|
@Input()
|
||||||
|
nodeType = 'cm:folder';
|
||||||
|
|
||||||
/** Emitted when the create folder give error for example a folder with same name already exist */
|
/** Emitted when the create folder give error for example a folder with same name already exist */
|
||||||
@Output()
|
@Output()
|
||||||
error: EventEmitter<any> = new EventEmitter<any>();
|
error: EventEmitter<any> = new EventEmitter<any>();
|
||||||
@@ -58,13 +61,10 @@ export class FolderCreateDirective {
|
|||||||
|
|
||||||
private get dialogConfig(): MatDialogConfig {
|
private get dialogConfig(): MatDialogConfig {
|
||||||
const { DIALOG_WIDTH: width } = FolderCreateDirective;
|
const { DIALOG_WIDTH: width } = FolderCreateDirective;
|
||||||
const { parentNodeId } = this;
|
const { parentNodeId, title: createTitle, nodeType } = this;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
data: {
|
data: { parentNodeId, createTitle, nodeType },
|
||||||
parentNodeId,
|
|
||||||
createTitle: this.title
|
|
||||||
},
|
|
||||||
width: `${width}px`
|
width: `${width}px`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
/* tslint:disable:no-input-rename */
|
/* tslint:disable:no-input-rename */
|
||||||
|
|
||||||
import { Component} from '@angular/core';
|
import { Component } from '@angular/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-no-permission-template',
|
selector: 'adf-no-permission-template',
|
||||||
|
@@ -24,7 +24,7 @@ import { PermissionListComponent } from './components/permission-list/permission
|
|||||||
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
|
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
|
||||||
import { InheritPermissionDirective } from './components/inherited-button.directive';
|
import { InheritPermissionDirective } from './components/inherited-button.directive';
|
||||||
import { NodePermissionService } from './services/node-permission.service';
|
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({
|
@NgModule({
|
||||||
imports: [
|
imports: [
|
||||||
|
Reference in New Issue
Block a user