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

@@ -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;
@@ -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>' }), {
@@ -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)

View File

@@ -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());
@@ -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 {
@@ -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;
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);
}
});
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> {
@@ -274,4 +280,8 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent i
ngOnDestroy() {
this.contentNodeSelectorPanelService.customModels = [];
}
private setPreviewState(): void {
this.previewState = this.formService.getPreviewState();
}
}