fix(Importer): collapse subProcesses only

Related to #49
This commit is contained in:
Nico Rehwaldt 2014-05-22 10:51:23 +02:00
parent acdf2d8615
commit 1733bc6de9
4 changed files with 212 additions and 68 deletions

View File

@ -17,7 +17,7 @@ function hasLabel(element) {
function isCollapsed(element, di) {
return di && !di.isExpanded;
return element.$instanceOf('bpmn:SubProcess') && di && !di.isExpanded;
}
function getWaypointsMid(waypoints) {

View File

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<bpmn2:definitions xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bpmn2="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL BPMN20.xsd" id="_gjIcQOGMEeOMxZBwjBin-g" targetNamespace="http://activiti.org/bpmn">
<bpmn2:collaboration id="_Collaboration_2">
<bpmn2:participant id="_Participant_2" name="Pool" processRef="Process_1"/>
<bpmn2:participant id="Participant_1" name="Pool" processRef="Process_2"/>
<bpmn2:participant id="Participant_2" name="Pool" processRef="Process_3"/>
</bpmn2:collaboration>
<bpmn2:process id="Process_1" isExecutable="false"/>
<bpmn2:process id="Process_2" isExecutable="false">
<bpmn2:laneSet id="LaneSet_1" name="Lane Set 1">
<bpmn2:lane id="Lane_1" name="Lane">
<bpmn2:flowNodeRef>SubProcess_2</bpmn2:flowNodeRef>
<bpmn2:flowNodeRef>SubProcess_1</bpmn2:flowNodeRef>
</bpmn2:lane>
</bpmn2:laneSet>
<bpmn2:subProcess id="SubProcess_2">
<bpmn2:startEvent id="StartEvent_1"/>
</bpmn2:subProcess>
<bpmn2:subProcess id="SubProcess_1">
<bpmn2:task id="Task_1"/>
</bpmn2:subProcess>
</bpmn2:process>
<bpmn2:process id="Process_3" isExecutable="false">
<bpmn2:subProcess id="SubProcess_3">
<bpmn2:startEvent id="StartEvent_2"/>
</bpmn2:subProcess>
<bpmn2:subProcess id="SubProcess_4">
<bpmn2:task id="Task_2"/>
</bpmn2:subProcess>
</bpmn2:process>
<bpmndi:BPMNDiagram id="BPMNDiagram_1">
<bpmndi:BPMNPlane id="BPMNPlane_1" bpmnElement="_Collaboration_2">
<bpmndi:BPMNShape id="_BPMNShape_Participant_2" bpmnElement="_Participant_2" isHorizontal="true">
<dc:Bounds height="133.0" width="540.0" x="36.0" y="24.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Participant_3" bpmnElement="Participant_1" isHorizontal="true">
<dc:Bounds height="217.0" width="600.0" x="36.0" y="180.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Lane_2" bpmnElement="Lane_1" isHorizontal="true">
<dc:Bounds height="217.0" width="570.0" x="66.0" y="180.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_SubProcess_2" bpmnElement="SubProcess_1">
<dc:Bounds height="80.0" width="100.0" x="144.0" y="239.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_SubProcess_3" bpmnElement="SubProcess_2" isExpanded="true">
<dc:Bounds height="150.0" width="200.0" x="396.0" y="204.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Task_2" bpmnElement="Task_1">
<dc:Bounds height="80.0" width="100.0" x="144.0" y="239.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_2" bpmnElement="StartEvent_1">
<dc:Bounds height="36.0" width="36.0" x="528.0" y="288.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="546.0" y="329.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Participant_4" bpmnElement="Participant_2" isHorizontal="true">
<dc:Bounds height="193.0" width="600.0" x="36.0" y="420.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_SubProcess_4" bpmnElement="SubProcess_3" isExpanded="true">
<dc:Bounds height="150.0" width="200.0" x="396.0" y="442.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_StartEvent_3" bpmnElement="StartEvent_2">
<dc:Bounds height="36.0" width="36.0" x="538.0" y="529.0"/>
<bpmndi:BPMNLabel>
<dc:Bounds height="0.0" width="0.0" x="556.0" y="570.0"/>
</bpmndi:BPMNLabel>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_SubProcess_5" bpmnElement="SubProcess_4">
<dc:Bounds height="80.0" width="100.0" x="144.0" y="477.0"/>
</bpmndi:BPMNShape>
<bpmndi:BPMNShape id="_BPMNShape_Task_3" bpmnElement="Task_2">
<dc:Bounds height="80.0" width="100.0" x="144.0" y="477.0"/>
</bpmndi:BPMNShape>
</bpmndi:BPMNPlane>
</bpmndi:BPMNDiagram>
</bpmn2:definitions>

View File

@ -11,95 +11,162 @@ describe('import - collapsed container', function() {
beforeEach(Matchers.add);
var loadedXml;
var container, renderer;
beforeEach(function(done) {
if (!container) {
function ensureLoaded(xml, done) {
if (xml !== loadedXml) {
// create container
var c = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(c);
container = document.createElement('div');
document.getElementsByTagName('body')[0].appendChild(container);
// import XML
var xml = fs.readFileSync('test/fixtures/bpmn/import/collapsed-subprocess-children.bpmn', 'utf8');
renderer = new Viewer(c);
renderer = new Viewer(container);
renderer.importXML(xml, function(err) {
if (err) {
done(err);
} else {
container = c;
loadedXml = xml;
done();
}
});
} else {
done();
}
}
describe('in process', function() {
beforeEach(function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/collapsed.bpmn', 'utf8');
ensureLoaded(xml, done);
});
it('should import collapsed subProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('SubProcess_1');
var childShape = elementRegistry.getShapeById('IntermediateCatchEvent_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import collapsed transaction', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('Transaction_1');
var childShape = elementRegistry.getShapeById('UserTask_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import collapsed adhocSubProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('AdHocSubProcess_1');
var childShape = elementRegistry.getShapeById('StartEvent_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import collapsed with nested elements', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('SubProcess_4');
var childShape = elementRegistry.getShapeById('SubProcess_5');
var nestedChildShape = elementRegistry.getShapeById('Task_3');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
expect(nestedChildShape.hidden).toBe(true);
});
it('should import expanded subProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
var expandedShape = elementRegistry.getShapeById('SubProcess_3');
var childShape = elementRegistry.getShapeById('Task_2');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
});
it('should import collapsed subProcess', function() {
describe('in collaboration', function() {
var elementRegistry = renderer.get('elementRegistry');
beforeEach(function(done) {
var xml = fs.readFileSync('test/fixtures/bpmn/import/collapsed-collaboration.bpmn', 'utf8');
ensureLoaded(xml, done);
});
var collapsedShape = elementRegistry.getShapeById('SubProcess_1');
var childShape = elementRegistry.getShapeById('IntermediateCatchEvent_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
it('should import collapsed subProcess in pool', function() {
var elementRegistry = renderer.get('elementRegistry');
var expandedShape = elementRegistry.getShapeById('SubProcess_1');
var childShape = elementRegistry.getShapeById('Task_1');
expect(expandedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import expanded subProcess in pool', function() {
var elementRegistry = renderer.get('elementRegistry');
var expandedShape = elementRegistry.getShapeById('SubProcess_2');
var childShape = elementRegistry.getShapeById('StartEvent_1');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
it('should import collapsed subProcess in lane', function() {
var elementRegistry = renderer.get('elementRegistry');
var expandedShape = elementRegistry.getShapeById('SubProcess_4');
var childShape = elementRegistry.getShapeById('Task_2');
expect(expandedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import expanded subProcess in lane', function() {
var elementRegistry = renderer.get('elementRegistry');
var expandedShape = elementRegistry.getShapeById('SubProcess_3');
var childShape = elementRegistry.getShapeById('StartEvent_2');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
});
it('should import collapsed transaction', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('Transaction_1');
var childShape = elementRegistry.getShapeById('UserTask_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import collapsed adhocSubProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('AdHocSubProcess_1');
var childShape = elementRegistry.getShapeById('StartEvent_1');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
});
it('should import collapsed with nested elements', function() {
var elementRegistry = renderer.get('elementRegistry');
var collapsedShape = elementRegistry.getShapeById('SubProcess_4');
var childShape = elementRegistry.getShapeById('SubProcess_5');
var nestedChildShape = elementRegistry.getShapeById('Task_3');
expect(collapsedShape.collapsed).toBe(true);
expect(childShape.hidden).toBe(true);
expect(nestedChildShape.hidden).toBe(true);
});
it('should import expanded subProcess', function() {
var elementRegistry = renderer.get('elementRegistry');
var expandedShape = elementRegistry.getShapeById('SubProcess_3');
var childShape = elementRegistry.getShapeById('Task_2');
expect(expandedShape.collapsed).toBe(false);
expect(childShape.hidden).toBe(false);
});
});