activitiExtension.js 2.2 KB

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