mirror of
https://github.com/status-im/spiff-arena.git
synced 2025-01-30 19:56:20 +00:00
9213cea140
96dcd1a24 Merge pull request #23 from sartography/feature/more_launch_buttons_and_dropdowns f6eb4123d disable test for disabled button. 84593aee1 remove launch button for call activities. b28569687 fixing a bug in SpiffScript Group e12e27ed5 fixing a bug in SpiffScript Group 7b4ca1919 Merge branch 'main' into feature/more_launch_buttons_and_dropdowns 38b23ae4e No reason to force _files on there, when this could work for any set of options. 1e75ff7b5 Standardize all Event Names, and document in README. Fix the SpiffExtensions so they work consistently with both nested Extension Properties, and as single extensions depending on the namespace. Add a Spiff Extension Text Area. Everything that is within the body of tag can be referenced with ".value" -- there was a lot of pointless inconsistency in the moddle json file. aeeaf1596 DMN selection should be from a dropdown, not by hand entering a process id. ecb175d72 Add Launch Editor buttons for Json files. (fires 'file.editor.launch', with a fileName) 6467e967b Adding a Launch Button for Call Activity Json files are now a selection list, not a text field -- see app.json for usage. New SpiffExtensionSelect can be used to add select boxes anywhere you want. git-subtree-dir: bpmn-js-spiffworkflow git-subtree-split: 96dcd1a2497f84f8ca3f2a82e311d50e391bf7b7
118 lines
3.4 KiB
JavaScript
118 lines
3.4 KiB
JavaScript
const SPIFF_PARENT_PROP = 'spiffworkflow:properties';
|
|
const SPIFF_PROP = 'spiffworkflow:property';
|
|
const PREFIX = 'spiffworkflow:';
|
|
|
|
/**
|
|
*
|
|
* Spiff Extensions can show up in two distinct ways. The useProperties toggles between them
|
|
*
|
|
* 1. They might be a top level extension, such as a buisness rule, for example:
|
|
*
|
|
* <bpmn:extensionElements>
|
|
* <spiffworkflow:calledDecisionId>my_id</spiffworkflow:calledDecisionId>
|
|
* </bpmn:extensionElements>
|
|
*
|
|
* 2. Or the extension value may exist in a name/value pair inside a Spiffworkflow Properties extension. You would
|
|
* do this if you wanted to hide the values from the SpiffWorkflow enginge completely, and pass these values
|
|
* through unaltered to your actual application. For Example:
|
|
*
|
|
* <bpmn:extensionElements>
|
|
* <spiffworkflow:properties>
|
|
* <spiffworkflow:property name="formJsonSchemaFilename" value="json_schema.json" />
|
|
* </spiffworkflow:properties>
|
|
* </bpmn:extensionElements>
|
|
*
|
|
*
|
|
*/
|
|
|
|
|
|
/**
|
|
* Returns the string value of the spiff extension with the given name on the provided element. ""
|
|
* @param useProperties if set to true, will look inside extensions/spiffworkflow:properties otherwise, just
|
|
* looks for a spiffworkflow:[name] and returns that value inside of it.
|
|
* @param element
|
|
* @param name
|
|
*/
|
|
export function getExtensionValue(element, name) {
|
|
|
|
const useProperties = !name.startsWith(PREFIX);
|
|
let extension;
|
|
if (useProperties) {
|
|
extension = getExtensionProperty(element, name);
|
|
} else {
|
|
extension = getExtension(element, name);
|
|
}
|
|
if (extension) {
|
|
return extension.value;
|
|
}
|
|
return '';
|
|
}
|
|
|
|
export function setExtensionValue(element, name, value, moddle, commandStack) {
|
|
|
|
const useProperties = !name.startsWith(PREFIX)
|
|
const { businessObject } = element;
|
|
|
|
// Assure we have extensions
|
|
let extensions = businessObject.extensionElements;
|
|
if (!extensions) {
|
|
extensions = moddle.create('bpmn:ExtensionElements');
|
|
}
|
|
|
|
if (useProperties) {
|
|
let properties = getExtension(element, SPIFF_PARENT_PROP);
|
|
let property = getExtensionProperty(element, name);
|
|
if (!properties) {
|
|
properties = moddle.create(SPIFF_PARENT_PROP);
|
|
extensions.get('values').push(properties);
|
|
}
|
|
if (!property) {
|
|
property = moddle.create(SPIFF_PROP);
|
|
properties.get('properties').push(property);
|
|
}
|
|
property.value = value;
|
|
property.name = name;
|
|
} else {
|
|
let extension = getExtension(element, name);
|
|
if (!extension) {
|
|
extension = moddle.create(name);
|
|
extensions.get('values').push(extension)
|
|
}
|
|
extension.value = value;
|
|
}
|
|
|
|
commandStack.execute('element.updateModdleProperties', {
|
|
element,
|
|
moddleElement: businessObject,
|
|
properties: {
|
|
extensionElements: extensions,
|
|
},
|
|
});
|
|
}
|
|
|
|
function getExtension(element, name) {
|
|
const bizObj = element.businessObject;
|
|
if (!bizObj.extensionElements) {
|
|
return null;
|
|
}
|
|
const extensionElements = bizObj.extensionElements.get('values');
|
|
return extensionElements.filter(function (extensionElement) {
|
|
if (extensionElement.$instanceOf(name)) {
|
|
return true;
|
|
}
|
|
})[0];
|
|
}
|
|
|
|
|
|
function getExtensionProperty(element, name) {
|
|
const parentElement = getExtension(element, SPIFF_PARENT_PROP);
|
|
if (parentElement) {
|
|
return parentElement.get('properties').filter(function (propertyElement) {
|
|
return (
|
|
propertyElement.$instanceOf(SPIFF_PROP) && propertyElement.name === name
|
|
);
|
|
})[0];
|
|
}
|
|
return null;
|
|
}
|