Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add errors group to input output tab #435

Merged
merged 1 commit into from
Mar 5, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ module.exports = function(element, definition, bpmnFactory, translate, options)
var modelProperty = options.modelProperty || 'name';
var shouldValidate = options.shouldValidate || false;
var description = options.description;
var canBeHidden = !!options.hidden && typeof options.hidden === 'function';

var entry = entryFactory.textField(translate, {
id: id,
Expand All @@ -50,6 +51,9 @@ module.exports = function(element, definition, bpmnFactory, translate, options)
},

hidden: function(element, node) {
if (canBeHidden) {
return options.hidden.apply(definition, arguments) || !definition.get(referenceProperty);
}
return !definition.get(referenceProperty);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = function(group, element, bpmnFactory, errorEventDefinition, tra
group.entries = group.entries.concat(
elementReferenceProperty(element, errorEventDefinition, bpmnFactory, translate, {
id: 'error-element-name',
label: translate('Global Error Name'),
label: translate('Name'),
pinussilvestrus marked this conversation as resolved.
Show resolved Hide resolved
referenceProperty: 'errorRef',
modelProperty: 'name',
shouldValidate: true
Expand All @@ -30,7 +30,7 @@ module.exports = function(group, element, bpmnFactory, errorEventDefinition, tra
group.entries = group.entries.concat(
elementReferenceProperty(element, errorEventDefinition, bpmnFactory, translate, {
id: 'error-element-code',
label: translate('Global Error Code'),
label: translate('Code'),
referenceProperty: 'errorRef',
modelProperty: 'errorCode'
})
Expand Down
14 changes: 11 additions & 3 deletions lib/provider/bpmn/parts/implementation/EventDefinitionReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ var selector = 'select[name=selectedElement]';
* @return {DOMElement} the select box
*/
function getSelectBox(node) {
return domQuery(selector, node.parentElement);
return domQuery(selector, node);
}

/**
Expand Down Expand Up @@ -70,11 +70,19 @@ module.exports = function(element, definition, bpmnFactory, options) {

var entries = [];

var canBeHidden = !!options.hidden && typeof options.hidden === 'function';

entries.push({

id: 'event-definitions-' + elementName,
id: options.id || 'event-definitions-' + elementName,
description: description,
html: '<div class="bpp-row bpp-select">' +
isShown: function() {
if (canBeHidden) {
return !options.hidden.apply(definition, arguments);
}
return !options.hidden;
},
html: '<div class="bpp-row bpp-select" data-show="isShown">' +
'<label for="camunda-' + escapeHTML(elementName) + '">' + escapeHTML(label) + '</label>' +
'<div class="bpp-field-wrapper">' +
'<select id="camunda-' + escapeHTML(elementName) + '" name="selectedElement" data-value>' +
Expand Down
21 changes: 19 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,25 @@ function createInputOutputTabGroups(element, bpmnFactory, elementTemplates, tran

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

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

enabled: function(element, node) {
var businessObject = getBusinessObject(element);
var isExternal = ImplementationTypeHelper.getImplementationType(businessObject) === 'external';

return is(element, 'bpmn:ServiceTask') && isExternal;
},
};

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);
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ module.exports = function(
group.entries = group.entries.concat(
elementReferenceProperty(element, errorEventDefinition, bpmnFactory, translate, {
id: 'error-element-message',
label: translate('Global Error Message'),
label: translate('Message'),
referenceProperty: 'errorRef',
modelProperty: 'errorMessage'
})
Expand All @@ -41,7 +41,7 @@ module.exports = function(
if (showErrorCodeVariable) {
group.entries.push(entryFactory.validationAwareTextField(translate, {
id: 'errorCodeVariable',
label: translate('Error Code Variable'),
label: translate('Code Variable'),
modelProperty : 'errorCodeVariable',
description: translate('Define the name of the variable that will contain the error code'),

Expand All @@ -64,7 +64,7 @@ module.exports = function(
if (showErrorMessageVariable) {
group.entries.push(entryFactory.validationAwareTextField(translate, {
id: 'errorMessageVariable',
label: translate('Error Message Variable'),
label: translate('Message Variable'),
modelProperty: 'errorMessageVariable',

getProperty: getValue('errorMessageVariable'),
Expand Down
175 changes: 175 additions & 0 deletions lib/provider/camunda/parts/implementation/Errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
'use strict';

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


var entryFieldDescription = require('../../../../factory/EntryFieldDescription');

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

var ErrorsEntries = require('./ErrorsEntries');

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

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

options = options || {};

var result = {};

var entries = result.entries = [];

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

append(entries,
getErrorsEntries(element, bpmnFactory, {}, translate)
);

return result;
};

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

var entry = {
id: prefix + '-heading',
cssClasses: [ 'bpp-error' ],
html: '<div class="bpp-field-wrapper">' +
'<button type="button" class="bpp-error__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;
}

function getErrors(bo) {
return extensionElementsHelper.getExtensionElements(bo, 'camunda:ErrorEventDefinition') || [];
}


function getErrorsEntries(element, bpmnFactory, options, translate) {
var idPrefix = options.idPrefix || '',
bo = getBusinessObject(element),
errorEventDefinitions = getErrors(bo),
extensionElements = bo.get('extensionElements'),
entries;

if (errorEventDefinitions && !errorEventDefinitions.length) {
var description = entryFieldDescription(translate, translate('No errors defined.'));

return [{
id: idPrefix + 'error-placeholder',
cssClasses: [ 'bpp-error-placeholder' ],
html: description
}];
}

var errorsEntries = errorEventDefinitions.map(function(definition, index) {

function onRemove() {
var commands = [];

commands.push(cmdHelper.removeElementsFromList(element, extensionElements, 'values', 'extensionElements', [definition]));
return commands;
}

return ErrorsEntries(definition, bpmnFactory, element,
{
idPrefix: idPrefix + 'error-' + index,
onRemove: onRemove,
onToggle: onToggle
}, translate);

/**
* Close remaining collapsible entries within group.
*
* @param {boolean} value
* @param {HTMLElement} entryNode
*/
function onToggle(value, entryNode) {
if (!value) {
return;
}

var currentEntryId = entryNode.dataset.entry;

errorsEntries.forEach(function(entry) {
if (entry.entries[0].id === currentEntryId) {
return;
}

entry.setOpen(false);
});

}
});

entries = errorsEntries.map(function(input) {
return input.entries;
});

return flatten(entries);
}

function flatten(arrays) {
return Array.prototype.concat.apply([], arrays);
}

function append(array, items) {
Array.prototype.push.apply(array, items);
}
Loading