From eb5d0da079d0dc55886a3ac7b627db8044ec7782 Mon Sep 17 00:00:00 2001 From: siva kumar Date: Thu, 13 Aug 2020 17:15:01 +0530 Subject: [PATCH] [ACA-3603] Destination picker is not opening on My Files when clicking on Attach file widget (#5865) * [ACA-3603] Destination picker is not opening on My Files when clicking on Attach file widget * * * * Fixed failing unit tests * * Used openFileBrowseDialogByFolderId --- .../content-node-dialog.service.ts | 9 ++++++ .../site-dropdown/sites-dropdown.component.ts | 4 +-- ...-file-widget-dialog-component.interface.ts | 1 + .../attach-file-widget-dialog.component.html | 1 + ...ttach-file-widget-dialog.component.spec.ts | 30 ++++++++++++++----- .../attach-file-widget-dialog.service.ts | 1 + .../attach-file-widget.component.spec.ts | 8 ++--- .../attach-file-widget.component.ts | 2 +- 8 files changed, 41 insertions(+), 15 deletions(-) diff --git a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts index 6e3e8fd796..db3d006da9 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-dialog.service.ts @@ -102,6 +102,15 @@ export class ContentNodeDialogService { })); } + /** + * Opens a file browser at a default myFile location. + * shows files and folders in the dialog search result. + * @returns Information about the selected file(s) + */ + openFileBrowseDialogByDefaultLocation(): Observable { + return this.openFileBrowseDialogByFolderId('-my-'); + } + /** * Opens a folder browser at a chosen site location. * @returns Information about the selected folder(s) diff --git a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts index 357f99feb0..fce650d616 100644 --- a/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts +++ b/lib/content-services/src/lib/site-dropdown/sites-dropdown.component.ts @@ -18,7 +18,7 @@ import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ViewEncapsulation, OnDestroy } from '@angular/core'; import { SitesService, LogService } from '@alfresco/adf-core'; import { SitePaging, SiteEntry } from '@alfresco/js-api'; -import { MatSelect } from '@angular/material/select'; +import { MatSelect, MatSelectChange } from '@angular/material/select'; import { Subject } from 'rxjs'; import { takeUntil } from 'rxjs/operators'; @@ -118,7 +118,7 @@ export class DropdownSitesComponent implements OnInit, OnDestroy { return event.target.scrollTop >= (event.target.scrollHeight - event.target.offsetHeight - this.ITEM_HEIGHT_TO_WAIT_BEFORE_LOAD_NEXT); } - selectedSite(event: any) { + selectedSite(event: MatSelectChange) { this.change.emit(event.value); } diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog-component.interface.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog-component.interface.ts index 966174954e..e193301b12 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog-component.interface.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog-component.interface.ts @@ -22,6 +22,7 @@ export interface AttachFileWidgetDialogComponentData { title: string; actionName?: string; selected: Subject; + currentFolderId: string; ecmHost: string; context?: string; isSelectionValid?: (entry: Node) => boolean; diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html index 500df55247..2a3981b53e 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.component.html @@ -10,6 +10,7 @@ { @@ -35,14 +35,18 @@ describe('AttachFileWidgetDialogComponent', () => { const data: AttachFileWidgetDialogComponentData = { title: 'Choose along citizen...', actionName: 'Choose', + currentFolderId: '-my-', selected: new EventEmitter(), - ecmHost: 'http://fakeUrl.com/' + ecmHost: 'http://fakeUrl.com' }; let element: HTMLInputElement; let authService: AuthenticationService; let siteService: SitesService; + let nodeService: NodesApiService; + let documentListService: DocumentListService; let isLogged = false; + const fakeSite = new SiteEntry({ entry: { id: 'fake-site', guid: 'fake-site', title: 'fake-site', visibility: 'visible' } }); setupTestBed({ imports: [ @@ -51,8 +55,10 @@ describe('AttachFileWidgetDialogComponent', () => { ContentModule.forRoot() ], providers: [ - { provide: MAT_DIALOG_DATA, useValue: data } - ] + { provide: MAT_DIALOG_DATA, useValue: data }, + { provide: AlfrescoApiService, useClass: AlfrescoApiServiceMock } + ], + schemas: [NO_ERRORS_SCHEMA] }); beforeEach(async(() => { @@ -61,6 +67,14 @@ describe('AttachFileWidgetDialogComponent', () => { element = fixture.nativeElement; authService = fixture.debugElement.injector.get(AuthenticationService); siteService = fixture.debugElement.injector.get(SitesService); + nodeService = fixture.debugElement.injector.get(NodesApiService); + documentListService = fixture.debugElement.injector.get(DocumentListService); + + spyOn(documentListService, 'getFolderNode').and.returnValue(of( { entry: { path: { elements: [] } } })); + spyOn(documentListService, 'getFolder').and.returnValue(throwError('No results for test')); + spyOn(nodeService, 'getNode').and.returnValue(of({ id: 'fake-node', path: { elements: [{ nodeType: 'st:site', name: 'fake-site'}] } })); + + spyOn(siteService, 'getSite').and.returnValue(of(fakeSite)); spyOn(siteService, 'getSites').and.returnValue(of({ list: { entries: [] } })); spyOn(widget, 'isLoggedIn').and.callFake(() => { return isLogged; diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts index f5d19726bf..d640fc33dd 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget-dialog.service.ts @@ -54,6 +54,7 @@ export class AttachFileWidgetDialogService { actionName, selected, ecmHost, + currentFolderId: '-my-', context, isSelectionValid: (entry: Node) => entry.isFile, showFilesInResult: true diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts b/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts index cd264bfd18..fc119680e7 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget.component.spec.ts @@ -241,7 +241,7 @@ describe('AttachFileWidgetComponent', () => { it('should isLink property of the selected node become true when the widget has link enabled', async (done) => { spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); const applyAlfrescoNodeSpy = spyOn(activitiContentService, 'applyAlfrescoNode'); - spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(of([fakeMinimalNode])); + spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -267,7 +267,7 @@ describe('AttachFileWidgetComponent', () => { it('should isLink property of the selected node become false when the widget has link disabled', async (done) => { spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); const applyAlfrescoNodeSpy = spyOn(activitiContentService, 'applyAlfrescoNode'); - spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(of([fakeMinimalNode])); + spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -293,7 +293,7 @@ describe('AttachFileWidgetComponent', () => { it('should be able to upload files coming from content node selector', async(() => { spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValue(of(fakePngAnswer)); - spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(of([fakeMinimalNode])); + spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] @@ -323,7 +323,7 @@ describe('AttachFileWidgetComponent', () => { }; spyOn(activitiContentService, 'getAlfrescoRepositories').and.returnValue(of(fakeRepositoryListAnswer)); spyOn(activitiContentService, 'applyAlfrescoNode').and.returnValues(of(fakePngAnswer), of(fakePngUpload)); - spyOn(contentNodeDialogService, 'openFileBrowseDialogBySite').and.returnValue(of([fakeMinimalNode])); + spyOn(contentNodeDialogService, 'openFileBrowseDialogByDefaultLocation').and.returnValue(of([fakeMinimalNode])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] diff --git a/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts b/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts index 93d282fe15..2c060f22fe 100644 --- a/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts +++ b/lib/process-services/src/lib/content-widget/attach-file-widget.component.ts @@ -215,7 +215,7 @@ export class AttachFileWidgetComponent extends UploadWidgetComponent implements this.uploadFileFromCS(selections, accountIdentifier); }); } else { - this.contentDialog.openFileBrowseDialogBySite().subscribe( + this.contentDialog.openFileBrowseDialogByDefaultLocation().subscribe( (selections: Node[]) => { this.tempFilesList.push(...selections); this.uploadFileFromCS(selections, accountIdentifier);