mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-2188] Start Process - Change processDefinition property and fix bug (#2884)
* Change processDefinition property and fix bug * Fix unit test * Fix async * Fix id
This commit is contained in:
committed by
Eugenio Romano
parent
abca6e481d
commit
657c28491a
@@ -341,6 +341,10 @@
|
||||
]
|
||||
}
|
||||
},
|
||||
"adf-start-process": {
|
||||
"name": "My Default Name",
|
||||
"processDefinitionName": "My default process def name"
|
||||
},
|
||||
"adf-process-list": {
|
||||
"presets": {
|
||||
"default": [
|
||||
|
@@ -182,6 +182,8 @@
|
||||
*ngIf="isStartProcessMode()">
|
||||
<adf-start-process
|
||||
[appId]="appId"
|
||||
[name]="defaultProcessName"
|
||||
[processDefinitionName]="defaultProcessDefinitionName"
|
||||
(start)="onStartProcessInstance($event)"
|
||||
(cancel)="onCancelProcessInstance()">
|
||||
</adf-start-process>
|
||||
|
@@ -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<string>('adf-start-process.name');
|
||||
this.defaultProcessDefinitionName = this.appConfig.get<string>('adf-start-process.processDefinitionName');
|
||||
|
||||
// Uncomment this line to replace all 'text' field editors with custom component
|
||||
// formRenderingService.setComponentTypeResolver('text', () => CustomEditorComponent, true);
|
||||
|
||||
|
@@ -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<ProcessInstance>` | Emitted when the process is canceled |
|
||||
| error | `EventEmitter<ProcessInstance>` | 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
|
||||
<adf-start-process
|
||||
[appId]="YOUR_APP_ID"
|
||||
[processDefinition]="PROCESS_DEFINITION">
|
||||
[name]="PROCESS_NAME"
|
||||
[processDefinitionName]="PROCESS_DEFINITION_NAME">
|
||||
</adf-start-process>
|
||||
```
|
||||
|
||||
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
|
||||
<adf-start-process
|
||||
[processDefinition]="PROCESS_DEFINITION">
|
||||
[processDefinitionName]="PROCESS_DEFINITION_NAME">
|
||||
</adf-start-process>
|
||||
```
|
||||
|
||||
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
|
||||
|
@@ -12,7 +12,7 @@
|
||||
<div *ngIf="showSelectProcessDropdown">
|
||||
<mat-form-field>
|
||||
<mat-select [(value)]="selectedProcessDef" placeholder="{{'ADF_PROCESS_LIST.START_PROCESS.FORM.LABEL.TYPE'|translate}}" required>
|
||||
<mat-option>{{'ADF_PROCESS_LIST.START_PROCESS.FORM.TYPE_PLACEHOLDER' | translate}}</mat-option>
|
||||
<mat-option *ngIf="!hasSingleProcessDefinition()">{{'ADF_PROCESS_LIST.START_PROCESS.FORM.TYPE_PLACEHOLDER' | translate}}</mat-option>
|
||||
<mat-option *ngFor="let processDef of processDefinitions" [value]="processDef">
|
||||
{{ processDef.name }}
|
||||
</mat-option>
|
||||
|
@@ -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;
|
||||
|
@@ -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<string>('alfrescoRepositoryName');
|
||||
if (!alfrescoRepositoryName) {
|
||||
|
Reference in New Issue
Block a user