parent
00b7d9ecc2
commit
0c71ad30a0
|
@ -345,14 +345,6 @@ Viewer.prototype.saveSVG = function(options, done) {
|
|||
* @method Viewer#invoke
|
||||
*/
|
||||
|
||||
/**
|
||||
* Remove all drawn elements from the viewer.
|
||||
*
|
||||
* After calling this method the viewer can still
|
||||
* be reused for opening another diagram.
|
||||
*
|
||||
* @method Viewer#clear
|
||||
*/
|
||||
|
||||
Viewer.prototype.importDefinitions = function(definitions, done) {
|
||||
|
||||
|
@ -377,6 +369,33 @@ Viewer.prototype.getModules = function() {
|
|||
return this._modules;
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove all drawn elements from the viewer.
|
||||
*
|
||||
* After calling this method the viewer can still
|
||||
* be reused for opening another diagram.
|
||||
*
|
||||
* @method Viewer#clear
|
||||
*/
|
||||
Viewer.prototype.clear = function() {
|
||||
|
||||
// remove businessObject#di binding
|
||||
//
|
||||
// this is necessary, as we establish the bindings
|
||||
// in the BpmnTreeWalker (and assume none are given
|
||||
// on reimport)
|
||||
this.get('elementRegistry').forEach(function(element) {
|
||||
var bo = element.businessObject;
|
||||
|
||||
if (bo && bo.di) {
|
||||
delete bo.di;
|
||||
}
|
||||
});
|
||||
|
||||
// remove drawn elements
|
||||
Diagram.prototype.clear.call(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Destroy the viewer instance and remove all its
|
||||
* remainders from the document tree.
|
||||
|
|
|
@ -1082,6 +1082,48 @@ describe('Viewer', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('#clear', function() {
|
||||
|
||||
it('should not throw if diagram is already empty', function() {
|
||||
|
||||
// given
|
||||
var viewer = new Viewer({ container: container });
|
||||
|
||||
function clearDiagram() {
|
||||
viewer.clear();
|
||||
}
|
||||
|
||||
// then
|
||||
expect(clearDiagram).to.not.throw();
|
||||
});
|
||||
|
||||
|
||||
it('should remove di property', function(done) {
|
||||
|
||||
var xml = require('../fixtures/bpmn/simple.bpmn');
|
||||
|
||||
var viewer = new Viewer({ container: container }),
|
||||
elementRegistry = viewer.get('elementRegistry');
|
||||
|
||||
viewer.importXML(xml, function(err, warnings) {
|
||||
|
||||
var elements = elementRegistry.getAll();
|
||||
|
||||
// when
|
||||
viewer.clear();
|
||||
|
||||
// then
|
||||
expect(elements.some(function(el) {
|
||||
return el && el.businessObject && el.businessObject.di;
|
||||
}), 'at least one element still has di').to.be.false;
|
||||
|
||||
done(err, warnings);
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('default export', function() {
|
||||
expect(ViewerDefaultExport).to.equal(Viewer);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue