mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[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:
@@ -24,6 +24,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|||||||
import { Subject, of } from 'rxjs';
|
import { Subject, of } from 'rxjs';
|
||||||
import { ContentTestingModule } from '../testing/content.testing.module';
|
import { ContentTestingModule } from '../testing/content.testing.module';
|
||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
|
import { NodeAction } from '../document-list/models/node-action.enum';
|
||||||
|
|
||||||
const fakeNodeEntry: NodeEntry = <NodeEntry> {
|
const fakeNodeEntry: NodeEntry = <NodeEntry> {
|
||||||
entry: {
|
entry: {
|
||||||
@@ -105,12 +106,12 @@ describe('ContentNodeDialogService', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to open the dialog when node has permission', () => {
|
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();
|
expect(spyOnDialogOpen).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT be able to open the dialog when node has NOT permission', () => {
|
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) => {
|
(error) => {
|
||||||
expect(spyOnDialogOpen).not.toHaveBeenCalled();
|
expect(spyOnDialogOpen).not.toHaveBeenCalled();
|
||||||
@@ -202,7 +203,7 @@ describe('ContentNodeDialogService', () => {
|
|||||||
testContentNodeSelectorComponentData = config.data;
|
testContentNodeSelectorComponentData = config.data;
|
||||||
return { componentInstance: {} };
|
return { componentInstance: {} };
|
||||||
});
|
});
|
||||||
service.openCopyMoveDialog('fake-action', fakeNode, '!update');
|
service.openCopyMoveDialog(NodeAction.CHOOSE, fakeNode, '!update');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should NOT allow selection for sites', () => {
|
it('should NOT allow selection for sites', () => {
|
||||||
|
@@ -24,6 +24,7 @@ import { Node, NodeEntry, SitePaging } from '@alfresco/js-api';
|
|||||||
import { DocumentListService } from '../document-list/services/document-list.service';
|
import { DocumentListService } from '../document-list/services/document-list.service';
|
||||||
import { ContentNodeSelectorComponent } from './content-node-selector.component';
|
import { ContentNodeSelectorComponent } from './content-node-selector.component';
|
||||||
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
|
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 { NodeLockDialogComponent } from '../dialogs/node-lock.dialog';
|
||||||
import { switchMap } from 'rxjs/operators';
|
import { switchMap } from 'rxjs/operators';
|
||||||
|
|
||||||
@@ -61,7 +62,7 @@ export class ContentNodeDialogService {
|
|||||||
*/
|
*/
|
||||||
openFileBrowseDialogByFolderId(folderNodeId: string): Observable<Node[]> {
|
openFileBrowseDialogByFolderId(folderNodeId: string): Observable<Node[]> {
|
||||||
return this.documentListService.getFolderNode(folderNodeId).pipe(switchMap((nodeEntry: NodeEntry) => {
|
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[]> {
|
openFolderBrowseDialogByFolderId(folderNodeId: string): Observable<Node[]> {
|
||||||
return this.documentListService.getFolderNode(folderNodeId).pipe(switchMap((node: NodeEntry) => {
|
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
|
* @param excludeSiteContent The site content that should be filtered out
|
||||||
* @returns Information about files that were copied/moved
|
* @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)) {
|
if (this.contentService.hasAllowableOperations(contentEntry, permission)) {
|
||||||
|
|
||||||
const select = new Subject<Node[]>();
|
const select = new Subject<Node[]>();
|
||||||
@@ -183,7 +184,7 @@ export class ContentNodeDialogService {
|
|||||||
* @param contentEntry Item to upload
|
* @param contentEntry Item to upload
|
||||||
* @returns Information about the chosen folder(s)
|
* @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[]>();
|
const select = new Subject<Node[]>();
|
||||||
select.subscribe({
|
select.subscribe({
|
||||||
complete: this.close.bind(this)
|
complete: this.close.bind(this)
|
||||||
@@ -211,7 +212,7 @@ export class ContentNodeDialogService {
|
|||||||
* @param showFilesInResult Show files in dialog search result
|
* @param showFilesInResult Show files in dialog search result
|
||||||
* @returns Information about the chosen file(s)
|
* @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[]>();
|
const select = new Subject<Node[]>();
|
||||||
select.subscribe({
|
select.subscribe({
|
||||||
complete: this.close.bind(this)
|
complete: this.close.bind(this)
|
||||||
|
@@ -17,10 +17,11 @@
|
|||||||
|
|
||||||
import { Node, SitePaging } from '@alfresco/js-api';
|
import { Node, SitePaging } from '@alfresco/js-api';
|
||||||
import { Subject } from 'rxjs';
|
import { Subject } from 'rxjs';
|
||||||
|
import { NodeAction } from '../document-list/models/node-action.enum';
|
||||||
|
|
||||||
export interface ContentNodeSelectorComponentData {
|
export interface ContentNodeSelectorComponentData {
|
||||||
title: string;
|
title: string;
|
||||||
actionName?: string;
|
actionName?: NodeAction;
|
||||||
currentFolderId: string;
|
currentFolderId: string;
|
||||||
dropdownHideMyFiles?: boolean;
|
dropdownHideMyFiles?: boolean;
|
||||||
restrictRootToCurrentFolderId?: boolean;
|
restrictRootToCurrentFolderId?: boolean;
|
||||||
|
@@ -30,6 +30,7 @@ import { ShareDataRow } from '../document-list';
|
|||||||
import { TranslateModule } from '@ngx-translate/core';
|
import { TranslateModule } from '@ngx-translate/core';
|
||||||
import { UploadModule } from '../upload';
|
import { UploadModule } from '../upload';
|
||||||
import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component';
|
import { ContentNodeSelectorPanelComponent } from './content-node-selector-panel.component';
|
||||||
|
import { NodeAction } from '../document-list/models/node-action.enum';
|
||||||
|
|
||||||
describe('ContentNodeSelectorComponent', () => {
|
describe('ContentNodeSelectorComponent', () => {
|
||||||
let component: ContentNodeSelectorComponent;
|
let component: ContentNodeSelectorComponent;
|
||||||
@@ -40,7 +41,7 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
data = {
|
data = {
|
||||||
title: 'Choose along citizen...',
|
title: 'Choose along citizen...',
|
||||||
actionName: 'choose',
|
actionName: NodeAction.CHOOSE,
|
||||||
select: new EventEmitter<Node>(),
|
select: new EventEmitter<Node>(),
|
||||||
rowFilter: (shareDataRow) => shareDataRow.node.entry.name === 'impossible-name',
|
rowFilter: (shareDataRow) => shareDataRow.node.entry.name === 'impossible-name',
|
||||||
imageResolver: () => 'piccolo',
|
imageResolver: () => 'piccolo',
|
||||||
@@ -448,19 +449,19 @@ describe('ContentNodeSelectorComponent', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should show the counter depending on the action', () => {
|
it('should show the counter depending on the action', () => {
|
||||||
component.action = 'ATTACH';
|
component.action = NodeAction.ATTACH;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).not.toBe(null);
|
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).not.toBe(null);
|
||||||
|
|
||||||
component.action = 'CHOOSE';
|
component.action = NodeAction.CHOOSE;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).not.toBe(null);
|
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).not.toBe(null);
|
||||||
|
|
||||||
component.action = 'COPY';
|
component.action = NodeAction.COPY;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).toBe(null);
|
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).toBe(null);
|
||||||
|
|
||||||
component.action = 'MOVE';
|
component.action = NodeAction.MOVE;
|
||||||
fixture.detectChanges();
|
fixture.detectChanges();
|
||||||
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).toBe(null);
|
expect(fixture.debugElement.nativeElement.querySelector('adf-node-counter')).toBe(null);
|
||||||
});
|
});
|
||||||
|
@@ -22,6 +22,7 @@ import { Node } from '@alfresco/js-api';
|
|||||||
|
|
||||||
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
|
import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface';
|
||||||
import { NodeEntryEvent } from '../document-list/components/node.event';
|
import { NodeEntryEvent } from '../document-list/components/node.event';
|
||||||
|
import { NodeAction } from '../document-list/models/node-action.enum';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'adf-content-node-selector',
|
selector: 'adf-content-node-selector',
|
||||||
@@ -31,7 +32,7 @@ import { NodeEntryEvent } from '../document-list/components/node.event';
|
|||||||
})
|
})
|
||||||
export class ContentNodeSelectorComponent implements OnInit {
|
export class ContentNodeSelectorComponent implements OnInit {
|
||||||
title: string;
|
title: string;
|
||||||
action: string;
|
action: NodeAction;
|
||||||
buttonActionName: string;
|
buttonActionName: string;
|
||||||
chosenNode: Node[];
|
chosenNode: Node[];
|
||||||
currentDirectoryId: string;
|
currentDirectoryId: string;
|
||||||
@@ -50,7 +51,7 @@ export class ContentNodeSelectorComponent implements OnInit {
|
|||||||
private uploadService: UploadService,
|
private uploadService: UploadService,
|
||||||
private dialog: MatDialogRef<ContentNodeSelectorComponent>,
|
private dialog: MatDialogRef<ContentNodeSelectorComponent>,
|
||||||
@Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) {
|
@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.buttonActionName = `NODE_SELECTOR.${this.action}`;
|
||||||
this.title = data.title;
|
this.title = data.title;
|
||||||
this.currentDirectoryId = data.currentFolderId;
|
this.currentDirectoryId = data.currentFolderId;
|
||||||
@@ -98,12 +99,12 @@ export class ContentNodeSelectorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
updateTitle(siteTitle: string) {
|
updateTitle(siteTitle: string) {
|
||||||
if (this.action === 'CHOOSE' && siteTitle) {
|
if (this.action === NodeAction.CHOOSE && siteTitle) {
|
||||||
this.title = this.getTitleTranslation(this.action, 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) });
|
return this.translation.instant(`NODE_SELECTOR.${action}_ITEM`, { name: this.translation.instant(name) });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +113,7 @@ export class ContentNodeSelectorComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isCounterVisible(): boolean {
|
isCounterVisible(): boolean {
|
||||||
return this.action === 'ATTACH' || this.action === 'CHOOSE';
|
return this.action === NodeAction.ATTACH || this.action === NodeAction.CHOOSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
isMultipleSelection(): boolean {
|
isMultipleSelection(): boolean {
|
||||||
|
@@ -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'
|
||||||
|
}
|
@@ -44,6 +44,7 @@ export * from './models/content-action.model';
|
|||||||
export * from './models/document-library.model';
|
export * from './models/document-library.model';
|
||||||
export * from './models/permissions.model';
|
export * from './models/permissions.model';
|
||||||
export * from './models/permissions-style.model';
|
export * from './models/permissions-style.model';
|
||||||
|
export * from './models/node-action.enum';
|
||||||
|
|
||||||
export * from './interfaces/document-list-loader.interface';
|
export * from './interfaces/document-list-loader.interface';
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@ import { MatDialog } from '@angular/material/dialog';
|
|||||||
|
|
||||||
import { DocumentListService } from './document-list.service';
|
import { DocumentListService } from './document-list.service';
|
||||||
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
|
import { ContentNodeDialogService } from '../../content-node-selector/content-node-dialog.service';
|
||||||
|
import { NodeAction } from '../models/node-action.enum';
|
||||||
|
|
||||||
@Injectable({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -53,7 +54,7 @@ export class NodeActionsService {
|
|||||||
* @param permission permission which is needed to apply the action
|
* @param permission permission which is needed to apply the action
|
||||||
*/
|
*/
|
||||||
copyContent(contentEntry: Node, permission?: string): Subject<string> {
|
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
|
* @param permission permission which is needed to apply the action
|
||||||
*/
|
*/
|
||||||
copyFolder(contentEntry: Node, permission?: string): Subject<string> {
|
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
|
* @param permission permission which is needed to apply the action
|
||||||
*/
|
*/
|
||||||
moveContent(contentEntry: Node, permission?: string): Subject<string> {
|
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
|
* @param permission permission which is needed to apply the action
|
||||||
*/
|
*/
|
||||||
moveFolder(contentEntry: Node, permission?: string): Subject<string> {
|
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 contentEntry the contentEntry which has to have the action performed on
|
||||||
* @param permission permission which is needed to apply the action
|
* @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>();
|
const observable = new Subject<string>();
|
||||||
|
|
||||||
this.contentDialogService
|
this.contentDialogService
|
||||||
.openCopyMoveDialog(action, contentEntry, permission)
|
.openCopyMoveDialog(action, contentEntry, permission)
|
||||||
.subscribe((selections: Node[]) => {
|
.subscribe((selections: Node[]) => {
|
||||||
const selection = selections[0];
|
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(
|
.subscribe(
|
||||||
observable.next.bind(observable, `OPERATION.SUCCESS.${type.toUpperCase()}.${action.toUpperCase()}`),
|
observable.next.bind(observable, `OPERATION.SUCCESS.${type.toUpperCase()}.${action}`),
|
||||||
observable.error.bind(observable)
|
observable.error.bind(observable)
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@@ -18,7 +18,7 @@
|
|||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { AlfrescoApiService } from '@alfresco/adf-core';
|
import { AlfrescoApiService } from '@alfresco/adf-core';
|
||||||
import { MatDialog } from '@angular/material/dialog';
|
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 { Node } from '@alfresco/js-api';
|
||||||
import { Observable, Subject, throwError } from 'rxjs';
|
import { Observable, Subject, throwError } from 'rxjs';
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ export class ContentCloudNodeSelectorService {
|
|||||||
});
|
});
|
||||||
const data = <ContentNodeSelectorComponentData> {
|
const data = <ContentNodeSelectorComponentData> {
|
||||||
title: 'Select a file',
|
title: 'Select a file',
|
||||||
actionName: 'Attach',
|
actionName: NodeAction.ATTACH,
|
||||||
currentFolderId,
|
currentFolderId,
|
||||||
restrictRootToCurrentFolderId,
|
restrictRootToCurrentFolderId,
|
||||||
select,
|
select,
|
||||||
|
Reference in New Issue
Block a user