#1432 - Added new system outcome : Start Process (#1453)

* #1432 - Added system outcome for start process

* 1432 - improved condition for system outcome check

* #1432 - fix test for start process system outcome
This commit is contained in:
Vito 2017-01-13 04:46:40 -08:00 committed by Mario Romano
parent 0fa87bb17d
commit fcdc628d35
5 changed files with 43 additions and 6 deletions

View File

@ -15,7 +15,16 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, OnInit, AfterViewChecked, OnChanges, SimpleChanges, Input, Output, EventEmitter } from '@angular/core'; import {
Component,
OnInit,
AfterViewChecked,
OnChanges,
SimpleChanges,
Input,
Output,
EventEmitter
} from '@angular/core';
import { LogService } from 'ng2-alfresco-core'; import { LogService } from 'ng2-alfresco-core';
import { EcmModelService } from './../services/ecm-model.service'; import { EcmModelService } from './../services/ecm-model.service';
import { FormService } from './../services/form.service'; import { FormService } from './../services/form.service';
@ -79,6 +88,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
static SAVE_OUTCOME_ID: string = '$save'; static SAVE_OUTCOME_ID: string = '$save';
static COMPLETE_OUTCOME_ID: string = '$complete'; static COMPLETE_OUTCOME_ID: string = '$complete';
static START_PROCESS_OUTCOME_ID: string = '$startProcess';
static CUSTOM_OUTCOME_ID: string = '$custom'; static CUSTOM_OUTCOME_ID: string = '$custom';
@Input() @Input()
@ -185,6 +195,9 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
if (outcome.name === FormOutcomeModel.SAVE_ACTION) { if (outcome.name === FormOutcomeModel.SAVE_ACTION) {
return this.showSaveButton; return this.showSaveButton;
} }
if (outcome.name === FormOutcomeModel.START_PROCESS_ACTION) {
return false;
}
return true; return true;
} }
return false; return false;
@ -247,6 +260,11 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
return true; return true;
} }
if (outcome.id === ActivitiForm.START_PROCESS_OUTCOME_ID) {
this.completeTaskForm();
return true;
}
if (outcome.id === ActivitiForm.CUSTOM_OUTCOME_ID) { if (outcome.id === ActivitiForm.CUSTOM_OUTCOME_ID) {
this.formSaved.emit(this.form); this.formSaved.emit(this.form);
this.storeFormAsMetadata(); this.storeFormAsMetadata();
@ -421,7 +439,7 @@ export class ActivitiForm implements OnInit, AfterViewChecked, OnChanges {
*/ */
getFormDefinitionOutcomes(form: FormModel): FormOutcomeModel[] { getFormDefinitionOutcomes(form: FormModel): FormOutcomeModel[] {
return [ return [
new FormOutcomeModel(form, {id: '$custom', name: FormOutcomeModel.SAVE_ACTION, isSystem: true}) new FormOutcomeModel(form, { id: '$custom', name: FormOutcomeModel.SAVE_ACTION, isSystem: true })
]; ];
} }

View File

@ -15,7 +15,17 @@
* limitations under the License. * limitations under the License.
*/ */
import { Component, AfterViewChecked, OnChanges, SimpleChanges, Input, ViewChild, ElementRef, Output, EventEmitter } from '@angular/core'; import {
Component,
AfterViewChecked,
OnChanges,
SimpleChanges,
Input,
ViewChild,
ElementRef,
Output,
EventEmitter
} from '@angular/core';
import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core'; import { AlfrescoTranslateService, LogService } from 'ng2-alfresco-core';
import { ActivitiForm } from './activiti-form.component'; import { ActivitiForm } from './activiti-form.component';
import { FormService } from './../services/form.service'; import { FormService } from './../services/form.service';
@ -124,8 +134,11 @@ export class ActivitiStartForm extends ActivitiForm implements AfterViewChecked,
/** @override */ /** @override */
isOutcomeButtonVisible(outcome: FormOutcomeModel): boolean { isOutcomeButtonVisible(outcome: FormOutcomeModel): boolean {
if (outcome && outcome.name === FormOutcomeModel.SAVE_ACTION) { if (outcome && outcome.isSystem && ( outcome.name === FormOutcomeModel.SAVE_ACTION ||
outcome.name === FormOutcomeModel.COMPLETE_ACTION )) {
return false; return false;
} else if (outcome && outcome.name === FormOutcomeModel.START_PROCESS_ACTION) {
return true;
} }
return super.isOutcomeButtonVisible(outcome); return super.isOutcomeButtonVisible(outcome);
} }

View File

@ -22,6 +22,7 @@ export class FormOutcomeModel extends FormWidgetModel {
static SAVE_ACTION: string = 'Save'; // Activiti 'Save' action name static SAVE_ACTION: string = 'Save'; // Activiti 'Save' action name
static COMPLETE_ACTION: string = 'Complete'; // Activiti 'Complete' action name static COMPLETE_ACTION: string = 'Complete'; // Activiti 'Complete' action name
static START_PROCESS_ACTION: string = 'Start Process'; // Activiti 'Start Process' action name
isSystem: boolean = false; isSystem: boolean = false;

View File

@ -270,13 +270,16 @@ describe('FormModel', () => {
}; };
let form = new FormModel(json); let form = new FormModel(json);
expect(form.outcomes.length).toBe(2); expect(form.outcomes.length).toBe(3);
expect(form.outcomes[0].id).toBe(FormModel.SAVE_OUTCOME); expect(form.outcomes[0].id).toBe(FormModel.SAVE_OUTCOME);
expect(form.outcomes[0].isSystem).toBeTruthy(); expect(form.outcomes[0].isSystem).toBeTruthy();
expect(form.outcomes[1].id).toBe(FormModel.COMPLETE_OUTCOME); expect(form.outcomes[1].id).toBe(FormModel.COMPLETE_OUTCOME);
expect(form.outcomes[1].isSystem).toBeTruthy(); expect(form.outcomes[1].isSystem).toBeTruthy();
expect(form.outcomes[2].id).toBe(FormModel.START_PROCESS_OUTCOME);
expect(form.outcomes[2].isSystem).toBeTruthy();
}); });
it('should create outcomes only when fields available', () => { it('should create outcomes only when fields available', () => {

View File

@ -29,6 +29,7 @@ export class FormModel {
static UNSET_TASK_NAME: string = 'Nameless task'; static UNSET_TASK_NAME: string = 'Nameless task';
static SAVE_OUTCOME: string = '$save'; static SAVE_OUTCOME: string = '$save';
static COMPLETE_OUTCOME: string = '$complete'; static COMPLETE_OUTCOME: string = '$complete';
static START_PROCESS_OUTCOME: string = '$startProcess';
readonly id: string; readonly id: string;
readonly name: string; readonly name: string;
@ -103,11 +104,12 @@ export class FormModel {
if (json.fields) { if (json.fields) {
let saveOutcome = new FormOutcomeModel(this, { id: FormModel.SAVE_OUTCOME, name: 'Save', isSystem: true }); let saveOutcome = new FormOutcomeModel(this, { id: FormModel.SAVE_OUTCOME, name: 'Save', isSystem: true });
let completeOutcome = new FormOutcomeModel(this, {id: FormModel.COMPLETE_OUTCOME, name: 'Complete', isSystem: true }); let completeOutcome = new FormOutcomeModel(this, {id: FormModel.COMPLETE_OUTCOME, name: 'Complete', isSystem: true });
let startProcessOutcome = new FormOutcomeModel(this, { id: FormModel.START_PROCESS_OUTCOME, name: 'Start Process', isSystem: true });
let customOutcomes = (json.outcomes || []).map(obj => new FormOutcomeModel(this, obj)); let customOutcomes = (json.outcomes || []).map(obj => new FormOutcomeModel(this, obj));
this.outcomes = [saveOutcome].concat( this.outcomes = [saveOutcome].concat(
customOutcomes.length > 0 ? customOutcomes : [completeOutcome] customOutcomes.length > 0 ? customOutcomes : [completeOutcome, startProcessOutcome]
); );
} }
} }