Delete behavior

This commit is contained in:
Martin Stamm 2021-08-27 11:21:09 +02:00
parent a0ee240fe7
commit 49e064ddf5
No known key found for this signature in database
GPG Key ID: B3A641060A8CBCF4
3 changed files with 74 additions and 4 deletions

View File

@ -0,0 +1,68 @@
import inherits from 'inherits';
import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
import { is } from '../../util/ModelUtil';
export default function RemoveDiagramBehavior(canvas, bpmnjs, injector, elementRegistry, commandStack) {
var removeNestedProcesses = function(process) {
console.log(process);
var removedProcesses = [];
process.flowElements && process.flowElements.forEach(element => {
if (is(element, 'bpmn:SubProcess')) {
removedProcesses = removedProcesses.concat(removeNestedProcesses(element));
}
});
var removedDi = removeProcess(process.id);
if (removedDi) {
removedProcesses.push(removedDi);
}
return removedProcesses;
};
injector.invoke(CommandInterceptor, this);
this.executed('shape.delete', function(event) {
console.log(event);
var context = event.context;
if (is(context.shape, 'bpmn:SubProcess')) {
var removedDi = removeNestedProcesses(context.shape.businessObject);
context.removedDiDiagrams = removedDi;
}
});
this.reverted('shape.delete', function(event) {
var context = event.context;
if (is(context.shape, 'bpmn:SubProcess') && context.removedDiDiagrams) {
var diagrams = bpmnjs.getDefinitions().diagrams;
Array.prototype.push.apply(diagrams, context.removedDiDiagrams);
}
});
// Util
var removeProcess = function(id) {
var diagrams = bpmnjs.getDefinitions().diagrams,
removedDiagram;
var diagramIndex = diagrams.findIndex(element => {
return element.plane.bpmnElement.id === id;
});
if (diagramIndex > -1) {
removedDiagram = diagrams[diagramIndex];
diagrams.splice(diagramIndex, 1);
}
return removedDiagram;
};
}
inherits(RemoveDiagramBehavior, CommandInterceptor);
RemoveDiagramBehavior.$inject = [ 'canvas', 'bpmnjs', 'injector', 'elementRegistry', 'commandStack' ];

View File

@ -1,7 +1,8 @@
import NavigationBehaviour from './NavigationBehaviour';
import ExpandBehaviour from './ToggleCollapseBehaviour';
// import RemoveDiagramBehavior from './DeleteBehaviour';
import RemoveDiagramBehavior from './DeleteBehaviour';
// import DiagramUtil from './diagramUtil';
@ -11,7 +12,8 @@ export default {
__depends__: [ ],
__init__: [ 'navigationBehaviour',
// 'diagramUtil', 'removeDiagramBehavior',
// 'diagramUtil',
'removeDiagramBehavior',
// // 'undoBehaviour',
'expandBehaviour'
@ -19,7 +21,7 @@ export default {
navigationBehaviour: [ 'type', NavigationBehaviour ],
// diagramUtil: [ 'type', DiagramUtil ],
// removeDiagramBehavior: ['type', RemoveDiagramBehavior],
removeDiagramBehavior: ['type', RemoveDiagramBehavior],
// // undoBehaviour: ['type', UndoBehaviour],
expandBehaviour: ['type', ExpandBehaviour]

View File

@ -262,7 +262,7 @@ describe('features/modeling - append shape', function() {
}));
it.only('should redo add connection', inject(function(elementRegistry, modeling, commandStack) {
it('should redo add connection', inject(function(elementRegistry, modeling, commandStack) {
// given
var startEventShape = elementRegistry.get('StartEvent_1');