From d553c71b1e035d5389c2e7001482c889c1b6be45 Mon Sep 17 00:00:00 2001 From: arditdomi <32884230+arditdomi@users.noreply.github.com> Date: Fri, 31 Jul 2020 07:38:58 +0200 Subject: [PATCH] [AAE-3110] Move upload button inside the node selector dialog (#5901) * Open select dialog on all types, fetch destination folder from a relative path * Dialog UI refactor, multiple upload from local * Fix document list should automatically reload after upload * Remove not used ViewChild * Fix imports, read destination folder from form field * support different alias * Remove not needed property, reuse selection mode * Remove unused methods * Fix unit tests * * Added unit tests * Fixed failing unit tests * * Added unit for upload button * Skipped failing e2e * * Removed process-storage related code * * Removed unncessory model and code * * * Removed contentHost from formCloud model * * Skiped content-services e2e * Skip failing process e2e related to attachment Co-authored-by: sivakumar414ram Co-authored-by: maurizio vitale --- .../app/components/files/files.component.ts | 22 +- .../content-node-selector-panel.component.md | 1 + .../services/form-cloud.service.md | 10 +- e2e/protractor.excludes.json | 15 +- ...content-node-selector-panel.component.html | 2 +- ...tent-node-selector-panel.component.spec.ts | 10 +- .../content-node-selector-panel.component.ts | 9 +- ...-node-selector.component-data.interface.ts | 2 + .../content-node-selector.component.html | 38 ++- .../content-node-selector.component.scss | 3 +- .../content-node-selector.component.spec.ts | 21 +- .../content-node-selector.component.ts | 23 +- .../content-node-selector.module.ts | 4 +- .../components/document-list.component.ts | 18 +- lib/content-services/src/lib/i18n/en.json | 1 + .../components/upload-button.component.html | 6 +- .../widgets/core/form-field-file-source.ts | 1 + .../components/widgets/core/form.model.ts | 1 - lib/core/i18n/en.json | 3 +- .../components/form-cloud.component.spec.ts | 41 +-- .../form/components/form-cloud.component.ts | 35 +-- .../attach-file-cloud-widget.component.html | 32 +-- ...attach-file-cloud-widget.component.spec.ts | 262 ++++++++++-------- .../attach-file-cloud-widget.component.ts | 88 +++--- .../attach-file/upload-cloud.widget.ts | 4 +- .../form/models/task-variable-cloud.model.ts | 13 - .../content-cloud-node-selector.service.ts | 23 +- .../form/services/form-cloud.service.spec.ts | 39 --- .../lib/form/services/form-cloud.service.ts | 18 +- .../services/process-cloud-content.service.ts | 22 +- .../src/lib/i18n/en.json | 3 + 31 files changed, 338 insertions(+), 432 deletions(-) diff --git a/demo-shell/src/app/components/files/files.component.ts b/demo-shell/src/app/components/files/files.component.ts index c727dc8447..00e3bf185e 100644 --- a/demo-shell/src/app/components/files/files.component.ts +++ b/demo-shell/src/app/components/files/files.component.ts @@ -25,8 +25,7 @@ import { MatDialog } from '@angular/material/dialog'; import { ActivatedRoute, Params, Router } from '@angular/router'; import { MinimalNodeEntity, NodePaging, Pagination, MinimalNodeEntryEntity, SiteEntry, SearchEntry } from '@alfresco/js-api'; import { - AlfrescoApiService, AuthenticationService, AppConfigService, AppConfigValues, ContentService, TranslationService, - FileUploadEvent, FolderCreatedEvent, LogService, NotificationService, + AlfrescoApiService, AuthenticationService, AppConfigService, AppConfigValues, ContentService, TranslationService, FolderCreatedEvent, LogService, NotificationService, UploadService, DataRow, UserPreferencesService, PaginationComponent, FormValues, DisplayMode, ShowHeaderMode, InfinitePaginationComponent, HighlightDirective, SharedLinksApiService @@ -47,7 +46,7 @@ import { VersionManagerDialogAdapterComponent } from './version-manager-dialog-a import { MetadataDialogAdapterComponent } from './metadata-dialog-adapter.component'; import { Subject } from 'rxjs'; import { PreviewService } from '../../services/preview.service'; -import { debounceTime, takeUntil } from 'rxjs/operators'; +import { takeUntil } from 'rxjs/operators'; const DEFAULT_FOLDER_TO_SHOW = '-my-'; @@ -272,17 +271,6 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy { }); } - this.uploadService.fileUploadComplete - .pipe( - debounceTime(300), - takeUntil(this.onDestroy$) - ) - .subscribe(value => this.onFileUploadEvent(value)); - - this.uploadService.fileUploadDeleted - .pipe(takeUntil(this.onDestroy$)) - .subscribe(value => this.onFileUploadEvent(value)); - this.contentService.folderCreated .pipe(takeUntil(this.onDestroy$)) .subscribe(value => this.onFolderCreated(value)); @@ -350,12 +338,6 @@ export class FilesComponent implements OnInit, OnChanges, OnDestroy { this.errorMessage = null; } - onFileUploadEvent(event: FileUploadEvent) { - if (event && event.file.options.parentId === this.documentList.currentFolderId) { - this.documentList.reload(); - } - } - onFolderCreated(event: FolderCreatedEvent) { this.logService.log('FOLDER CREATED'); this.logService.log(event); diff --git a/docs/content-services/components/content-node-selector-panel.component.md b/docs/content-services/components/content-node-selector-panel.component.md index 2085b971e0..dbbcbf887d 100644 --- a/docs/content-services/components/content-node-selector-panel.component.md +++ b/docs/content-services/components/content-node-selector-panel.component.md @@ -52,6 +52,7 @@ Opens a [Content Node Selector](content-node-selector.component.md) in its own | ---- | ---- | ----------- | | select | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`<`[`Node`](https://github.com/Alfresco/alfresco-js-api/blob/development/src/api/content-rest-api/docs/Node.md)`[]>` | Emitted when the user has chosen an item. | | siteChange | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the select site changes. | +| navigationChange | [`EventEmitter`](https://angular.io/api/core/EventEmitter)`` | Emitted when the navigation changes. | ## Details diff --git a/docs/process-services-cloud/services/form-cloud.service.md b/docs/process-services-cloud/services/form-cloud.service.md index 16335d6553..8611fcd44a 100644 --- a/docs/process-services-cloud/services/form-cloud.service.md +++ b/docs/process-services-cloud/services/form-cloud.service.md @@ -36,11 +36,10 @@ class MyComponent { - _outcome:_ `string` - [Form](../../../lib/process-services/src/lib/task-list/models/form.model.ts) outcome - _version:_ `number` - of the form - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskDetailsCloudModel`](../../../lib/process-services-cloud/src/lib/task/start-task/models/task-details-cloud.model.ts)`>` - Updated task details -- **createTemporaryRawRelatedContent**(file: `any`, nodeId: `string`, contentHost: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)``
+- **createTemporaryRawRelatedContent**(file: `any`, nodeId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)``
- _file:_ `any` - - _nodeId:_ `string` - - - _contentHost:_ `string` - - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`` - - **getBasePath**(appName: `string`): `string`
@@ -58,13 +57,6 @@ class MyComponent { - _formKey:_ `string` - key of the target task - _version:_ `number` - (Optional) Version of the form - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`FormContent`](../../../lib/process-services-cloud/src/lib/services/form-fields.interfaces.ts)`>` - Form definition -- **getProcessStorageFolderTask**(appName: `string`, taskId: `string`, processInstanceId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ProcessStorageCloudModel`](../../../lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts)`>`
- - - _appName:_ `string` - - - _taskId:_ `string` - - - _processInstanceId:_ `string` - - - **Returns** [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`ProcessStorageCloudModel`](../../../lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts)`>` - - - **getTask**(appName: `string`, taskId: `string`): [`Observable`](http://reactivex.io/documentation/observable.html)`<`[`TaskDetailsCloudModel`](../../../lib/process-services-cloud/src/lib/task/start-task/models/task-details-cloud.model.ts)`>`
Gets details of a task - _appName:_ `string` - Name of the app diff --git a/e2e/protractor.excludes.json b/e2e/protractor.excludes.json index 6661891991..05c3b07429 100644 --- a/e2e/protractor.excludes.json +++ b/e2e/protractor.excludes.json @@ -4,6 +4,19 @@ "C362240": "Include once ADF starts using ACS 7 , https://issues.alfresco.com/jira/browse/ADF-5182", "C362241": "Include once ADF starts using ACS 7, https://issues.alfresco.com/jira/browse/ADF-5182", "C362242": "Include once ADF starts using ACS 7, https://issues.alfresco.com/jira/browse/ADF-5182", - "C362265": "Include once ADF starts using ACS 7, https://issues.alfresco.com/jira/browse/ADF-5182" + "C362265": "Include once ADF starts using ACS 7, https://issues.alfresco.com/jira/browse/ADF-5182", + "C311290": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C310358": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311285": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311287": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311288": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311289": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311292": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311293": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C311295": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C315292": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C260140": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C261160": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177", + "C246534": "Include once process storage services removed, https://issues.alfresco.com/jira/browse/AAE-3177" } diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html index 60de757949..4db38d3496 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.html @@ -71,7 +71,7 @@ [allowDropFiles]="false" [sorting]="'server'" [where]="where" - (folderChange)="onFolderChange()" + (folderChange)="onFolderChange($event)" (ready)="onFolderLoaded()" (nodeSelected)="onCurrentSelection($event)" data-automation-id="content-node-selector-document-list"> diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts index aebd12f6a8..bd0e6f7264 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.spec.ts @@ -29,7 +29,7 @@ import { DocumentListService } from '../document-list/services/document-list.ser import { DocumentListComponent } from '../document-list/components/document-list.component'; import { DropdownSitesComponent } from '../site-dropdown/sites-dropdown.component'; import { CustomResourcesService } from '../document-list/services/custom-resources.service'; -import { ShareDataRow } from '../document-list'; +import { NodeEntryEvent, ShareDataRow } from '../document-list'; import { TranslateModule } from '@ngx-translate/core'; const ONE_FOLDER_RESULT = { @@ -59,6 +59,8 @@ describe('ContentNodeSelectorComponent', () => { let sitesService: SitesService; let searchSpy: jasmine.Spy; let cnSearchSpy: jasmine.Spy; + const fakeNodeEntry = new Node({ id: 'fakeId' }); + const nodeEntryEvent = new NodeEntryEvent(fakeNodeEntry); let _observer: Observer; @@ -271,7 +273,7 @@ describe('ContentNodeSelectorComponent', () => { tick(debounceSearch); - component.onFolderChange(); + component.onFolderChange(nodeEntryEvent); fixture.detectChanges(); const breadcrumb = fixture.debugElement.query(By.directive(DropdownBreadcrumbComponent)); expect(breadcrumb).not.toBeNull(); @@ -309,7 +311,7 @@ describe('ContentNodeSelectorComponent', () => { respondWithSearchResults(ONE_FOLDER_RESULT); fixture.detectChanges(); - component.onFolderChange(); + component.onFolderChange(nodeEntryEvent); fixture.detectChanges(); const chosenNode = { path: { elements: [] } }; @@ -700,7 +702,7 @@ describe('ContentNodeSelectorComponent', () => { tick(); fixture.detectChanges(); - component.onFolderChange(); + component.onFolderChange(nodeEntryEvent); fixture.detectChanges(); expect(component.clearSearch).toHaveBeenCalled(); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts index 0c43102a42..d4fec5ac1b 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector-panel.component.ts @@ -33,7 +33,7 @@ import { ImageResolver } from '../document-list/data/image-resolver.model'; import { ContentNodeSelectorService } from './content-node-selector.service'; import { debounceTime, takeUntil } from 'rxjs/operators'; import { CustomResourcesService } from '../document-list/services/custom-resources.service'; -import { ShareDataRow } from '../document-list'; +import { NodeEntryEvent, ShareDataRow } from '../document-list'; import { Subject } from 'rxjs'; export type ValidationFunction = (entry: Node) => boolean; @@ -186,6 +186,10 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { @Output() select: EventEmitter = new EventEmitter(); + /** Emitted when the navigation changes. */ + @Output() + navigationChange: EventEmitter = new EventEmitter(); + /** Emitted when the select site changes. */ @Output() siteChange: EventEmitter = new EventEmitter(); @@ -426,11 +430,12 @@ export class ContentNodeSelectorPanelComponent implements OnInit, OnDestroy { /** * Sets showingSearchResults state to be able to differentiate between search results or folder results */ - onFolderChange(): void { + onFolderChange($event: NodeEntryEvent): void { this.showingSearchResults = false; this.infiniteScroll = false; this.breadcrumbFolderTitle = null; this.clearSearch(); + this.navigationChange.emit($event); } /** diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts index 69e283e1db..b7f4270c53 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component-data.interface.ts @@ -36,4 +36,6 @@ export interface ContentNodeSelectorComponentData { showSearch?: boolean; showFilesInResult?: boolean; showDropdownSiteList?: boolean; + showLocalUploadButton?: boolean; + multipleUpload?: boolean; } diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html index b3f76c70a4..4f7e190fa0 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.html @@ -21,21 +21,33 @@ [showDropdownSiteList]="data?.showDropdownSiteList" [showFilesInResult]="data?.showFilesInResult" (select)="onSelect($event)" - (siteChange)="onSiteChange($event)"> + (siteChange)="onSiteChange($event)" + (navigationChange)="onNavigationChange($event)"> - - + +
+ + +
+
+ - + +
diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.scss b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.scss index e31653d11e..b638e57fe3 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.scss +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.scss @@ -36,7 +36,8 @@ padding: 8px; background-color: mat-color($background, background); display: flex; - justify-content: flex-end; + flex-direction: row; + justify-content: space-between; color: mat-color($foreground, text, 0.72); button { diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts index f7d6678d80..3a590d974d 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.spec.ts @@ -40,7 +40,8 @@ describe('ContentNodeSelectorDialogComponent', () => { select: new EventEmitter(), rowFilter: (shareDataRow: ShareDataRow) => shareDataRow.node.entry.name === 'impossible-name', imageResolver: () => 'piccolo', - currentFolderId: 'cat-girl-nuku-nuku' + currentFolderId: 'cat-girl-nuku-nuku', + showLocalUploadButton: true }; setupTestBed({ @@ -175,4 +176,22 @@ describe('ContentNodeSelectorDialogComponent', () => { expect(titleElement.nativeElement.innerText).toBe('NODE_SELECTOR.CHOOSE_ITEM'); }); }); + + describe('Upload button', () => { + + it('should be able to show upload button if showLocalUploadButton set to true', () => { + const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button')); + + expect(adfUploadButton).not.toBeNull(); + expect(adfUploadButton.nativeElement.innerText).toEqual('file_uploadFORM.FIELD.UPLOAD'); + }); + + it('should not be able to show upload button if showLocalUploadButton set to false', () => { + component.data.showLocalUploadButton = false; + fixture.detectChanges(); + const adfUploadButton = fixture.debugElement.query(By.css('adf-upload-button span')); + + expect(adfUploadButton).toBeNull(); + }); + }); }); diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts index 3e2e2e9233..d89311b0eb 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.component.ts @@ -17,9 +17,10 @@ import { Component, Inject, ViewEncapsulation } from '@angular/core'; import { MAT_DIALOG_DATA } from '@angular/material/dialog'; -import { TranslationService } from '@alfresco/adf-core'; +import { TranslationService, NotificationService } from '@alfresco/adf-core'; import { Node } from '@alfresco/js-api'; import { ContentNodeSelectorComponentData } from './content-node-selector.component-data.interface'; +import { NodeEntryEvent } from '../document-list/components/node.event'; @Component({ selector: 'adf-content-node-selector', @@ -28,17 +29,19 @@ import { ContentNodeSelectorComponentData } from './content-node-selector.compon encapsulation: ViewEncapsulation.None }) export class ContentNodeSelectorComponent { - title: string; action: string; buttonActionName: string; chosenNode: Node[]; + currentDirectoryId: string; constructor(private translation: TranslationService, + private notificationService: NotificationService, @Inject(MAT_DIALOG_DATA) public data: ContentNodeSelectorComponentData) { this.action = data.actionName ? data.actionName.toUpperCase() : 'CHOOSE'; this.buttonActionName = `NODE_SELECTOR.${this.action}`; this.title = data.title; + this.currentDirectoryId = data.currentFolderId; } close() { @@ -49,14 +52,14 @@ export class ContentNodeSelectorComponent { this.chosenNode = nodeList; } - hasNodeSelected(): boolean { - return this.chosenNode?.length > 0; - } - onSiteChange(siteTitle: string) { this.updateTitle(siteTitle); } + onNavigationChange(pathElement: NodeEntryEvent) { + this.currentDirectoryId = pathElement.value.id; + } + onClick(): void { this.data.select.next(this.chosenNode); this.data.select.complete(); @@ -71,4 +74,12 @@ export class ContentNodeSelectorComponent { getTitleTranslation(action: string, name: string): string { return this.translation.instant(`NODE_SELECTOR.${action}_ITEM`, { name: this.translation.instant(name) }); } + + isMultipleSelection(): boolean { + return this.data.selectionMode === 'multiple'; + } + + onError(error) { + this.notificationService.showError(error); + } } diff --git a/lib/content-services/src/lib/content-node-selector/content-node-selector.module.ts b/lib/content-services/src/lib/content-node-selector/content-node-selector.module.ts index 5b267e2d18..21e6baf3eb 100644 --- a/lib/content-services/src/lib/content-node-selector/content-node-selector.module.ts +++ b/lib/content-services/src/lib/content-node-selector/content-node-selector.module.ts @@ -27,6 +27,7 @@ import { BreadcrumbModule } from '../breadcrumb/breadcrumb.module'; import { CoreModule } from '@alfresco/adf-core'; import { DocumentListModule } from '../document-list/document-list.module'; import { NameLocationCellComponent } from './name-location-cell/name-location-cell.component'; +import { UploadModule } from '../upload/upload.module'; @NgModule({ imports: [ @@ -37,7 +38,8 @@ import { NameLocationCellComponent } from './name-location-cell/name-location-ce MaterialModule, SitesDropdownModule, BreadcrumbModule, - DocumentListModule + DocumentListModule, + UploadModule ], exports: [ ContentNodeSelectorPanelComponent, diff --git a/lib/content-services/src/lib/document-list/components/document-list.component.ts b/lib/content-services/src/lib/document-list/components/document-list.component.ts index 0b38ba2344..2231740dfd 100644 --- a/lib/content-services/src/lib/document-list/components/document-list.component.ts +++ b/lib/content-services/src/lib/document-list/components/document-list.component.ts @@ -45,7 +45,8 @@ import { RequestPaginationModel, AlfrescoApiService, UserPreferenceValues, - LockService + LockService, + UploadService } from '@alfresco/adf-core'; import { Node, NodeEntry, NodePaging, Pagination } from '@alfresco/js-api'; @@ -60,7 +61,7 @@ import { NavigableComponentInterface } from '../../breadcrumb/navigable-componen import { RowFilter } from '../data/row-filter.model'; import { DocumentListService } from '../services/document-list.service'; import { DocumentLoaderNode } from '../models/document-folder.model'; -import { takeUntil } from 'rxjs/operators'; +import { debounceTime, takeUntil } from 'rxjs/operators'; @Component({ selector: 'adf-document-list', @@ -337,6 +338,7 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte private appConfig: AppConfigService, private userPreferencesService: UserPreferencesService, private contentService: ContentService, + private uploadService: UploadService, private thumbnailService: ThumbnailService, private alfrescoApiService: AlfrescoApiService, private lockService: LockService) { @@ -346,6 +348,18 @@ export class DocumentListComponent implements OnInit, OnChanges, OnDestroy, Afte .subscribe(pagSize => { this.maxItems = this._pagination.maxItems = pagSize; }); + + this.uploadService.fileUploadComplete + .pipe( + debounceTime(300), + takeUntil(this.onDestroy$)) + .subscribe(() => this.reload()); + + this.uploadService.fileUploadDeleted + .pipe( + debounceTime(300), + takeUntil(this.onDestroy$)) + .subscribe(() => this.reload()); } getContextActions(node: NodeEntry) { diff --git a/lib/content-services/src/lib/i18n/en.json b/lib/content-services/src/lib/i18n/en.json index a441716bc6..c29bc231b5 100644 --- a/lib/content-services/src/lib/i18n/en.json +++ b/lib/content-services/src/lib/i18n/en.json @@ -80,6 +80,7 @@ "NODE_SELECTOR": { "CANCEL": "Cancel", "CHOOSE": "Select", + "ATTACH": "Attach", "CHOOSE_ITEM": "Select content to attach from '{{ name }}'", "COPY": "Copy", "COPY_ITEM": "Copy '{{ name }}' to...", diff --git a/lib/content-services/src/lib/upload/components/upload-button.component.html b/lib/content-services/src/lib/upload/components/upload-button.component.html index f75f991cf2..a8d3107712 100644 --- a/lib/content-services/src/lib/upload/components/upload-button.component.html +++ b/lib/content-services/src/lib/upload/components/upload-button.component.html @@ -5,7 +5,7 @@ - -
- -
-
diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts index 9e7e0b7dde..23ea888db6 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.spec.ts @@ -27,7 +27,8 @@ import { FormFieldTypes, FormFieldMetadata, FormService, - DownloadService + DownloadService, + NotificationService } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../../../testing/process-service-cloud.testing.module'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; @@ -44,6 +45,7 @@ describe('AttachFileCloudWidgetComponent', () => { let element: HTMLInputElement; let contentCloudNodeSelectorService: ContentCloudNodeSelectorService; let processCloudContentService: ProcessCloudContentService; + let notificationService: NotificationService; let formService: FormService; let downloadService: DownloadService; @@ -80,6 +82,22 @@ describe('AttachFileCloudWidgetComponent', () => { } }; + const allSourceParams = { + fileSource: { + name: 'all file sources', + serviceId: 'all-file-sources', + destinationFolderPath: '-root-/myfiles' + } + }; + + const allSourceParamsWithWrongPath = { + fileSource: { + name: 'all file sources', + serviceId: 'all-file-sources', + destinationFolderPath: 'mock-folder' + } + }; + const fakeMinimalNode: Node = { id: 'fake', name: 'fake-name', @@ -88,25 +106,9 @@ describe('AttachFileCloudWidgetComponent', () => { } }; - const fakeLocalPngAnswer = { - id: 1155, - nodeId: 1155, - name: 'a_png_file.png', - created: '2017-07-25T17:17:37.099Z', - createdBy: { - id: 1001, - firstName: 'Admin', - lastName: 'admin', - email: 'admin' - }, - relatedContent: false, - contentAvailable: true, - link: false, - mimeType: 'image/png', - simpleType: 'image', - previewStatus: 'queued', - thumbnailStatus: 'queued' - }; + const mockNodeId = new Promise(function (resolve) { + resolve('mock-node-id'); + }); setupTestBed({ imports: [ @@ -128,23 +130,20 @@ describe('AttachFileCloudWidgetComponent', () => { ContentCloudNodeSelectorService ); formService = TestBed.inject(FormService); + notificationService = TestBed.inject(NotificationService); })); afterEach(() => { fixture.destroy(); }); - it('should be able to create the widget', () => { - expect(widget).not.toBeNull(); - }); - it('should show up as simple upload when is configured for only local files', async(() => { widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] }); widget.field.id = 'simple-upload-button'; - widget.field.params = onlyLocalParams; + widget.field.params = allSourceParams; fixture.detectChanges(); fixture.whenStable().then(() => { expect( @@ -168,7 +167,7 @@ describe('AttachFileCloudWidgetComponent', () => { }); })); - it('should be able to attach files coming from content selector', async(() => { + it('should be able to attach files coming from content selector', async() => { spyOn( contentCloudNodeSelectorService, 'openUploadFileDialog' @@ -180,47 +179,108 @@ describe('AttachFileCloudWidgetComponent', () => { widget.field.id = 'attach-file-alfresco'; widget.field.params = contentSourceParam; fixture.detectChanges(); - fixture.whenStable().then(() => { - const attachButton: HTMLButtonElement = element.querySelector( - '#attach-file-alfresco' - ); - expect(attachButton).not.toBeNull(); - attachButton.click(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - fixture.debugElement - .query(By.css('#attach-mock-alf-content')) - .nativeElement.click(); - fixture.detectChanges(); - expect(element.querySelector('#file-fake-icon')).not.toBeNull(); - }); - }); - })); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); - it('should be able to upload files from local source', async(() => { + expect(attachButton).not.toBeNull(); + + attachButton.click(); + await fixture.whenStable(); + fixture.detectChanges(); + const attachedFileName = fixture.debugElement.query(By.css('.adf-file')); + const fileIcon = element.querySelector('#file-fake-icon'); + + expect(attachedFileName.nativeElement.innerText).toEqual('fake-name'); + expect(fileIcon).not.toBeNull(); + }); + + it('should be able to attach files coming from all files source', async() => { + spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); + spyOn( + contentCloudNodeSelectorService, + 'openUploadFileDialog' + ).and.returnValue(of([fakeMinimalNode])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] }); - widget.field.id = 'attach-file-local'; - widget.field.params = onlyLocalParams; - spyOn( - processCloudContentService, - 'createTemporaryRawRelatedContent' - ).and.returnValue(of(fakeLocalPngAnswer)); + widget.field.id = 'attach-file-alfresco'; + widget.field.params = allSourceParams; fixture.detectChanges(); - fixture.whenStable().then(() => { - fixture.detectChanges(); - const inputDebugElement = fixture.debugElement.query( - By.css('#attach-file-local') - ); - inputDebugElement.triggerEventHandler('change', { - target: { files: [fakeLocalPngAnswer] } - }); - fixture.detectChanges(); - expect(element.querySelector('#file-1155-icon')).not.toBeNull(); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); + + expect(attachButton).not.toBeNull(); + + attachButton.click(); + await fixture.whenStable(); + fixture.detectChanges(); + const attachedFileName = fixture.debugElement.query(By.css('.adf-file')); + const fileIcon = element.querySelector('#file-fake-icon'); + + expect(attachedFileName.nativeElement.innerText).toEqual('fake-name'); + expect(fileIcon).not.toBeNull(); + }); + + it('should be able to fetch nodeId if destinationFolderPtah defined ', async() => { + const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); + spyOn( + contentCloudNodeSelectorService, + 'openUploadFileDialog' + ).and.returnValue(of([fakeMinimalNode])); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + value: [] }); - })); + widget.field.id = 'attach-file-alfresco'; + widget.field.params = allSourceParams; + fixture.detectChanges(); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); + + expect(attachButton).not.toBeNull(); + + attachButton.click(); + await fixture.whenStable(); + fixture.detectChanges(); + + const alias = '-root-'; + const opt = { relativePath: '/myfiles' }; + expect(fetchNodeIdFromRelativePathSpy).toHaveBeenCalledWith(alias, opt); + expect(widget.field.params.fileSource.destinationFolderPath).toBe('-root-/myfiles'); + expect(widget.rootNodeId).toEqual('mock-node-id'); + }); + + it('should be able to show error notification if destinationFolderPtah wrong/undefined', async() => { + const fetchNodeIdFromRelativePathSpy = spyOn(contentCloudNodeSelectorService, 'fetchNodeIdFromRelativePath').and.returnValue(mockNodeId); + spyOn( + contentCloudNodeSelectorService, + 'openUploadFileDialog' + ).and.returnValue(of([fakeMinimalNode])); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + value: [] + }); + const showErrorSpy = spyOn(notificationService, 'showError').and.callThrough(); + widget.field = new FormFieldModel(new FormModel(), { + type: FormFieldTypes.UPLOAD, + value: [] + }); + widget.field.id = 'attach-file-alfresco'; + widget.field.params = allSourceParamsWithWrongPath; + fixture.detectChanges(); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); + + expect(attachButton).not.toBeNull(); + + attachButton.click(); + await fixture.whenStable(); + fixture.detectChanges(); + + expect(fetchNodeIdFromRelativePathSpy).not.toHaveBeenCalled(); + expect(showErrorSpy).toHaveBeenCalled(); + }); it('should display file list when field has value', async(() => { widget.field = new FormFieldModel(new FormModel(), { @@ -249,38 +309,6 @@ describe('AttachFileCloudWidgetComponent', () => { }); }); - it('should be able to enable multiple file upload', async(() => { - const files = [fakeLocalPngAnswer, { ...fakeLocalPngAnswer, id: 1166, nodeId: 1166, name: 'second_png_file.png' }]; - widget.field = new FormFieldModel(new FormModel(), { - type: FormFieldTypes.UPLOAD, - id: 'attach-file', - name: 'Upload', - value: [], - params: { onlyLocalParams, multiple: true } - }); - spyOn(processCloudContentService, 'createTemporaryRawRelatedContent') - .and.returnValues(of(files[0]), of(files[1])); - fixture.detectChanges(); - fixture.whenStable().then(() => { - const inputDebugElement = fixture.debugElement.query(By.css('#attach-file')); - expect(inputDebugElement.nativeElement.multiple).toBe(true); - inputDebugElement.triggerEventHandler('change', { - target: { files: [ files[0] ] } - }); - fixture.detectChanges(); - expect(element.querySelector('#file-1155-icon')).toBeDefined(); - let name: HTMLElement = element.querySelector('span[id="file-1155"]'); - expect(name.innerText).toEqual('a_png_file.png'); - inputDebugElement.triggerEventHandler('change', { - target: { files: [ files[1] ] } - }); - fixture.detectChanges(); - expect(element.querySelector('#file-1166-icon')).toBeDefined(); - name = element.querySelector('span[id="file-1166"]'); - expect(name.innerText).toEqual('second_png_file.png'); - }); - })); - describe('when is readonly', () => { it('should show empty list message when there are no file', async(() => { @@ -332,46 +360,44 @@ describe('AttachFileCloudWidgetComponent', () => { }); describe('when a file is uploaded', () => { - beforeEach(async(() => { + beforeEach(async() => { + spyOn( + contentCloudNodeSelectorService, + 'openUploadFileDialog' + ).and.returnValue(of([fakeMinimalNode])); widget.field = new FormFieldModel(new FormModel(), { type: FormFieldTypes.UPLOAD, value: [] }); - widget.field.id = 'attach-file-attach'; - widget.field.params = onlyLocalParams; - spyOn( - processCloudContentService, - 'createTemporaryRawRelatedContent' - ).and.returnValue(of(fakeLocalPngAnswer)); + widget.field.id = 'attach-file-alfresco'; + widget.field.params = contentSourceParam; fixture.detectChanges(); - fixture.whenStable().then(() => { - const inputDebugElement = fixture.debugElement.query( - By.css('#attach-file-attach') - ); - inputDebugElement.triggerEventHandler('change', { - target: { files: [fakeLocalPngAnswer] } - }); - fixture.detectChanges(); - expect(element.querySelector('#file-1155-icon')).not.toBeNull(); - }); - })); + await fixture.whenStable(); + const attachButton: HTMLButtonElement = element.querySelector('#attach-file-alfresco'); + + expect(attachButton).not.toBeNull(); + + attachButton.click(); + fixture.detectChanges(); + await fixture.whenStable(); + }); it('should remove file when remove is clicked', (done) => { fixture.detectChanges(); const menuButton: HTMLButtonElement = ( - fixture.debugElement.query(By.css('#file-1155-option-menu')) + fixture.debugElement.query(By.css('#file-fake-option-menu')) .nativeElement ); menuButton.click(); fixture.detectChanges(); const removeOption: HTMLButtonElement = ( - fixture.debugElement.query(By.css('#file-1155-remove')) + fixture.debugElement.query(By.css('#file-fake-remove')) .nativeElement ); removeOption.click(); fixture.detectChanges(); fixture.whenRenderingDone().then(() => { - expect(element.querySelector('#file-1155-icon')).toBeNull(); + expect(element.querySelector('#file-fake-icon')).toBeNull(); done(); }); }); @@ -384,7 +410,7 @@ describe('AttachFileCloudWidgetComponent', () => { fixture.detectChanges(); const menuButton: HTMLButtonElement = ( - fixture.debugElement.query(By.css('#file-1155-option-menu')) + fixture.debugElement.query(By.css('#file-fake-option-menu')) .nativeElement ); @@ -392,7 +418,7 @@ describe('AttachFileCloudWidgetComponent', () => { fixture.detectChanges(); const downloadOption: HTMLButtonElement = ( - fixture.debugElement.query(By.css('#file-1155-download-file')) + fixture.debugElement.query(By.css('#file-fake-download-file')) .nativeElement ); @@ -409,7 +435,7 @@ describe('AttachFileCloudWidgetComponent', () => { spyOn(processCloudContentService, 'getRawContentNode').and.returnValue(of(new Blob())); formService.formContentClicked.subscribe( (fileClicked: any) => { - expect(fileClicked.nodeId).toBe(1155); + expect(fileClicked.nodeId).toBe('fake'); done(); } ); @@ -417,14 +443,14 @@ describe('AttachFileCloudWidgetComponent', () => { fixture.detectChanges(); const menuButton: HTMLButtonElement = ( fixture.debugElement.query( - By.css('#file-1155-option-menu') + By.css('#file-fake-option-menu') ).nativeElement ); menuButton.click(); fixture.detectChanges(); const showOption: HTMLButtonElement = ( fixture.debugElement.query( - By.css('#file-1155-show-file') + By.css('#file-fake-show-file') ).nativeElement ); showOption.click(); diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts index cfff3c4a01..38d5288c1f 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/attach-file-cloud-widget.component.ts @@ -23,7 +23,8 @@ import { LogService, ThumbnailService, NotificationService, - ContentLinkModel + ContentLinkModel, + TranslationService } from '@alfresco/adf-core'; import { Node, RelatedContentRepresentation } from '@alfresco/js-api'; import { ContentCloudNodeSelectorService } from '../../../services/content-cloud-node-selector.service'; @@ -49,9 +50,9 @@ import { UploadCloudWidgetComponent } from './upload-cloud.widget'; }) export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent implements OnInit { - static ACS_SERVICE = 'alfresco-content'; typeId = 'AttachFileCloudWidgetComponent'; + rootNodeId = '-my-'; constructor( formService: FormService, @@ -59,35 +60,18 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent thumbnails: ThumbnailService, processCloudContentService: ProcessCloudContentService, notificationService: NotificationService, - private contentNodeSelectorService: ContentCloudNodeSelectorService + private contentNodeSelectorService: ContentCloudNodeSelectorService, + private translationService: TranslationService ) { super(formService, thumbnails, processCloudContentService, notificationService, logger); } - isFileSourceConfigured(): boolean { - return !!this.field.params && !!this.field.params.fileSource; - } - - isMultipleSourceUpload(): boolean { - return ( - !this.field.readOnly && - this.isFileSourceConfigured() && - !this.isOnlyLocalSourceSelected() - ); - } - - isOnlyLocalSourceSelected(): boolean { + isAlfrescoAndLocal(): boolean { return ( this.field.params && this.field.params.fileSource && - this.field.params.fileSource.serviceId === 'local-file' - ); - } - - isSimpleUploadButton(): boolean { - return ( - (this.isUploadButtonVisible() && !this.isFileSourceConfigured()) || - this.isOnlyLocalSourceSelected() + this.field.params.fileSource.serviceId === 'all-file-sources' + || this.field.params.fileSource.serviceId === 'local-file' ); } @@ -95,23 +79,31 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent return (!this.hasFile || this.multipleOption) && !this.field.readOnly; } - onAttachFileChanged(event: any) { - this.onFileChanged(event); - } - onRemoveAttachFile(file: File | RelatedContentRepresentation | Node) { this.removeFile(file); } - uploadFileFromCS() { - this.openSelectDialog(); - } - - openSelectDialog() { + async openSelectDialog() { const selectedMode = this.field.params.multiple ? 'multiple' : 'single'; + if (this.isAlfrescoAndLocal()) { + const destinationFolderPath = this.field.params.fileSource.destinationFolderPath; + const alias = this.getAliasFromDestinationFolderPath(destinationFolderPath); + const opts = { + relativePath: this.getRelativePathFromDestinationFolderPath(destinationFolderPath) + }; + + if (alias && opts && opts.relativePath) { + await this.contentNodeSelectorService.fetchNodeIdFromRelativePath(alias, opts).then((nodeId: string) => { + this.rootNodeId = nodeId; + }); + } else { + const errorMessage = this.translationService.instant('ADF_CLOUD_TASK_FORM.ERROR.INVALID_DESTINATION_FOLDER_PATH'); + this.notificationService.showError(errorMessage); + } + } this.contentNodeSelectorService - .openUploadFileDialog(this.field.form.contentHost, '-my-', selectedMode) + .openUploadFileDialog(this.rootNodeId, selectedMode, this.isAlfrescoAndLocal()) .subscribe((selections: Node[]) => { selections.forEach(node => (node['isExternal'] = true)); const selectionWithoutDuplication = this.removeExistingSelection(selections); @@ -119,29 +111,31 @@ export class AttachFileCloudWidgetComponent extends UploadCloudWidgetComponent }); } + getAliasFromDestinationFolderPath(destinationFolderPath: string): string { + const startOfRelativePathIndex = destinationFolderPath.indexOf('/'); + return destinationFolderPath.substring(0, startOfRelativePathIndex); + } + + getRelativePathFromDestinationFolderPath(destinationFolderPath: string): string { + const startOfRelativePathIndex = destinationFolderPath.indexOf('/'); + return destinationFolderPath.substring(startOfRelativePathIndex, destinationFolderPath.length); + } + removeExistingSelection(selections: Node[]) { const existingNode: Node[] = [...this.field.value || []]; return selections.filter(opt => !existingNode.some( (node) => node.id === opt.id)); } - isContentSourceSelected(): boolean { - return ( - this.field.params && - this.field.params.fileSource && - this.field.params.fileSource.serviceId === - AttachFileCloudWidgetComponent.ACS_SERVICE - ); - } - downloadContent(file: Node): void { - this.processCloudContentService.downloadFile( - file.id, - this.field.form.contentHost - ); + this.processCloudContentService.downloadFile(file.id); } onAttachFileClicked(nodeSelector: any) { nodeSelector.nodeId = nodeSelector.id; this.fileClicked(new ContentLinkModel(nodeSelector)); } + + getWidgetIcon(): string { + return this.isAlfrescoAndLocal() ? 'file_upload' : 'attach_file'; + } } diff --git a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts index 7d50357170..7d91ca4fce 100644 --- a/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts +++ b/lib/process-services-cloud/src/lib/form/components/widgets/attach-file/upload-cloud.widget.ts @@ -124,9 +124,7 @@ export class UploadCloudWidgetComponent extends WidgetComponent implements OnIni } private uploadRawContent(file: File): Observable { - return this.processCloudContentService.createTemporaryRawRelatedContent( - file, this.field.form.nodeId, this.field.form.contentHost - ); + return this.processCloudContentService.createTemporaryRawRelatedContent(file, this.field.form.nodeId); } getMultipleFileParam() { diff --git a/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts b/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts index b94549bbc7..05ef43f792 100644 --- a/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts +++ b/lib/process-services-cloud/src/lib/form/models/task-variable-cloud.model.ts @@ -23,16 +23,3 @@ export class TaskVariableCloud { this.value = obj.value || null; } } - -export class ProcessStorageCloudModel { - - nodeId: string; - path: string; - type: string; - - constructor(obj) { - this.nodeId = obj.nodeId || null; - this.path = obj.path || null; - this.type = obj.type || null; - } -} diff --git a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts index 6aa2e05d91..b49226f61c 100644 --- a/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/content-cloud-node-selector.service.ts @@ -32,30 +32,35 @@ export class ContentCloudNodeSelectorService { private dialog: MatDialog) { } - openUploadFileDialog(contentHost: string, currentFolderId?: string, selectionMode?: string): Observable { - const changedConfig = this.apiService.lastConfig; - changedConfig.provider = 'ALL'; - changedConfig.hostEcm = contentHost.replace('/alfresco', ''); - this.apiService.getInstance().setConfig(changedConfig); + openUploadFileDialog(currentFolderId?: string, selectionMode?: string, showLocalUploadButton?: boolean): Observable { const select = new Subject(); select.subscribe({ complete: this.close.bind(this) }); const data = { title: 'Select a file', - actionName: 'Choose', + actionName: 'Attach', currentFolderId, restrictRootToCurrentFolderId: true, select, selectionMode, isSelectionValid: (entry: Node) => entry.isFile, - showFilesInResult: true - }; - + showFilesInResult: true, + showDropdownSiteList: false, + showLocalUploadButton + }; this.openContentNodeDialog(data, 'adf-content-node-selector-dialog', '630px'); return select; } + async fetchNodeIdFromRelativePath(alias: string, opts: { relativePath: string }): Promise { + let nodeId = ''; + await this.apiService.getInstance().node.getNode(alias, opts).then(node => { + nodeId = node.entry.id; + }); + return nodeId; + } + private openContentNodeDialog(data: ContentNodeSelectorComponentData, currentPanelClass: string, chosenWidth: string) { this.dialog.open(ContentNodeSelectorComponent, { data, panelClass: currentPanelClass, width: chosenWidth }); } diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts index c52fd007fd..cef3a5865b 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.spec.ts @@ -183,45 +183,6 @@ describe('Form Cloud service', () => { expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('POST'); done(); }); - - }); - - it('should fetch process storage folder with process instance id and task id', (done) => { - oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ - nodeId: 'fake-node-id-really-long', - path: 'path/to/node/id', - type: 'nodeType' - })); - - service.getProcessStorageFolderTask(appName, taskId, processInstanceId).subscribe((result) => { - expect(result).toBeDefined(); - expect(result).not.toBeNull(); - expect(result.nodeId).toBe('fake-node-id-really-long'); - expect(result.path).toBe('path/to/node/id'); - expect(result.type).toBe('nodeType'); - expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/process-storage/v1/folders/${processInstanceId}/${taskId}`)).toBeTruthy(); - expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); - done(); - }); - }); - - it('should fetch process storage folder with task id only', (done) => { - oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ - nodeId: 'fake-node-id-really-long', - path: 'path/to/node/id', - type: 'nodeType' - })); - - service.getProcessStorageFolderTask(appName, taskId, null).subscribe((result) => { - expect(result).toBeDefined(); - expect(result).not.toBeNull(); - expect(result.nodeId).toBe('fake-node-id-really-long'); - expect(result.path).toBe('path/to/node/id'); - expect(result.type).toBe('nodeType'); - expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/process-storage/v1/folders/${taskId}`)).toBeTruthy(); - expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET'); - done(); - }); }); }); }); diff --git a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts index c69149e3ee..bbd320042a 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-cloud.service.ts @@ -27,7 +27,7 @@ import { Observable, from } from 'rxjs'; import { map, switchMap } from 'rxjs/operators'; import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details-cloud.model'; import { CompleteFormRepresentation } from '@alfresco/js-api'; -import { TaskVariableCloud, ProcessStorageCloudModel } from '../models/task-variable-cloud.model'; +import { TaskVariableCloud } from '../models/task-variable-cloud.model'; import { BaseCloudService } from '../../services/base-cloud.service'; import { FormContent } from '../../services/form-fields.interfaces'; @@ -151,16 +151,6 @@ export class FormCloudService extends BaseCloudService { ); } - getProcessStorageFolderTask(appName: string, taskId: string, processInstanceId: string): Observable { - const apiUrl = this.buildFolderTask(appName, taskId, processInstanceId); - - return this.get(apiUrl).pipe( - map((res: any) => { - return new ProcessStorageCloudModel(res); - }) - ); - } - /** * Gets the variables of a task. * @param appName Name of the app @@ -237,10 +227,4 @@ export class FormCloudService extends BaseCloudService { } return null; } - - private buildFolderTask(appName: string, taskId: string, processInstanceId: string): string { - return processInstanceId - ? `${this.getBasePath(appName)}/process-storage/v1/folders/${processInstanceId}/${taskId}` - : `${this.getBasePath(appName)}/process-storage/v1/folders/${taskId}`; - } } diff --git a/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts b/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts index ef799543c9..c0e5a68191 100644 --- a/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/process-cloud-content.service.ts @@ -39,10 +39,8 @@ export class ProcessCloudContentService { createTemporaryRawRelatedContent( file: File, - nodeId: string, - contentHost: string + nodeId: string ): Observable { - this.updateConfig(contentHost); return from( this.apiService @@ -59,8 +57,7 @@ export class ProcessCloudContentService { ); } - getRawContentNode(nodeId: string, contentHost: string): Observable { - this.updateConfig(contentHost); + getRawContentNode(nodeId: string): Observable { return this.contentService.getNodeContent(nodeId); } @@ -68,8 +65,7 @@ export class ProcessCloudContentService { this.contentService.downloadBlob(blob, fileName); } - async downloadFile(nodeId: string, contentHost: string) { - this.updateConfig(contentHost); + async downloadFile(nodeId: string) { const ticket = await this.getAuthTicket(); const url = this.contentService.getContentUrl(nodeId, true, ticket); @@ -88,18 +84,6 @@ export class ProcessCloudContentService { return ''; } - private updateConfig(contentHost: string) { - const changedConfig = this.apiService.lastConfig; - - changedConfig.provider = 'ALL'; - - if (contentHost) { - changedConfig.hostEcm = contentHost.replace('/alfresco', ''); - } - - this.apiService.getInstance().setConfig(changedConfig); - } - private handleError(error: any) { this.logService.error(error); return throwError(error || 'Server error'); diff --git a/lib/process-services-cloud/src/lib/i18n/en.json b/lib/process-services-cloud/src/lib/i18n/en.json index 37c4de318a..8b1e888289 100644 --- a/lib/process-services-cloud/src/lib/i18n/en.json +++ b/lib/process-services-cloud/src/lib/i18n/en.json @@ -266,6 +266,9 @@ "CLAIM": "CLAIM", "UNCLAIM": "RELEASE" } + }, + "ERROR": { + "INVALID_DESTINATION_FOLDER_PATH": "Invalid destination folder path" } }