mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-02-03 12:43:47 +00:00
feat(Viewer): fire <import.*> events
This commit is contained in:
parent
911e991bc8
commit
c21b295ec2
@ -185,21 +185,19 @@ Viewer.prototype.invoke = function(fn) {
|
|||||||
|
|
||||||
Viewer.prototype.importDefinitions = function(definitions, done) {
|
Viewer.prototype.importDefinitions = function(definitions, done) {
|
||||||
|
|
||||||
var diagram = this.diagram;
|
|
||||||
|
|
||||||
// use try/catch to not swallow synchronous exceptions
|
// use try/catch to not swallow synchronous exceptions
|
||||||
// that may be raised during model parsing
|
// that may be raised during model parsing
|
||||||
try {
|
try {
|
||||||
if (diagram) {
|
if (this.diagram) {
|
||||||
this.clear();
|
this.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.diagram = diagram = this._createDiagram(this.options);
|
|
||||||
this.definitions = definitions;
|
this.definitions = definitions;
|
||||||
|
this.diagram = this._createDiagram(this.options);
|
||||||
|
|
||||||
this._init(diagram);
|
this._init(this.diagram);
|
||||||
|
|
||||||
Importer.importBpmnDiagram(diagram, definitions, done);
|
Importer.importBpmnDiagram(this.diagram, definitions, done);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
done(e);
|
done(e);
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,8 @@ var BpmnTreeWalker = require('./BpmnTreeWalker');
|
|||||||
*/
|
*/
|
||||||
function importBpmnDiagram(diagram, definitions, done) {
|
function importBpmnDiagram(diagram, definitions, done) {
|
||||||
|
|
||||||
var importer = diagram.get('bpmnImporter');
|
var importer = diagram.get('bpmnImporter'),
|
||||||
|
eventBus = diagram.get('eventBus');
|
||||||
|
|
||||||
var warnings = [];
|
var warnings = [];
|
||||||
|
|
||||||
@ -35,10 +36,19 @@ function importBpmnDiagram(diagram, definitions, done) {
|
|||||||
|
|
||||||
var walker = new BpmnTreeWalker(visitor);
|
var walker = new BpmnTreeWalker(visitor);
|
||||||
|
|
||||||
// import
|
try {
|
||||||
walker.handleDefinitions(definitions);
|
eventBus.fire('import.start');
|
||||||
|
|
||||||
done(null, warnings);
|
// import
|
||||||
|
walker.handleDefinitions(definitions);
|
||||||
|
|
||||||
|
eventBus.fire('import.success', warnings);
|
||||||
|
|
||||||
|
done(null, warnings);
|
||||||
|
} catch (e) {
|
||||||
|
eventBus.fire('import.error', e);
|
||||||
|
done(e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.importBpmnDiagram = importBpmnDiagram;
|
module.exports.importBpmnDiagram = importBpmnDiagram;
|
@ -48,6 +48,45 @@ describe('viewer', function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
describe('import events', function() {
|
||||||
|
|
||||||
|
iit('should fire <import.*> events', function(done) {
|
||||||
|
|
||||||
|
// given
|
||||||
|
var viewer = new Viewer({ container: container });
|
||||||
|
|
||||||
|
var xml = fs.readFileSync('test/fixtures/bpmn/empty-definitions.bpmn', 'utf8');
|
||||||
|
|
||||||
|
var events = [];
|
||||||
|
|
||||||
|
viewer.on('import.start', function() {
|
||||||
|
events.push('import.start');
|
||||||
|
});
|
||||||
|
|
||||||
|
viewer.on('import.success', function() {
|
||||||
|
events.push('import.success');
|
||||||
|
});
|
||||||
|
|
||||||
|
viewer.on('import.error', function() {
|
||||||
|
events.push('import.error');
|
||||||
|
});
|
||||||
|
|
||||||
|
// when
|
||||||
|
viewer.importXML(xml, function(err) {
|
||||||
|
|
||||||
|
// then
|
||||||
|
expect(events).toEqual([
|
||||||
|
'import.start',
|
||||||
|
'import.success'
|
||||||
|
]);
|
||||||
|
|
||||||
|
done(err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('error handling', function() {
|
describe('error handling', function() {
|
||||||
|
|
||||||
it('should handle non-bpmn input', function(done) {
|
it('should handle non-bpmn input', function(done) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user