mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-05-12 17:04:46 +00:00
[ACA-1921] Create folder structure from template (#1309)
* update template actions * update template effects * declare menu option * rename dialog component * rename service * update tests * update docs * e2e fix locator * fix translation reference
This commit is contained in:
parent
653be8bbcd
commit
8603d13f71
@ -124,6 +124,6 @@ Below is the list of public actions types you can use in the plugin definitions
|
|||||||
| 1.8.0 | VIEW_NODE | NodeId<`string`> , [ViewNodeExtras](../features/file-viewer.md#details)<`any`> | Lightweight preview of a node by id. Can be invoked from extensions. For details also see [File Viewer](../features/file-viewer.md#details) |
|
| 1.8.0 | VIEW_NODE | NodeId<`string`> , [ViewNodeExtras](../features/file-viewer.md#details)<`any`> | Lightweight preview of a node by id. Can be invoked from extensions. For details also see [File Viewer](../features/file-viewer.md#details) |
|
||||||
| 1.8.0 | CLOSE_PREVIEW | n/a | Closes the viewer ( preview of the item ) |
|
| 1.8.0 | CLOSE_PREVIEW | n/a | Closes the viewer ( preview of the item ) |
|
||||||
| 1.9.0 | RESET_SELECTION | n/a | Resets active document list selection |
|
| 1.9.0 | RESET_SELECTION | n/a | Resets active document list selection |
|
||||||
| 1.10.0 | FILE_FROM_TEMPLATE | n/a | Invoke dialogs flow for creating a file from selected template|
|
| 1.10.0 | FILE_FROM_TEMPLATE | n/a | Invoke dialogs flow for creating a file from a template into current folder |
|
||||||
| 1.10.0 | CREATE_FILE_FROM_TEMPLATE | Node | Copy selected template into current folder |
|
| 1.10.0 | FOLDER_FROM_TEMPLATE | n/a | Invoke dialogs flow for creating a folder structure from a template into current folder |
|
||||||
| 1.10.0 | CONTEXT_MENU | MouseEvent | Invoke context menu for [DocumentListComponent](https://www.alfresco.com/abn/adf/docs/content-services/components/document-list.component) |
|
| 1.10.0 | CONTEXT_MENU | MouseEvent | Invoke context menu for [DocumentListComponent](https://www.alfresco.com/abn/adf/docs/content-services/components/document-list.component) |
|
||||||
|
@ -29,7 +29,7 @@ import { Component } from '../component';
|
|||||||
|
|
||||||
export class CreateFromTemplateDialog extends Component {
|
export class CreateFromTemplateDialog extends Component {
|
||||||
private static selectors = {
|
private static selectors = {
|
||||||
root: '.aca-file-from-template-dialog',
|
root: '.aca-create-from-template-dialog',
|
||||||
|
|
||||||
title: '.mat-dialog-title',
|
title: '.mat-dialog-title',
|
||||||
nameInput: 'input[placeholder="Name" i]',
|
nameInput: 'input[placeholder="Name" i]',
|
||||||
|
@ -28,7 +28,9 @@ import { Node } from '@alfresco/js-api';
|
|||||||
|
|
||||||
export enum TemplateActionTypes {
|
export enum TemplateActionTypes {
|
||||||
FileFromTemplate = 'FILE_FROM_TEMPLATE',
|
FileFromTemplate = 'FILE_FROM_TEMPLATE',
|
||||||
CreateFileFromTemplate = 'CREATE_FILE_FROM_TEMPLATE'
|
FolderFromTemplate = 'FOLDER_FROM_TEMPLATE',
|
||||||
|
CreateFromTemplate = 'CREATE_FROM_TEMPLATE',
|
||||||
|
CreateFromTemplateSuccess = 'CREATE_FROM_TEMPLATE_SUCCESS'
|
||||||
}
|
}
|
||||||
|
|
||||||
export class FileFromTemplate implements Action {
|
export class FileFromTemplate implements Action {
|
||||||
@ -37,8 +39,20 @@ export class FileFromTemplate implements Action {
|
|||||||
constructor() {}
|
constructor() {}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CreateFileFromTemplate implements Action {
|
export class FolderFromTemplate implements Action {
|
||||||
readonly type = TemplateActionTypes.CreateFileFromTemplate;
|
readonly type = TemplateActionTypes.FolderFromTemplate;
|
||||||
|
|
||||||
|
constructor() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
export class CreateFromTemplate implements Action {
|
||||||
|
readonly type = TemplateActionTypes.CreateFromTemplate;
|
||||||
|
|
||||||
constructor(public payload: Node) {}
|
constructor(public payload: Node) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class CreateFromTemplateSuccess implements Action {
|
||||||
|
readonly type = TemplateActionTypes.CreateFromTemplateSuccess;
|
||||||
|
|
||||||
|
constructor(public node: Node) {}
|
||||||
|
}
|
||||||
|
@ -76,7 +76,7 @@ import { AppNodeVersionModule } from './components/node-version/node-version.mod
|
|||||||
import { FavoritesComponent } from './components/favorites/favorites.component';
|
import { FavoritesComponent } from './components/favorites/favorites.component';
|
||||||
import { RecentFilesComponent } from './components/recent-files/recent-files.component';
|
import { RecentFilesComponent } from './components/recent-files/recent-files.component';
|
||||||
import { SharedFilesComponent } from './components/shared-files/shared-files.component';
|
import { SharedFilesComponent } from './components/shared-files/shared-files.component';
|
||||||
import { CreateFileFromTemplateDialogComponent } from './dialogs/node-templates/create-from-template.dialog';
|
import { CreateFromTemplateDialogComponent } from './dialogs/node-template/create-from-template.dialog';
|
||||||
import { environment } from '../environments/environment';
|
import { environment } from '../environments/environment';
|
||||||
|
|
||||||
import { registerLocaleData } from '@angular/common';
|
import { registerLocaleData } from '@angular/common';
|
||||||
@ -159,7 +159,7 @@ registerLocaleData(localeSv);
|
|||||||
FavoritesComponent,
|
FavoritesComponent,
|
||||||
RecentFilesComponent,
|
RecentFilesComponent,
|
||||||
SharedFilesComponent,
|
SharedFilesComponent,
|
||||||
CreateFileFromTemplateDialogComponent
|
CreateFromTemplateDialogComponent
|
||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: RouteReuseStrategy, useClass: AppRouteReuseStrategy },
|
{ provide: RouteReuseStrategy, useClass: AppRouteReuseStrategy },
|
||||||
@ -177,7 +177,7 @@ registerLocaleData(localeSv);
|
|||||||
NodeVersionsDialogComponent,
|
NodeVersionsDialogComponent,
|
||||||
NodeVersionUploadDialogComponent,
|
NodeVersionUploadDialogComponent,
|
||||||
LibraryDialogComponent,
|
LibraryDialogComponent,
|
||||||
CreateFileFromTemplateDialogComponent
|
CreateFromTemplateDialogComponent
|
||||||
],
|
],
|
||||||
bootstrap: [AppComponent]
|
bootstrap: [AppComponent]
|
||||||
})
|
})
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
<h2
|
<h2 mat-dialog-title [innerHTML]="title()"></h2>
|
||||||
mat-dialog-title
|
|
||||||
[innerHTML]="'FILE_FROM_TEMPLATE.TITLE' | translate: { template: data.name } "
|
|
||||||
></h2>
|
|
||||||
<div mat-dialog-content>
|
<div mat-dialog-content>
|
||||||
<form [formGroup]="form" novalidate>
|
<form [formGroup]="form" novalidate>
|
||||||
<mat-form-field class="adf-full-width">
|
<mat-form-field class="adf-full-width">
|
||||||
<input
|
<input
|
||||||
cdkFocusInitial
|
cdkFocusInitial
|
||||||
placeholder="{{ 'FILE_FROM_TEMPLATE.FORM.PLACEHOLDER.NAME' | translate }}"
|
placeholder="{{ 'NODE_FROM_TEMPLATE.FORM.PLACEHOLDER.NAME' | translate }}"
|
||||||
matInput
|
matInput
|
||||||
formControlName="name"
|
formControlName="name"
|
||||||
required
|
required
|
||||||
@ -20,33 +17,33 @@
|
|||||||
|
|
||||||
<mat-form-field class="adf-full-width">
|
<mat-form-field class="adf-full-width">
|
||||||
<input
|
<input
|
||||||
placeholder="{{ 'FILE_FROM_TEMPLATE.FORM.PLACEHOLDER.TITLE' | translate }}"
|
placeholder="{{ 'NODE_FROM_TEMPLATE.FORM.PLACEHOLDER.TITLE' | translate }}"
|
||||||
matInput
|
matInput
|
||||||
formControlName="title"
|
formControlName="title"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<mat-error *ngIf="form.controls['title'].hasError('maxlength')">
|
<mat-error *ngIf="form.controls['title'].hasError('maxlength')">
|
||||||
{{ 'FILE_FROM_TEMPLATE.FORM.ERRORS.TITLE_TOO_LONG' | translate }}
|
{{ 'NODE_FROM_TEMPLATE.FORM.ERRORS.TITLE_TOO_LONG' | translate }}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
|
|
||||||
<mat-form-field class="adf-full-width">
|
<mat-form-field class="adf-full-width">
|
||||||
<textarea
|
<textarea
|
||||||
matInput
|
matInput
|
||||||
placeholder="{{ 'FILE_FROM_TEMPLATE.FORM.PLACEHOLDER.DESCRIPTION' | translate }}"
|
placeholder="{{ 'NODE_FROM_TEMPLATE.FORM.PLACEHOLDER.DESCRIPTION' | translate }}"
|
||||||
rows="2"
|
rows="2"
|
||||||
formControlName="description"
|
formControlName="description"
|
||||||
></textarea>
|
></textarea>
|
||||||
|
|
||||||
<mat-error *ngIf="form.controls['description'].hasError('maxlength')">
|
<mat-error *ngIf="form.controls['description'].hasError('maxlength')">
|
||||||
{{ 'FILE_FROM_TEMPLATE.FORM.ERRORS.DESCRIPTION_TOO_LONG' | translate }}
|
{{ 'NODE_FROM_TEMPLATE.FORM.ERRORS.DESCRIPTION_TOO_LONG' | translate }}
|
||||||
</mat-error>
|
</mat-error>
|
||||||
</mat-form-field>
|
</mat-form-field>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div mat-dialog-actions>
|
<div mat-dialog-actions>
|
||||||
<button mat-button mat-dialog-close>
|
<button mat-button mat-dialog-close>
|
||||||
{{ 'FILE_FROM_TEMPLATE.CANCEL' | translate }}
|
{{ 'NODE_FROM_TEMPLATE.CANCEL' | translate }}
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
class="create"
|
class="create"
|
||||||
@ -54,6 +51,6 @@
|
|||||||
mat-button
|
mat-button
|
||||||
(click)="onSubmit()"
|
(click)="onSubmit()"
|
||||||
>
|
>
|
||||||
{{ 'FILE_FROM_TEMPLATE.CREATE' | translate }}
|
{{ 'NODE_FROM_TEMPLATE.CREATE' | translate }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
@ -1,10 +1,10 @@
|
|||||||
@mixin app-create-file-from-template-theme($theme) {
|
@mixin app-create-from-template-theme($theme) {
|
||||||
$primary: map-get($theme, primary);
|
$primary: map-get($theme, primary);
|
||||||
$accent: map-get($theme, accent);
|
$accent: map-get($theme, accent);
|
||||||
$foreground: map-get($theme, foreground);
|
$foreground: map-get($theme, foreground);
|
||||||
$background: map-get($theme, background);
|
$background: map-get($theme, background);
|
||||||
|
|
||||||
.aca-file-from-template-dialog {
|
.aca-create-from-template-dialog {
|
||||||
ng-component {
|
ng-component {
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
}
|
}
|
@ -23,19 +23,18 @@
|
|||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { CreateFileFromTemplateDialogComponent } from './create-from-template.dialog';
|
import { CreateFromTemplateDialogComponent } from './create-from-template.dialog';
|
||||||
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
import { TestBed, ComponentFixture } from '@angular/core/testing';
|
||||||
import { AppTestingModule } from '../../testing/app-testing.module';
|
import { AppTestingModule } from '../../testing/app-testing.module';
|
||||||
import { CoreModule } from '@alfresco/adf-core';
|
import { CoreModule, TranslationMock } from '@alfresco/adf-core';
|
||||||
import {
|
import {
|
||||||
MatDialogModule,
|
MatDialogModule,
|
||||||
MatDialogRef,
|
MAT_DIALOG_DATA,
|
||||||
MAT_DIALOG_DATA
|
MatDialogRef
|
||||||
} from '@angular/material/dialog';
|
} from '@angular/material/dialog';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { CreateFileFromTemplate } from '@alfresco/aca-shared/store';
|
import { CreateFromTemplate } from '@alfresco/aca-shared/store';
|
||||||
import { Node } from '@alfresco/js-api';
|
import { Node } from '@alfresco/js-api';
|
||||||
import { CreateFromTemplateDialogService } from './create-from-template-dialog.service';
|
|
||||||
|
|
||||||
function text(length: number) {
|
function text(length: number) {
|
||||||
return new Array(length)
|
return new Array(length)
|
||||||
@ -48,15 +47,15 @@ function text(length: number) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
describe('CreateFileFromTemplateDialogComponent', () => {
|
describe('CreateFileFromTemplateDialogComponent', () => {
|
||||||
let fixture: ComponentFixture<CreateFileFromTemplateDialogComponent>;
|
let fixture: ComponentFixture<CreateFromTemplateDialogComponent>;
|
||||||
let component: CreateFileFromTemplateDialogComponent;
|
let component: CreateFromTemplateDialogComponent;
|
||||||
let dialogRef: MatDialogRef<CreateFileFromTemplateDialogComponent>;
|
|
||||||
let store;
|
let store;
|
||||||
let createFromTemplateDialogService: CreateFromTemplateDialogService;
|
|
||||||
|
|
||||||
const data = {
|
const data = {
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
name: 'node-name',
|
name: 'node-name',
|
||||||
|
isFolder: false,
|
||||||
|
isFile: true,
|
||||||
properties: {
|
properties: {
|
||||||
'cm:title': 'node-title',
|
'cm:title': 'node-title',
|
||||||
'cm:description': ''
|
'cm:description': ''
|
||||||
@ -66,36 +65,39 @@ describe('CreateFileFromTemplateDialogComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [CoreModule.forRoot(), AppTestingModule, MatDialogModule],
|
imports: [CoreModule.forRoot(), AppTestingModule, MatDialogModule],
|
||||||
declarations: [CreateFileFromTemplateDialogComponent],
|
declarations: [CreateFromTemplateDialogComponent],
|
||||||
providers: [
|
providers: [
|
||||||
|
{
|
||||||
|
provide: MatDialogRef,
|
||||||
|
useValue: {
|
||||||
|
close: jasmine.createSpy('close')
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
provide: TranslationMock,
|
||||||
|
useValue: {
|
||||||
|
instant: jasmine.createSpy('instant')
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
provide: Store,
|
provide: Store,
|
||||||
useValue: {
|
useValue: {
|
||||||
dispatch: jasmine.createSpy('dispatch')
|
dispatch: jasmine.createSpy('dispatch')
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ provide: MAT_DIALOG_DATA, useValue: data },
|
{ provide: MAT_DIALOG_DATA, useValue: {} }
|
||||||
{
|
|
||||||
provide: MatDialogRef,
|
|
||||||
useValue: {
|
|
||||||
close: jasmine.createSpy('close')
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
fixture = TestBed.createComponent(CreateFileFromTemplateDialogComponent);
|
fixture = TestBed.createComponent(CreateFromTemplateDialogComponent);
|
||||||
dialogRef = TestBed.get(MatDialogRef);
|
|
||||||
store = TestBed.get(Store);
|
store = TestBed.get(Store);
|
||||||
createFromTemplateDialogService = TestBed.get(
|
|
||||||
CreateFromTemplateDialogService
|
|
||||||
);
|
|
||||||
component = fixture.componentInstance;
|
component = fixture.componentInstance;
|
||||||
|
component.data = data as Node;
|
||||||
fixture.detectChanges();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should populate form with provided dialog data', () => {
|
it('should populate form with provided dialog data', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.form.controls.name.value).toBe(data.name);
|
expect(component.form.controls.name.value).toBe(data.name);
|
||||||
expect(component.form.controls.title.value).toBe(
|
expect(component.form.controls.title.value).toBe(
|
||||||
data.properties['cm:title']
|
data.properties['cm:title']
|
||||||
@ -106,32 +108,47 @@ describe('CreateFileFromTemplateDialogComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should invalidate form if required `name` field is invalid', () => {
|
it('should invalidate form if required `name` field is invalid', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls.name.setValue('');
|
component.form.controls.name.setValue('');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.form.invalid).toBe(true);
|
expect(component.form.invalid).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invalidate form if required `name` field has `only spaces`', () => {
|
it('should invalidate form if required `name` field has `only spaces`', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls.name.setValue(' ');
|
component.form.controls.name.setValue(' ');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.form.invalid).toBe(true);
|
expect(component.form.invalid).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invalidate form if required `name` field has `ending dot`', () => {
|
it('should invalidate form if required `name` field has `ending dot`', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls.name.setValue('something.');
|
component.form.controls.name.setValue('something.');
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.form.invalid).toBe(true);
|
expect(component.form.invalid).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invalidate form if `title` text length is long', () => {
|
it('should invalidate form if `title` text length is long', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls.title.setValue(text(260));
|
component.form.controls.title.setValue(text(260));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.form.invalid).toBe(true);
|
expect(component.form.invalid).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should invalidate form if `description` text length is long', () => {
|
it('should invalidate form if `description` text length is long', () => {
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls.description.setValue(text(520));
|
component.form.controls.description.setValue(text(520));
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
|
|
||||||
expect(component.form.invalid).toBe(true);
|
expect(component.form.invalid).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -139,11 +156,16 @@ describe('CreateFileFromTemplateDialogComponent', () => {
|
|||||||
const newNode = {
|
const newNode = {
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
name: 'new-node-name',
|
name: 'new-node-name',
|
||||||
|
isFolder: false,
|
||||||
|
isFile: true,
|
||||||
properties: {
|
properties: {
|
||||||
'cm:title': 'new-node-title',
|
'cm:title': 'new-node-title',
|
||||||
'cm:description': 'new-node-description'
|
'cm:description': 'new-node-description'
|
||||||
}
|
}
|
||||||
} as Node;
|
} as Node;
|
||||||
|
|
||||||
|
fixture.detectChanges();
|
||||||
|
|
||||||
component.form.controls.name.setValue('new-node-name');
|
component.form.controls.name.setValue('new-node-name');
|
||||||
component.form.controls.title.setValue('new-node-title');
|
component.form.controls.title.setValue('new-node-title');
|
||||||
component.form.controls.description.setValue('new-node-description');
|
component.form.controls.description.setValue('new-node-description');
|
||||||
@ -152,27 +174,8 @@ describe('CreateFileFromTemplateDialogComponent', () => {
|
|||||||
|
|
||||||
component.onSubmit();
|
component.onSubmit();
|
||||||
|
|
||||||
expect(store.dispatch).toHaveBeenCalledWith(
|
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(
|
||||||
new CreateFileFromTemplate(newNode)
|
new CreateFromTemplate(newNode)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should close dialog on create file from template success', done => {
|
|
||||||
const newNode = {
|
|
||||||
id: 'node-id',
|
|
||||||
name: 'new-node-name',
|
|
||||||
properties: {
|
|
||||||
'cm:title': 'new-node-title',
|
|
||||||
'cm:description': 'new-node-description'
|
|
||||||
}
|
|
||||||
} as Node;
|
|
||||||
|
|
||||||
fixture.detectChanges();
|
|
||||||
createFromTemplateDialogService.success$.subscribe(node => {
|
|
||||||
expect(dialogRef.close).toHaveBeenCalledWith(node);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
|
|
||||||
createFromTemplateDialogService.success$.next(newNode);
|
|
||||||
});
|
|
||||||
});
|
});
|
@ -33,31 +33,27 @@ import {
|
|||||||
FormControl,
|
FormControl,
|
||||||
ValidationErrors
|
ValidationErrors
|
||||||
} from '@angular/forms';
|
} from '@angular/forms';
|
||||||
import { CreateFromTemplateDialogService } from './create-from-template-dialog.service';
|
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import { AppStore, CreateFileFromTemplate } from '@alfresco/aca-shared/store';
|
import { AppStore, CreateFromTemplate } from '@alfresco/aca-shared/store';
|
||||||
|
import { TranslationService } from '@alfresco/adf-core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: './create-from-template.dialog.html',
|
templateUrl: './create-from-template.dialog.html',
|
||||||
encapsulation: ViewEncapsulation.None,
|
encapsulation: ViewEncapsulation.None,
|
||||||
styleUrls: ['./create-from-template.dialog.scss']
|
styleUrls: ['./create-from-template.dialog.scss']
|
||||||
})
|
})
|
||||||
export class CreateFileFromTemplateDialogComponent implements OnInit {
|
export class CreateFromTemplateDialogComponent implements OnInit {
|
||||||
public form: FormGroup;
|
public form: FormGroup;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private createFromTemplateDialogService: CreateFromTemplateDialogService,
|
private translationService: TranslationService,
|
||||||
private store: Store<AppStore>,
|
private store: Store<AppStore>,
|
||||||
private formBuilder: FormBuilder,
|
private formBuilder: FormBuilder,
|
||||||
private dialogRef: MatDialogRef<CreateFileFromTemplateDialogComponent>,
|
private dialogRef: MatDialogRef<CreateFromTemplateDialogComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: any
|
@Inject(MAT_DIALOG_DATA) public data: Node
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
this.createFromTemplateDialogService.success$.subscribe((data: Node) => {
|
|
||||||
this.dialogRef.close(data);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.form = this.formBuilder.group({
|
this.form = this.formBuilder.group({
|
||||||
name: [
|
name: [
|
||||||
this.data.name,
|
this.data.name,
|
||||||
@ -85,7 +81,21 @@ export class CreateFileFromTemplateDialogComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const data: Node = Object.assign({}, this.data, update);
|
const data: Node = Object.assign({}, this.data, update);
|
||||||
this.store.dispatch(new CreateFileFromTemplate(data));
|
this.store.dispatch(new CreateFromTemplate(data));
|
||||||
|
}
|
||||||
|
|
||||||
|
title(): string {
|
||||||
|
if (this.data.isFolder) {
|
||||||
|
return this.translationService.instant(
|
||||||
|
'NODE_FROM_TEMPLATE.FOLDER_DIALOG_TITLE',
|
||||||
|
{ template: this.data.name }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.translationService.instant(
|
||||||
|
'NODE_FROM_TEMPLATE.FILE_DIALOG_TITLE',
|
||||||
|
{ template: this.data.name }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
close() {
|
close() {
|
||||||
@ -101,7 +111,7 @@ export class CreateFileFromTemplateDialogComponent implements OnInit {
|
|||||||
return isValid
|
return isValid
|
||||||
? null
|
? null
|
||||||
: {
|
: {
|
||||||
message: `FILE_FROM_TEMPLATE.FORM.ERRORS.SPECIAL_CHARACTERS`
|
message: `NODE_FROM_TEMPLATE.FORM.ERRORS.SPECIAL_CHARACTERS`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,7 +125,7 @@ export class CreateFileFromTemplateDialogComponent implements OnInit {
|
|||||||
return isValid
|
return isValid
|
||||||
? null
|
? null
|
||||||
: {
|
: {
|
||||||
message: `FILE_FROM_TEMPLATE.FORM.ERRORS.ENDING_DOT`
|
message: `NODE_FROM_TEMPLATE.FORM.ERRORS.ENDING_DOT`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -126,11 +136,11 @@ export class CreateFileFromTemplateDialogComponent implements OnInit {
|
|||||||
return isValid
|
return isValid
|
||||||
? null
|
? null
|
||||||
: {
|
: {
|
||||||
message: `FILE_FROM_TEMPLATE.FORM.ERRORS.ONLY_SPACES`
|
message: `NODE_FROM_TEMPLATE.FORM.ERRORS.ONLY_SPACES`
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
message: `FILE_FROM_TEMPLATE.FORM.ERRORS.REQUIRED`
|
message: `NODE_FROM_TEMPLATE.FORM.ERRORS.REQUIRED`
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,35 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Alfresco Example Content Application
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
|
||||||
*
|
|
||||||
* This file is part of the Alfresco Example Content Application.
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
|
||||||
import { Subject } from 'rxjs';
|
|
||||||
import { Node } from '@alfresco/js-api';
|
|
||||||
|
|
||||||
@Injectable({
|
|
||||||
providedIn: 'root'
|
|
||||||
})
|
|
||||||
export class CreateFromTemplateDialogService {
|
|
||||||
success$: Subject<Node> = new Subject();
|
|
||||||
}
|
|
@ -1,204 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Alfresco Example Content Application
|
|
||||||
*
|
|
||||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
|
||||||
*
|
|
||||||
* This file is part of the Alfresco Example Content Application.
|
|
||||||
* If the software was purchased under a paid Alfresco license, the terms of
|
|
||||||
* the paid license agreement will prevail. Otherwise, the software is
|
|
||||||
* provided under the following open source license terms:
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
|
||||||
* it under the terms of the GNU Lesser General Public License as published by
|
|
||||||
* the Free Software Foundation, either version 3 of the License, or
|
|
||||||
* (at your option) any later version.
|
|
||||||
*
|
|
||||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU Lesser General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU Lesser General Public License
|
|
||||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
|
|
||||||
import { EffectsModule } from '@ngrx/effects';
|
|
||||||
import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/store';
|
|
||||||
import { TemplateEffects } from '../store/effects/template.effects';
|
|
||||||
import { AppTestingModule } from '../testing/app-testing.module';
|
|
||||||
import { Store } from '@ngrx/store';
|
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
|
||||||
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
|
||||||
import { CreateFileFromTemplateService } from './create-file-from-template.service';
|
|
||||||
import { of } from 'rxjs';
|
|
||||||
|
|
||||||
describe('CreateFileFromTemplateService', () => {
|
|
||||||
let dialog: MatDialog;
|
|
||||||
let store: Store<AppStore>;
|
|
||||||
let alfrescoApiService: AlfrescoApiService;
|
|
||||||
let createFileFromTemplateService: CreateFileFromTemplateService;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
TestBed.configureTestingModule({
|
|
||||||
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])],
|
|
||||||
providers: [
|
|
||||||
CreateFileFromTemplateService,
|
|
||||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
store = TestBed.get(Store);
|
|
||||||
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
|
||||||
dialog = TestBed.get(MatDialog);
|
|
||||||
createFileFromTemplateService = TestBed.get(CreateFileFromTemplateService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should open dialog with `Node Templates` folder id as data property', () => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(of({ id: 'templates-folder-id' }));
|
|
||||||
spyOn(dialog, 'open');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
|
|
||||||
expect(dialog.open['calls'].argsFor(0)[1].data).toEqual(
|
|
||||||
jasmine.objectContaining({ currentFolderId: 'templates-folder-id' })
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should remove parents for templates node breadcrumb path', () => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(
|
|
||||||
of({
|
|
||||||
id: 'templates-folder-id',
|
|
||||||
path: {
|
|
||||||
elements: [],
|
|
||||||
name: '/Company Home/Data Dictionary'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
spyOn(dialog, 'open');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
|
|
||||||
const breadcrumb = dialog.open['calls']
|
|
||||||
.argsFor(0)[1]
|
|
||||||
.data.breadcrumbTransform({
|
|
||||||
name: 'Node Templates',
|
|
||||||
path: {
|
|
||||||
elements: [{ name: 'Company Home' }, { name: 'Data Dictionary' }],
|
|
||||||
name: '/Company Home/Data Dictionary'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(breadcrumb.path.elements).toEqual([]);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if selected node is not a template file', () => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(of({ id: 'templates-folder-id' }));
|
|
||||||
spyOn(dialog, 'open');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
|
|
||||||
const isSelectionValid = dialog.open['calls']
|
|
||||||
.argsFor(0)[1]
|
|
||||||
.data.isSelectionValid({
|
|
||||||
isFile: false
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(isSelectionValid).toBe(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true if selected node is a template file', () => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(of({ id: 'templates-folder-id' }));
|
|
||||||
spyOn(dialog, 'open');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
|
|
||||||
const isSelectionValid = dialog.open['calls']
|
|
||||||
.argsFor(0)[1]
|
|
||||||
.data.isSelectionValid({
|
|
||||||
isFile: true
|
|
||||||
});
|
|
||||||
|
|
||||||
expect(isSelectionValid).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should raise an error when getNodeInfo fails', fakeAsync(() => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(
|
|
||||||
Promise.reject({
|
|
||||||
message: `{ "error": { "statusCode": 404 } } `
|
|
||||||
})
|
|
||||||
);
|
|
||||||
spyOn(store, 'dispatch');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
tick();
|
|
||||||
|
|
||||||
expect(store.dispatch).toHaveBeenCalledWith(
|
|
||||||
new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
|
|
||||||
);
|
|
||||||
}));
|
|
||||||
|
|
||||||
it('should return true if row is not a `link` nodeType', () => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(
|
|
||||||
of({
|
|
||||||
id: 'templates-folder-id',
|
|
||||||
path: {
|
|
||||||
elements: [],
|
|
||||||
name: '/Company Home/Data Dictionary'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
spyOn(dialog, 'open');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
|
|
||||||
expect(
|
|
||||||
dialog.open['calls'].argsFor(0)[1].data.rowFilter({
|
|
||||||
node: { entry: { nodeType: 'text' } }
|
|
||||||
})
|
|
||||||
).toBe(true);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false if row is a `link` nodeType', () => {
|
|
||||||
spyOn(
|
|
||||||
alfrescoApiService.getInstance().nodes,
|
|
||||||
'getNodeInfo'
|
|
||||||
).and.returnValue(
|
|
||||||
of({
|
|
||||||
id: 'templates-folder-id',
|
|
||||||
path: {
|
|
||||||
elements: [],
|
|
||||||
name: '/Company Home/Data Dictionary'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
);
|
|
||||||
spyOn(dialog, 'open');
|
|
||||||
|
|
||||||
createFileFromTemplateService.openTemplatesDialog();
|
|
||||||
|
|
||||||
expect(
|
|
||||||
dialog.open['calls'].argsFor(0)[1].data.rowFilter({
|
|
||||||
node: { entry: { nodeType: 'app:filelink' } }
|
|
||||||
})
|
|
||||||
).toBe(false);
|
|
||||||
});
|
|
||||||
});
|
|
308
src/app/services/node-template.service.spec.ts
Normal file
308
src/app/services/node-template.service.spec.ts
Normal file
@ -0,0 +1,308 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Alfresco Example Content Application
|
||||||
|
*
|
||||||
|
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||||
|
*
|
||||||
|
* This file is part of the Alfresco Example Content Application.
|
||||||
|
* If the software was purchased under a paid Alfresco license, the terms of
|
||||||
|
* the paid license agreement will prevail. Otherwise, the software is
|
||||||
|
* provided under the following open source license terms:
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Lesser General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public License
|
||||||
|
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import { TestBed, fakeAsync, tick } from '@angular/core/testing';
|
||||||
|
import { EffectsModule } from '@ngrx/effects';
|
||||||
|
import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/store';
|
||||||
|
import { TemplateEffects } from '../store/effects/template.effects';
|
||||||
|
import { AppTestingModule } from '../testing/app-testing.module';
|
||||||
|
import { Store } from '@ngrx/store';
|
||||||
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
import { AlfrescoApiService, AlfrescoApiServiceMock } from '@alfresco/adf-core';
|
||||||
|
import { NodeTemplateService } from './node-template.service';
|
||||||
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
|
describe('NodeTemplateService', () => {
|
||||||
|
let dialog: MatDialog;
|
||||||
|
let store: Store<AppStore>;
|
||||||
|
let alfrescoApiService: AlfrescoApiService;
|
||||||
|
let nodeTemplateService: NodeTemplateService;
|
||||||
|
const fileTemplateConfig = {
|
||||||
|
relativePath: 'relative-path/parent-file-templates',
|
||||||
|
selectionType: 'file'
|
||||||
|
};
|
||||||
|
const folderTemplateConfig = {
|
||||||
|
relativePath: 'relative-path/parent-folder-templates',
|
||||||
|
selectionType: 'folder'
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
TestBed.configureTestingModule({
|
||||||
|
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])],
|
||||||
|
providers: [
|
||||||
|
NodeTemplateService,
|
||||||
|
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
|
||||||
|
]
|
||||||
|
});
|
||||||
|
|
||||||
|
store = TestBed.get(Store);
|
||||||
|
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||||
|
dialog = TestBed.get(MatDialog);
|
||||||
|
nodeTemplateService = TestBed.get(NodeTemplateService);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should open dialog with parent node `id` as data property', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'parent-node-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
expect(dialog.open['calls'].argsFor(0)[1].data).toEqual(
|
||||||
|
jasmine.objectContaining({ currentFolderId: 'parent-node-id' })
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should remove parents for templates node breadcrumb path', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(
|
||||||
|
of({
|
||||||
|
id: 'parent-node-id',
|
||||||
|
path: {
|
||||||
|
elements: [],
|
||||||
|
name: '/Company Home/Data Dictionary'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
const breadcrumb = dialog.open['calls']
|
||||||
|
.argsFor(0)[1]
|
||||||
|
.data.breadcrumbTransform({
|
||||||
|
name: 'Node Templates',
|
||||||
|
path: {
|
||||||
|
elements: [{ name: 'Company Home' }, { name: 'Data Dictionary' }],
|
||||||
|
name: '/Company Home/Data Dictionary'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(breadcrumb.path.elements).toEqual([]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should raise an error when getNodeInfo fails', fakeAsync(() => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(
|
||||||
|
Promise.reject({
|
||||||
|
message: `{ "error": { "statusCode": 404 } } `
|
||||||
|
})
|
||||||
|
);
|
||||||
|
spyOn(store, 'dispatch');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
tick();
|
||||||
|
|
||||||
|
expect(store.dispatch).toHaveBeenCalledWith(
|
||||||
|
new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should return true if row is not a `link` nodeType', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(
|
||||||
|
of({
|
||||||
|
id: 'templates-folder-id',
|
||||||
|
path: {
|
||||||
|
elements: [],
|
||||||
|
name: '/Company Home/Data Dictionary'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
dialog.open['calls'].argsFor(0)[1].data.rowFilter({
|
||||||
|
node: { entry: { nodeType: 'text' } }
|
||||||
|
})
|
||||||
|
).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if row is a `link` nodeType', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(
|
||||||
|
of({
|
||||||
|
id: 'templates-folder-id',
|
||||||
|
path: {
|
||||||
|
elements: [],
|
||||||
|
name: '/Company Home/Data Dictionary'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
);
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
dialog.open['calls'].argsFor(0)[1].data.rowFilter({
|
||||||
|
node: { entry: { nodeType: 'app:filelink' } }
|
||||||
|
})
|
||||||
|
).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('File templates', () => {
|
||||||
|
it('should return false if selected node is not a file', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
const isSelectionValid = dialog.open['calls']
|
||||||
|
.argsFor(0)[1]
|
||||||
|
.data.isSelectionValid({
|
||||||
|
name: 'some-folder-template',
|
||||||
|
isFile: false,
|
||||||
|
isFolder: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(isSelectionValid).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if selected node is a template file', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
const isSelectionValid = dialog.open['calls']
|
||||||
|
.argsFor(0)[1]
|
||||||
|
.data.isSelectionValid({
|
||||||
|
name: 'some-file-template',
|
||||||
|
isFile: true,
|
||||||
|
isFolder: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(isSelectionValid).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set dialog title for file templates', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(fileTemplateConfig);
|
||||||
|
|
||||||
|
const title = dialog.open['calls'].argsFor(0)[1].data.title;
|
||||||
|
|
||||||
|
expect(title).toBe('NODE_SELECTOR.SELECT_FILE_TEMPLATE_TITLE');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('Folder templates', () => {
|
||||||
|
it('should return false if selected node is not a folder', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(folderTemplateConfig);
|
||||||
|
|
||||||
|
const isSelectionValid = dialog.open['calls']
|
||||||
|
.argsFor(0)[1]
|
||||||
|
.data.isSelectionValid({
|
||||||
|
name: 'some-file-template',
|
||||||
|
isFile: true,
|
||||||
|
isFolder: false
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(isSelectionValid).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return false if current node is the parent folder', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(folderTemplateConfig);
|
||||||
|
|
||||||
|
const isSelectionValid = dialog.open['calls']
|
||||||
|
.argsFor(0)[1]
|
||||||
|
.data.isSelectionValid({
|
||||||
|
name: 'parent-folder-templates',
|
||||||
|
isFile: false,
|
||||||
|
isFolder: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(isSelectionValid).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return true if selected node is a folder template', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(folderTemplateConfig);
|
||||||
|
|
||||||
|
const isSelectionValid = dialog.open['calls']
|
||||||
|
.argsFor(0)[1]
|
||||||
|
.data.isSelectionValid({
|
||||||
|
name: 'some-folder-template',
|
||||||
|
isFile: false,
|
||||||
|
isFolder: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(isSelectionValid).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should set dialog title for folder templates', () => {
|
||||||
|
spyOn(
|
||||||
|
alfrescoApiService.getInstance().nodes,
|
||||||
|
'getNodeInfo'
|
||||||
|
).and.returnValue(of({ id: 'templates-folder-id' }));
|
||||||
|
spyOn(dialog, 'open');
|
||||||
|
|
||||||
|
nodeTemplateService.selectTemplateDialog(folderTemplateConfig);
|
||||||
|
|
||||||
|
const title = dialog.open['calls'].argsFor(0)[1].data.title;
|
||||||
|
|
||||||
|
expect(title).toBe('NODE_SELECTOR.SELECT_FOLDER_TEMPLATE_TITLE');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
|
import { MatDialog, MatDialogConfig, MatDialogRef } from '@angular/material';
|
||||||
import { CreateFileFromTemplateDialogComponent } from '../dialogs/node-templates/create-from-template.dialog';
|
import { CreateFromTemplateDialogComponent } from '../dialogs/node-template/create-from-template.dialog';
|
||||||
import { Subject, from, of } from 'rxjs';
|
import { Subject, from, of } from 'rxjs';
|
||||||
import { Node, MinimalNode, MinimalNodeEntryEntity } from '@alfresco/js-api';
|
import { Node, MinimalNode, MinimalNodeEntryEntity } from '@alfresco/js-api';
|
||||||
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
|
import { AlfrescoApiService, TranslationService } from '@alfresco/adf-core';
|
||||||
@ -38,10 +38,17 @@ import {
|
|||||||
ShareDataRow
|
ShareDataRow
|
||||||
} from '@alfresco/adf-content-services';
|
} from '@alfresco/adf-content-services';
|
||||||
|
|
||||||
|
export interface TemplateDialogConfig {
|
||||||
|
relativePath: string;
|
||||||
|
selectionType: string;
|
||||||
|
}
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
})
|
})
|
||||||
export class CreateFileFromTemplateService {
|
export class NodeTemplateService {
|
||||||
|
private currentTemplateConfig: TemplateDialogConfig = null;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private store: Store<AppStore>,
|
private store: Store<AppStore>,
|
||||||
private alfrescoApiService: AlfrescoApiService,
|
private alfrescoApiService: AlfrescoApiService,
|
||||||
@ -49,14 +56,16 @@ export class CreateFileFromTemplateService {
|
|||||||
public dialog: MatDialog
|
public dialog: MatDialog
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
openTemplatesDialog(): Subject<Node[]> {
|
selectTemplateDialog(config: TemplateDialogConfig): Subject<Node[]> {
|
||||||
|
this.currentTemplateConfig = config;
|
||||||
|
|
||||||
const select = new Subject<Node[]>();
|
const select = new Subject<Node[]>();
|
||||||
select.subscribe({
|
select.subscribe({
|
||||||
complete: this.close.bind(this)
|
complete: this.close.bind(this)
|
||||||
});
|
});
|
||||||
|
|
||||||
const data: ContentNodeSelectorComponentData = {
|
const data: ContentNodeSelectorComponentData = {
|
||||||
title: this.title,
|
title: this.title(config.selectionType),
|
||||||
actionName: 'NEXT',
|
actionName: 'NEXT',
|
||||||
dropdownHideMyFiles: true,
|
dropdownHideMyFiles: true,
|
||||||
currentFolderId: null,
|
currentFolderId: null,
|
||||||
@ -69,7 +78,7 @@ export class CreateFileFromTemplateService {
|
|||||||
|
|
||||||
from(
|
from(
|
||||||
this.alfrescoApiService.getInstance().nodes.getNodeInfo('-root-', {
|
this.alfrescoApiService.getInstance().nodes.getNodeInfo('-root-', {
|
||||||
relativePath: 'Data Dictionary/Node Templates'
|
relativePath: config.relativePath
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
.pipe(
|
.pipe(
|
||||||
@ -100,10 +109,10 @@ export class CreateFileFromTemplateService {
|
|||||||
|
|
||||||
createTemplateDialog(
|
createTemplateDialog(
|
||||||
node: Node
|
node: Node
|
||||||
): MatDialogRef<CreateFileFromTemplateDialogComponent> {
|
): MatDialogRef<CreateFromTemplateDialogComponent> {
|
||||||
return this.dialog.open(CreateFileFromTemplateDialogComponent, {
|
return this.dialog.open(CreateFromTemplateDialogComponent, {
|
||||||
data: node,
|
data: node,
|
||||||
panelClass: 'aca-file-from-template-dialog',
|
panelClass: 'aca-create-from-template-dialog',
|
||||||
width: '630px'
|
width: '630px'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -123,6 +132,14 @@ export class CreateFileFromTemplateService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private isSelectionValid(node: Node): boolean {
|
private isSelectionValid(node: Node): boolean {
|
||||||
|
if (node.name === this.currentTemplateConfig.relativePath.split('/')[1]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.currentTemplateConfig.selectionType === 'folder') {
|
||||||
|
return node.isFolder;
|
||||||
|
}
|
||||||
|
|
||||||
return node.isFile;
|
return node.isFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,8 +147,16 @@ export class CreateFileFromTemplateService {
|
|||||||
this.dialog.closeAll();
|
this.dialog.closeAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
private get title() {
|
private title(selectionType: string) {
|
||||||
return this.translation.instant('NODE_SELECTOR.SELECT_TEMPLATE_TITLE');
|
if (selectionType === 'file') {
|
||||||
|
return this.translation.instant(
|
||||||
|
'NODE_SELECTOR.SELECT_FILE_TEMPLATE_TITLE'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.translation.instant(
|
||||||
|
'NODE_SELECTOR.SELECT_FOLDER_TEMPLATE_TITLE'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private rowFilter(row: ShareDataRow): boolean {
|
private rowFilter(row: ShareDataRow): boolean {
|
@ -29,25 +29,27 @@ import { TemplateEffects } from './template.effects';
|
|||||||
import { EffectsModule } from '@ngrx/effects';
|
import { EffectsModule } from '@ngrx/effects';
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import {
|
import {
|
||||||
CreateFileFromTemplate,
|
CreateFromTemplate,
|
||||||
|
CreateFromTemplateSuccess,
|
||||||
FileFromTemplate,
|
FileFromTemplate,
|
||||||
|
FolderFromTemplate,
|
||||||
SnackbarErrorAction
|
SnackbarErrorAction
|
||||||
} from '@alfresco/aca-shared/store';
|
} from '@alfresco/aca-shared/store';
|
||||||
import { CreateFileFromTemplateService } from '../../services/create-file-from-template.service';
|
import { NodeTemplateService } from '../../services/node-template.service';
|
||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
import { AlfrescoApiServiceMock, AlfrescoApiService } from '@alfresco/adf-core';
|
import { AlfrescoApiServiceMock, AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
import { ContentManagementService } from '../../services/content-management.service';
|
import { ContentManagementService } from '../../services/content-management.service';
|
||||||
import { Node, NodeEntry } from '@alfresco/js-api';
|
import { Node, NodeEntry } from '@alfresco/js-api';
|
||||||
import { CreateFromTemplateDialogService } from '../../dialogs/node-templates/create-from-template-dialog.service';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
|
||||||
describe('TemplateEffects', () => {
|
describe('TemplateEffects', () => {
|
||||||
let store: Store<any>;
|
let store: Store<any>;
|
||||||
let createFileFromTemplateService: CreateFileFromTemplateService;
|
let nodeTemplateService: NodeTemplateService;
|
||||||
let alfrescoApiService: AlfrescoApiService;
|
let alfrescoApiService: AlfrescoApiService;
|
||||||
let contentManagementService: ContentManagementService;
|
let contentManagementService: ContentManagementService;
|
||||||
let createFromTemplateDialogService: CreateFromTemplateDialogService;
|
|
||||||
let copyNodeSpy;
|
let copyNodeSpy;
|
||||||
let updateNodeSpy;
|
let updateNodeSpy;
|
||||||
|
let matDialog: MatDialog;
|
||||||
const node: Node = {
|
const node: Node = {
|
||||||
name: 'node-name',
|
name: 'node-name',
|
||||||
id: 'node-id',
|
id: 'node-id',
|
||||||
@ -63,29 +65,41 @@ describe('TemplateEffects', () => {
|
|||||||
'cm:description': 'description'
|
'cm:description': 'description'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
const fileTemplateConfig = {
|
||||||
|
relativePath: 'Data Dictionary/Node Templates',
|
||||||
|
selectionType: 'file'
|
||||||
|
};
|
||||||
|
|
||||||
|
const folderTemplateConfig = {
|
||||||
|
relativePath: 'Data Dictionary/Space Templates',
|
||||||
|
selectionType: 'folder'
|
||||||
|
};
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])],
|
imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])],
|
||||||
providers: [
|
providers: [
|
||||||
CreateFileFromTemplateService,
|
NodeTemplateService,
|
||||||
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
|
{ provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock },
|
||||||
|
{
|
||||||
|
provide: MatDialog,
|
||||||
|
useValue: {
|
||||||
|
closeAll: jasmine.createSpy('closeAll')
|
||||||
|
}
|
||||||
|
}
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
|
|
||||||
store = TestBed.get(Store);
|
store = TestBed.get(Store);
|
||||||
createFileFromTemplateService = TestBed.get(CreateFileFromTemplateService);
|
nodeTemplateService = TestBed.get(NodeTemplateService);
|
||||||
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
alfrescoApiService = TestBed.get(AlfrescoApiService);
|
||||||
createFromTemplateDialogService = TestBed.get(
|
|
||||||
CreateFromTemplateDialogService
|
|
||||||
);
|
|
||||||
contentManagementService = TestBed.get(ContentManagementService);
|
contentManagementService = TestBed.get(ContentManagementService);
|
||||||
|
matDialog = TestBed.get(MatDialog);
|
||||||
|
|
||||||
spyOn(store, 'dispatch').and.callThrough();
|
spyOn(store, 'dispatch').and.callThrough();
|
||||||
spyOn(createFromTemplateDialogService.success$, 'next');
|
|
||||||
spyOn(contentManagementService.reload, 'next');
|
spyOn(contentManagementService.reload, 'next');
|
||||||
spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
|
spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
|
||||||
spyOn(createFileFromTemplateService, 'openTemplatesDialog').and.returnValue(
|
spyOn(nodeTemplateService, 'selectTemplateDialog').and.returnValue(
|
||||||
of([{ id: 'template-id' }])
|
of([{ id: 'template-id' }])
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -98,41 +112,43 @@ describe('TemplateEffects', () => {
|
|||||||
updateNodeSpy.calls.reset();
|
updateNodeSpy.calls.reset();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should reload content on create file from template', fakeAsync(() => {
|
it('should open dialog to select template files', fakeAsync(() => {
|
||||||
spyOn(
|
spyOn(nodeTemplateService, 'createTemplateDialog').and.returnValue({
|
||||||
createFileFromTemplateService,
|
afterClosed: () => of(node)
|
||||||
'createTemplateDialog'
|
});
|
||||||
).and.returnValue({ afterClosed: () => of(node) });
|
|
||||||
|
|
||||||
store.dispatch(new FileFromTemplate());
|
store.dispatch(new FileFromTemplate());
|
||||||
tick(300);
|
tick();
|
||||||
|
|
||||||
expect(contentManagementService.reload.next).toHaveBeenCalled();
|
expect(nodeTemplateService.selectTemplateDialog).toHaveBeenCalledWith(
|
||||||
|
fileTemplateConfig
|
||||||
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should not reload content if no file was created', fakeAsync(() => {
|
it('should open dialog to select template folders', fakeAsync(() => {
|
||||||
spyOn(
|
spyOn(nodeTemplateService, 'createTemplateDialog').and.returnValue({
|
||||||
createFileFromTemplateService,
|
afterClosed: () => of(node)
|
||||||
'createTemplateDialog'
|
});
|
||||||
).and.returnValue({ afterClosed: () => of(null) });
|
|
||||||
|
|
||||||
store.dispatch(new FileFromTemplate());
|
store.dispatch(new FolderFromTemplate());
|
||||||
tick(300);
|
tick();
|
||||||
|
|
||||||
expect(contentManagementService.reload.next).not.toHaveBeenCalled();
|
expect(nodeTemplateService.selectTemplateDialog).toHaveBeenCalledWith(
|
||||||
|
folderTemplateConfig
|
||||||
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
it('should call dialog service success event on create file from template', fakeAsync(() => {
|
it('should create node from template successful', fakeAsync(() => {
|
||||||
copyNodeSpy.and.returnValue(
|
copyNodeSpy.and.returnValue(
|
||||||
of({ entry: { id: 'node-id', properties: {} } })
|
of({ entry: { id: 'node-id', properties: {} } })
|
||||||
);
|
);
|
||||||
updateNodeSpy.and.returnValue(of({ entry: node }));
|
updateNodeSpy.and.returnValue(of({ entry: node }));
|
||||||
|
|
||||||
store.dispatch(new CreateFileFromTemplate(node));
|
store.dispatch(new CreateFromTemplate(node));
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(createFromTemplateDialogService.success$.next).toHaveBeenCalledWith(
|
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(
|
||||||
node
|
new CreateFromTemplateSuccess(node)
|
||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
@ -143,12 +159,12 @@ describe('TemplateEffects', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
store.dispatch(new CreateFileFromTemplate(node));
|
store.dispatch(new CreateFromTemplate(node));
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(
|
expect(store.dispatch['calls'].mostRecent().args[0]).not.toEqual(
|
||||||
createFromTemplateDialogService.success$.next
|
new CreateFromTemplateSuccess(node)
|
||||||
).not.toHaveBeenCalledWith();
|
);
|
||||||
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(
|
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(
|
||||||
new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
|
new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
|
||||||
);
|
);
|
||||||
@ -161,12 +177,12 @@ describe('TemplateEffects', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
store.dispatch(new CreateFileFromTemplate(node));
|
store.dispatch(new CreateFromTemplate(node));
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(
|
expect(store.dispatch['calls'].mostRecent().args[0]).not.toEqual(
|
||||||
createFromTemplateDialogService.success$.next
|
new CreateFromTemplateSuccess(node)
|
||||||
).not.toHaveBeenCalledWith();
|
);
|
||||||
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(
|
expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(
|
||||||
new SnackbarErrorAction('APP.MESSAGES.ERRORS.CONFLICT')
|
new SnackbarErrorAction('APP.MESSAGES.ERRORS.CONFLICT')
|
||||||
);
|
);
|
||||||
@ -190,11 +206,26 @@ describe('TemplateEffects', () => {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
store.dispatch(new CreateFileFromTemplate(test_node.entry));
|
store.dispatch(new CreateFromTemplate(test_node.entry));
|
||||||
tick();
|
tick();
|
||||||
|
|
||||||
expect(createFromTemplateDialogService.success$.next).toHaveBeenCalledWith(
|
expect(store.dispatch['calls'].mostRecent().args[0]).toEqual(
|
||||||
test_node.entry
|
new CreateFromTemplateSuccess(test_node.entry)
|
||||||
|
);
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should close dialog on create template success', fakeAsync(() => {
|
||||||
|
store.dispatch(new CreateFromTemplateSuccess({} as Node));
|
||||||
|
tick();
|
||||||
|
expect(matDialog.closeAll).toHaveBeenCalled();
|
||||||
|
}));
|
||||||
|
|
||||||
|
it('should should reload content on create template success', fakeAsync(() => {
|
||||||
|
const test_node = { id: 'test-node-id' } as Node;
|
||||||
|
store.dispatch(new CreateFromTemplateSuccess(test_node));
|
||||||
|
tick();
|
||||||
|
expect(contentManagementService.reload.next).toHaveBeenCalledWith(
|
||||||
|
test_node
|
||||||
);
|
);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
@ -25,65 +25,64 @@
|
|||||||
|
|
||||||
import { Effect, Actions, ofType } from '@ngrx/effects';
|
import { Effect, Actions, ofType } from '@ngrx/effects';
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import {
|
import { map, switchMap, debounceTime, take, catchError } from 'rxjs/operators';
|
||||||
map,
|
|
||||||
switchMap,
|
|
||||||
debounceTime,
|
|
||||||
flatMap,
|
|
||||||
take,
|
|
||||||
catchError
|
|
||||||
} from 'rxjs/operators';
|
|
||||||
import { Store } from '@ngrx/store';
|
import { Store } from '@ngrx/store';
|
||||||
import {
|
import {
|
||||||
FileFromTemplate,
|
FileFromTemplate,
|
||||||
CreateFileFromTemplate,
|
FolderFromTemplate,
|
||||||
|
CreateFromTemplate,
|
||||||
|
CreateFromTemplateSuccess,
|
||||||
TemplateActionTypes,
|
TemplateActionTypes,
|
||||||
getCurrentFolder,
|
getCurrentFolder,
|
||||||
AppStore,
|
AppStore,
|
||||||
SnackbarErrorAction
|
SnackbarErrorAction
|
||||||
} from '@alfresco/aca-shared/store';
|
} from '@alfresco/aca-shared/store';
|
||||||
import { CreateFileFromTemplateService } from '../../services/create-file-from-template.service';
|
import {
|
||||||
|
NodeTemplateService,
|
||||||
|
TemplateDialogConfig
|
||||||
|
} from '../../services/node-template.service';
|
||||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
import { ContentManagementService } from '../../services/content-management.service';
|
import { ContentManagementService } from '../../services/content-management.service';
|
||||||
import { from, Observable, of } from 'rxjs';
|
import { from, Observable, of } from 'rxjs';
|
||||||
import { NodeEntry, NodeBodyUpdate, Node } from '@alfresco/js-api';
|
import { NodeEntry, NodeBodyUpdate, Node } from '@alfresco/js-api';
|
||||||
import { CreateFromTemplateDialogService } from '../../dialogs/node-templates/create-from-template-dialog.service';
|
import { MatDialog } from '@angular/material/dialog';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TemplateEffects {
|
export class TemplateEffects {
|
||||||
constructor(
|
constructor(
|
||||||
|
private matDialog: MatDialog,
|
||||||
private content: ContentManagementService,
|
private content: ContentManagementService,
|
||||||
private store: Store<AppStore>,
|
private store: Store<AppStore>,
|
||||||
private apiService: AlfrescoApiService,
|
private apiService: AlfrescoApiService,
|
||||||
private actions$: Actions,
|
private actions$: Actions,
|
||||||
private createFromTemplateDialogService: CreateFromTemplateDialogService,
|
private nodeTemplateService: NodeTemplateService
|
||||||
private createFileFromTemplateService: CreateFileFromTemplateService
|
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect({ dispatch: false })
|
||||||
fileFromTemplate$ = this.actions$.pipe(
|
fileFromTemplate$ = this.actions$.pipe(
|
||||||
ofType<FileFromTemplate>(TemplateActionTypes.FileFromTemplate),
|
ofType<FileFromTemplate>(TemplateActionTypes.FileFromTemplate),
|
||||||
map(() => {
|
map(() => {
|
||||||
this.createFileFromTemplateService
|
this.openDialog({
|
||||||
.openTemplatesDialog()
|
relativePath: 'Data Dictionary/Node Templates',
|
||||||
.pipe(
|
selectionType: 'file'
|
||||||
debounceTime(300),
|
|
||||||
flatMap(([node]) =>
|
|
||||||
this.createFileFromTemplateService
|
|
||||||
.createTemplateDialog(node)
|
|
||||||
.afterClosed()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
.subscribe((node: NodeEntry | null) => {
|
|
||||||
if (node) {
|
|
||||||
this.content.reload.next(node);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
@Effect({ dispatch: false })
|
@Effect({ dispatch: false })
|
||||||
createFileFromTemplate$ = this.actions$.pipe(
|
folderFromTemplate$ = this.actions$.pipe(
|
||||||
ofType<CreateFileFromTemplate>(TemplateActionTypes.CreateFileFromTemplate),
|
ofType<FolderFromTemplate>(TemplateActionTypes.FolderFromTemplate),
|
||||||
|
map(() =>
|
||||||
|
this.openDialog({
|
||||||
|
relativePath: 'Data Dictionary/Space Templates',
|
||||||
|
selectionType: 'folder'
|
||||||
|
})
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
@Effect({ dispatch: false })
|
||||||
|
createFromTemplate$ = this.actions$.pipe(
|
||||||
|
ofType<CreateFromTemplate>(TemplateActionTypes.CreateFromTemplate),
|
||||||
map(action => {
|
map(action => {
|
||||||
this.store
|
this.store
|
||||||
.select(getCurrentFolder)
|
.select(getCurrentFolder)
|
||||||
@ -95,12 +94,32 @@ export class TemplateEffects {
|
|||||||
)
|
)
|
||||||
.subscribe((node: NodeEntry | null) => {
|
.subscribe((node: NodeEntry | null) => {
|
||||||
if (node) {
|
if (node) {
|
||||||
this.createFromTemplateDialogService.success$.next(node.entry);
|
this.store.dispatch(new CreateFromTemplateSuccess(node.entry));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@Effect({ dispatch: false })
|
||||||
|
createFromTemplateSuccess$ = this.actions$.pipe(
|
||||||
|
ofType<CreateFromTemplateSuccess>(
|
||||||
|
TemplateActionTypes.CreateFromTemplateSuccess
|
||||||
|
),
|
||||||
|
map(payload => {
|
||||||
|
this.matDialog.closeAll();
|
||||||
|
this.content.reload.next(payload.node);
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
private openDialog(config: TemplateDialogConfig) {
|
||||||
|
this.nodeTemplateService
|
||||||
|
.selectTemplateDialog(config)
|
||||||
|
.pipe(debounceTime(300))
|
||||||
|
.subscribe(([node]) =>
|
||||||
|
this.nodeTemplateService.createTemplateDialog(node)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private copyNode(source: Node, parentId: string): Observable<NodeEntry> {
|
private copyNode(source: Node, parentId: string): Observable<NodeEntry> {
|
||||||
return from(
|
return from(
|
||||||
this.apiService.getInstance().nodes.copyNode(source.id, {
|
this.apiService.getInstance().nodes.copyNode(source.id, {
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
@import '../dialogs/node-versions/node-versions.dialog.theme';
|
@import '../dialogs/node-versions/node-versions.dialog.theme';
|
||||||
@import '../components/create-menu/create-menu.component.scss';
|
@import '../components/create-menu/create-menu.component.scss';
|
||||||
@import '../components/layout/layout.theme.scss';
|
@import '../components/layout/layout.theme.scss';
|
||||||
@import '../dialogs/node-templates/create-from-template.dialog.scss';
|
@import '../dialogs/node-template/create-from-template.dialog.scss';
|
||||||
|
|
||||||
@import './overrides/adf-style-fixes.theme';
|
@import './overrides/adf-style-fixes.theme';
|
||||||
|
|
||||||
@ -68,7 +68,7 @@ $warn: map-get($custom-theme, warn);
|
|||||||
@include sidenav-component-theme($theme);
|
@include sidenav-component-theme($theme);
|
||||||
@include aca-current-user-theme($theme);
|
@include aca-current-user-theme($theme);
|
||||||
@include aca-context-menu-theme($theme);
|
@include aca-context-menu-theme($theme);
|
||||||
@include app-create-file-from-template-theme($theme);
|
@include app-create-from-template-theme($theme);
|
||||||
@include app-create-menu-theme($theme);
|
@include app-create-menu-theme($theme);
|
||||||
@include adf-style-fixes($theme);
|
@include adf-style-fixes($theme);
|
||||||
|
|
||||||
|
@ -121,6 +121,20 @@
|
|||||||
"rules": {
|
"rules": {
|
||||||
"enabled": "app.navigation.folder.canUpload"
|
"enabled": "app.navigation.folder.canUpload"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "app.create.folderFromTemplate",
|
||||||
|
"order": 800,
|
||||||
|
"icon": "create_new_folder",
|
||||||
|
"title": "APP.NEW_MENU.MENU_ITEMS.FOLDER_TEMPLATE",
|
||||||
|
"description": "APP.NEW_MENU.MENU_ITEMS.FOLDER_TEMPLATE",
|
||||||
|
"description-disabled": "APP.NEW_MENU.TOOLTIPS.CREATE_FOLDER_NOT_ALLOWED",
|
||||||
|
"actions": {
|
||||||
|
"click": "FOLDER_FROM_TEMPLATE"
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"enabled": "app.navigation.folder.canUpload"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"navbar": [
|
"navbar": [
|
||||||
|
@ -58,7 +58,8 @@
|
|||||||
"UPLOAD_FILE": "Upload File",
|
"UPLOAD_FILE": "Upload File",
|
||||||
"UPLOAD_FOLDER": "Upload Folder",
|
"UPLOAD_FOLDER": "Upload Folder",
|
||||||
"CREATE_LIBRARY": "Create Library",
|
"CREATE_LIBRARY": "Create Library",
|
||||||
"FILE_TEMPLATE": "Create file from template"
|
"FILE_TEMPLATE": "Create file from template",
|
||||||
|
"FOLDER_TEMPLATE": "Create folder from template"
|
||||||
},
|
},
|
||||||
"TOOLTIPS": {
|
"TOOLTIPS": {
|
||||||
"CREATE_FOLDER": "Create new folder",
|
"CREATE_FOLDER": "Create new folder",
|
||||||
@ -359,12 +360,14 @@
|
|||||||
"MOVE_ITEMS": "Move {{ number }} items to...",
|
"MOVE_ITEMS": "Move {{ number }} items to...",
|
||||||
"SEARCH": "Search",
|
"SEARCH": "Search",
|
||||||
"NEXT": "Next",
|
"NEXT": "Next",
|
||||||
"SELECT_TEMPLATE_TITLE": "Select a document template"
|
"SELECT_FILE_TEMPLATE_TITLE": "Select a document template",
|
||||||
|
"SELECT_FOLDER_TEMPLATE_TITLE": "Select a folder template"
|
||||||
},
|
},
|
||||||
"FILE_FROM_TEMPLATE": {
|
"NODE_FROM_TEMPLATE": {
|
||||||
"CANCEL": "CANCEL",
|
"CANCEL": "CANCEL",
|
||||||
"CREATE": "Create",
|
"CREATE": "Create",
|
||||||
"TITLE": "Create new document from <span class=\"bold\">'{{ template }}'</span>",
|
"FOLDER_DIALOG_TITLE": "Create new folder from <span class=\"bold\">'{{ template }}'</span>",
|
||||||
|
"FILE_DIALOG_TITLE": "Create new document from <span class=\"bold\">'{{ template }}'</span>",
|
||||||
"FORM": {
|
"FORM": {
|
||||||
"PLACEHOLDER": {
|
"PLACEHOLDER": {
|
||||||
"NAME": "Name",
|
"NAME": "Name",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user