Skip to content

Commit

Permalink
feat(errors): add errors subsection to support error event definitions
Browse files Browse the repository at this point in the history
Closes #422
  • Loading branch information
azeghers committed Mar 1, 2021
1 parent 760e566 commit 906d9d2
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 7 deletions.
15 changes: 13 additions & 2 deletions lib/provider/camunda/CamundaPropertiesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ var elementTemplateDescriptionProps = require('./element-templates/parts/Descrip

// Input/Output
var inputParameters = require('./parts/InputParametersProps'),
outputParameters = require('./parts/OutputParametersProps');
outputParameters = require('./parts/OutputParametersProps'),
errorsProps = require('./parts/ErrorsProps');

// Connector
var connectorDetails = require('./parts/ConnectorDetailProps'),
Expand Down Expand Up @@ -420,9 +421,19 @@ function createInputOutputTabGroups(element, bpmnFactory, elementTemplates, tran

outputParameters(outputParametersGroup, element, bpmnFactory, elementTemplates, translate);

var errorsGroup = {
id: 'errors',
label: translate('Errors'),
entries: []
};

errorsProps(errorsGroup, element, bpmnFactory, elementTemplates, translate);

return [
inputParametersGroup,
outputParametersGroup
outputParametersGroup,

errorsGroup
];
}

Expand Down
16 changes: 16 additions & 0 deletions lib/provider/camunda/parts/ErrorsProps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
'use strict';

var errors = require('./implementation/Errors');

module.exports = function(group, element, bpmnFactory, elementTemplates, translate) {

var template = elementTemplates.get(element);

if (template) {
return;
}

var errorsEntry = errors(element, bpmnFactory, {}, translate);

group.entries = group.entries.concat(errorsEntry.entries);
};
97 changes: 97 additions & 0 deletions lib/provider/camunda/parts/implementation/Errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
'use strict';

var is = require('bpmn-js/lib/util/ModelUtil').is,
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;

var elementHelper = require('../../../../helper/ElementHelper'),
cmdHelper = require('../../../../helper/CmdHelper');

var domQuery = require('min-dom').query;

function supportsErrors(element) {
return is(element, 'bpmn:ServiceTask');
}

module.exports = function(element, bpmnFactory, options, translate) {

options = options || {};

var result = {};

var entries = result.entries = [];

if (!supportsErrors(element)) {
return result;
}

entries.push(
getErrorsHeading(element, bpmnFactory, {
type: 'camunda:ErrorEventDefinition',
prop: 'errorEventDefinition',
prefix: 'Error'
}));

return result;
};

function getErrorsHeading(element, bpmnFactory, options) {
var prefix = options.prefix;

var entry = {
id: prefix + '-heading',
cssClasses: [ 'bpp-input-output' ],
html: '<div class="bpp-field-wrapper">' +
'<button type="button" class="bpp-input-output__add add action-button" ' + 'data-action="createElement">' +
'</button><input name="hidden" type="hidden">' +
'</div>'
};

entry.createElement = function(_, entryNode) {
var commands = createElement();

if (commands) {
scheduleCommands(commands, entryNode);
return true;
}
};

entry.set = function() {
var commands = entry._commands;

if (commands) {
delete entry._commands;
return commands;
}
};

function createElement() {
var commands = [];
var bo = getBusinessObject(element);
var extensionElements = bo.get('extensionElements');

if (!extensionElements) {
extensionElements = elementHelper.createElement('bpmn:ExtensionElements', { values: [] }, bo, bpmnFactory);
commands.push(cmdHelper.updateBusinessObject(element, bo, { extensionElements: extensionElements }));
}
var newElem = elementHelper.createElement('camunda:ErrorEventDefinition', {}, extensionElements, bpmnFactory);
commands.push(cmdHelper.addElementsTolist(element, extensionElements, 'values', [ newElem ]));

return commands;
}

/**
* Schedule commands to be run with next `set` method call.
*
* @param {Array<any>} commands
* @param {HTMLElement} entryNode
*/
function scheduleCommands(commands, entryNode) {
entry._commands = commands;

// @barmac: hack to make properties panel call `set`
var input = domQuery('input[type="hidden"]', entryNode);
input.value = 1;
}

return entry;
}
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"devDependencies": {
"bpmn-js": "^8.2.0",
"bpmn-moddle": "^7.0.4",
"camunda-bpmn-moddle": "^4.5.0",
"camunda-bpmn-moddle": "5.0.0",
"chai": "^4.1.2",
"diagram-js": "^7.2.0",
"eslint": "^7.12.1",
Expand Down

0 comments on commit 906d9d2

Please sign in to comment.