From 925fbc98b8e0ee82ca4952098836e7cf764d2a7c Mon Sep 17 00:00:00 2001 From: Nico Rehwaldt Date: Mon, 4 Aug 2014 16:32:11 +0200 Subject: [PATCH] chore(project): pull bpmn-moddle changes --- lib/Viewer.js | 15 +++++++++++---- lib/features/modeling/BpmnFactory.js | 8 +++----- test/spec/import/ImporterSpec.js | 8 ++++---- test/spec/model/BpmnModelSpec.js | 7 +++++-- 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/lib/Viewer.js b/lib/Viewer.js index 894c1d1c..36bb14bc 100644 --- a/lib/Viewer.js +++ b/lib/Viewer.js @@ -1,7 +1,7 @@ 'use strict'; var Diagram = require('diagram-js'), - BpmnModel = require('bpmn-moddle'), + BpmnModdle = require('bpmn-moddle'), $ = require('jquery'), _ = require('lodash'); @@ -72,6 +72,7 @@ function Viewer(options) { // unwrap jquery this.container = container.get(0); + /** * The code in the area * must not be changed, see http://bpmn.io/license for more information @@ -104,7 +105,9 @@ Viewer.prototype.importXML = function(xml, done) { var self = this; - BpmnModel.fromXML(xml, 'bpmn:Definitions', function(err, definitions) { + this.moddle = this.createModdle(); + + this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions) { if (err) { err = checkValidationError(err); @@ -128,11 +131,14 @@ Viewer.prototype.saveXML = function(options, done) { return done(new Error('no definitions loaded')); } - BpmnModel.toXML(definitions, options, function(err, xml) { + this.moddle.toXML(definitions, options, function(err, xml) { done(err, xml); }); }; +Viewer.prototype.createModdle = function() { + return new BpmnModdle(); +}; var SVG_HEADER = '\n' + @@ -209,7 +215,8 @@ Viewer.prototype._createDiagram = function(options) { // add self as an available service modules.unshift({ - bpmnjs: [ 'value', this ] + bpmnjs: [ 'value', this ], + moddle: [ 'value', this.moddle ] }); options = _.omit(options, 'additionalModules'); diff --git a/lib/features/modeling/BpmnFactory.js b/lib/features/modeling/BpmnFactory.js index a9cda403..7215348c 100644 --- a/lib/features/modeling/BpmnFactory.js +++ b/lib/features/modeling/BpmnFactory.js @@ -2,15 +2,13 @@ var _ = require('lodash'); -var BpmnModdle = require('bpmn-moddle'); - -function BpmnFactory() { - this._model = BpmnModdle.instance(); +function BpmnFactory(moddle) { + this._model = moddle; this._uuid = 1; } -BpmnFactory.$inject = [ ]; +BpmnFactory.$inject = [ 'moddle' ]; BpmnFactory.prototype._needsId = function(element) { diff --git a/test/spec/import/ImporterSpec.js b/test/spec/import/ImporterSpec.js index 2022ca9a..0d5bd579 100644 --- a/test/spec/import/ImporterSpec.js +++ b/test/spec/import/ImporterSpec.js @@ -9,17 +9,17 @@ var Matchers = require('../../Matchers'), var fs = require('fs'); var Diagram = require('diagram-js/lib/Diagram'), - BpmnModel = require('bpmn-moddle'), + BpmnModdle = require('bpmn-moddle'), Importer = require('../../../lib/import/Importer'), Viewer = require('../../../lib/Viewer'); describe('import - importer', function() { - var bpmnModel = BpmnModel.instance(); + var moddle = new BpmnModdle(); function read(xml, opts, callback) { - return BpmnModel.fromXML(xml, 'bpmn:Definitions', opts, callback); + return moddle.fromXML(xml, 'bpmn:Definitions', opts, callback); } beforeEach(Matchers.addDeepEquals); @@ -47,7 +47,7 @@ describe('import - importer', function() { function runImport(diagram, xml, done) { - BpmnModel.fromXML(xml, function(err, definitions) { + moddle.fromXML(xml, function(err, definitions) { if (err) { return done(err); } diff --git a/test/spec/model/BpmnModelSpec.js b/test/spec/model/BpmnModelSpec.js index 1cab0d5e..e4770624 100644 --- a/test/spec/model/BpmnModelSpec.js +++ b/test/spec/model/BpmnModelSpec.js @@ -1,10 +1,12 @@ -var BpmnModel = require('bpmn-moddle'); +var BpmnModdle = require('bpmn-moddle'); describe('model - browser support', function() { + var moddle = new BpmnModdle(); + function read(xml, callback, done) { - BpmnModel.fromXML(xml, 'bpmn:Definitions', function(err, definitions) { + moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions) { if (err) { done(err); @@ -15,6 +17,7 @@ describe('model - browser support', function() { }); } + it('should parse simple xml', function(done) { var xml =