feat(import): support importing multiple diagrams at once
This commit is contained in:
parent
794bdd7827
commit
a94795f957
|
@ -1,4 +1,4 @@
|
||||||
import { is } from '../../util/ModelUtil';
|
import { getDi, is } from '../../util/ModelUtil';
|
||||||
|
|
||||||
import inherits from 'inherits';
|
import inherits from 'inherits';
|
||||||
|
|
||||||
|
@ -32,8 +32,11 @@ BpmnAutoResizeProvider.$inject = [
|
||||||
* @return {boolean}
|
* @return {boolean}
|
||||||
*/
|
*/
|
||||||
BpmnAutoResizeProvider.prototype.canResize = function(elements, target) {
|
BpmnAutoResizeProvider.prototype.canResize = function(elements, target) {
|
||||||
|
if (
|
||||||
if (!is(target, 'bpmn:Participant') && !is(target, 'bpmn:Lane') && !(is(target, 'bpmn:SubProcess'))) {
|
!is(target, 'bpmn:Participant') &&
|
||||||
|
!is(target, 'bpmn:Lane') &&
|
||||||
|
(!is(target, 'bpmn:SubProcess') || is(getDi(target), 'bpmndi:BPMNPlane'))
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -93,10 +93,12 @@ BpmnImporter.$inject = [
|
||||||
* Add bpmn element (semantic) to the canvas onto the
|
* Add bpmn element (semantic) to the canvas onto the
|
||||||
* specified parent shape.
|
* specified parent shape.
|
||||||
*/
|
*/
|
||||||
BpmnImporter.prototype.add = function(semantic, di, parentElement) {
|
BpmnImporter.prototype.add = function(context, parentElement) {
|
||||||
var element,
|
var element,
|
||||||
translate = this._translate,
|
translate = this._translate,
|
||||||
hidden;
|
hidden,
|
||||||
|
semantic = context.element,
|
||||||
|
di = context.di;
|
||||||
|
|
||||||
var parentIndex;
|
var parentIndex;
|
||||||
|
|
||||||
|
@ -108,7 +110,11 @@ BpmnImporter.prototype.add = function(semantic, di, parentElement) {
|
||||||
// add a virtual element (not being drawn)
|
// add a virtual element (not being drawn)
|
||||||
element = this._elementFactory.createRoot(elementData(semantic, di));
|
element = this._elementFactory.createRoot(elementData(semantic, di));
|
||||||
|
|
||||||
this._canvas.setRootElement(element);
|
if (this._elementRegistry.get(element.id)) {
|
||||||
|
element.id = element.id + '_layer';
|
||||||
|
}
|
||||||
|
|
||||||
|
this._canvas.setRootElementForPlane(element, semantic.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
// SHAPE
|
// SHAPE
|
||||||
|
@ -116,7 +122,6 @@ BpmnImporter.prototype.add = function(semantic, di, parentElement) {
|
||||||
|
|
||||||
var collapsed = !isExpanded(semantic, di),
|
var collapsed = !isExpanded(semantic, di),
|
||||||
isFrame = isFrameElement(semantic);
|
isFrame = isFrameElement(semantic);
|
||||||
|
|
||||||
hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
hidden = parentElement && (parentElement.hidden || parentElement.collapsed);
|
||||||
|
|
||||||
var bounds = di.bounds;
|
var bounds = di.bounds;
|
||||||
|
@ -144,7 +149,7 @@ BpmnImporter.prototype.add = function(semantic, di, parentElement) {
|
||||||
|
|
||||||
// check whether data store is inside our outside of its semantic parent
|
// check whether data store is inside our outside of its semantic parent
|
||||||
if (!isPointInsideBBox(parentElement, getMid(bounds))) {
|
if (!isPointInsideBBox(parentElement, getMid(bounds))) {
|
||||||
parentElement = this._canvas.getRootElement();
|
parentElement = this._canvas.findPlane(parentElement).rootElement;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,7 +177,7 @@ BpmnImporter.prototype.add = function(semantic, di, parentElement) {
|
||||||
// are rendered correctly across different "hacks" people
|
// are rendered correctly across different "hacks" people
|
||||||
// love to model such as cross participant / sub process
|
// love to model such as cross participant / sub process
|
||||||
// associations
|
// associations
|
||||||
parentElement = null;
|
parentElement = this._canvas.findPlane(parentElement).rootElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert sequence flows behind other flow nodes (cf. #727)
|
// insert sequence flows behind other flow nodes (cf. #727)
|
||||||
|
|
|
@ -76,11 +76,11 @@ export default function BpmnTreeWalker(handler, translate) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// call handler
|
// call handler
|
||||||
return handler.element(element, diMap[element.id], ctx);
|
return handler.element({ element: element, di: diMap[element.id] }, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
function visitRoot(element, diagram) {
|
function visitRoot(element, diagram) {
|
||||||
return handler.root(element, diMap[element.id], diagram);
|
return handler.root({ element: element, di: diMap[element.id] }, diagram);
|
||||||
}
|
}
|
||||||
|
|
||||||
function visitIfDi(element, ctx) {
|
function visitIfDi(element, ctx) {
|
||||||
|
@ -216,7 +216,7 @@ export default function BpmnTreeWalker(handler, translate) {
|
||||||
|
|
||||||
var ctx = visitRoot(rootElement, plane);
|
var ctx = visitRoot(rootElement, plane);
|
||||||
|
|
||||||
if (is(rootElement, 'bpmn:Process')) {
|
if (is(rootElement, 'bpmn:Process') || is(rootElement, 'bpmn:SubProcess')) {
|
||||||
handleProcess(rootElement, ctx);
|
handleProcess(rootElement, ctx);
|
||||||
} else if (is(rootElement, 'bpmn:Collaboration')) {
|
} else if (is(rootElement, 'bpmn:Collaboration')) {
|
||||||
handleCollaboration(rootElement, ctx);
|
handleCollaboration(rootElement, ctx);
|
||||||
|
|
|
@ -33,7 +33,8 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
|
||||||
|
|
||||||
var importer,
|
var importer,
|
||||||
eventBus,
|
eventBus,
|
||||||
translate;
|
translate,
|
||||||
|
canvas;
|
||||||
|
|
||||||
var error,
|
var error,
|
||||||
warnings = [];
|
warnings = [];
|
||||||
|
@ -49,12 +50,12 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
|
||||||
|
|
||||||
var visitor = {
|
var visitor = {
|
||||||
|
|
||||||
root: function(element, di) {
|
root: function(element) {
|
||||||
return importer.add(element, di);
|
return importer.add(element);
|
||||||
},
|
},
|
||||||
|
|
||||||
element: function(element, di, parentShape) {
|
element: function(element, parentShape) {
|
||||||
return importer.add(element, di, parentShape);
|
return importer.add(element, parentShape);
|
||||||
},
|
},
|
||||||
|
|
||||||
error: function(message, context) {
|
error: function(message, context) {
|
||||||
|
@ -66,7 +67,16 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
|
||||||
|
|
||||||
// traverse BPMN 2.0 document model,
|
// traverse BPMN 2.0 document model,
|
||||||
// starting at definitions
|
// starting at definitions
|
||||||
walker.handleDefinitions(definitions, bpmnDiagram);
|
if (!bpmnDiagram && definitions.diagrams) {
|
||||||
|
for (var i = 0; i < definitions.diagrams.length; i++) {
|
||||||
|
walker.handleDefinitions(definitions, definitions.diagrams[i]);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
walker.handleDefinitions(definitions, bpmnDiagram);
|
||||||
|
}
|
||||||
|
|
||||||
|
var mainDiagram = bpmnDiagram || definitions.diagrams[0];
|
||||||
|
canvas.setActivePlane(mainDiagram.plane.bpmnElement.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Promise(function(resolve, reject) {
|
return new Promise(function(resolve, reject) {
|
||||||
|
@ -74,6 +84,7 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
|
||||||
importer = diagram.get('bpmnImporter');
|
importer = diagram.get('bpmnImporter');
|
||||||
eventBus = diagram.get('eventBus');
|
eventBus = diagram.get('eventBus');
|
||||||
translate = diagram.get('translate');
|
translate = diagram.get('translate');
|
||||||
|
canvas = diagram.get('canvas');
|
||||||
|
|
||||||
eventBus.fire('import.render.start', { definitions: definitions });
|
eventBus.fire('import.render.start', { definitions: definitions });
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,10 @@ import {
|
||||||
|
|
||||||
export function isExpanded(element, di) {
|
export function isExpanded(element, di) {
|
||||||
|
|
||||||
|
if (di && is(di, 'bpmndi:BPMNPlane')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
if (is(element, 'bpmn:CallActivity')) {
|
if (is(element, 'bpmn:CallActivity')) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -569,7 +569,7 @@ describe('draw - bpmn renderer', function() {
|
||||||
var rootElement = canvas.getRootElement();
|
var rootElement = canvas.getRootElement();
|
||||||
|
|
||||||
elementRegistry.forEach(function(element) {
|
elementRegistry.forEach(function(element) {
|
||||||
if (element === rootElement) {
|
if (element === rootElement || element.isImplicit) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -895,7 +895,7 @@ function integrationTest(elementIds) {
|
||||||
getBpmnJS().invoke(function(canvas, commandStack, copyPaste, elementRegistry, modeling) {
|
getBpmnJS().invoke(function(canvas, commandStack, copyPaste, elementRegistry, modeling) {
|
||||||
|
|
||||||
// given
|
// given
|
||||||
var allElements = elementRegistry.getAll();
|
var allElements = elementRegistry.filter(isImplicit);
|
||||||
|
|
||||||
var initialContext = {
|
var initialContext = {
|
||||||
length: allElements.length,
|
length: allElements.length,
|
||||||
|
@ -934,7 +934,7 @@ function integrationTest(elementIds) {
|
||||||
commandStack.undo();
|
commandStack.undo();
|
||||||
commandStack.undo();
|
commandStack.undo();
|
||||||
|
|
||||||
elements = elementRegistry.getAll();
|
elements = elementRegistry.filter(isImplicit);
|
||||||
|
|
||||||
currentContext = {
|
currentContext = {
|
||||||
length: elements.length,
|
length: elements.length,
|
||||||
|
@ -951,7 +951,7 @@ function integrationTest(elementIds) {
|
||||||
commandStack.redo();
|
commandStack.redo();
|
||||||
commandStack.redo();
|
commandStack.redo();
|
||||||
|
|
||||||
elements = elementRegistry.getAll();
|
elements = elementRegistry.filter(isImplicit);
|
||||||
|
|
||||||
currentContext = {
|
currentContext = {
|
||||||
length: elements.length,
|
length: elements.length,
|
||||||
|
@ -972,6 +972,10 @@ function isRoot(element) {
|
||||||
return !!element.parent;
|
return !!element.parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isImplicit(element) {
|
||||||
|
return !element.isImplicit;
|
||||||
|
}
|
||||||
|
|
||||||
function getPropertyForElements(elements, property) {
|
function getPropertyForElements(elements, property) {
|
||||||
return map(elements, function(element) {
|
return map(elements, function(element) {
|
||||||
return element[ property ];
|
return element[ property ];
|
||||||
|
|
|
@ -665,6 +665,52 @@ describe('import - Importer', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('Multiple Planes', function() {
|
||||||
|
|
||||||
|
it('should import multiple diagrams', function() {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var xml = require('../../fixtures/bpmn/multiple-diagrams.bpmn');
|
||||||
|
|
||||||
|
// when
|
||||||
|
return runImport(diagram, xml).then(function(result) {
|
||||||
|
|
||||||
|
var warnings = result.warnings;
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(warnings).to.have.length(0);
|
||||||
|
|
||||||
|
expect(diagram.get('elementRegistry').get('Task_A')).to.exist;
|
||||||
|
expect(diagram.get('elementRegistry').get('Task_B')).to.exist;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
it('should render Tasks on different layers', function() {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var xml = require('../../fixtures/bpmn/multiple-diagrams.bpmn');
|
||||||
|
|
||||||
|
// when
|
||||||
|
return runImport(diagram, xml).then(function() {
|
||||||
|
|
||||||
|
var elementRegistry = diagram.get('elementRegistry'),
|
||||||
|
canvas = diagram.get('canvas'),
|
||||||
|
taskA = elementRegistry.get('Task_A'),
|
||||||
|
taskB = elementRegistry.get('Task_B');
|
||||||
|
|
||||||
|
var activePlane = canvas.getActivePlane(),
|
||||||
|
planeA = canvas.findPlane(taskA),
|
||||||
|
planeB = canvas.findPlane(taskB);
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(activePlane).to.eql(planeA);
|
||||||
|
expect(planeA).to.not.eql(planeB);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue