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:
parent
ac3669f0ca
commit
58b9964828
|
@ -47,7 +47,7 @@ Modeler.prototype.createDiagram = function(done) {
|
|||
Modeler.prototype.createModdle = function() {
|
||||
var moddle = new BpmnModdle();
|
||||
|
||||
IdSupport.extend(moddle, new Ids());
|
||||
IdSupport.extend(moddle, new Ids([ 32, 36, 1 ]));
|
||||
|
||||
return moddle;
|
||||
};
|
||||
|
|
|
@ -21,8 +21,11 @@ BpmnFactory.prototype._needsId = function(element) {
|
|||
};
|
||||
|
||||
BpmnFactory.prototype._ensureId = function(element) {
|
||||
|
||||
var prefix = (element.$type || '').replace(/^\s*bpmn:/g, '') + '_';
|
||||
|
||||
if (!element.id && this._needsId(element)) {
|
||||
element.id = this._model.ids.next(element);
|
||||
element.id = this._model.ids.nextPrefixed(prefix, element);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -22,6 +22,20 @@ describe('features - bpmn-factory', function() {
|
|||
|
||||
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() {
|
||||
|
||||
|
@ -45,8 +59,6 @@ describe('features - bpmn-factory', function() {
|
|||
// expect original not to have been accidently serialized
|
||||
expect(result[0].$attrs).toEqual({});
|
||||
}));
|
||||
|
||||
|
||||
});
|
||||
|
||||
});
|
Loading…
Reference in New Issue