AAE-18890 Disable attach file in form preview mode (#9469)

This commit is contained in:
Ehsan Rezaei
2024-03-27 13:28:26 +01:00
committed by GitHub
parent f66342df2f
commit 55a306c7b2
4 changed files with 45 additions and 17 deletions

View File

@@ -83,4 +83,8 @@ export class FormService implements FormValidationService {
} }
return null; return null;
} }
getPreviewState(): boolean {
return false;
}
} }

View File

@@ -35,7 +35,10 @@
"TITLE": "Start Form" "TITLE": "Start Form"
}, },
"PREVIEW": { "PREVIEW": {
"IMAGE_NOT_AVAILABLE": "Preview not available" "IMAGE_NOT_AVAILABLE": "Preview not available",
"ATTACH_FILE_WIDGET": {
"ON_ATTACH_FILE_CLICK": "In preview mode you cannot attach a file"
}
}, },
"FIELD": { "FIELD": {
"LOCALSTORAGE": "Local storage", "LOCALSTORAGE": "Local storage",

View File

@@ -154,6 +154,7 @@ describe('AttachFileCloudWidgetComponent', () => {
imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, FormCloudModule, ContentModule.forRoot()], imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, FormCloudModule, ContentModule.forRoot()],
schemas: [CUSTOM_ELEMENTS_SCHEMA] schemas: [CUSTOM_ELEMENTS_SCHEMA]
}); });
notificationService = TestBed.inject(NotificationService);
downloadService = TestBed.inject(DownloadService); downloadService = TestBed.inject(DownloadService);
fixture = TestBed.createComponent(AttachFileCloudWidgetComponent); fixture = TestBed.createComponent(AttachFileCloudWidgetComponent);
widget = fixture.componentInstance; widget = fixture.componentInstance;
@@ -241,6 +242,17 @@ describe('AttachFileCloudWidgetComponent', () => {
expect(contentNodeSelectorPanelService.customModels).toEqual([]); expect(contentNodeSelectorPanelService.customModels).toEqual([]);
}); });
it('should display warning message when is in preview state', () => {
spyOn(notificationService, 'showWarning');
spyOn(formService, 'getPreviewState').and.returnValue(true);
createUploadWidgetField(new FormModel(), 'attach-file-alfresco', [], contentSourceParam);
fixture.detectChanges();
clickOnAttachFileWidget('attach-file-alfresco');
expect(notificationService.showWarning).toHaveBeenCalledWith('FORM.PREVIEW.ATTACH_FILE_WIDGET.ON_ATTACH_FILE_CLICK');
});
describe('when is required', () => { describe('when is required', () => {
it('should be able to display label with asterisk', async () => { it('should be able to display label with asterisk', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), { widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), {
@@ -874,7 +886,6 @@ describe('AttachFileCloudWidgetComponent', () => {
let spyOnShowError: jasmine.Spy; let spyOnShowError: jasmine.Spy;
beforeEach(() => { beforeEach(() => {
notificationService = TestBed.inject(NotificationService);
newVersionUploaderService = TestBed.inject(NewVersionUploaderService); newVersionUploaderService = TestBed.inject(NewVersionUploaderService);
spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue( spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue(
of({ action: NewVersionUploaderDataAction.refresh } as any) of({ action: NewVersionUploaderDataAction.refresh } as any)

View File

@@ -65,6 +65,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
rootNodeId = ALIAS_USER_FOLDER; rootNodeId = ALIAS_USER_FOLDER;
selectedNode: Node; selectedNode: Node;
private previewState = false;
private _nodesApi: NodesApi; private _nodesApi: NodesApi;
get nodesApi(): NodesApi { get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance()); this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
@@ -95,6 +96,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
} }
this.field.params.displayableCMProperties = this.field.params.displayableCMProperties ?? []; this.field.params.displayableCMProperties = this.field.params.displayableCMProperties ?? [];
this.displayedColumns.splice(2, 0, ...(this.field.params.displayableCMProperties?.map(property => property?.name) || [])); this.displayedColumns.splice(2, 0, ...(this.field.params.displayableCMProperties?.map(property => property?.name) || []));
this.setPreviewState();
} }
isPathStaticType(): boolean { isPathStaticType(): boolean {
@@ -126,22 +128,26 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
} }
async openSelectDialog() { async openSelectDialog() {
const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; if (this.previewState) {
const nodeId = await this.getDestinationFolderNodeId(); this.notificationService.showWarning('FORM.PREVIEW.ATTACH_FILE_WIDGET.ON_ATTACH_FILE_CLICK');
this.rootNodeId = nodeId ? nodeId : ALIAS_USER_FOLDER; } else {
this.contentNodeSelectorPanelService.customModels = this.field.params.customModels; const selectedMode = this.field.params.multiple ? 'multiple' : 'single';
const nodeId = await this.getDestinationFolderNodeId();
this.rootNodeId = nodeId ? nodeId : ALIAS_USER_FOLDER;
this.contentNodeSelectorPanelService.customModels = this.field.params.customModels;
this.contentNodeSelectorService this.contentNodeSelectorService
.openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true) .openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true)
.subscribe((selections: Node[]) => { .subscribe((selections: Node[]) => {
selections.forEach(node => (node['isExternal'] = true)); selections.forEach(node => (node['isExternal'] = true));
const selectionWithoutDuplication = this.removeExistingSelection(selections); const selectionWithoutDuplication = this.removeExistingSelection(selections);
const hadFilesAttached = this.field.value?.length > 0; const hadFilesAttached = this.field.value?.length > 0;
this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication); this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication);
if(!hadFilesAttached) { if (!hadFilesAttached) {
this.contentModelFormFileHandler(this.field.value.length > 0 ? this.field.value[0] : null); this.contentModelFormFileHandler(this.field.value.length > 0 ? this.field.value[0] : null);
} }
}); });
}
} }
private async getDestinationFolderNodeId(): Promise<string> { private async getDestinationFolderNodeId(): Promise<string> {
@@ -274,4 +280,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
ngOnDestroy() { ngOnDestroy() {
this.contentNodeSelectorPanelService.customModels = []; this.contentNodeSelectorPanelService.customModels = [];
} }
private setPreviewState(): void {
this.previewState = this.formService.getPreviewState();
}
} }