[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
This commit is contained in:
Thomas Hunter
2021-05-25 14:02:42 +02:00
committed by GitHub
parent 73ccb3e92c
commit bbbdcbdaa5
9 changed files with 59 additions and 28 deletions

View File

@@ -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 = <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', () => {

View File

@@ -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<Node[]> {
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<Node[]> {
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<Node[]> {
openCopyMoveDialog(action: NodeAction, contentEntry: Node, permission?: string, excludeSiteContent?: string[]): Observable<Node[]> {
if (this.contentService.hasAllowableOperations(contentEntry, permission)) {
const select = new Subject<Node[]>();
@@ -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<Node[]> {
openUploadFolderDialog(action: NodeAction, contentEntry: Node): Observable<Node[]> {
const select = new Subject<Node[]>();
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<Node[]> {
openUploadFileDialog(action: NodeAction, contentEntry: Node, showFilesInResult = false): Observable<Node[]> {
const select = new Subject<Node[]>();
select.subscribe({
complete: this.close.bind(this)

View File

@@ -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;

View File

@@ -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<Node>(),
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);
});

View File

@@ -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<ContentNodeSelectorComponent>,
@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 {

View File

@@ -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'
}

View File

@@ -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';

View File

@@ -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<string> {
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<string> {
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<string> {
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<string> {
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<string> {
private doFileOperation(action: NodeAction.COPY | NodeAction.MOVE, type: 'content' | 'folder', contentEntry: Node, permission?: string): Subject<string> {
const observable = new Subject<string>();
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)
);
},