improve(bpmnfactory): add semantic element IDs

The ID will have an semantic prefix: SequenceFlow_6bpz90i

related to bpmn-io/bpmn-js#108
This commit is contained in:
jdotzki 2014-08-11 17:45:47 +02:00
parent ac3669f0ca
commit 58b9964828
3 changed files with 19 additions and 4 deletions

View File

@ -47,7 +47,7 @@ Modeler.prototype.createDiagram = function(done) {
Modeler.prototype.createModdle = function() { Modeler.prototype.createModdle = function() {
var moddle = new BpmnModdle(); var moddle = new BpmnModdle();
IdSupport.extend(moddle, new Ids()); IdSupport.extend(moddle, new Ids([ 32, 36, 1 ]));
return moddle; return moddle;
}; };

View File

@ -21,8 +21,11 @@ BpmnFactory.prototype._needsId = function(element) {
}; };
BpmnFactory.prototype._ensureId = function(element) { BpmnFactory.prototype._ensureId = function(element) {
var prefix = (element.$type || '').replace(/^\s*bpmn:/g, '') + '_';
if (!element.id && this._needsId(element)) { if (!element.id && this._needsId(element)) {
element.id = this._model.ids.next(element); element.id = this._model.ids.nextPrefixed(prefix, element);
} }
}; };

View File

@ -22,6 +22,20 @@ describe('features - bpmn-factory', function() {
beforeEach(bootstrapModeler(diagramXML, { modules: testModules })); beforeEach(bootstrapModeler(diagramXML, { modules: testModules }));
describe('create element', function() {
it('element should be created', inject(function(bpmnFactory) {
var task = bpmnFactory.create('bpmn:Task');
expect(task).toBeDefined();
expect(task.$type).toEqual('bpmn:Task');
}));
it('element id should have semantic prefix', inject(function(bpmnFactory) {
var task = bpmnFactory.create('bpmn:ServiceTask');
expect(task.$type).toEqual('bpmn:ServiceTask');
expect(task.id).toMatch(/^ServiceTask_/g);
}));
});
describe('create di', function() { describe('create di', function() {
@ -45,8 +59,6 @@ describe('features - bpmn-factory', function() {
// expect original not to have been accidently serialized // expect original not to have been accidently serialized
expect(result[0].$attrs).toEqual({}); expect(result[0].$attrs).toEqual({});
})); }));
}); });
}); });