From bbbdcbdaa5a12082a3e3aa8d65d7e3812cca7def Mon Sep 17 00:00:00 2001 From: Thomas Hunter Date: Tue, 25 May 2021 14:02:42 +0200 Subject: [PATCH] [AAE-5145] Add enum for content node selector actions (#7039) * [AAE-5145] Add enum for content node selector actions * [AAE-5145] Fix lint and unit tests * Order imports back to original order * Rename to NodeAction --- .../content-node-dialog.service.spec.ts | 7 +++--- .../content-node-dialog.service.ts | 11 +++++---- ...-node-selector.component-data.interface.ts | 3 ++- .../content-node-selector.component.spec.ts | 11 +++++---- .../content-node-selector.component.ts | 11 +++++---- .../document-list/models/node-action.enum.ts | 24 +++++++++++++++++++ .../src/lib/document-list/public-api.ts | 1 + .../services/node-actions.service.ts | 15 ++++++------ .../content-cloud-node-selector.service.ts | 4 ++-- 9 files changed, 59 insertions(+), 28 deletions(-) create mode 100644 lib/content-services/src/lib/document-list/models/node-action.enum.ts diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts index c74d5bd3c3..ef3b156d07 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.spec.ts @@ -24,6 +24,7 @@ import { MatDialog } from '@angular/material/dialog'; import { Subject, of } from 'rxjs'; import { ContentTestingModule } from '../testing/content.testing.module'; import { TranslateModule } from '@ngx-translate/core'; +import { NodeAction } from '../document-list/models/node-action.enum'; const fakeNodeEntry: NodeEntry = { entry: { @@ -105,12 +106,12 @@ describe('ContentNodeDialogService', () => { }); it('should be able to open the dialog when node has permission', () => { - service.openCopyMoveDialog('fake-action', fakeNode, '!update'); + service.openCopyMoveDialog(NodeAction.CHOOSE, fakeNode, '!update'); expect(spyOnDialogOpen).toHaveBeenCalled(); }); it('should NOT be able to open the dialog when node has NOT permission', () => { - service.openCopyMoveDialog('fake-action', fakeNode, 'noperm').subscribe( + service.openCopyMoveDialog(NodeAction.CHOOSE, fakeNode, 'noperm').subscribe( () => {}, (error) => { expect(spyOnDialogOpen).not.toHaveBeenCalled(); @@ -202,7 +203,7 @@ describe('ContentNodeDialogService', () => { testContentNodeSelectorComponentData = config.data; return { componentInstance: {} }; }); - service.openCopyMoveDialog('fake-action', fakeNode, '!update'); + service.openCopyMoveDialog(NodeAction.CHOOSE, fakeNode, '!update'); }); it('should NOT allow selection for sites', () => { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts index 39f6fcf248..87f5f4fe44 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts @@ -24,6 +24,7 @@ import { Node, NodeEntry, SitePaging } from '@alfresco/js-api'; import { DocumentListService } from '../document-list/services/document-list.service'; import { ContentNodeSelectorComponent } from './content-node-selector.component'; import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface'; +import { NodeAction } from '../document-list/models/node-action.enum'; import { NodeLockDialogComponent } from '../dialogs/node-lock.dialog'; import { switchMap } from 'rxjs/operators'; @@ -61,7 +62,7 @@ export class ContentNodeDialogService { */ openFileBrowseDialogByFolderId(folderNodeId: string): Observable { return this.documentListService.getFolderNode(folderNodeId).pipe(switchMap((nodeEntry: NodeEntry) => { - return this.openUploadFileDialog('Choose', nodeEntry.entry, true); + return this.openUploadFileDialog(NodeAction.CHOOSE, nodeEntry.entry, true); })); } @@ -126,7 +127,7 @@ export class ContentNodeDialogService { */ openFolderBrowseDialogByFolderId(folderNodeId: string): Observable { return this.documentListService.getFolderNode(folderNodeId).pipe(switchMap((node: NodeEntry) => { - return this.openUploadFolderDialog('Choose', node.entry); + return this.openUploadFolderDialog(NodeAction.CHOOSE, node.entry); })); } @@ -138,7 +139,7 @@ export class ContentNodeDialogService { * @param excludeSiteContent The site content that should be filtered out * @returns Information about files that were copied/moved */ - openCopyMoveDialog(action: string, contentEntry: Node, permission?: string, excludeSiteContent?: string[]): Observable { + openCopyMoveDialog(action: NodeAction, contentEntry: Node, permission?: string, excludeSiteContent?: string[]): Observable { if (this.contentService.hasAllowableOperations(contentEntry, permission)) { const select = new Subject(); @@ -183,7 +184,7 @@ export class ContentNodeDialogService { * @param contentEntry Item to upload * @returns Information about the chosen folder(s) */ - openUploadFolderDialog(action: string, contentEntry: Node): Observable { + openUploadFolderDialog(action: NodeAction, contentEntry: Node): Observable { const select = new Subject(); select.subscribe({ complete: this.close.bind(this) @@ -211,7 +212,7 @@ export class ContentNodeDialogService { * @param showFilesInResult Show files in dialog search result * @returns Information about the chosen file(s) */ - openUploadFileDialog(action: string, contentEntry: Node, showFilesInResult = false): Observable { + openUploadFileDialog(action: NodeAction, contentEntry: Node, showFilesInResult = false): Observable { const select = new Subject(); select.subscribe({ complete: this.close.bind(this) diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts index 1c7f5691b1..318a290825 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts @@ -17,10 +17,11 @@ import { Node, SitePaging } from '@alfresco/js-api'; import { Subject } from 'rxjs'; +import { NodeAction } from '../document-list/models/node-action.enum'; export interface ContentNodeSelectorComponentData { title: string; - actionName?: string; + actionName?: NodeAction; currentFolderId: string; dropdownHideMyFiles?: boolean; restrictRootToCurrentFolderId?: boolean; diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts index 399cb66693..cf5909187d 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts @@ -30,6 +30,7 @@ import { ShareDataRow } from '../document-list'; import { TranslateModule } from '@ngx-translate/core'; import { UploadModule } from '../upload'; import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component'; +import { NodeAction } from '../document-list/models/node-action.enum'; describe('ContentNodeSelectorComponent', () => { let component: ContentNodeSelectorComponent; @@ -40,7 +41,7 @@ describe('ContentNodeSelectorComponent', () => { beforeEach(() => { data = { title: 'Choose along citizen...', - actionName: 'choose', + actionName: NodeAction.CHOOSE, select: new EventEmitter(), rowFilter: (shareDataRow) => shareDataRow.node.entry.name === 'impossible-name', imageResolver: () => 'piccolo', @@ -448,19 +449,19 @@ describe('ContentNodeSelectorComponent', () => { }); it('should show the counter depending on the action', () => { - component.action = 'ATTACH'; + component.action = NodeAction.ATTACH; fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).not.toBe(null); - component.action = 'CHOOSE'; + component.action = NodeAction.CHOOSE; fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).not.toBe(null); - component.action = 'COPY'; + component.action = NodeAction.COPY; fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).toBe(null); - component.action = 'MOVE'; + component.action = NodeAction.MOVE; fixture.detectChanges(); expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).toBe(null); }); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts index 350ad9c8ef..9ecfe725bb 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts @@ -22,6 +22,7 @@ import { Node } from '@alfresco/js-api'; import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface'; import { NodeEntryEvent } from '../document-list/components/node.event'; +import { NodeAction } from '../document-list/models/node-action.enum'; @Component({ selector: 'adf-content-node-selector', @@ -31,7 +32,7 @@ import { NodeEntryEvent } from '../document-list/components/node.event'; }) export class ContentNodeSelectorComponent implements OnInit { title: string; - action: string; + action: NodeAction; buttonActionName: string; chosenNode: Node[]; currentDirectoryId: string; @@ -50,7 +51,7 @@ export class ContentNodeSelectorComponent implements OnInit { private uploadService: UploadService, private dialog: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) { - this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE'; + this.action = data.actionName ?? NodeAction.CHOOSE; this.buttonActionName = `NODE_SELECTOR.${this.action}`; this.title = data.title; this.currentDirectoryId = data.currentFolderId; @@ -98,12 +99,12 @@ export class ContentNodeSelectorComponent implements OnInit { } updateTitle(siteTitle: string) { - if (this.action === 'CHOOSE' && siteTitle) { + if (this.action === NodeAction.CHOOSE && siteTitle) { this.title = this.getTitleTranslation(this.action, siteTitle); } } - getTitleTranslation(action: string, name: string): string { + getTitleTranslation(action: NodeAction, name: string): string { return this.translation.instant(`NODE_SELECTOR.${action}_ITEM`, { name: this.translation.instant(name) }); } @@ -112,7 +113,7 @@ export class ContentNodeSelectorComponent implements OnInit { } isCounterVisible(): boolean { - return this.action === 'ATTACH' || this.action === 'CHOOSE'; + return this.action === NodeAction.ATTACH || this.action === NodeAction.CHOOSE; } isMultipleSelection(): boolean { diff --git a/lib/content-services/src/lib/document-list/models/node-action.enum.ts b/lib/content-services/src/lib/document-list/models/node-action.enum.ts new file mode 100644 index 0000000000..c426a4b902 --- /dev/null +++ b/lib/content-services/src/lib/document-list/models/node-action.enum.ts @@ -0,0 +1,24 @@ +/*! + * @license + * Copyright 2019 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export enum NodeAction { + ATTACH = 'ATTACH', + CHOOSE = 'CHOOSE', + COPY = 'COPY', + MOVE = 'MOVE', + NEXT = 'NEXT' +} diff --git a/lib/content-services/src/lib/document-list/public-api.ts b/lib/content-services/src/lib/document-list/public-api.ts index aa6f90591f..5e56de9760 100644 --- a/lib/content-services/src/lib/document-list/public-api.ts +++ b/lib/content-services/src/lib/document-list/public-api.ts @@ -44,6 +44,7 @@ export * from './models/content-action.model'; export * from './models/document-library.model'; export * from './models/permissions.model'; export * from './models/permissions-style.model'; +export * from './models/node-action.enum'; export * from './interfaces/document-list-loader.interface'; diff --git a/lib/content-services/src/lib/document-list/services/node-actions.service.ts b/lib/content-services/src/lib/document-list/services/node-actions.service.ts index 3062d0e285..0ebd7ec3d5 100644 --- a/lib/content-services/src/lib/document-list/services/node-actions.service.ts +++ b/lib/content-services/src/lib/document-list/services/node-actions.service.ts @@ -23,6 +23,7 @@ import { MatDialog } from '@angular/material/dialog'; import { DocumentListService } from './document-list.service'; import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service'; +import { NodeAction } from '../models/node-action.enum'; @Injectable({ providedIn: 'root' @@ -53,7 +54,7 @@ export class NodeActionsService { * @param permission permission which is needed to apply the action */ copyContent(contentEntry: Node, permission?: string): Subject { - return this.doFileOperation('copy', 'content', contentEntry, permission); + return this.doFileOperation(NodeAction.COPY, 'content', contentEntry, permission); } /** @@ -63,7 +64,7 @@ export class NodeActionsService { * @param permission permission which is needed to apply the action */ copyFolder(contentEntry: Node, permission?: string): Subject { - return this.doFileOperation('copy', 'folder', contentEntry, permission); + return this.doFileOperation(NodeAction.COPY, 'folder', contentEntry, permission); } /** @@ -73,7 +74,7 @@ export class NodeActionsService { * @param permission permission which is needed to apply the action */ moveContent(contentEntry: Node, permission?: string): Subject { - return this.doFileOperation('move', 'content', contentEntry, permission); + return this.doFileOperation(NodeAction.MOVE, 'content', contentEntry, permission); } /** @@ -83,7 +84,7 @@ export class NodeActionsService { * @param permission permission which is needed to apply the action */ moveFolder(contentEntry: Node, permission?: string): Subject { - return this.doFileOperation('move', 'folder', contentEntry, permission); + return this.doFileOperation(NodeAction.MOVE, 'folder', contentEntry, permission); } /** @@ -94,16 +95,16 @@ export class NodeActionsService { * @param contentEntry the contentEntry which has to have the action performed on * @param permission permission which is needed to apply the action */ - private doFileOperation(action: string, type: string, contentEntry: Node, permission?: string): Subject { + private doFileOperation(action: NodeAction.COPY | NodeAction.MOVE, type: 'content' | 'folder', contentEntry: Node, permission?: string): Subject { const observable = new Subject(); this.contentDialogService .openCopyMoveDialog(action, contentEntry, permission) .subscribe((selections: Node[]) => { const selection = selections[0]; - this.documentListService[`${action}Node`].call(this.documentListService, contentEntry.id, selection.id) + this.documentListService[`${action.toLowerCase()}Node`].call(this.documentListService, contentEntry.id, selection.id) .subscribe( - observable.next.bind(observable, `OPERATION.SUCCESS.${type.toUpperCase()}.${action.toUpperCase()}`), + observable.next.bind(observable, `OPERATION.SUCCESS.${type.toUpperCase()}.${action}`), observable.error.bind(observable) ); }, diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts index 0be3cb3bc2..5c79643c66 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts @@ -18,7 +18,7 @@ import { Injectable } from '@angular/core'; import { AlfrescoApiService } from '@alfresco/adf-core'; import { MatDialog } from '@angular/material/dialog'; -import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData } from '@alfresco/adf-content-services'; +import { ContentNodeSelectorComponent, ContentNodeSelectorComponentData, NodeAction } from '@alfresco/adf-content-services'; import { Node } from '@alfresco/js-api'; import { Observable, Subject, throwError } from 'rxjs'; @@ -39,7 +39,7 @@ export class ContentCloudNodeSelectorService { }); const data = { title: 'Select a file', - actionName: 'Attach', + actionName: NodeAction.ATTACH, currentFolderId, restrictRootToCurrentFolderId, select,