diff --git a/demo-shell/src/app/components/cloud/community/community-process-details-cloud.component.html b/demo-shell/src/app/components/cloud/community/community-process-details-cloud.component.html index 6fc529df18..cc41129884 100644 --- a/demo-shell/src/app/components/cloud/community/community-process-details-cloud.component.html +++ b/demo-shell/src/app/components/cloud/community/community-process-details-cloud.component.html @@ -10,6 +10,7 @@ diff --git a/demo-shell/src/app/components/cloud/community/community-start-task-cloud.component.html b/demo-shell/src/app/components/cloud/community/community-start-task-cloud.component.html index 9975b99cc6..2a305e9ba5 100644 --- a/demo-shell/src/app/components/cloud/community/community-start-task-cloud.component.html +++ b/demo-shell/src/app/components/cloud/community/community-start-task-cloud.component.html @@ -1,4 +1,5 @@ diff --git a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts index 59f0ef38b0..5fd6e8079c 100644 --- a/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts +++ b/lib/process-services-cloud/src/lib/form/components/form-cloud.component.spec.ts @@ -19,7 +19,8 @@ import { SimpleChange, DebugElement, CUSTOM_ELEMENTS_SCHEMA, Component } from '@ import { By } from '@angular/platform-browser'; import { ComponentFixture, TestBed } from '@angular/core/testing'; import { Observable, of, throwError } from 'rxjs'; -import { FormFieldModel, FormFieldTypes, FormService, FormOutcomeEvent, FormOutcomeModel, LogService, WidgetVisibilityService, setupTestBed } from '@alfresco/adf-core'; +import { FormFieldModel, FormFieldTypes, FormService, FormOutcomeEvent, FormOutcomeModel, LogService, WidgetVisibilityService, + setupTestBed, AppConfigService } from '@alfresco/adf-core'; import { ProcessServiceCloudTestingModule } from '../../testing/process-service-cloud.testing.module'; import { FormCloudService } from '../services/form-cloud.service'; import { FormCloudComponent } from './form-cloud.component'; @@ -38,7 +39,7 @@ describe('FormCloudComponent', () => { logService = new LogService(null); visibilityService = new WidgetVisibilityService(null, logService); spyOn(visibilityService, 'refreshVisibility').and.stub(); - formCloudService = new FormCloudService(null, null, logService); + formCloudService = new FormCloudService(null, new AppConfigService(null), logService); formService = new FormService(null, null, logService); formComponent = new FormCloudComponent(formCloudService, formService, null, visibilityService); }); diff --git a/lib/process-services-cloud/src/lib/form/models/form-cloud.model.spec.ts b/lib/process-services-cloud/src/lib/form/models/form-cloud.model.spec.ts index 7a9b1a5fdf..672d34d846 100644 --- a/lib/process-services-cloud/src/lib/form/models/form-cloud.model.spec.ts +++ b/lib/process-services-cloud/src/lib/form/models/form-cloud.model.spec.ts @@ -17,14 +17,14 @@ import { FormCloudService } from '../services/form-cloud.service'; import { FormCloud } from './form-cloud.model'; -import { TabModel, FormFieldModel, ContainerModel, FormOutcomeModel, FormFieldTypes } from '@alfresco/adf-core'; +import { TabModel, FormFieldModel, ContainerModel, FormOutcomeModel, FormFieldTypes, AppConfigService } from '@alfresco/adf-core'; describe('FormCloud', () => { let formCloudService: FormCloudService; beforeEach(() => { - formCloudService = new FormCloudService(null, null, null); + formCloudService = new FormCloudService(null, new AppConfigService(null), null); }); it('should store original json', () => { 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 3396ba691c..c6e2c04466 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 @@ -23,18 +23,22 @@ import { TaskDetailsCloudModel } from '../../task/start-task/models/task-details import { SaveFormRepresentation, CompleteFormRepresentation } from '@alfresco/js-api'; import { FormCloud } from '../models/form-cloud.model'; import { TaskVariableCloud } from '../models/task-variable-cloud.model'; +import { BaseCloudService } from '../../services/base-cloud.service'; @Injectable({ providedIn: 'root' }) -export class FormCloudService { +export class FormCloudService extends BaseCloudService { contentTypes = ['application/json']; accepts = ['application/json']; returnType = Object; constructor( private apiService: AlfrescoApiService, private appConfigService: AppConfigService, private logService: LogService - ) {} + ) { + super(); + this.contextRoot = this.appConfigService.get('bpmHost', ''); + } /** * Gets the form definition of a task. @@ -245,15 +249,15 @@ export class FormCloudService { } private buildGetTaskUrl(appName: string, taskId: string): string { - return `${this.appConfigService.get('bpmHost')}/${appName}/query/v1/tasks/${taskId}`; + return `${this.getBasePath(appName)}/query/v1/tasks/${taskId}`; } private buildGetFormUrl(appName: string, formId: string): string { - return `${this.appConfigService.get('bpmHost')}/${appName}/form/v1/forms/${formId}`; + return `${this.getBasePath(appName)}/form/v1/forms/${formId}`; } private buildSaveFormUrl(appName: string, formId: string): string { - return `${this.appConfigService.get('bpmHost')}/${appName}/form/v1/forms/${formId}/save`; + return `${this.getBasePath(appName)}/form/v1/forms/${formId}/save`; } private buildUploadUrl(nodeId: string): string { @@ -261,15 +265,15 @@ export class FormCloudService { } private buildSubmitFormUrl(appName: string, formId: string): string { - return `${this.appConfigService.get('bpmHost')}/${appName}/form/v1/forms/${formId}/submit`; + return `${this.getBasePath(appName)}/form/v1/forms/${formId}/submit`; } private buildGetTaskVariablesUrl(appName: string, taskId: string): string { - return `${this.appConfigService.get('bpmHost')}/${appName}/query/v1/tasks/${taskId}/variables`; + return `${this.getBasePath(appName)}/query/v1/tasks/${taskId}/variables`; } private buildFolderTask(appName: string, taskId: string): string { - return `${this.appConfigService.get('bpmHost')}/${appName}/process-storage/v1/folders/tasks/${taskId}`; + return `${this.getBasePath(appName)}/process-storage/v1/folders/tasks/${taskId}`; } private handleError(error: any) { diff --git a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts index 03826a00f4..a5f680204e 100644 --- a/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/form/services/form-definition-selector-cloud.service.ts @@ -20,13 +20,13 @@ import { AlfrescoApiService, AppConfigService, LogService } from '@alfresco/adf- import { catchError, map } from 'rxjs/operators'; import { FormDefinitionSelectorCloudModel } from '../models/form-definition-selector-cloud.model'; import { from, Observable, throwError } from 'rxjs'; +import { BaseCloudService } from '../../services/base-cloud.service'; @Injectable({ providedIn: 'root' }) -export class FormDefinitionSelectorCloudService { +export class FormDefinitionSelectorCloudService extends BaseCloudService { - contextRoot: string; contentTypes = ['application/json']; accepts = ['application/json']; returnType = Object; @@ -34,6 +34,7 @@ export class FormDefinitionSelectorCloudService { constructor(private apiService: AlfrescoApiService, private appConfigService: AppConfigService, private logService: LogService) { + super(); this.contextRoot = this.appConfigService.get('bpmHost', ''); } @@ -65,7 +66,7 @@ export class FormDefinitionSelectorCloudService { } private buildGetFormsUrl(appName: string): any { - return `${this.appConfigService.get('bpmHost')}/${appName}/form/v1/forms`; + return `${this.getBasePath(appName)}/form/v1/forms`; } private handleError(error: any) { diff --git a/lib/process-services-cloud/src/lib/task/directives/claim-task.directive.ts b/lib/process-services-cloud/src/lib/task/directives/claim-task.directive.ts index 54bbd8e46d..fe3962c89a 100644 --- a/lib/process-services-cloud/src/lib/task/directives/claim-task.directive.ts +++ b/lib/process-services-cloud/src/lib/task/directives/claim-task.directive.ts @@ -67,7 +67,7 @@ export class ClaimTaskDirective implements OnInit { } isAppValid(): boolean { - return this.appName && this.appName.length > 0; + return (this.appName && this.appName.length > 0) || (this.appName === ''); } @HostListener('click') diff --git a/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.ts b/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.ts index 8652123ebf..094a2401fb 100644 --- a/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.ts +++ b/lib/process-services-cloud/src/lib/task/directives/complete-task.directive.ts @@ -64,7 +64,7 @@ export class CompleteTaskDirective implements OnInit { } isAppValid(): boolean { - return this.appName && this.appName.length > 0; + return (this.appName && this.appName.length > 0) || (this.appName === ''); } @HostListener('click') diff --git a/lib/process-services-cloud/src/lib/task/directives/unclaim-task.directive.ts b/lib/process-services-cloud/src/lib/task/directives/unclaim-task.directive.ts index 492e372450..c152f40606 100644 --- a/lib/process-services-cloud/src/lib/task/directives/unclaim-task.directive.ts +++ b/lib/process-services-cloud/src/lib/task/directives/unclaim-task.directive.ts @@ -65,7 +65,7 @@ export class UnClaimTaskDirective implements OnInit { } isAppValid(): boolean { - return this.appName && this.appName.length > 0; + return (this.appName && this.appName.length > 0) || (this.appName === ''); } @HostListener('click') diff --git a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts index a6af517e40..4763ef28d3 100644 --- a/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts +++ b/lib/process-services-cloud/src/lib/task/services/task-cloud.service.ts @@ -48,21 +48,26 @@ export class TaskCloudService extends BaseCloudService { * @returns Details of the task that was completed */ completeTask(appName: string, taskId: string): Observable { - const queryUrl = this.buildCompleteTaskUrl(appName, taskId); - const bodyParam = { 'payloadType': 'CompleteTaskPayload' }; - const pathParams = {}, queryParams = {}, headerParams = {}, - formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; + if ((appName || appName === '') && taskId) { + const queryUrl = this.buildCompleteTaskUrl(appName, taskId); + const bodyParam = { 'payloadType': 'CompleteTaskPayload' }; + const pathParams = {}, queryParams = {}, headerParams = {}, + formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; - return from( - this.apiService - .getInstance() - .oauth2Auth.callCustomApi( - queryUrl, 'POST', pathParams, queryParams, - headerParams, formParams, bodyParam, - contentTypes, accepts, null, null) - ).pipe( - catchError((err) => this.handleError(err)) - ); + return from( + this.apiService + .getInstance() + .oauth2Auth.callCustomApi( + queryUrl, 'POST', pathParams, queryParams, + headerParams, formParams, bodyParam, + contentTypes, accepts, null, null) + ).pipe( + catchError((err) => this.handleError(err)) + ); + } else { + this.logService.error('AppName and TaskId are mandatory for complete a task'); + return throwError('AppName/TaskId not configured'); + } } /** @@ -102,7 +107,7 @@ export class TaskCloudService extends BaseCloudService { * @returns Details of the claimed task */ claimTask(appName: string, taskId: string, assignee: string): Observable { - if (appName && taskId) { + if ((appName || appName === '') && taskId) { const queryUrl = `${this.getBasePath(appName)}/rb/v1/tasks/${taskId}/claim?assignee=${assignee}`; return from(this.apiService.getInstance() .oauth2Auth.callCustomApi(queryUrl, 'POST', @@ -129,7 +134,7 @@ export class TaskCloudService extends BaseCloudService { * @returns Details of the task that was unclaimed */ unclaimTask(appName: string, taskId: string): Observable { - if (appName && taskId) { + if ((appName || appName === '') && taskId) { const queryUrl = `${this.getBasePath(appName)}/rb/v1/tasks/${taskId}/release`; return from(this.apiService.getInstance() .oauth2Auth.callCustomApi(queryUrl, 'POST', @@ -184,7 +189,7 @@ export class TaskCloudService extends BaseCloudService { * @returns Updated task details */ updateTask(appName: string, taskId: string, updatePayload: any): Observable { - if (appName && taskId) { + if ((appName || appName === '') && taskId) { updatePayload.payloadType = 'UpdateTaskPayload'; const queryUrl = `${this.getBasePath(appName)}/rb/v1/tasks/${taskId}`; diff --git a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts index 962eaaca4b..5ecac0805d 100644 --- a/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-form/components/task-form-cloud.component.ts @@ -98,7 +98,7 @@ export class TaskFormCloudComponent implements OnChanges { ngOnChanges(changes: SimpleChanges) { const appName = changes['appName']; - if (appName && appName.currentValue && this.taskId) { + if (appName && (appName.currentValue || appName.currentValue === '' ) && this.taskId) { this.loadTask(); return; } diff --git a/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.ts b/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.ts index 1b726e4429..6224e9bc4f 100644 --- a/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.ts +++ b/lib/process-services-cloud/src/lib/task/task-header/components/task-header-cloud.component.ts @@ -15,7 +15,7 @@ * limitations under the License. */ -import { Component, Input, OnInit, EventEmitter, Output } from '@angular/core'; +import { Component, Input, OnInit, EventEmitter, Output, OnDestroy } from '@angular/core'; import { CardViewDateItemModel, CardViewItem, @@ -29,13 +29,14 @@ import { import { TaskDetailsCloudModel, TaskStatusEnum } from '../../start-task/models/task-details-cloud.model'; import { Router } from '@angular/router'; import { TaskCloudService } from '../../services/task-cloud.service'; +import { Subscription } from 'rxjs'; @Component({ selector: 'adf-cloud-task-header', templateUrl: './task-header-cloud.component.html', styleUrls: ['./task-header-cloud.component.scss'] }) -export class TaskHeaderCloudComponent implements OnInit { +export class TaskHeaderCloudComponent implements OnInit, OnDestroy { /** (Required) The name of the application. */ @Input() @@ -58,6 +59,8 @@ export class TaskHeaderCloudComponent implements OnInit { inEdit: boolean = false; parentTaskName: string; + private subscriptions: Subscription[] = []; + constructor( private taskCloudService: TaskCloudService, private translationService: TranslationService, @@ -71,11 +74,11 @@ export class TaskHeaderCloudComponent implements OnInit { this.loadTaskDetailsById(this.appName, this.taskId); } - this.cardViewUpdateService.itemUpdated$.subscribe(this.updateTaskDetails.bind(this)); + this.subscriptions.push(this.cardViewUpdateService.itemUpdated$.subscribe(this.updateTaskDetails.bind(this))); } loadTaskDetailsById(appName: string, taskId: string): any { - this.taskCloudService.getTaskById(appName, taskId).subscribe( + this.subscriptions.push(this.taskCloudService.getTaskById(appName, taskId).subscribe( (taskDetails) => { this.taskDetails = taskDetails; if (this.taskDetails.parentTaskId) { @@ -83,7 +86,7 @@ export class TaskHeaderCloudComponent implements OnInit { } else { this.refreshData(); } - }); + })); } private initDefaultProperties() { @@ -244,4 +247,9 @@ export class TaskHeaderCloudComponent implements OnInit { onCompletedTask(event: any) { this.goBack(); } + + ngOnDestroy() { + this.subscriptions.forEach((subscription) => subscription.unsubscribe()); + this.subscriptions = []; + } }