From 399b716d8281a66168fbcad3d4065f15c45f8f42 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Tue, 17 Jan 2017 13:37:30 +0000 Subject: [PATCH] #1467 customs outcome (#1483) --- .../components/activiti-form.component.html | 2 +- .../activiti-form.component.spec.ts | 50 ++++++++++++++++--- .../src/components/activiti-form.component.ts | 5 +- .../activiti-start-form.component.html | 2 +- .../activiti-start-form.component.ts | 4 +- .../widgets/core/form-outcome.model.ts | 2 + .../src/components/widgets/core/form.model.ts | 2 + 7 files changed, 56 insertions(+), 11 deletions(-) diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html index b1af9c278b..e6cbc5d8e9 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.html @@ -24,7 +24,7 @@ alfresco-mdl-button [disabled]="!isOutcomeButtonEnabled(outcome)" [class.mdl-button--colored]="!outcome.isSystem" - [class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome)" + [class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)" (click)="onOutcomeClicked(outcome, $event)"> {{outcome.name}} diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts index a10895e55d..79b6d1e18e 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.spec.ts @@ -101,35 +101,73 @@ describe('ActivitiForm', () => { }); it('should not enable outcome button when model missing', () => { - expect(formComponent.isOutcomeButtonVisible(null)).toBeFalsy(); + expect(formComponent.isOutcomeButtonVisible(null, false)).toBeFalsy(); }); it('should enable custom outcome buttons', () => { let formModel = new FormModel(); + formComponent.form = formModel; let outcome = new FormOutcomeModel(formModel, {id: 'action1', name: 'Action 1'}); - expect(formComponent.isOutcomeButtonVisible(outcome)).toBeTruthy(); + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); }); it('should allow controlling [complete] button visibility', () => { let formModel = new FormModel(); + formComponent.form = formModel; let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION}); formComponent.showSaveButton = true; - expect(formComponent.isOutcomeButtonVisible(outcome)).toBeTruthy(); + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); formComponent.showSaveButton = false; - expect(formComponent.isOutcomeButtonVisible(outcome)).toBeFalsy(); + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy(); + }); + + it('should show only [complete] button with readOnly form ', () => { + let formModel = new FormModel(); + formModel.readOnly = true; + formComponent.form = formModel; + let outcome = new FormOutcomeModel(formModel, {id: '$complete', name: FormOutcomeModel.COMPLETE_ACTION}); + + formComponent.showCompleteButton = true; + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); + }); + + it('should not show [save] button with readOnly form ', () => { + let formModel = new FormModel(); + formModel.readOnly = true; + formComponent.form = formModel; + let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.SAVE_ACTION}); + + formComponent.showSaveButton = true; + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy(); + }); + + it('should show [custom-outcome] button with readOnly form and selected custom-outcome', () => { + let formModel = new FormModel({selectedOutcome: 'custom-outcome'}); + formModel.readOnly = true; + formComponent.form = formModel; + let outcome = new FormOutcomeModel(formModel, {id: '$customoutome', name: 'custom-outcome'}); + + formComponent.showCompleteButton = true; + formComponent.showSaveButton = true; + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); + + outcome = new FormOutcomeModel(formModel, {id: '$customoutome2', name: 'custom-outcome2'}); + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy(); }); it('should allow controlling [save] button visibility', () => { let formModel = new FormModel(); + formModel.readOnly = false; + formComponent.form = formModel; let outcome = new FormOutcomeModel(formModel, {id: '$save', name: FormOutcomeModel.COMPLETE_ACTION}); formComponent.showCompleteButton = true; - expect(formComponent.isOutcomeButtonVisible(outcome)).toBeTruthy(); + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeTruthy(); formComponent.showCompleteButton = false; - expect(formComponent.isOutcomeButtonVisible(outcome)).toBeFalsy(); + expect(formComponent.isOutcomeButtonVisible(outcome, formComponent.form.readOnly)).toBeFalsy(); }); it('should load form on refresh', () => { diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts index 278c534234..396f30b5d0 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-form.component.ts @@ -190,11 +190,14 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges { return false; } - isOutcomeButtonVisible(outcome: FormOutcomeModel): boolean { + isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean { if (outcome && outcome.name) { if (outcome.name === FormOutcomeModel.COMPLETE_ACTION) { return this.showCompleteButton; } + if (isFormReadOnly) { + return outcome.isSelected ; + } if (outcome.name === FormOutcomeModel.SAVE_ACTION) { return this.showSaveButton; } diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html index 5914fefde0..04c6311f78 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html +++ b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.html @@ -21,7 +21,7 @@ alfresco-mdl-button [disabled]="!isOutcomeButtonEnabled(outcome)" [class.mdl-button--colored]="!outcome.isSystem" - [class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome)" + [class.activiti-form-hide-button]="!isOutcomeButtonVisible(outcome, form.readOnly)" (click)="onOutcomeClicked(outcome, $event)"> {{outcome.name}} diff --git a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts index 003d788ba8..232e1551e8 100644 --- a/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts +++ b/ng2-components/ng2-activiti-form/src/components/activiti-start-form.component.ts @@ -133,14 +133,14 @@ export class ActivitiStartForm extends ActivitiForm implements AfterViewChecked, } /** @override */ - isOutcomeButtonVisible(outcome: FormOutcomeModel): boolean { + isOutcomeButtonVisible(outcome: FormOutcomeModel, isFormReadOnly: boolean): boolean { if (outcome && outcome.isSystem && ( outcome.name === FormOutcomeModel.SAVE_ACTION || outcome.name === FormOutcomeModel.COMPLETE_ACTION )) { return false; } else if (outcome && outcome.name === FormOutcomeModel.START_PROCESS_ACTION) { return true; } - return super.isOutcomeButtonVisible(outcome); + return super.isOutcomeButtonVisible(outcome, isFormReadOnly); } /** @override */ diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/core/form-outcome.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/core/form-outcome.model.ts index 2e0baed29b..0d364cdb18 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/core/form-outcome.model.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/core/form-outcome.model.ts @@ -25,12 +25,14 @@ export class FormOutcomeModel extends FormWidgetModel { static START_PROCESS_ACTION: string = 'Start Process'; // Activiti 'Start Process' action name isSystem: boolean = false; + isSelected: boolean = false; constructor(form: FormModel, json?: any) { super(form, json); if (json) { this.isSystem = json.isSystem ? true : false; + this.isSelected = form && json.name === form.selectedOutcome ? true : false; } } } diff --git a/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts b/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts index d28fcc7e3d..cc31cf1101 100644 --- a/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts +++ b/ng2-components/ng2-activiti-form/src/components/widgets/core/form.model.ts @@ -48,6 +48,7 @@ export class FormModel { fields: FormWidgetModel[] = []; outcomes: FormOutcomeModel[] = []; customFieldTemplates: FormFieldTemplates = {}; + readonly selectedOutcome: string; values: FormValues = {}; @@ -77,6 +78,7 @@ export class FormModel { this.taskName = json.taskName || json.name || FormModel.UNSET_TASK_NAME; this.processDefinitionId = json.processDefinitionId; this.customFieldTemplates = json.customFieldTemplates || {}; + this.selectedOutcome = json.selectedOutcome || {}; let tabCache: FormWidgetModelCache = {};