flowableExtension.js 2.2 KB

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