merged reverse of pre/post scripts

updated spiffworkflow moddle to use "script" rather than "text" - to match up with bpmn.io's script task.
Added some ability to change what a DataObjectReference, references.  But more work needed here.
Fixed a bug in the script task that prevented you from writing text in that script object.
This commit is contained in:
Dan 2022-07-05 10:27:38 -04:00
parent b9ed7363f3
commit 4c413c4907
7 changed files with 113 additions and 51 deletions

View File

@ -43,7 +43,6 @@ export default class IoInterceptor extends CommandInterceptor {
} else {
collectionAdd(ioSpecification.get('dataOutputs'), dataIO);
}
}
});

View File

@ -1,6 +1,6 @@
import scriptProps, { SCRIPT_TYPE } from './parts/ScriptProps';
import { is, isAny } from 'bpmn-js/lib/util/ModelUtil';
import dataObjectProps from './parts/DataObjectProps';
import dataObjectProps from './parts/DataReferenceProps';
const LOW_PRIORITY = 500;

View File

@ -1,23 +1,37 @@
import { SelectEntry, isTextFieldEntryEdited} from '@bpmn-io/properties-panel';
import { Group, ListGroup, SelectEntry, isTextFieldEntryEdited, TextEntry } from '@bpmn-io/properties-panel';
import {useService} from 'bpmn-js-properties-panel';
import {getBusinessObject} from 'bpmn-js/lib/util/ModelUtil';
import {remove as collectionRemove} from 'diagram-js/lib/util/Collections';
/**
* Allows for the creation and deletion of Data Objects
* and connecting those data objects to Data References.
* Allows you to associate the selected Data Reference to a
* data object. Many references can point to the same data object.
* Also allows you to select which Data Objects are available
* in the system overall.
* @param dataElement The selected Data Object Reference
* @param moddle For updating the underlying xml object
* @returns {[{component: (function(*)), isEdited: *, id: string, element},{component: (function(*)), isEdited: *, id: string, element}]}
*/
export default function (dataElement, moddle) {
return [
{
id: 'dataObjects',
id: 'selectDataObject',
dataElement,
component: DataObjectSelector,
isEdited: isTextFieldEntryEdited,
moddle: moddle,
},
];
{
id: 'editDataObjects',
dataElement,
label: 'Available Data Objects',
component: Group,
entries: [
...DataObjectProps({dataElement, moddle})
]
}
];
}
/**
@ -79,3 +93,56 @@ function DataObjectSelector(props) {
debounce={debounce}
/>;
}
/**
* Provides a list of data objects, and allows you to add / remove data objects, and change their ids.
* @param props
* @constructor
*/
function DataObjectProps(props) {
const moddle = props.moddle;
const id = props.id;
const element = props.dataElement;
const businessObject = element.businessObject;
const parent = businessObject.$parent;
let dataObjects = []
for (const element of parent.flowElements) {
if (element.$type === 'bpmn:DataObject') {
dataObjects.push(element)
}
}
const entries = dataObjects.map((dataObject, index) => {
return {
id: dataObject.id,
label: dataObject.id,
autoFocusEntry: dataObject.id,
remove: removeDataObject({ dataObject })
};
});
return entries
function removeDataObject({ dataObject }) {
return function(event) {
const parent = dataObject.$parent
collectionRemove(parent, dataObject);
};
}
function addFactory({ bpmnFactory, commandStack, element }) {
return function(event) {
event.stopPropagation();
const businessObject = element.businessObject.$parent;
businessObject.add('bpmn:DataObject')
};
}
}

View File

@ -69,46 +69,40 @@ function PythonScript(props) {
const getScriptObject = () => {
const bizObj = element.businessObject;
if (type === SCRIPT_TYPE.bpmn) {
return bizObj.script || '';
return bizObj;
}
if (!bizObj.extensionElements) {
return null;
} else {
if (!bizObj.extensionElements) {
return null;
} else {
return bizObj.extensionElements.values.filter(function(e) {
return e.$instanceOf(type);
})[0];
}
return bizObj.extensionElements.values.filter(function(e) {
return e.$instanceOf(type);
})[0];
}
};
const getValue = () => {
const script = getScriptObject();
if (script) {
return (script.text);
const scriptObj = getScriptObject()
if (scriptObj) {
return scriptObj.script;
} else {
return ('');
return ""
}
};
const setValue = value => {
const businessObject = element.businessObject;
if (type === SCRIPT_TYPE.bpmn) {
return modeling.updateProperties(element, {
scriptFormat: 'python',
script: value
});
} else {
let script = getScriptObject();
if (!script) {
script = moddle.create(type);
let scriptObj = getScriptObject()
// Create the script object if needed.
if (!scriptObj) {
scriptObj = moddle.create(type);
if (type !== SCRIPT_TYPE.bpmn) {
if (!businessObject.extensionElements) {
businessObject.extensionElements = moddle.create('bpmn:ExtensionElements');
}
businessObject.extensionElements.get('values').push(script);
businessObject.extensionElements.get('values').push(scriptObj);
}
script.text = value;
return script;
}
scriptObj.script = value;
};
return <TextAreaEntry

View File

@ -12,7 +12,7 @@
"superClass": [ "Element" ],
"properties": [
{
"name": "text",
"name": "script",
"isBody": true,
"type": "String"
}
@ -23,7 +23,7 @@
"superClass": [ "Element" ],
"properties": [
{
"name": "text",
"name": "script",
"isBody": true,
"type": "String"
}

View File

@ -46,11 +46,12 @@ describe('Properties Panel Script Tasks', function() {
const scriptTask = await expectSelected('my_script_task');
let entry = findEntry('pythonScript_bpmn:script', PROPERTIES_PANEL_CONTAINER);
const scriptInput = domQuery('textarea', entry);
changeInput(scriptInput, 'x = 1');
changeInput(scriptInput, 'x = 100');
// THEN - the script tag in the BPMN Business object / XML is updated as well.
let businessObject = getBusinessObject(scriptTask);
expect(businessObject.get('script')).to.equal('x = 1');
expect(businessObject.get('script')).to.equal('x = 100');
expect(scriptInput.value).to.equal('x = 100');
});
});

View File

@ -30,6 +30,7 @@
<bpmn:sourceRef>my_data_ref_2</bpmn:sourceRef>
<bpmn:targetRef>Property_1w1963p</bpmn:targetRef>
</bpmn:dataInputAssociation>
<bpmn:script>elizabeth="awesome"</bpmn:script>
</bpmn:scriptTask>
<bpmn:dataObject id="my_data_object" />
<bpmn:dataObject id="my_other_data_object" />
@ -39,12 +40,6 @@
</bpmn:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="Process_1mzevep">
<bpmndi:BPMNShape id="dataInput_2" bpmnElement="happy_index">
<dc:Bounds x="602" y="85" width="36" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="580" y="142" width="83" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="Flow_0q4oys2_di" bpmnElement="Flow_0q4oys2">
<di:waypoint x="540" y="197" />
<di:waypoint x="602" y="197" />
@ -60,19 +55,13 @@
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds x="179" y="179" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_14wzv4j_di" bpmnElement="Event_14wzv4j">
<dc:Bounds x="602" y="179" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0t7iwfm_di" bpmnElement="Activity_15zz6ya">
<dc:Bounds x="280" y="157" width="100" height="80" />
<bpmndi:BPMNLabel />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="dataInput_1" bpmnElement="num_dogs">
<dc:Bounds x="179" y="85" width="36" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="158" y="135" width="81" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Event_14wzv4j_di" bpmnElement="Event_14wzv4j">
<dc:Bounds x="602" y="179" width="36" height="36" />
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="Activity_0h86vbv_di" bpmnElement="my_script_task">
<dc:Bounds x="440" y="157" width="100" height="80" />
</bpmndi:BPMNShape>
@ -88,6 +77,18 @@
<dc:Bounds x="464" y="332" width="33" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="dataInput_1" bpmnElement="num_dogs">
<dc:Bounds x="179" y="85" width="36" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="158" y="135" width="81" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="dataInput_2" bpmnElement="happy_index">
<dc:Bounds x="602" y="85" width="36" height="50" />
<bpmndi:BPMNLabel>
<dc:Bounds x="580" y="142" width="83" height="14" />
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNEdge id="DataOutputAssociation_1uj5jzs_di" bpmnElement="DataOutputAssociation_1uj5jzs">
<di:waypoint x="329" y="237" />
<di:waypoint x="328" y="275" />
@ -98,4 +99,4 @@
</bpmndi:BPMNEdge>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn:definitions>
</bpmn:definitions>