flowableExtension.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. const some = require('min-dash').some
  3. const ALLOWED_TYPES = {
  4. FailedJobRetryTimeCycle: ['bpmn:StartEvent', 'bpmn:BoundaryEvent', 'bpmn:IntermediateCatchEvent', 'bpmn:Activity'],
  5. Connector: ['bpmn:EndEvent', 'bpmn:IntermediateThrowEvent'],
  6. Field: ['bpmn:EndEvent', 'bpmn:IntermediateThrowEvent']
  7. }
  8. function is(element, type) {
  9. return element && typeof element.$instanceOf === "function" && element.$instanceOf(type);
  10. }
  11. function exists(element) {
  12. return element && element.length;
  13. }
  14. function includesType(collection, type) {
  15. return (
  16. exists(collection) &&
  17. some(collection, function(element) {
  18. return is(element, type);
  19. })
  20. );
  21. }
  22. function anyType(element, types) {
  23. return some(types, function(type) {
  24. return is(element, type);
  25. });
  26. }
  27. function isAllowed(propName, propDescriptor, newElement) {
  28. const name = propDescriptor.name,
  29. types = ALLOWED_TYPES[name.replace(/flowable:/, '')]
  30. return name === propName && anyType(newElement, types);
  31. }
  32. function FlowableModdleExtension(eventBus) {
  33. eventBus.on(
  34. "property.clone",
  35. function(context) {
  36. const newElement = context.newElement,
  37. propDescriptor = context.propertyDescriptor
  38. this.canCloneProperty(newElement, propDescriptor);
  39. },
  40. this
  41. );
  42. }
  43. FlowableModdleExtension.$inject = ["eventBus"];
  44. FlowableModdleExtension.prototype.canCloneProperty = function(newElement, propDescriptor) {
  45. if (isAllowed("flowable:FailedJobRetryTimeCycle", propDescriptor, newElement)) {
  46. return (
  47. includesType(newElement.eventDefinitions, "bpmn:TimerEventDefinition") ||
  48. includesType(newElement.eventDefinitions, "bpmn:SignalEventDefinition") ||
  49. is(newElement.loopCharacteristics, "bpmn:MultiInstanceLoopCharacteristics")
  50. );
  51. }
  52. if (isAllowed("flowable:Connector", propDescriptor, newElement)) {
  53. return includesType(newElement.eventDefinitions, "bpmn:MessageEventDefinition");
  54. }
  55. if (isAllowed("flowable:Field", propDescriptor, newElement)) {
  56. return includesType(newElement.eventDefinitions, "bpmn:MessageEventDefinition");
  57. }
  58. };
  59. module.exports = FlowableModdleExtension;