From 1c0585aaafa4211536ad51c7bfdc8bc8428eefaa Mon Sep 17 00:00:00 2001 From: Valerio Spadaro Date: Thu, 4 Apr 2019 16:17:43 +0200 Subject: [PATCH] feat(Viewer): allow to select diagram to view This introduces a new parameter to `Viewer#importXML` which enables to choose the diagram to display. ``` var viewer = new Viewer({ container: container }); viewer.importXML(xml, diagramId, done); ``` Closes #87 --- lib/Viewer.js | 54 +- lib/import/Importer.js | 19 +- .../bpmn/import/multiple-diagrams.bpmn | 78 + test/fixtures/bpmn/multiple-diagrams.bpmn | 5976 +++++++++++++++++ test/spec/ViewerSpec.js | 75 +- test/spec/import/ImporterSpec.js | 89 +- 6 files changed, 6277 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/bpmn/import/multiple-diagrams.bpmn create mode 100644 test/fixtures/bpmn/multiple-diagrams.bpmn diff --git a/lib/Viewer.js b/lib/Viewer.js index 60c9df2f..52b7840d 100644 --- a/lib/Viewer.js +++ b/lib/Viewer.js @@ -6,6 +6,8 @@ */ import { assign, + find, + isFunction, isNumber, omit } from 'min-dash'; @@ -66,6 +68,26 @@ function ensureUnit(val) { return val + (isNumber(val) ? 'px' : ''); } + +/** + * + * Find BPMNDiagram in definitions by ID + * + * @param {ModdleElement} definitions + * @param {String} diagramId + * + * @return {Diagram|undefined} + */ +function findDiagram(definitions, diagramId) { + if (!diagramId) { + return; + } + + return find(definitions.diagrams, function(element) { + return element.id === diagramId; + }); +} + /** * A viewer for BPMN 2.0 diagrams. * @@ -152,9 +174,15 @@ inherits(Viewer, Diagram); * You can use these events to hook into the life-cycle. * * @param {String} xml the BPMN 2.0 xml + * @param {String} [diagramId] id of the diagram to render (if not provided, the first one will be rendered) * @param {Function} [done] invoked with (err, warnings=[]) */ -Viewer.prototype.importXML = function(xml, done) { +Viewer.prototype.importXML = function(xml, diagramId, done) { + + if (isFunction(diagramId)) { + done = diagramId; + diagramId = null; + } // done is optional done = done || function() {}; @@ -175,7 +203,8 @@ Viewer.prototype.importXML = function(xml, done) { context: context }) || definitions; - var parseWarnings = context.warnings; + var parseWarnings = context.warnings, + diagram; if (err) { err = checkValidationError(err); @@ -185,7 +214,17 @@ Viewer.prototype.importXML = function(xml, done) { return done(err, parseWarnings); } - self.importDefinitions(definitions, function(err, importWarnings) { + diagram = findDiagram(definitions, diagramId); + + if (diagramId && !diagram) { + err = new Error('BPMNDiagram not found'); + + self._emit('import.done', { error: err, warnings: parseWarnings || [] }); + + return done(err); + } + + self.importDefinitions(definitions, diagram, function(err, importWarnings) { var allWarnings = [].concat(parseWarnings, importWarnings || []); self._emit('import.done', { error: err, warnings: allWarnings }); @@ -346,7 +385,12 @@ Viewer.prototype.saveSVG = function(options, done) { */ -Viewer.prototype.importDefinitions = function(definitions, done) { +Viewer.prototype.importDefinitions = function(definitions, diagram, done) { + + if (isFunction(diagram)) { + done = diagram; + diagram = null; + } // catch synchronous exceptions during #clear() try { @@ -362,7 +406,7 @@ Viewer.prototype.importDefinitions = function(definitions, done) { } // perform graphical import - return importBpmnDiagram(this, definitions, done); + return importBpmnDiagram(this, definitions, diagram, done); }; Viewer.prototype.getModules = function() { diff --git a/lib/import/Importer.js b/lib/import/Importer.js index 1796e8d8..e431720d 100644 --- a/lib/import/Importer.js +++ b/lib/import/Importer.js @@ -1,5 +1,8 @@ import BpmnTreeWalker from './BpmnTreeWalker'; +import { + isFunction +} from 'min-dash'; /** * Import the definitions into a diagram. @@ -8,9 +11,16 @@ import BpmnTreeWalker from './BpmnTreeWalker'; * * @param {Diagram} diagram * @param {ModdleElement} definitions + * @param {ModdleElement} [selectedDiagram] the BPMNDiagram element selected to be rendered + * (if not provided, the first one will be rendered) * @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done */ -export function importBpmnDiagram(diagram, definitions, done) { +export function importBpmnDiagram(diagram, definitions, selectedDiagram, done) { + + if (isFunction(selectedDiagram)) { + done = selectedDiagram; + selectedDiagram = null; + } var importer, eventBus, @@ -24,8 +34,9 @@ export function importBpmnDiagram(diagram, definitions, done) { * all elements you encounter. * * @param {ModdleElement} definitions + * @param {ModdleElement} selectedDiagram */ - function render(definitions) { + function render(definitions, selectedDiagram) { var visitor = { @@ -46,7 +57,7 @@ export function importBpmnDiagram(diagram, definitions, done) { // traverse BPMN 2.0 document model, // starting at definitions - walker.handleDefinitions(definitions); + walker.handleDefinitions(definitions, selectedDiagram); } try { @@ -56,7 +67,7 @@ export function importBpmnDiagram(diagram, definitions, done) { eventBus.fire('import.render.start', { definitions: definitions }); - render(definitions); + render(definitions, selectedDiagram); eventBus.fire('import.render.complete', { error: error, diff --git a/test/fixtures/bpmn/import/multiple-diagrams.bpmn b/test/fixtures/bpmn/import/multiple-diagrams.bpmn new file mode 100644 index 00000000..1acc5a5b --- /dev/null +++ b/test/fixtures/bpmn/import/multiple-diagrams.bpmn @@ -0,0 +1,78 @@ + + + + + SequenceFlow_1 + + + + SequenceFlow_1 + SequenceFlow_2 + + + + SequenceFlow_2 + SequenceFlow_3 + + + SequenceFlow_3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/test/fixtures/bpmn/multiple-diagrams.bpmn b/test/fixtures/bpmn/multiple-diagrams.bpmn new file mode 100644 index 00000000..b2f3f639 --- /dev/null +++ b/test/fixtures/bpmn/multiple-diagrams.bpmn @@ -0,0 +1,5976 @@ + + + + + + + + + + + + + + + + + No entry + + + + No entry + + + + false + + + + No entry + + + + No entry + + + + None + + + + No entry + + + + No entry + + + + Draft + + + + No entry + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 62220 + + + + false + + + + false + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 0 + + + + None + + + + false + + + + 15060 + + + + 0.01 + + + + No entry + + + + 1483612400369 + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No entry + + + + No entry + + + + false + + + + No entry + + + + No entry + + + + None + + + + No entry + + + + No entry + + + + Draft + + + + No entry + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 28050 + + + + false + + + + false + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 0 + + + + None + + + + false + + + + 13605 + + + + No entry + + + + 1484049748817 + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No entry + + + + No entry + + + + false + + + + No entry + + + + No entry + + + + None + + + + No entry + + + + No entry + + + + Draft + + + + No entry + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 28050 + + + + false + + + + false + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 0 + + + + None + + + + false + + + + 13605 + + + + No entry + + + + 1484049756036 + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No entry + + + + No entry + + + + false + + + + No entry + + + + No entry + + + + None + + + + No entry + + + + No entry + + + + Draft + + + + No entry + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 28050 + + + + false + + + + false + + + + No entry + + + + No entry + + + + No entry + + + + 0 + + + + 0 + + + + None + + + + false + + + + 13605 + + + + No entry + + + + 1484049765159 + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + No change + + + + false + + + + true + + + + true + + + + 16777215 + + + + false + + + + false + + + + 0 + + + + 1 + + + + false + + + + 0 + + + + None + + + + + + + + + + + + + + + No change + + + + true + + + + 16777215 + + + + false + + + + false + + + + 0 + + + + + + + + + + Bpmn_UserTask_S6a9oSqSEee9dOUnH0MpZQ + Bpmn_UserTask_P2qRsSqSEee9dOUnH0MpZQ + Bpmn_ParallelGateway_MQGukQQuEeev4LOvjrydZw + _584c4307-b03c-4df7-ad30-d606bee9b472 + _73701b0e-a784-4e60-bddf-80bf629651b8 + _871c8a75-ffb3-46af-9850-0300e4d59ec6 + _8c0abe58-e74b-488b-840b-f02ccd6547cc + Bpmn_UserTask_QO2IMCqSEee9dOUnH0MpZQ + Bpmn_UserTask_TsKjoSqSEee9dOUnH0MpZQ + Bpmn_UserTask_RgGUsCqSEee9dOUnH0MpZQ + _d67789fb-e055-47ac-9802-6efa6a7e4390 + Bpmn_ParallelGateway_LXMJkQQuEeev4LOvjrydZw + + + + + + No change + + + + true + + + + 16777215 + + + + false + + + + false + + + + 0 + + + + + + + + + + + _4f16497f-746f-4193-894f-f452aab466cf + Bpmn_UserTask_X-cRISqSEee9dOUnH0MpZQ + Bpmn_UserTask_dqvsoSqSEee9dOUnH0MpZQ + Bpmn_UserTask_U7bzISqSEee9dOUnH0MpZQ + _74c6a2e9-2b77-4a99-8f1c-25f441138582 + Bpmn_UserTask_aCRxISqSEee9dOUnH0MpZQ + Bpmn_UserTask_Wl8NISqSEee9dOUnH0MpZQ + _3e9a1729-6121-4d60-84a1-eceff1073a48 + Bpmn_UserTask_XCx6ISqSEee9dOUnH0MpZQ + _86c24c30-155f-437b-877f-f66b2e8c9f48 + Bpmn_UserTask_ZLf6ISqSEee9dOUnH0MpZQ + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 17 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + + _c33b796d-5b30-49ae-aa21-5c362c610d7f + _14cd639b-5a75-4351-be98-9709f980859c + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 14 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _2bdba22a-0209-4e67-9be3-58bc2e618207 + _bfb20993-bbf5-4c91-853a-acad6690bf22 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + do not show + + + + false + + + + 0 + + + + false + + + + + + + + + + + _8ce148f6-f444-4a02-8625-8c19fc8cb5fb + _0faf8d5f-a3b5-4fa4-ae90-d29ecd5903c6 + _d9ba759c-0465-43cb-86a2-7e6fb7e6eee6 + _fe33bf0a-fb09-44dd-8b07-01b795945ab2 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + false + + + + 0 + + + + 09 + + + + false + + + + No entry + + + + false + + + + false + + + + true + + + + + + + + + + _3a3a19fc-0c56-4305-b1e2-d7c63aa0c546 + _7be50ce1-4794-43f3-8afc-b0f4ae141389 + + + + + + + + + Bpmn_DataObject_kTDHAQQqEeev4LOvjrydZw + Bpmn_DataInput_3-A1wQQqEeev4LOvjrydZw + + + Bpmn_DataInput_3-A1wQQqEeev4LOvjrydZw + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + true + + + + + + + + + + + _0faf8d5f-a3b5-4fa4-ae90-d29ecd5903c6 + _64fa4026-30d5-4b19-ad56-00d3bae7c818 + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + true + + + + + + + + + + + _d9ba759c-0465-43cb-86a2-7e6fb7e6eee6 + _4c451dd2-6ba3-4709-94ab-c964cdb527fb + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + local + + + + 18 + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + _14cd639b-5a75-4351-be98-9709f980859c + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 15 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _bfb20993-bbf5-4c91-853a-acad6690bf22 + _8ce148f6-f444-4a02-8625-8c19fc8cb5fb + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 08 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _804ed46a-48d6-4c00-a57d-95fb43f9e431 + _3a3a19fc-0c56-4305-b1e2-d7c63aa0c546 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + Inputs from: +IT +Payroll +Facilities + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 16 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + + _0bd61b86-7bbc-466a-a877-ea7f991d7e6e + _c33b796d-5b30-49ae-aa21-5c362c610d7f + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + true + + + + + + + + + + + _fe33bf0a-fb09-44dd-8b07-01b795945ab2 + _fd140ddd-e6e2-4eed-bdbe-ac8c4f489b43 + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + do not show + + + + false + + + + 0 + + + + false + + + + + + + + + + + _64fa4026-30d5-4b19-ad56-00d3bae7c818 + _4c451dd2-6ba3-4709-94ab-c964cdb527fb + _fd140ddd-e6e2-4eed-bdbe-ac8c4f489b43 + _0bd61b86-7bbc-466a-a877-ea7f991d7e6e + + + + + + No change + + + + do not show + + + + false + + + + 0 + + + + 06 + + + + false + + + + + + + + + + _c0325c1b-c662-4a6b-a40d-d1c8650465db + _022a5543-01bf-4ad7-a7e9-b310cdbf14f7 + _804ed46a-48d6-4c00-a57d-95fb43f9e431 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 07 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _022a5543-01bf-4ad7-a7e9-b310cdbf14f7 + _fc6b3471-0eb0-4aa4-bd38-e39885ea8c2f + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + + + Bpmn_SequenceFlow_dRgtQCqSEee9dOUnH0MpZQ + _680a535d-10e1-43bd-b0fb-ff16afb75c99 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 02 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _77882ac9-e101-4d8d-bb2e-ce57f0b81a4f + _c310fe18-3c8f-4f7d-b4b9-db17e41ce02a + _79166e63-e378-4424-95ee-a30c7c42a55a + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + below + + + + false + + + + 0 + + + + 04 + + + + + + + + + + _79166e63-e378-4424-95ee-a30c7c42a55a + _8d55b014-266e-436c-bdb9-05e0c747d350 + _294d1aa2-1fdf-4d35-837c-204fc4a4b67b + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + Yes + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + No + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 11 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _63974b42-2159-4908-b54c-797466ceeb08 + Bpmn_SequenceFlow_dRgtQCqSEee9dOUnH0MpZQ + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 03 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _294d1aa2-1fdf-4d35-837c-204fc4a4b67b + _77882ac9-e101-4d8d-bb2e-ce57f0b81a4f + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + 01 + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + _c310fe18-3c8f-4f7d-b4b9-db17e41ce02a + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 05 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + + _8d55b014-266e-436c-bdb9-05e0c747d350 + _c0325c1b-c662-4a6b-a40d-d1c8650465db + + + + + + + + + + Bpmn_OutputSet_kbn0MQQqEeev4LOvjrydZw + + + Bpmn_DataOutput_kbobQAQqEeev4LOvjrydZw + Bpmn_InputSet_kbn0MgQqEeev4LOvjrydZw + + + + + + + + + + Bpmn_DataOutput_kbobQAQqEeev4LOvjrydZw + Bpmn_DataObject_kTDHAQQqEeev4LOvjrydZw + + + + + + + No change + + + + do not show + + + + false + + + + 0 + + + + 13 + + + + false + + + + + + + + + + + _7be50ce1-4794-43f3-8afc-b0f4ae141389 + _680a535d-10e1-43bd-b0fb-ff16afb75c99 + _2bdba22a-0209-4e67-9be3-58bc2e618207 + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + 10 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _fc6b3471-0eb0-4aa4-bd38-e39885ea8c2f + _63974b42-2159-4908-b54c-797466ceeb08 + + + + + + + + + + + + + + + No change + + + + false + + + + true + + + + false + + + + 16777215 + + + + false + + + + false + + + + 0 + + + + 1 + + + + false + + + + 0 + + + + None + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + local + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + + _f423b6da-adea-44cf-b2df-b5f3b1021e6a + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + + _9bd2bec1-4e16-4796-9116-973580864a83 + + + + + + + + + Bpmn_DataOutput_0F2mgAQsEeev4LOvjrydZw + Bpmn_DataStoreReference_xkakgAQsEeev4LOvjrydZw + + + Bpmn_DataOutput_0F2mgAQsEeev4LOvjrydZw + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _425a3093-06b7-490e-9d8e-dd7056fb0095 + _f423b6da-adea-44cf-b2df-b5f3b1021e6a + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + 0 + + + + false + + + + false + + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _4b3d40cd-bcf5-4296-b244-b6ca7a458f78 + _544ce9a6-a3da-418f-9f29-9244fbf8f5bc + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _544ce9a6-a3da-418f-9f29-9244fbf8f5bc + _1a4f06b1-2ba2-4e0f-a6bb-1f51e59e31d4 + + + + + dataOutput_14e102e8-c9a3-4f05-b536-8c3ddd5a52f0 + + + + + + + false + + + + automatic + + + + + + + + + dataOutput_14e102e8-c9a3-4f05-b536-8c3ddd5a52f0 + dataStoreReference_dd0b0e9f-11af-40ca-ae66-c6bdcbd4c859 + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _1a4f06b1-2ba2-4e0f-a6bb-1f51e59e31d4 + _425a3093-06b7-490e-9d8e-dd7056fb0095 + + + + dataInput_a7686b51-3e57-4c5c-bfd3-582d75e85ef2 + + + + + + + + false + + + + automatic + + + + + + + + + dataStoreReference_dd0b0e9f-11af-40ca-ae66-c6bdcbd4c859 + dataInput_a7686b51-3e57-4c5c-bfd3-582d75e85ef2 + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + + _9bd2bec1-4e16-4796-9116-973580864a83 + _4b3d40cd-bcf5-4296-b244-b6ca7a458f78 + + + + + + + + + + + Bpmn_DataInput_zKPS0QQsEeev4LOvjrydZw + + + dataOutput_40f59712-22d7-4a8a-8fdb-ef1461b2d8be + + + + + + + + + + Bpmn_DataStoreReference_xkakgAQsEeev4LOvjrydZw + Bpmn_DataInput_zKPS0QQsEeev4LOvjrydZw + + + + + + false + + + + automatic + + + + + + + + + dataOutput_40f59712-22d7-4a8a-8fdb-ef1461b2d8be + dataStoreReference_dd0b0e9f-11af-40ca-ae66-c6bdcbd4c859 + + + + + + + + + + + + + + + No change + + + + false + + + + 0 + + + + + + + + + + With PowerShell + + + + + + false + + + + automatic + + + + + + + + + + + + + + + No change + + + + false + + + + true + + + + false + + + + 16777215 + + + + false + + + + false + + + + 0 + + + + 1 + + + + false + + + + 0 + + + + None + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _80ec0079-4266-4d71-8f9d-ff979f0d8884 + _17ebbefb-67fe-4e16-b21d-d7267c965946 + _0caff436-0236-4ccc-85df-9ea1bd413f1a + + + + + dataOutput_0d4940de-b2cc-4216-8fd7-efc71ecebf80 + + + + + + + false + + + + automatic + + + + + + + + + dataOutput_0d4940de-b2cc-4216-8fd7-efc71ecebf80 + dataStoreReference_88bbd82d-e83a-41c9-82c7-4f12e87faa9c + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + Yes + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + below + + + + false + + + + 0 + + + + + + + + + + _bc6f05af-a198-4b6f-9e16-1b7991481787 + _424096a5-1272-4c87-8325-a68b47505510 + _80ec0079-4266-4d71-8f9d-ff979f0d8884 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + No + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + + _5da6e12e-f982-469a-bb0a-0bd37d83acb8 + + + + + + + + + Bpmn_DataOutput_iOqigAQsEeev4LOvjrydZw + Bpmn_DataObject_iLnOgQQsEeev4LOvjrydZw + + + Bpmn_DataOutput_iOqigAQsEeev4LOvjrydZw + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + 0 + + + + false + + + + false + + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + local + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + + _0caff436-0236-4ccc-85df-9ea1bd413f1a + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _424096a5-1272-4c87-8325-a68b47505510 + _17ebbefb-67fe-4e16-b21d-d7267c965946 + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _5da6e12e-f982-469a-bb0a-0bd37d83acb8 + _bc6f05af-a198-4b6f-9e16-1b7991481787 + + + + + + + + + + Bpmn_DataInput_lqNcUwQsEeev4LOvjrydZw + Bpmn_OutputSet_lqNcUQQsEeev4LOvjrydZw + + + Bpmn_InputSet_lqNcUgQsEeev4LOvjrydZw + + + + + + + + + + Bpmn_DataObject_iLnOgQQsEeev4LOvjrydZw + Bpmn_DataInput_lqNcUwQsEeev4LOvjrydZw + + + + + + + + + + + + + + + + No change + + + + false + + + + true + + + + false + + + + 16777215 + + + + false + + + + false + + + + 0 + + + + 1 + + + + false + + + + 0 + + + + None + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + + _4e16051c-1b37-432a-80d6-647c47b5586c + + + + + + + + + Bpmn_DataOutput_RdnAIAQsEeev4LOvjrydZw + Bpmn_DataObject_RX4LkQQsEeev4LOvjrydZw + + + Bpmn_DataOutput_RdnAIAQsEeev4LOvjrydZw + + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _4e16051c-1b37-432a-80d6-647c47b5586c + _81b63d83-b0d6-4941-8df4-4aec650abb56 + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + true + + + + false + + + + true + + + + false + + + + false + + + + true + + + + center + + + + false + + + + true + + + + false + + + + 0 + + + + false + + + + No entry + + + + false + + + + false + + + + false + + + + + + + + + + + _81b63d83-b0d6-4941-8df4-4aec650abb56 + _d37a24be-32ed-4e3e-8e91-0d14a5af4e46 + + + + + + + + + + Bpmn_DataInput_SnLQQwQsEeev4LOvjrydZw + Bpmn_OutputSet_SnLQQQQsEeev4LOvjrydZw + + + Bpmn_InputSet_SnLQQgQsEeev4LOvjrydZw + + + + + + + + + + Bpmn_DataObject_RX4LkQQsEeev4LOvjrydZw + Bpmn_DataInput_SnLQQwQsEeev4LOvjrydZw + + + + + + + Name + + + + false + + + + 0 + + + + false + + + + automatic + + + + false + + + + + + + + + + + + + + No change + + + + false + + + + false + + + + false + + + + 0 + + + + local + + + + false + + + + No entry + + + + false + + + + true + + + + + + + + + + + _d37a24be-32ed-4e3e-8e91-0d14a5af4e46 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/test/spec/ViewerSpec.js b/test/spec/ViewerSpec.js index 7ed9f7eb..b39454a5 100644 --- a/test/spec/ViewerSpec.js +++ b/test/spec/ViewerSpec.js @@ -8,6 +8,10 @@ import Viewer from 'lib/Viewer'; import inherits from 'inherits'; +import { + isFunction +} from 'min-dash'; + describe('Viewer', function() { @@ -18,10 +22,15 @@ describe('Viewer', function() { }); - function createViewer(xml, done) { + function createViewer(xml, diagramId, done) { + if (isFunction(diagramId)) { + done = diagramId; + diagramId = null; + } + var viewer = new Viewer({ container: container }); - viewer.importXML(xml, function(err, warnings) { + viewer.importXML(xml, diagramId, function(err, warnings) { done(err, warnings, viewer); }); } @@ -670,6 +679,68 @@ describe('Viewer', function() { }); }); + + it('should import BPMN with multiple diagrams without diagram id specified', function(done) { + + // given + var xml = require('../fixtures/bpmn/multiple-diagrams.bpmn'); + + // when + createViewer(xml, function(err) { + + // then + done(err); + }); + }); + + + it('should import BPMN with multiple diagrams with diagram id specified', function(done) { + + // given + var xml = require('../fixtures/bpmn/multiple-diagrams.bpmn'); + + // when + createViewer(xml, 'Diagram_80fecfcd-0165-4c36-90b6-3ea384265fe7', function(err) { + + // then + done(err); + }); + }); + + + it('should complete with error if diagram of provided ID does not exist', function(done) { + + // given + var xml = require('../fixtures/bpmn/multiple-diagrams.bpmn'); + + // when + createViewer(xml, 'Diagram_IDontExist', function(err) { + + // then + expect(err).to.exist; + expect(err.message).to.eql('BPMNDiagram not found'); + + done(); + }); + }); + + + it('should import BPMN with multiple diagrams when only xml is provided', function(done) { + + // given + var viewer = new Viewer({ container: container }); + + var xml = require('../fixtures/bpmn/multiple-diagrams.bpmn'); + + // when + viewer.importXML(xml); + + // then + viewer.on('import.done', function(event) { + done(); + }); + }); + }); diff --git a/test/spec/import/ImporterSpec.js b/test/spec/import/ImporterSpec.js index c1007c62..b376af42 100644 --- a/test/spec/import/ImporterSpec.js +++ b/test/spec/import/ImporterSpec.js @@ -18,7 +18,8 @@ import { } from 'diagram-js/lib/util/GraphicsUtil'; import { - find + find, + isFunction } from 'min-dash'; import { is } from 'lib/util/ModelUtil'; @@ -40,12 +41,22 @@ describe('import - Importer', function() { }); - function runImport(diagram, xml, done) { + function runImport(diagram, xml, diagramId, done) { + + if (isFunction(diagramId)) { + done = diagramId; + diagramId = null; + } var moddle = new BpmnModdle(); moddle.fromXML(xml, function(err, definitions) { - importBpmnDiagram(diagram, definitions, done); + + var selectedDiagram = find(definitions.diagrams, function(element) { + return element.id === diagramId; + }); + + importBpmnDiagram(diagram, definitions, selectedDiagram, done); }); } @@ -394,7 +405,79 @@ describe('import - Importer', function() { done(err); }); + }); + + it('should import single diagram from multiple diagrams 2', function(done) { + + // given + var xml = require('../../fixtures/bpmn/import/multiple-diagrams.bpmn'); + + var events = []; + + // log events + diagram.get('eventBus').on('bpmnElement.added', function(e) { + events.push({ + type: 'add', + semantic: e.element.businessObject.id, + di: e.element.businessObject.di.id, + diagramElement: e.element && e.element.id + }); + }); + + // when + runImport(diagram, xml, 'BPMNDiagram_2', function(err, warnings) { + + // then + expect(events).to.eql([ + { type: 'add', semantic: 'Process_2', di: 'BPMNPlane_2', diagramElement: 'Process_2' }, + { type: 'add', semantic: 'StartEvent_2', di: '_BPMNShape_StartEvent_2', diagramElement: 'StartEvent_2' }, + { type: 'add', semantic: 'IntermediateThrowEvent_1', di: '_BPMNShape_IntermediateThrowEvent_1', diagramElement: 'IntermediateThrowEvent_1' }, + { type: 'add', semantic: 'EndEvent_2', di: '_BPMNShape_EndEvent_2', diagramElement: 'EndEvent_2' }, + { type: 'add', semantic: 'SequenceFlow_4', di: 'BPMNEdge_SequenceFlow_4', diagramElement: 'SequenceFlow_4' }, + { type: 'add', semantic: 'SequenceFlow_5', di: 'BPMNEdge_SequenceFlow_5', diagramElement: 'SequenceFlow_5' } + ]); + + done(err); + }); + }); + + + it('should import single diagram from multiple diagrams 1', function(done) { + + // given + var xml = require('../../fixtures/bpmn/import/multiple-diagrams.bpmn'); + + var events = []; + + // log events + diagram.get('eventBus').on('bpmnElement.added', function(e) { + events.push({ + type: 'add', + semantic: e.element.businessObject.id, + di: e.element.businessObject.di.id, + diagramElement: e.element && e.element.id + }); + }); + + // when + runImport(diagram, xml, 'BPMNDiagram_1', function(err, warnings) { + + // then + expect(events).to.eql([ + { type: 'add', semantic: 'Process_1', di: 'BPMNPlane_1', diagramElement: 'Process_1' }, + { type: 'add', semantic: 'StartEvent_1', di: '_BPMNShape_StartEvent_1', diagramElement: 'StartEvent_1' }, + { type: 'add', semantic: 'Task_1', di: '_BPMNShape_Task_1', diagramElement: 'Task_1' }, + { type: 'add', semantic: 'Task_2', di: '_BPMNShape_Task_2', diagramElement: 'Task_2' }, + { type: 'add', semantic: 'EndEvent_1', di: '_BPMNShape_EndEvent_1', diagramElement: 'EndEvent_1' }, + { type: 'add', semantic: 'SequenceFlow_1', di: 'BPMNEdge_SequenceFlow_1', diagramElement: 'SequenceFlow_1' }, + { type: 'add', semantic: 'SequenceFlow_2', di: 'BPMNEdge_SequenceFlow_2', diagramElement: 'SequenceFlow_2' }, + { type: 'add', semantic: 'SequenceFlow_3', di: 'BPMNEdge_SequenceFlow_3', diagramElement: 'SequenceFlow_3' } + ]); + + done(err); + + }); }); });