-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(errors): add errors subsection to support error event definitions
Closes #422
- Loading branch information
Showing
5 changed files
with
131 additions
and
7 deletions.
There are no files selected for viewing
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
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,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); | ||
}; |
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,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; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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