feat(modeling): validate + create unique ids

This adds id logging + validation to the Modeler. As a result the
modeler will throw hard exeptions on colliding id mappings and may
generated unique ids.

Related to bpmn-io/bpmn-js#92
This commit is contained in:
Nico Rehwaldt 2014-08-04 16:34:37 +02:00
parent 925fbc98b8
commit 4a824911c2
5 changed files with 16 additions and 6 deletions

View File

@ -1,6 +1,9 @@
'use strict';
var Diagram = require('diagram-js');
var Diagram = require('diagram-js'),
BpmnModdle = require('bpmn-moddle'),
IdSupport = require('bpmn-moddle/lib/id-support'),
Ids = require('ids');
var Viewer = require('./Viewer');
@ -41,6 +44,13 @@ Modeler.prototype.createDiagram = function(done) {
return this.importXML(initialDiagram, done);
};
Modeler.prototype.createModdle = function() {
var moddle = new BpmnModdle();
IdSupport.extend(moddle, new Ids());
return moddle;
};
// modules the modeler is composed of
Modeler.prototype._modules = Modeler.prototype._modules.concat([

View File

@ -5,7 +5,6 @@ var _ = require('lodash');
function BpmnFactory(moddle) {
this._model = moddle;
this._uuid = 1;
}
BpmnFactory.$inject = [ 'moddle' ];
@ -23,7 +22,7 @@ BpmnFactory.prototype._needsId = function(element) {
BpmnFactory.prototype._ensureId = function(element) {
if (!element.id && this._needsId(element)) {
element.id = '' + (++this._uuid);
element.id = this._model.ids.next(element);
}
};

View File

@ -59,6 +59,7 @@
"jquery": "~2.1.0",
"jquery-mousewheel": "~3.1.11",
"lodash": "~2.4.0",
"object-refs": "^0.1.0"
"object-refs": "^0.1.0",
"ids": "0.0.3"
}
}

View File

@ -1,7 +1,7 @@
'use strict';
var _ = require('lodash');
var BpmnJS = require('../');
var BpmnJS = require('../lib/Modeler');
// enhance jasmine with test container API
require('jasmine-test-container-support').extend(jasmine);

View File

@ -4,7 +4,7 @@
xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
expressionLanguage="http://www.w3.org/1999/XPath"
id="task-types"
id="task-types-diagram"
typeLanguage="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL http://www.omg.org/spec/BPMN/2.0/20100501/BPMN20.xsd">
<process id="task-types" isClosed="false" isExecutable="false" processType="None">