diff --git a/demo-shell/src/app.config.json b/demo-shell/src/app.config.json index 7e8727d03f..5030d4ac60 100644 --- a/demo-shell/src/app.config.json +++ b/demo-shell/src/app.config.json @@ -341,6 +341,10 @@ ] } }, + "adf-start-process": { + "name": "My Default Name", + "processDefinitionName": "My default process def name" + }, "adf-process-list": { "presets": { "default": [ diff --git a/demo-shell/src/app/components/process-service/process-service.component.html b/demo-shell/src/app/components/process-service/process-service.component.html index 51b7e7a427..bd82e5e4da 100644 --- a/demo-shell/src/app/components/process-service/process-service.component.html +++ b/demo-shell/src/app/components/process-service/process-service.component.html @@ -182,6 +182,8 @@ *ngIf="isStartProcessMode()"> diff --git a/demo-shell/src/app/components/process-service/process-service.component.ts b/demo-shell/src/app/components/process-service/process-service.component.ts index 839c783c07..57c678f0ea 100644 --- a/demo-shell/src/app/components/process-service/process-service.component.ts +++ b/demo-shell/src/app/components/process-service/process-service.component.ts @@ -30,7 +30,7 @@ import { ActivatedRoute, Router } from '@angular/router'; import { Pagination, ProcessInstanceFilterRepresentation } from 'alfresco-js-api'; import { FORM_FIELD_VALIDATORS, FormEvent, FormFieldEvent, FormRenderingService, FormService, - DynamicTableRow, ValidateDynamicTableRowEvent + DynamicTableRow, ValidateDynamicTableRowEvent, AppConfigService } from '@alfresco/adf-core'; import { AnalyticsReportListComponent } from '@alfresco/adf-insights'; @@ -123,6 +123,9 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit supportedPages: number[]; + defaultProcessDefinitionName: string; + defaultProcessName: string; + activeTab: number = this.tabs.tasks; // tasks|processes|reports taskFilter: FilterRepresentationModel; @@ -148,6 +151,7 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit private taskListService: TaskListService, private apiService: AlfrescoApiService, private logService: LogService, + private appConfig: AppConfigService, formRenderingService: FormRenderingService, formService: FormService, private preferenceService: UserPreferencesService) { @@ -156,6 +160,9 @@ export class ProcessServiceComponent implements AfterViewInit, OnDestroy, OnInit this.supportedPages = this.preferenceService.getDifferentPageSizes(); this.taskPagination.maxItems = this.preferenceService.paginationSize; + this.defaultProcessName = this.appConfig.get('adf-start-process.name'); + this.defaultProcessDefinitionName = this.appConfig.get('adf-start-process.processDefinitionName'); + // Uncomment this line to replace all 'text' field editors with custom component // formRenderingService.setComponentTypeResolver('text', () => CustomEditorComponent, true); diff --git a/docs/start-process.component.md b/docs/start-process.component.md index ba351523e9..282076b025 100644 --- a/docs/start-process.component.md +++ b/docs/start-process.component.md @@ -18,7 +18,7 @@ Starts a process. | ---- | -- | ----------- | | appId | `number` | (optional): Limit the list of processes which can be started to those contained in the specified app | | name | `string` | (optional) name to assign to the current process | -| processDefinition | `string` | (optional) definition name of the process to start | +| processDefinitionName | `string` | (optional) definition name of the process to start | | variables | `ProcessInstanceVariable[]` |Variables in input to the process [RestVariable](https://github.com/Alfresco/alfresco-js-api/tree/master/src/alfresco-activiti-rest-api/docs/RestVariable.md) | | values | `FormValues` | Parameter to pass form field values in the start form if is associated | | showSelectProcessDropdown | `boolean` | hide or show the process selection drodown, true by default | @@ -31,26 +31,30 @@ Starts a process. | cancel | `EventEmitter` | Emitted when the process is canceled | | error | `EventEmitter` | Emitted when the start process operation fails | -### Start a process part of an app +### Start a process with a default name and pre-selected process definition name ```html + [name]="PROCESS_NAME" + [processDefinitionName]="PROCESS_DEFINITION_NAME"> ``` -Use this method to preselect which process to start if there is more than one process in your app. +If your app has more than one process definition, with the property processDefinitionName you can select as dropdown default value your PROCESS_DEFINITION_NAME. The name will be the PROCESS_NAME. +You can configure the processDefinitionName value in your custom `app.config.json` +You can configure the process name value in your custom `app.config.json` ### Start a process not included in an app ```html + [processDefinitionName]="PROCESS_DEFINITION_NAME"> ``` -Use this method to preselect which process to start +With the property processDefinitionName you can select as dropdown default value your PROCESS_DEFINITION_NAME. +You can configure the processDefinitionName values in your custom `app.config.json` ### Custom data example diff --git a/lib/process-services/process-list/components/start-process.component.html b/lib/process-services/process-list/components/start-process.component.html index 98ebbd7843..8d8952a0c1 100644 --- a/lib/process-services/process-list/components/start-process.component.html +++ b/lib/process-services/process-list/components/start-process.component.html @@ -12,7 +12,7 @@
- {{'ADF_PROCESS_LIST.START_PROCESS.FORM.TYPE_PLACEHOLDER' | translate}} + {{'ADF_PROCESS_LIST.START_PROCESS.FORM.TYPE_PLACEHOLDER' | translate}} {{ processDef.name }} diff --git a/lib/process-services/process-list/components/start-process.component.spec.ts b/lib/process-services/process-list/components/start-process.component.spec.ts index 2dd0c70f58..ce8b1b9dda 100644 --- a/lib/process-services/process-list/components/start-process.component.spec.ts +++ b/lib/process-services/process-list/components/start-process.component.spec.ts @@ -274,7 +274,7 @@ describe('StartFormComponent', () => { it('should select processDefinition based on processDefinition input', async(() => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs)); component.appId = 123; - component.processDefinition = 'My Process 2'; + component.processDefinitionName = 'My Process 2'; component.ngOnChanges({}); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -292,16 +292,6 @@ describe('StartFormComponent', () => { }); })); - it('should select automatically the first processDefinition if the app contain multiple process and there is no processDefinition in input', async(() => { - getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs)); - component.appId = 123; - component.ngOnChanges({}); - fixture.detectChanges(); - fixture.whenStable().then(() => { - expect(component.selectedProcessDef.name).toBe(JSON.parse(JSON.stringify(testMultipleProcessDefs[0])).name); - }); - })); - describe('dropdown', () => { it('should hide the process dropdown if showSelectProcessDropdown is false', async(() => { @@ -319,7 +309,7 @@ describe('StartFormComponent', () => { it('should show the process dropdown if showSelectProcessDropdown is false', async(() => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs)); component.appId = 123; - component.processDefinition = 'My Process 2'; + component.processDefinitionName = 'My Process 2'; component.showSelectProcessDropdown = true; component.ngOnChanges({}); fixture.detectChanges(); @@ -332,7 +322,7 @@ describe('StartFormComponent', () => { it('should show the process dropdown by default', async(() => { getDefinitionsSpy = getDefinitionsSpy.and.returnValue(Observable.of(testMultipleProcessDefs)); component.appId = 123; - component.processDefinition = 'My Process 2'; + component.processDefinitionName = 'My Process 2'; component.ngOnChanges({}); fixture.detectChanges(); fixture.whenStable().then(() => { @@ -454,14 +444,18 @@ describe('StartFormComponent', () => { }); })); - it('should emit start event when start select a process and add a name', () => { + it('should emit start event when start select a process and add a name', async(() => { let startSpy: jasmine.Spy = spyOn(component.start, 'emit'); - component.selectedProcessDef.id = '1001'; + component.selectedProcessDef = testProcessDefRepr; component.name = 'my:Process'; component.startProcess(); fixture.detectChanges(); - expect(startSpy).toHaveBeenCalled(); - }); + fixture.whenStable().then(() => { + let startButton = fixture.nativeElement.querySelector('#button-start'); + startButton.click(); + expect(startSpy).toHaveBeenCalled(); + }); + })); it('should not emit start event when start the process without select a process and name', () => { component.name = null; diff --git a/lib/process-services/process-list/components/start-process.component.ts b/lib/process-services/process-list/components/start-process.component.ts index 86312cae2f..d08fda65ea 100644 --- a/lib/process-services/process-list/components/start-process.component.ts +++ b/lib/process-services/process-list/components/start-process.component.ts @@ -50,7 +50,7 @@ export class StartProcessInstanceComponent implements OnChanges { appId: number; @Input() - processDefinition: string; + processDefinitionName: string; @Input() variables: ProcessInstanceVariable[]; @@ -106,16 +106,12 @@ export class StartProcessInstanceComponent implements OnChanges { (processDefinitionRepresentations: ProcessDefinitionRepresentation[]) => { this.processDefinitions = processDefinitionRepresentations; - if (this.processDefinitions.length === 1 || !this.processDefinition) { + if (this.hasSingleProcessDefinition()) { this.selectedProcessDef = this.processDefinitions[0]; } else { this.selectedProcessDef = this.processDefinitions.find((currentProcessDefinition) => { - return currentProcessDefinition.name === this.processDefinition; + return currentProcessDefinition.name === this.processDefinitionName; }); - - if (!this.selectedProcessDef) { - this.selectedProcessDef = this.processDefinitions[0]; - } } }, () => { @@ -124,6 +120,10 @@ export class StartProcessInstanceComponent implements OnChanges { } + hasSingleProcessDefinition(): boolean { + return this.processDefinitions.length === 1; + } + getAlfrescoRepositoryName(): string { let alfrescoRepositoryName = this.appConfig.get('alfrescoRepositoryName'); if (!alfrescoRepositoryName) {