Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions app/spiffworkflow/DataObject/DataObjectHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
*/

export function findDataObjects(parent, dataObjects) {
if (typeof (dataObjects) === 'undefined')
dataObjects = [];
if (typeof dataObjects === 'undefined') dataObjects = [];
let process;
if (!parent) {
return [];
Expand All @@ -18,10 +17,9 @@ export function findDataObjects(parent, dataObjects) {
if (process.$type === 'bpmn:SubProcess')
findDataObjects(process.$parent, dataObjects);
}
if (typeof (process.flowElements) !== 'undefined') {
if (typeof process.flowElements !== 'undefined') {
for (const element of process.flowElements) {
if (element.$type === 'bpmn:DataObject')
dataObjects.push(element);
if (element.$type === 'bpmn:DataObject') dataObjects.push(element);
}
}
return dataObjects;
Expand All @@ -40,23 +38,27 @@ export function findDataObjectReferences(children, dataObjectId) {
return [];
}
return children.flatMap((child) => {
if (child.$type == 'bpmn:DataObjectReference' && child.dataObjectRef.id == dataObjectId)
if (
child.$type == 'bpmn:DataObjectReference' &&
child.dataObjectRef.id == dataObjectId
)
return [child];
else if (child.$type == 'bpmn:SubProcess')
return findDataObjectReferences(child.get('flowElements'), dataObjectId);
else
return [];
else return [];
});
}

export function findDataObjectReferenceShapes(children, dataObjectId) {
return children.flatMap((child) => {
if (child.type == 'bpmn:DataObjectReference' && child.businessObject.dataObjectRef.id == dataObjectId)
if (
child.type == 'bpmn:DataObjectReference' &&
child.businessObject.dataObjectRef.id == dataObjectId
)
return [child];
else if (child.type == 'bpmn:SubProcess')
return findDataObjectReferenceShapes(child.children, dataObjectId);
else
return [];
else return [];
});
}

Expand All @@ -69,10 +71,21 @@ export function idToHumanReadableName(id) {
}
}

export function updateDataObjectReferencesName(parent, nameValue, dataObjectId, commandStack) {
const references = findDataObjectReferenceShapes(parent.children, dataObjectId);
export function updateDataObjectReferencesName(
parent,
nameValue,
dataObjectId,
commandStack
) {
const references = findDataObjectReferenceShapes(
parent.children,
dataObjectId
);
for (const ref of references) {
const stateName = ref.businessObject.dataState && ref.businessObject.dataState.name ? ref.businessObject.dataState.name : '';
const stateName =
ref.businessObject.dataState && ref.businessObject.dataState.name
? ref.businessObject.dataState.name
: '';
const newName = stateName ? `${nameValue} [${stateName}]` : nameValue;
commandStack.execute('element.updateProperties', {
element: ref,
Expand Down
29 changes: 21 additions & 8 deletions app/spiffworkflow/DataObject/DataObjectInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ const HIGH_PRIORITY = 1500;
* 4) Don't allow someone to move a DataObjectReference from one process to another process.
*/
export default class DataObjectInterceptor extends CommandInterceptor {

constructor(eventBus, bpmnFactory, commandStack, bpmnUpdater) {
super(eventBus);

/* The default behavior is to move the data object into whatever object the reference is being created in.
* If a data object already has a parent, don't change it.
*/
bpmnUpdater.updateSemanticParent = (businessObject, parentBusinessObject) => {
bpmnUpdater.updateSemanticParent = (
businessObject,
parentBusinessObject
) => {
// Special case for participant - which is a valid place to drop a data object, but it needs to be added
// to the particpant's Process (which isn't directly accessible in BPMN.io
let realParent = parentBusinessObject;
Expand All @@ -42,20 +44,24 @@ export default class DataObjectInterceptor extends CommandInterceptor {
// when the shape is deleted, but not interested in refactoring at the moment.
if (realParent != null) {
const flowElements = realParent.get('flowElements');
const existingElement = flowElements.find(i => i.id === 1);
const existingElement = flowElements.find((i) => i.id === 1);
if (!existingElement) {
flowElements.push(businessObject);
}
}
} else if (is(businessObject, 'bpmn:DataObject')) {
// For data objects, only update the flowElements for new data objects, and set the parent so it doesn't get moved.
if (typeof (businessObject.$parent) === 'undefined') {
if (typeof businessObject.$parent === 'undefined') {
const flowElements = realParent.get('flowElements');
flowElements.push(businessObject);
businessObject.$parent = realParent;
}
} else {
bpmnUpdater.__proto__.updateSemanticParent.call(bpmnUpdater, businessObject, parentBusinessObject);
bpmnUpdater.__proto__.updateSemanticParent.call(
bpmnUpdater,
businessObject,
parentBusinessObject
);
}
};

Expand Down Expand Up @@ -131,15 +137,22 @@ export default class DataObjectInterceptor extends CommandInterceptor {
}
const flowElements = parent.get('flowElements');
collectionRemove(flowElements, shape.businessObject);
const references = findDataObjectReferences(flowElements, dataObject.id);
const references = findDataObjectReferences(
flowElements,
dataObject.id
);
if (references.length === 0) {
const dataFlowElements = dataObject.$parent.get('flowElements');
collectionRemove(dataFlowElements, dataObject);
}
}
});

}
}

DataObjectInterceptor.$inject = ['eventBus', 'bpmnFactory', 'commandStack', 'bpmnUpdater'];
DataObjectInterceptor.$inject = [
'eventBus',
'bpmnFactory',
'commandStack',
'bpmnUpdater',
];
113 changes: 64 additions & 49 deletions app/spiffworkflow/DataObject/DataObjectLabelEditingProvider.js
Original file line number Diff line number Diff line change
@@ -1,62 +1,77 @@
import { is } from 'bpmn-js/lib/util/ModelUtil';
import { findDataObject, updateDataObjectReferencesName } from './DataObjectHelpers';
import {
findDataObject,
updateDataObjectReferencesName,
} from './DataObjectHelpers';

export default function DataObjectLabelEditingProvider(eventBus, directEditing, commandStack, modeling) {
export default function DataObjectLabelEditingProvider(
eventBus,
directEditing,
commandStack,
modeling
) {
let el;

let el;
// listen to dblclick on non-root elements
eventBus.on('element.dblclick', function (event) {
const { element } = event;
if (is(element.businessObject, 'bpmn:DataObjectReference')) {
let label = element.businessObject.name;
label = label.replace(/\s*\[.*?\]\s*$/, '');
modeling.updateLabel(element, label);
directEditing.activate(element);
el = element;
}
});

// listen to dblclick on non-root elements
eventBus.on('element.dblclick', function (event) {
const { element } = event;
if (is(element.businessObject, 'bpmn:DataObjectReference')) {
let label = element.businessObject.name;
label = label.replace(/\s*\[.*?\]\s*$/, '');
modeling.updateLabel(element, label);
directEditing.activate(element);
el = element;
}
});

eventBus.on('directEditing.complete', function (event) {

const element = el;
eventBus.on('directEditing.complete', function (event) {
const element = el;

if (element && is(element.businessObject, 'bpmn:DataObjectReference')) {
if (element && is(element.businessObject, 'bpmn:DataObjectReference')) {
setTimeout(() => {
const process = element.parent.businessObject;
const dataObject = findDataObject(
process,
element.businessObject.dataObjectRef.id
);
const dataState =
element.businessObject.dataState &&
element.businessObject.dataState.name;

setTimeout(() => {
const process = element.parent.businessObject;
const dataObject = findDataObject(process, element.businessObject.dataObjectRef.id);
const dataState = element.businessObject.dataState && element.businessObject.dataState.name;
let newLabel = element.businessObject.name;

let newLabel = element.businessObject.name;
commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: dataObject,
properties: {
name: newLabel,
},
});

commandStack.execute('element.updateModdleProperties', {
element,
moddleElement: dataObject,
properties: {
name: newLabel,
},
});
// Update references name
updateDataObjectReferencesName(
element.parent,
newLabel,
dataObject.id,
commandStack
);

// Update references name
updateDataObjectReferencesName(element.parent, newLabel, dataObject.id, commandStack);

// Append the data state if it exists
if (dataState) {
newLabel += ` [${dataState}]`;
}

// Update the label with the data state
modeling.updateLabel(element, newLabel);
el = undefined;
}, 100);
// Append the data state if it exists
if (dataState) {
newLabel += ` [${dataState}]`;
}
});

// Update the label with the data state
modeling.updateLabel(element, newLabel);
el = undefined;
}, 100);
}
});
}

DataObjectLabelEditingProvider.$inject = [
'eventBus',
'directEditing',
'commandStack',
'modeling'
];
'eventBus',
'directEditing',
'commandStack',
'modeling',
];
8 changes: 3 additions & 5 deletions app/spiffworkflow/DataObject/DataObjectRenderer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import BaseRenderer from 'diagram-js/lib/draw/BaseRenderer';

import {
attr as svgAttr
} from 'tiny-svg';
import { attr as svgAttr } from 'tiny-svg';

import { getBusinessObject, is } from 'bpmn-js/lib/util/ModelUtil';
import { isAny } from 'bpmn-js/lib/features/modeling/util/ModelingUtil';
Expand All @@ -21,7 +19,7 @@ export default class DataObjectRenderer extends BaseRenderer {
}

canRender(element) {
return isAny(element, [ 'bpmn:DataObjectReference' ]) && !element.labelTarget;
return isAny(element, ['bpmn:DataObjectReference']) && !element.labelTarget;
}

drawShape(parentNode, element) {
Expand All @@ -41,4 +39,4 @@ export default class DataObjectRenderer extends BaseRenderer {
}
}

DataObjectRenderer.$inject = [ 'eventBus', 'bpmnRenderer' ];
DataObjectRenderer.$inject = ['eventBus', 'bpmnRenderer'];
6 changes: 3 additions & 3 deletions app/spiffworkflow/DataObject/DataObjectRules.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ export default function DataObjectRules(eventBus) {
inherits(DataObjectRules, RuleProvider);
const HIGH_PRIORITY = 1500;

DataObjectRules.prototype.init = function() {
this.addRule('elements.move', HIGH_PRIORITY,function(context) {
DataObjectRules.prototype.init = function () {
this.addRule('elements.move', HIGH_PRIORITY, function (context) {
let elements = context.shapes;
let target = context.target;
return canDrop(elements, target);
Expand All @@ -36,4 +36,4 @@ function canDrop(elements, target) {
}

DataObjectRules.prototype.canDrop = canDrop;
DataObjectRules.$inject = [ 'eventBus' ];
DataObjectRules.$inject = ['eventBus'];
23 changes: 12 additions & 11 deletions app/spiffworkflow/DataObject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@ import DataObjectPropertiesProvider from './propertiesPanel/DataObjectProperties
import DataObjectLabelEditingProvider from './DataObjectLabelEditingProvider';

export default {
__depends__: [
RulesModule
__depends__: [RulesModule],
__init__: [
'dataInterceptor',
'dataObjectRules',
'dataObjectRenderer',
'dataObjectPropertiesProvider',
'dataObjectLabelEditingProvider',
],
__init__: [ 'dataInterceptor', 'dataObjectRules', 'dataObjectRenderer', 'dataObjectPropertiesProvider', 'dataObjectLabelEditingProvider' ],
dataInterceptor: [ 'type', DataObjectInterceptor ],
dataObjectRules: [ 'type', DataObjectRules ],
dataObjectRenderer: [ 'type', DataObjectRenderer ],
dataObjectPropertiesProvider: [ 'type', DataObjectPropertiesProvider ],
dataObjectLabelEditingProvider: [ 'type', DataObjectLabelEditingProvider ]
dataInterceptor: ['type', DataObjectInterceptor],
dataObjectRules: ['type', DataObjectRules],
dataObjectRenderer: ['type', DataObjectRenderer],
dataObjectPropertiesProvider: ['type', DataObjectPropertiesProvider],
dataObjectLabelEditingProvider: ['type', DataObjectLabelEditingProvider],
};



Loading