From 906d9d2efe1fe659288242358040326313e18318 Mon Sep 17 00:00:00 2001 From: Alexis Zeghers <42282939+AZeghers@users.noreply.github.com> Date: Fri, 12 Feb 2021 14:43:53 +0100 Subject: [PATCH] feat(errors): add errors subsection to support error event definitions Closes #422 --- .../camunda/CamundaPropertiesProvider.js | 15 ++- lib/provider/camunda/parts/ErrorsProps.js | 16 +++ .../camunda/parts/implementation/Errors.js | 97 +++++++++++++++++++ package-lock.json | 8 +- package.json | 2 +- 5 files changed, 131 insertions(+), 7 deletions(-) create mode 100644 lib/provider/camunda/parts/ErrorsProps.js create mode 100644 lib/provider/camunda/parts/implementation/Errors.js diff --git a/lib/provider/camunda/CamundaPropertiesProvider.js b/lib/provider/camunda/CamundaPropertiesProvider.js index c13eda381..7b786824d 100644 --- a/lib/provider/camunda/CamundaPropertiesProvider.js +++ b/lib/provider/camunda/CamundaPropertiesProvider.js @@ -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'), @@ -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 ]; } diff --git a/lib/provider/camunda/parts/ErrorsProps.js b/lib/provider/camunda/parts/ErrorsProps.js new file mode 100644 index 000000000..266029dae --- /dev/null +++ b/lib/provider/camunda/parts/ErrorsProps.js @@ -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); +}; diff --git a/lib/provider/camunda/parts/implementation/Errors.js b/lib/provider/camunda/parts/implementation/Errors.js new file mode 100644 index 000000000..9e2ca66b1 --- /dev/null +++ b/lib/provider/camunda/parts/implementation/Errors.js @@ -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: '
' + + '' + + '
' + }; + + 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} 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; +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ede16893a..58f7d20df 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1198,12 +1198,12 @@ "dev": true }, "camunda-bpmn-moddle": { - "version": "4.5.0", - "resolved": "https://registry.npmjs.org/camunda-bpmn-moddle/-/camunda-bpmn-moddle-4.5.0.tgz", - "integrity": "sha512-g3d2ZaCac52WIXP3kwmYrBEkhm0nnXcWYNj5STDkmiWpDTKUzTj4ZIt38IRpci1Uj3a/rZACvXLnQj8xKFyp/w==", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/camunda-bpmn-moddle/-/camunda-bpmn-moddle-5.0.0.tgz", + "integrity": "sha512-GZ5Gv8T9NudQ6y28cVqW8XUZGlor0ZBnrEKMANYmcXF2TeSTi8nAZ/4KOBfcRdfd0FcpxKwfY0ictYGfULLoww==", "dev": true, "requires": { - "min-dash": "^3.0.0" + "min-dash": "^3.5.2" } }, "caseless": { diff --git a/package.json b/package.json index b5606d853..ca6522fd4 100644 --- a/package.json +++ b/package.json @@ -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",