diff --git a/docs/extending/application-actions.md b/docs/extending/application-actions.md
index cd48959b2..77083e036 100644
--- a/docs/extending/application-actions.md
+++ b/docs/extending/application-actions.md
@@ -124,3 +124,4 @@ 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 | CLOSE_PREVIEW | n/a | Closes the viewer ( preview of the item ) |
| 1.9.0 | RESET_SELECTION | n/a | Resets active document list selection |
+| 2.0.0 | CREATE_FILE_FROM_TEMPLATE | n/a | Invoke a dialog listing `Node Templates` folder. Selected template can be copied in the current folder from where tha action was invoked |
diff --git a/projects/aca-shared/store/src/actions/template.actions.ts b/projects/aca-shared/store/src/actions/template.actions.ts
new file mode 100644
index 000000000..ba6f9d172
--- /dev/null
+++ b/projects/aca-shared/store/src/actions/template.actions.ts
@@ -0,0 +1,36 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+import { Action } from '@ngrx/store';
+
+export enum TemplateActionTypes {
+ CreateFileFromTemplate = 'CREATE_FILE_FROM_TEMPLATE'
+}
+
+export class CreateFileFromTemplate implements Action {
+ readonly type = TemplateActionTypes.CreateFileFromTemplate;
+
+ constructor() {}
+}
diff --git a/projects/aca-shared/store/src/public_api.ts b/projects/aca-shared/store/src/public_api.ts
index c7695c5b9..c35d08eab 100644
--- a/projects/aca-shared/store/src/public_api.ts
+++ b/projects/aca-shared/store/src/public_api.ts
@@ -32,6 +32,7 @@ export * from './actions/snackbar.actions';
export * from './actions/upload.actions';
export * from './actions/viewer.actions';
export * from './actions/metadata-aspect.actions';
+export * from './actions/template.actions';
export * from './effects/dialog.effects';
export * from './effects/router.effects';
diff --git a/src/app/services/create-file-from-template.service.spec.ts b/src/app/services/create-file-from-template.service.spec.ts
new file mode 100644
index 000000000..70e7c89be
--- /dev/null
+++ b/src/app/services/create-file-from-template.service.spec.ts
@@ -0,0 +1,156 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+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;
+ 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')
+ );
+ }));
+});
diff --git a/src/app/services/create-file-from-template.service.ts b/src/app/services/create-file-from-template.service.ts
new file mode 100644
index 000000000..9848b22c0
--- /dev/null
+++ b/src/app/services/create-file-from-template.service.ts
@@ -0,0 +1,121 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+import { Injectable } from '@angular/core';
+import { MatDialog, MatDialogConfig } from '@angular/material';
+import {
+ ContentNodeSelectorComponentData,
+ ContentNodeSelectorComponent
+} from '@alfresco/adf-content-services';
+import { Subject, from, of } from 'rxjs';
+import { Node } from '@alfresco/js-api';
+import { AlfrescoApiService } from '@alfresco/adf-core';
+import { switchMap, catchError } from 'rxjs/operators';
+import { Store } from '@ngrx/store';
+import { AppStore, SnackbarErrorAction } from '@alfresco/aca-shared/store';
+
+@Injectable({
+ providedIn: 'root'
+})
+export class CreateFileFromTemplateService {
+ constructor(
+ private store: Store,
+ private alfrescoApiService: AlfrescoApiService,
+ public dialog: MatDialog
+ ) {}
+
+ openTemplatesDialog(): Subject {
+ const select = new Subject();
+ select.subscribe({
+ complete: this.close.bind(this)
+ });
+
+ const data: ContentNodeSelectorComponentData = {
+ title: null,
+ dropdownHideMyFiles: true,
+ currentFolderId: null,
+ dropdownSiteList: null,
+ breadcrumbTransform: this.transformNode.bind(this),
+ select,
+ isSelectionValid: this.isSelectionValid.bind(this)
+ };
+
+ data.select.subscribe({
+ complete: this.close.bind(this)
+ });
+
+ from(
+ this.alfrescoApiService.getInstance().nodes.getNodeInfo('-root-', {
+ relativePath: 'Data Dictionary/Node Templates'
+ })
+ )
+ .pipe(
+ switchMap(node => {
+ data.currentFolderId = node.id;
+ return this.dialog
+ .open(ContentNodeSelectorComponent, {
+ data,
+ panelClass: [
+ 'adf-content-node-selector-dialog',
+ 'aca-template-node-selector-dialog'
+ ],
+ width: '630px'
+ })
+ .afterClosed();
+ }),
+ catchError(error => {
+ this.store.dispatch(
+ new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
+ );
+ return of(error);
+ })
+ )
+ .subscribe({ next: () => select.complete() });
+
+ return select;
+ }
+
+ private transformNode(node: Node): Node {
+ if (node && node.path && node.path && node.path.elements instanceof Array) {
+ let {
+ path: { elements: elementsPath = [] }
+ } = node;
+ elementsPath = elementsPath.filter(
+ path => path.name !== 'Company Home' && path.name !== 'Data Dictionary'
+ );
+ node.path.elements = elementsPath;
+ }
+
+ return node;
+ }
+
+ private isSelectionValid(node: Node): boolean {
+ return node.isFile;
+ }
+
+ private close() {
+ this.dialog.closeAll();
+ }
+}
diff --git a/src/app/store/app-store.module.ts b/src/app/store/app-store.module.ts
index 4ea9aae32..bd71d2f60 100644
--- a/src/app/store/app-store.module.ts
+++ b/src/app/store/app-store.module.ts
@@ -39,7 +39,8 @@ import {
SearchEffects,
LibraryEffects,
UploadEffects,
- FavoriteEffects
+ FavoriteEffects,
+ TemplateEffects
} from './effects';
import { INITIAL_STATE } from './initial-state';
@@ -56,7 +57,8 @@ import { INITIAL_STATE } from './initial-state';
SearchEffects,
LibraryEffects,
UploadEffects,
- FavoriteEffects
+ FavoriteEffects,
+ TemplateEffects
]),
!environment.production
? StoreDevtoolsModule.instrument({ maxAge: 25 })
diff --git a/src/app/store/effects.ts b/src/app/store/effects.ts
index 29bee5773..4a7b28ca2 100644
--- a/src/app/store/effects.ts
+++ b/src/app/store/effects.ts
@@ -32,3 +32,4 @@ export * from './effects/search.effects';
export * from './effects/library.effects';
export * from './effects/upload.effects';
export * from './effects/upload.effects';
+export * from './effects/template.effects';
diff --git a/src/app/store/effects/template.effects.spec.ts b/src/app/store/effects/template.effects.spec.ts
new file mode 100644
index 000000000..51e976b27
--- /dev/null
+++ b/src/app/store/effects/template.effects.spec.ts
@@ -0,0 +1,93 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+import { TestBed, fakeAsync, tick } from '@angular/core/testing';
+import { AppTestingModule } from '../../testing/app-testing.module';
+import { TemplateEffects } from './template.effects';
+import { EffectsModule } from '@ngrx/effects';
+import { Store } from '@ngrx/store';
+import {
+ CreateFileFromTemplate,
+ SnackbarErrorAction
+} from '@alfresco/aca-shared/store';
+import { CreateFileFromTemplateService } from '../../services/create-file-from-template.service';
+import { of } from 'rxjs';
+import { AlfrescoApiServiceMock, AlfrescoApiService } from '@alfresco/adf-core';
+import { ContentManagementService } from '../../services/content-management.service';
+
+describe('TemplateEffects', () => {
+ let store: Store;
+ let createFileFromTemplateService: CreateFileFromTemplateService;
+ let alfrescoApiService: AlfrescoApiService;
+ let contentManagementService: ContentManagementService;
+
+ beforeEach(() => {
+ TestBed.configureTestingModule({
+ imports: [AppTestingModule, EffectsModule.forRoot([TemplateEffects])],
+ providers: [
+ CreateFileFromTemplateService,
+ { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock }
+ ]
+ });
+
+ store = TestBed.get(Store);
+ createFileFromTemplateService = TestBed.get(CreateFileFromTemplateService);
+ alfrescoApiService = TestBed.get(AlfrescoApiService);
+ contentManagementService = TestBed.get(ContentManagementService);
+
+ spyOn(contentManagementService.reload, 'next');
+ spyOn(store, 'select').and.returnValue(of({ id: 'parent-id' }));
+ spyOn(createFileFromTemplateService, 'openTemplatesDialog').and.returnValue(
+ of([{ id: 'template-id' }])
+ );
+ });
+
+ it('should reload content on template copy', fakeAsync(() => {
+ spyOn(alfrescoApiService.getInstance().nodes, 'copyNode').and.returnValue(
+ of({})
+ );
+ store.dispatch(new CreateFileFromTemplate());
+ tick();
+
+ expect(contentManagementService.reload.next).toHaveBeenCalled();
+ }));
+
+ it('should raise error when copy template fails', fakeAsync(() => {
+ spyOn(store, 'dispatch').and.callThrough();
+ spyOn(alfrescoApiService.getInstance().nodes, 'copyNode').and.returnValue(
+ Promise.reject({
+ message: `{ "error": { "statusCode": 404 } } `
+ })
+ );
+
+ store.dispatch(new CreateFileFromTemplate());
+ tick();
+
+ expect(contentManagementService.reload.next).not.toHaveBeenCalled();
+ expect(store.dispatch['calls'].argsFor(1)[0]).toEqual(
+ new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
+ );
+ }));
+});
diff --git a/src/app/store/effects/template.effects.ts b/src/app/store/effects/template.effects.ts
new file mode 100644
index 000000000..9ae79a2e1
--- /dev/null
+++ b/src/app/store/effects/template.effects.ts
@@ -0,0 +1,87 @@
+/*!
+ * @license
+ * Alfresco Example Content Application
+ *
+ * Copyright (C) 2005 - 2019 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 .
+ */
+
+import { Effect, Actions, ofType } from '@ngrx/effects';
+import { Injectable } from '@angular/core';
+import { map, withLatestFrom, switchMap, catchError } from 'rxjs/operators';
+import { Store } from '@ngrx/store';
+import {
+ CreateFileFromTemplate,
+ TemplateActionTypes,
+ getCurrentFolder,
+ AppStore,
+ SnackbarErrorAction
+} from '@alfresco/aca-shared/store';
+import { CreateFileFromTemplateService } from '../../services/create-file-from-template.service';
+import { AlfrescoApiService } from '@alfresco/adf-core';
+import { ContentManagementService } from '../../services/content-management.service';
+import { from, of } from 'rxjs';
+import { NodeEntry } from '@alfresco/js-api';
+
+@Injectable()
+export class TemplateEffects {
+ constructor(
+ private content: ContentManagementService,
+ private store: Store,
+ private apiService: AlfrescoApiService,
+ private actions$: Actions,
+ private createFileFromTemplateService: CreateFileFromTemplateService
+ ) {}
+
+ @Effect({ dispatch: false })
+ fileFromTemplate$ = this.actions$.pipe(
+ ofType(TemplateActionTypes.CreateFileFromTemplate),
+ map(() => {
+ this.createFileFromTemplateService
+ .openTemplatesDialog()
+ .pipe(
+ withLatestFrom(this.store.select(getCurrentFolder)),
+ switchMap(([[template], parentNode]) => {
+ return from(
+ this.apiService
+ .getInstance()
+ .nodes.copyNode(template.id, { targetParentId: parentNode.id })
+ );
+ }),
+ catchError(error => {
+ const { statusCode } = JSON.parse(error.message).error;
+
+ if (statusCode !== 409) {
+ this.store.dispatch(
+ new SnackbarErrorAction('APP.MESSAGES.ERRORS.GENERIC')
+ );
+ }
+
+ return of(null);
+ })
+ )
+ .subscribe((node: NodeEntry | null) => {
+ if (node) {
+ this.content.reload.next();
+ }
+ });
+ })
+ );
+}
diff --git a/src/app/ui/overrides/adf-style-fixes.theme.scss b/src/app/ui/overrides/adf-style-fixes.theme.scss
index 52383281a..b5279f1c8 100644
--- a/src/app/ui/overrides/adf-style-fixes.theme.scss
+++ b/src/app/ui/overrides/adf-style-fixes.theme.scss
@@ -13,4 +13,15 @@
display: none;
}
}
+
+ .aca-template-node-selector-dialog {
+ adf-content-node-selector-panel {
+ .adf-content-node-selector-content-input {
+ display: none;
+ }
+ .adf-sites-dropdown {
+ display: none;
+ }
+ }
+ }
}
diff --git a/src/assets/app.extensions.json b/src/assets/app.extensions.json
index 8a8c989b9..44a2fcd3b 100644
--- a/src/assets/app.extensions.json
+++ b/src/assets/app.extensions.json
@@ -102,6 +102,24 @@
"actions": {
"click": "CREATE_LIBRARY"
}
+ },
+ {
+ "id": "app.create.separator.2",
+ "type": "separator",
+ "order": 650
+ },
+ {
+ "id": "app.create.fileFromTemplate",
+ "order": 700,
+ "icon": "description",
+ "title": "APP.NEW_MENU.MENU_ITEMS.FILE_TEMPLATE",
+ "description": "APP.NEW_MENU.MENU_ITEMS.FILE_TEMPLATE",
+ "actions": {
+ "click": "CREATE_FILE_FROM_TEMPLATE"
+ },
+ "rules": {
+ "enabled": "app.navigation.folder.canUpload"
+ }
}
],
"navbar": [
diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json
index ec473ac55..7813a920c 100644
--- a/src/assets/i18n/en.json
+++ b/src/assets/i18n/en.json
@@ -57,7 +57,8 @@
"CREATE_FOLDER": "Create Folder",
"UPLOAD_FILE": "Upload File",
"UPLOAD_FOLDER": "Upload Folder",
- "CREATE_LIBRARY": "Create Library"
+ "CREATE_LIBRARY": "Create Library",
+ "FILE_TEMPLATE": "Create file from template"
},
"TOOLTIPS": {
"CREATE_FOLDER": "Create new folder",