-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(camunda-platform): add input output behavior
Related to bpmn-io/bpmn-properties-panel#54
- Loading branch information
1 parent
28da536
commit 83d8f7c
Showing
4 changed files
with
711 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
lib/camunda-platform/features/modeling/behavior/UpdateInputOutputBehavior.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import inherits from 'inherits'; | ||
|
||
import { | ||
getBusinessObject, | ||
is | ||
} from 'bpmn-js/lib/util/ModelUtil'; | ||
|
||
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor'; | ||
|
||
/** | ||
* Camunda BPMN specific `camunda:inputOutput` behavior. | ||
*/ | ||
export default function UpdateInputOutputBehavior(eventBus, modeling) { | ||
|
||
CommandInterceptor.call(this, eventBus); | ||
|
||
this.postExecute([ | ||
'element.updateProperties', | ||
'element.updateModdleProperties', | ||
'properties-panel.update-businessobject-list' | ||
], function(context) { | ||
const { | ||
element | ||
} = context; | ||
|
||
const businessObject = getBusinessObject(element); | ||
const inputOutput = getInputOutput(businessObject); | ||
const extensionElements = businessObject.get('extensionElements'); | ||
|
||
// Remove camunda:inputOutput if there are no input/output parameters anymore. | ||
if (inputOutput && isEmpty(inputOutput)) { | ||
const filtered = extensionElements.values.filter(function(element) { | ||
return element !== inputOutput; | ||
}); | ||
|
||
modeling.updateModdleProperties(element, extensionElements, { | ||
values: filtered | ||
}); | ||
} | ||
}, true); | ||
} | ||
|
||
|
||
UpdateInputOutputBehavior.$inject = [ | ||
'eventBus', | ||
'modeling' | ||
]; | ||
|
||
inherits(UpdateInputOutputBehavior, CommandInterceptor); | ||
|
||
|
||
// helper ////////////////// | ||
|
||
function getInputParameters(inputOutput) { | ||
return inputOutput.get('inputParameters'); | ||
} | ||
|
||
function getOutputParameters(inputOutput) { | ||
return inputOutput.get('outputParameters'); | ||
} | ||
|
||
function getInputOutput(businessObject) { | ||
return (getExtensionElementsList(businessObject, 'camunda:InputOutput') || [])[0]; | ||
} | ||
|
||
function getExtensionElementsList(businessObject, type = undefined) { | ||
const elements = ((businessObject.get('extensionElements') && | ||
businessObject.get('extensionElements').get('values')) || []); | ||
|
||
return (elements.length && type) ? | ||
elements.filter((value) => is(value, type)) : | ||
elements; | ||
} | ||
|
||
function isEmpty(inputOutput) { | ||
const inputParameters = getInputParameters(inputOutput); | ||
const outputParameters = getOutputParameters(inputOutput); | ||
|
||
return inputParameters.length === 0 && outputParameters.length === 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.