Skip to content

Commit

Permalink
AAE-18890 Disable attach file in form preview mode (#9469)
Browse files Browse the repository at this point in the history
  • Loading branch information
ehsan-2019 committed Mar 27, 2024
1 parent f66342d commit 55a306c
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
4 changes: 4 additions & 0 deletions lib/core/src/lib/form/services/form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,8 @@ export class FormService implements FormValidationService {
}
return null;
}

getPreviewState(): boolean {
return false;
}
}
5 changes: 4 additions & 1 deletion lib/core/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@
"TITLE": "Start Form"
},
"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": {
"LOCALSTORAGE": "Local storage",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ describe('AttachFileCloudWidgetComponent', () => {
imports: [TranslateModule.forRoot(), ProcessServiceCloudTestingModule, FormCloudModule, ContentModule.forRoot()],
schemas: [CUSTOM_ELEMENTS_SCHEMA]
});
notificationService = TestBed.inject(NotificationService);
downloadService = TestBed.inject(DownloadService);
fixture = TestBed.createComponent(AttachFileCloudWidgetComponent);
widget = fixture.componentInstance;
Expand Down Expand Up @@ -241,6 +242,17 @@ describe('AttachFileCloudWidgetComponent', () => {
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', () => {
it('should be able to display label with asterisk', async () => {
widget.field = new FormFieldModel(new FormModel({ taskId: '<id>' }), {
Expand Down Expand Up @@ -874,7 +886,6 @@ describe('AttachFileCloudWidgetComponent', () => {
let spyOnShowError: jasmine.Spy;

beforeEach(() => {
notificationService = TestBed.inject(NotificationService);
newVersionUploaderService = TestBed.inject(NewVersionUploaderService);
spyOnOpenUploadNewVersionDialog = spyOn(newVersionUploaderService, 'openUploadNewVersionDialog').and.returnValue(
of({ action: NewVersionUploaderDataAction.refresh } as any)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
rootNodeId = ALIAS_USER_FOLDER;
selectedNode: Node;

private previewState = false;
private _nodesApi: NodesApi;
get nodesApi(): NodesApi {
this._nodesApi = this._nodesApi ?? new NodesApi(this.apiService.getInstance());
Expand Down Expand Up @@ -95,6 +96,7 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
}
this.field.params.displayableCMProperties = this.field.params.displayableCMProperties ?? [];
this.displayedColumns.splice(2, 0, ...(this.field.params.displayableCMProperties?.map(property => property?.name) || []));
this.setPreviewState();
}

isPathStaticType(): boolean {
Expand Down Expand Up @@ -126,22 +128,26 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
}

async openSelectDialog() {
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
.openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true)
.subscribe((selections: Node[]) => {
selections.forEach(node => (node['isExternal'] = true));
const selectionWithoutDuplication = this.removeExistingSelection(selections);
const hadFilesAttached = this.field.value?.length > 0;
this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication);
if(!hadFilesAttached) {
this.contentModelFormFileHandler(this.field.value.length > 0 ? this.field.value[0] : null);
}
});
if (this.previewState) {
this.notificationService.showWarning('FORM.PREVIEW.ATTACH_FILE_WIDGET.ON_ATTACH_FILE_CLICK');
} else {
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
.openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal(), true)
.subscribe((selections: Node[]) => {
selections.forEach(node => (node['isExternal'] = true));
const selectionWithoutDuplication = this.removeExistingSelection(selections);
const hadFilesAttached = this.field.value?.length > 0;
this.fixIncompatibilityFromPreviousAndNewForm(selectionWithoutDuplication);
if (!hadFilesAttached) {
this.contentModelFormFileHandler(this.field.value.length > 0 ? this.field.value[0] : null);
}
});
}
}

private async getDestinationFolderNodeId(): Promise<string> {
Expand Down Expand Up @@ -274,4 +280,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
ngOnDestroy() {
this.contentNodeSelectorPanelService.customModels = [];
}

private setPreviewState(): void {
this.previewState = this.formService.getPreviewState();
}
}

0 comments on commit 55a306c

Please sign in to comment.