bpmn-js-properties-panel
Advanced tools
Comparing version 0.18.5 to 0.19.0
@@ -128,3 +128,3 @@ 'use strict'; | ||
resource.cssClasses = ['dropdown']; | ||
resource.cssClasses = ['bpp-dropdown']; | ||
@@ -131,0 +131,0 @@ return resource; |
@@ -12,3 +12,4 @@ 'use strict'; | ||
createCamundaInWithBusinessKey = require('../CreateHelper').createCamundaInWithBusinessKey, | ||
createCamundaExecutionListenerScript = require('../CreateHelper').createCamundaExecutionListenerScript; | ||
createCamundaExecutionListenerScript = require('../CreateHelper').createCamundaExecutionListenerScript, | ||
createCamundaFieldInjection = require('../CreateHelper').createCamundaFieldInjection; | ||
@@ -82,2 +83,31 @@ var forEach = require('lodash/collection/forEach'); | ||
function updateCamundaField(element, newTemplate, context) { | ||
var newMappings = createCamundaFieldInjections(newTemplate, bpmnFactory), | ||
oldMappings; | ||
if (!newMappings) { | ||
return; | ||
} | ||
if (context) { | ||
commandStack.execute('properties-panel.update-businessobject', { | ||
element: element, | ||
businessObject: context, | ||
properties: { field: newMappings } | ||
}); | ||
} else { | ||
context = getOrCreateExtensionElements(element); | ||
oldMappings = findExtensions(element, ['camunda:Field']); | ||
commandStack.execute('properties-panel.update-businessobject-list', { | ||
element: element, | ||
currentObject: context, | ||
propertyName: 'values', | ||
objectsToAdd: newMappings, | ||
objectsToRemove: oldMappings ? oldMappings : [] | ||
}); | ||
} | ||
} | ||
function updateCamundaProperties(element, newTemplate, context) { | ||
@@ -205,2 +235,5 @@ | ||
// update camunda:field | ||
updateCamundaField(element, scopeDefinition, scopeElement); | ||
// update camunda:properties | ||
@@ -252,2 +285,5 @@ updateCamundaProperties(element, scopeDefinition, scopeElement); | ||
// update camunda:field | ||
updateCamundaField(element, newTemplate); | ||
// update camunda:properties | ||
@@ -323,2 +359,20 @@ updateCamundaProperties(element, newTemplate); | ||
function createCamundaFieldInjections(template, bpmnFactory) { | ||
var injections = []; | ||
template.properties.forEach(function(p) { | ||
var binding = p.binding, | ||
bindingType = binding.type; | ||
if (bindingType === 'camunda:field') { | ||
injections.push(createCamundaFieldInjection( | ||
binding, p.value, bpmnFactory | ||
)); | ||
} | ||
}); | ||
if (injections.length) { | ||
return injections; | ||
} | ||
} | ||
function createCamundaProperties(template, bpmnFactory) { | ||
@@ -422,2 +476,2 @@ | ||
return executionListener; | ||
} | ||
} |
'use strict'; | ||
var assign = require('lodash/object/assign'); | ||
/** | ||
@@ -177,3 +179,32 @@ * Create an input parameter representing the given | ||
/** | ||
* Create camunda:field element containing string or expression from given binding. | ||
* | ||
* @param {PropertyBinding} binding | ||
* @param {String} value | ||
* @param {BpmnFactory} bpmnFactory | ||
* | ||
* @return {ModdleElement} | ||
*/ | ||
function createCamundaFieldInjection(binding, value, bpmnFactory) { | ||
var DEFAULT_PROPS = { | ||
'string': undefined, | ||
'expression': undefined, | ||
'name': undefined | ||
}; | ||
var props = assign({}, DEFAULT_PROPS); | ||
if (!binding.expression) { | ||
props.string = value; | ||
} else { | ||
props.expression = value; | ||
} | ||
props.name = binding.name; | ||
return bpmnFactory.create('camunda:Field', props); | ||
} | ||
module.exports.createCamundaFieldInjection = createCamundaFieldInjection; | ||
/////////// helpers //////////////////////////// | ||
@@ -180,0 +211,0 @@ |
@@ -12,2 +12,3 @@ 'use strict'; | ||
var findExtension = require('../Helper').findExtension, | ||
findExtensions = require('../Helper').findExtensions, | ||
findInputParameter = require('../Helper').findInputParameter, | ||
@@ -23,3 +24,4 @@ findOutputParameter = require('../Helper').findOutputParameter, | ||
createCamundaOut = require('../CreateHelper').createCamundaOut, | ||
createCamundaInWithBusinessKey = require('../CreateHelper').createCamundaInWithBusinessKey; | ||
createCamundaInWithBusinessKey = require('../CreateHelper').createCamundaInWithBusinessKey, | ||
createCamundaFieldInjection = require('../CreateHelper').createCamundaFieldInjection; | ||
@@ -32,3 +34,4 @@ var CAMUNDA_PROPERTY_TYPE = 'camunda:property', | ||
CAMUNDA_IN_BUSINESS_KEY_TYPE = 'camunda:in:businessKey', | ||
CAMUNDA_EXECUTION_LISTENER_TYPE = 'camunda:executionListener'; | ||
CAMUNDA_EXECUTION_LISTENER_TYPE = 'camunda:executionListener', | ||
CAMUNDA_FIELD = 'camunda:field'; | ||
@@ -47,3 +50,4 @@ var BASIC_MODDLE_TYPES = [ | ||
CAMUNDA_OUT_TYPE, | ||
CAMUNDA_IN_BUSINESS_KEY_TYPE | ||
CAMUNDA_IN_BUSINESS_KEY_TYPE, | ||
CAMUNDA_FIELD | ||
]; | ||
@@ -379,2 +383,17 @@ | ||
var fieldInjection; | ||
if (CAMUNDA_FIELD === bindingType) { | ||
var fieldInjections = findExtensions(bo, [ 'camunda:Field' ]); | ||
fieldInjections.forEach(function(item) { | ||
if (item.name === binding.name) { | ||
fieldInjection = item; | ||
} | ||
}); | ||
if (fieldInjection) { | ||
return fieldInjection.string || fieldInjection.expression; | ||
} else { | ||
return ''; | ||
} | ||
} | ||
throw unknownPropertyBinding(property); | ||
@@ -617,2 +636,16 @@ } | ||
if (bindingType === CAMUNDA_FIELD) { | ||
var existingFieldInjections = findExtensions(bo, [ 'camunda:Field' ]); | ||
var newFieldInjections = createCamundaFieldInjection(binding, value, bpmnFactory); | ||
updates.push(cmdHelper.addAndRemoveElementsFromList( | ||
element, | ||
extensionElements, | ||
'values', | ||
null, | ||
[ newFieldInjections ], | ||
existingFieldInjections ? existingFieldInjections : [] | ||
)); | ||
} | ||
if (updates.length) { | ||
@@ -619,0 +652,0 @@ return updates; |
@@ -17,3 +17,4 @@ 'use strict'; | ||
CAMUNDA_IN_BUSINESS_KEY_TYPE = 'camunda:in:businessKey', | ||
CAMUNDA_EXECUTION_LISTENER = 'camunda:executionListener'; | ||
CAMUNDA_EXECUTION_LISTENER = 'camunda:executionListener', | ||
CAMUNDA_FIELD = 'camunda:field'; | ||
@@ -28,3 +29,4 @@ var VALID_BINDING_TYPES = [ | ||
CAMUNDA_IN_BUSINESS_KEY_TYPE, | ||
CAMUNDA_EXECUTION_LISTENER | ||
CAMUNDA_EXECUTION_LISTENER, | ||
CAMUNDA_FIELD | ||
]; | ||
@@ -216,3 +218,4 @@ | ||
bindingType === CAMUNDA_PROPERTY_TYPE || | ||
bindingType === CAMUNDA_INPUT_PARAMETER_TYPE) { | ||
bindingType === CAMUNDA_INPUT_PARAMETER_TYPE || | ||
bindingType === CAMUNDA_FIELD) { | ||
@@ -294,2 +297,2 @@ if (!binding.name) { | ||
return 'name' in c && 'value' in c; | ||
} | ||
} |
{ | ||
"name": "bpmn-js-properties-panel", | ||
"version": "0.18.5", | ||
"version": "0.19.0", | ||
"description": "A simple properties panel for bpmn-js", | ||
@@ -5,0 +5,0 @@ "scripts": { |
@@ -791,2 +791,175 @@ 'use strict'; | ||
describe('with camunda:field', function() { | ||
var diagramXML = require('./task-clean.bpmn'); | ||
var currentTemplate = require('./field-injections'); | ||
beforeEach(bootstrapModeler(diagramXML, { | ||
container: container, | ||
modules: [ | ||
coreModule, | ||
modelingModule, | ||
propertiesPanelCommandsModule, | ||
elementTemplatesModule | ||
], | ||
moddleExtensions: { | ||
camunda: camundaModdlePackage | ||
} | ||
})); | ||
beforeEach(inject(function(elementRegistry) { | ||
var taskShape = elementRegistry.get('Task_1'); | ||
applyTemplate(taskShape, currentTemplate); | ||
})); | ||
it('execute', inject(function(elementRegistry) { | ||
// given | ||
var taskShape = elementRegistry.get('Task_1'), | ||
task = taskShape.businessObject; | ||
// when | ||
applyTemplate(taskShape, null); | ||
var fieldInjections = findExtensions(taskShape, [ 'camunda:Field' ]); | ||
// then | ||
expect(task.get('camunda:modelerTemplate')).not.to.exist; | ||
// removing a task template does | ||
// not change the applied values | ||
expect(fieldInjections).to.exist; | ||
expect(fieldInjections).to.jsonEqual([ | ||
{ | ||
$type: 'camunda:Field', | ||
string: 'My String Field Injection', | ||
name: 'sender' | ||
}, | ||
{ | ||
$type: 'camunda:Field', | ||
string: 'My String Field Injection 2', | ||
name: 'sender2' | ||
}, | ||
{ | ||
$type: 'camunda:Field', | ||
expression: '${PerfectExpression}', | ||
name: 'sender3' | ||
} | ||
]); | ||
})); | ||
it('undo', inject(function(elementRegistry, commandStack) { | ||
// given | ||
var taskShape = elementRegistry.get('Task_1'), | ||
task = taskShape.businessObject; | ||
applyTemplate(taskShape, null); | ||
// when | ||
commandStack.undo(); | ||
var fieldInjections = findExtensions(taskShape, [ 'camunda:Field' ]); | ||
// then | ||
expect(task.get('camunda:modelerTemplate')).to.eql(currentTemplate.id); | ||
expect(fieldInjections).to.exist; | ||
})); | ||
}); | ||
describe('setting camunda:field with existing fields', function() { | ||
var diagramXML = require('./task-field-injections.bpmn'); | ||
var fieldInjectionsTemplate = require('./field-injections'); | ||
beforeEach(bootstrapModeler(diagramXML, { | ||
container: container, | ||
modules: [ | ||
coreModule, | ||
modelingModule, | ||
propertiesPanelCommandsModule, | ||
elementTemplatesModule | ||
], | ||
moddleExtensions: { | ||
camunda: camundaModdlePackage | ||
} | ||
})); | ||
it('execute', inject(function(elementRegistry) { | ||
// given | ||
var taskShape = elementRegistry.get('Task_1'); | ||
// when | ||
applyTemplate(taskShape, fieldInjectionsTemplate); | ||
var fieldInjections = findExtensions(taskShape, [ 'camunda:Field' ]); | ||
// then | ||
expect(fieldInjections).to.exist; | ||
expect(fieldInjections).to.jsonEqual([ | ||
{ | ||
$type: 'camunda:Field', | ||
string: 'My String Field Injection', | ||
name: 'sender' | ||
}, | ||
{ | ||
$type: 'camunda:Field', | ||
string: 'My String Field Injection 2', | ||
name: 'sender2' | ||
}, | ||
{ | ||
$type: 'camunda:Field', | ||
expression: '${PerfectExpression}', | ||
name: 'sender3' | ||
} | ||
]); | ||
})); | ||
it('undo', inject(function(elementRegistry, commandStack) { | ||
// given | ||
var taskShape = elementRegistry.get('Task_1'); | ||
applyTemplate(taskShape, fieldInjectionsTemplate); | ||
// when | ||
commandStack.undo(); | ||
var fieldInjections = findExtensions(taskShape, [ 'camunda:Field' ]); | ||
// then | ||
expect(fieldInjections).to.exist; | ||
console.log(fieldInjections); | ||
expect(fieldInjections).to.jsonEqual([ | ||
{ | ||
$type: 'camunda:Field', | ||
name: 'existingField', | ||
string: 'myString' | ||
}, | ||
{ | ||
$type: 'camunda:Field', | ||
name: 'existingFieldExpression', | ||
expression: '${myStringExpression}' | ||
} | ||
]); | ||
})); | ||
}); | ||
describe('with scope connector', function() { | ||
@@ -793,0 +966,0 @@ |
@@ -492,3 +492,22 @@ [ | ||
] | ||
}, | ||
{ | ||
"name": "Valid", | ||
"id": "com.camunda.example.CustomServiceTaskFieldInjection", | ||
"appliesTo": [ | ||
"bpmn:ServiceTask" | ||
], | ||
"properties": [ | ||
{ | ||
"label": "Sender", | ||
"type": "String", | ||
"value": "My Field Injection Value", | ||
"binding": { | ||
"type": "camunda:field", | ||
"name": "sender", | ||
"expression": false | ||
} | ||
} | ||
] | ||
} | ||
] | ||
] |
@@ -8,2 +8,3 @@ 'use strict'; | ||
var findExtension = require('../../../../../../lib/provider/camunda/element-templates/Helper').findExtension, | ||
findExtensions = require('../../../../../../lib/provider/camunda/element-templates/Helper').findExtensions, | ||
findCamundaInOut = require('../../../../../../lib/provider/camunda/element-templates/Helper').findCamundaInOut, | ||
@@ -529,2 +530,69 @@ findInputParameter = require('../../../../../../lib/provider/camunda/element-templates/Helper').findInputParameter, | ||
describe('camunda:field', function() { | ||
it('should display', inject(function() { | ||
// given | ||
selectAndGet('ServiceTask_FieldInjection'); | ||
// when | ||
var endpointEntry = entrySelect('custom-com.camunda.example.CustomServiceTaskFieldInjection-0'), | ||
textField = entrySelect('custom-com.camunda.example.CustomServiceTaskFieldInjection-0', 'input'); | ||
// then | ||
expect(endpointEntry).to.exist; | ||
expect(textField).to.exist; | ||
})); | ||
it('should change, updating camunda:field', inject(function() { | ||
// given | ||
var task = selectAndGet('ServiceTask_FieldInjection'); | ||
var textField = entrySelect('custom-com.camunda.example.CustomServiceTaskFieldInjection-0', 'input'); | ||
// when | ||
TestHelper.triggerValue(textField, 'https://baba', 'change'); | ||
var fieldInjections = findExtensions(task, [ 'camunda:Field' ]); | ||
// then | ||
expect(fieldInjections).to.exist; | ||
expect(fieldInjections).to.jsonEqual([ | ||
{ | ||
$type: 'camunda:Field', | ||
string: 'https://baba', | ||
name: 'sender' | ||
} | ||
]); | ||
})); | ||
it('should change, creating camunda:field if non-existing', inject(function() { | ||
// given | ||
var task = selectAndGet('ServiceTask_FieldInjection_NoData'); | ||
var textField = entrySelect('custom-com.camunda.example.CustomServiceTaskFieldInjection-0', 'input'); | ||
// when | ||
TestHelper.triggerValue(textField, 'https://baba', 'change'); | ||
var fieldInjections = findExtensions(task, [ 'camunda:Field' ]); | ||
// then | ||
expect(fieldInjections).to.exist; | ||
expect(fieldInjections).to.jsonEqual([ | ||
{ | ||
$type: 'camunda:Field', | ||
string: 'https://baba', | ||
name: 'sender' | ||
} | ||
]); | ||
})); | ||
}); | ||
describe('camunda:Connector', function() { | ||
@@ -531,0 +599,0 @@ |
@@ -205,6 +205,11 @@ 'use strict'; | ||
expect(errors(templates)).to.eql([ | ||
'invalid property type <InvalidType>; must be any of { String, Text, Boolean, Hidden, Dropdown }', | ||
'invalid property type <InvalidType>; must be any of { ' + | ||
'String, Text, Boolean, Hidden, Dropdown ' + | ||
'}', | ||
'invalid property.binding type <alsoInvalid>; must be any of { ' + | ||
'property, camunda:property, camunda:inputParameter, ' + | ||
'camunda:outputParameter, camunda:in, camunda:out, camunda:in:businessKey, camunda:executionListener }' | ||
'camunda:outputParameter, camunda:in, camunda:out, ' + | ||
'camunda:in:businessKey, camunda:executionListener, ' + | ||
'camunda:field ' + | ||
'}' | ||
]); | ||
@@ -322,3 +327,5 @@ | ||
// then | ||
expect(errors(templates)).to.contain('template(id: foo) missing properties=[] in scope <camunda:Connector>'); | ||
expect(errors(templates)).to.contain( | ||
'template(id: foo) missing properties=[] in scope <camunda:Connector>' | ||
); | ||
@@ -341,6 +348,11 @@ expect(valid(templates)).to.be.empty; | ||
expect(errors(templates)).to.eql([ | ||
'invalid property type <InvalidType>; must be any of { String, Text, Boolean, Hidden, Dropdown }', | ||
'invalid property type <InvalidType>; must be any of { ' + | ||
'String, Text, Boolean, Hidden, Dropdown ' + | ||
'}', | ||
'invalid property.binding type <alsoInvalid>; must be any of { ' + | ||
'property, camunda:property, camunda:inputParameter, ' + | ||
'camunda:outputParameter, camunda:in, camunda:out, camunda:in:businessKey, camunda:executionListener }' | ||
'camunda:outputParameter, camunda:in, camunda:out, ' + | ||
'camunda:in:businessKey, camunda:executionListener, ' + | ||
'camunda:field ' + | ||
'}' | ||
]); | ||
@@ -367,2 +379,19 @@ expect(valid(templates)).to.be.empty; | ||
}); | ||
it('should accept field injections example template', function() { | ||
// given | ||
var templates = new Validator(); | ||
var templateDescriptors = require('./fixtures/field-injections'); | ||
// when | ||
templates.addAll(templateDescriptors); | ||
// then | ||
expect(errors(templates)).to.be.empty; | ||
expect(valid(templates)).to.have.length(1); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1855422
312
38023