Merge pull request #33 from sartography/bugfix/restore-references-without-breaking-messages
better method for fixing references
This commit is contained in:
commit
f6a79440eb
47
app/app.js
47
app/app.js
|
@ -41,34 +41,6 @@ try {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* The default importer drops the loop data inputs and outputs on multi instance tasks.
|
|
||||||
* They don't reference anything in our diagrams (which is a problem we should tackle, but not essential right now).
|
|
||||||
* This is probably a terrible solution, but given that the modifications happen every time a diagram is parsed,
|
|
||||||
* ia a locally defined function inside the parser, I don't see any other way of dealing with it than to just
|
|
||||||
* intercept the parsed results and patch them up again.
|
|
||||||
*/
|
|
||||||
|
|
||||||
function importWithUnresolvedRefs(bpmnModeler, xml) {
|
|
||||||
bpmnModeler._moddle.fromXML(xml).then((result) => {
|
|
||||||
const refs = result.references.filter(r => r.property === 'bpmn:loopDataInputRef' || r.property === 'bpmn:loopDataOutputRef');
|
|
||||||
const desc = bpmnModeler._moddle.registry.getEffectiveDescriptor('bpmn:ItemAwareElement');
|
|
||||||
refs.forEach(ref => {
|
|
||||||
const props = {
|
|
||||||
id: ref.id,
|
|
||||||
name: ref.id ? typeof(ref.name) === 'undefined': ref.name,
|
|
||||||
};
|
|
||||||
let elem = bpmnModeler._moddle.create(desc, props);
|
|
||||||
elem.$parent = ref.element;
|
|
||||||
ref.element.set(ref.property, elem);
|
|
||||||
});
|
|
||||||
bpmnModeler.importDefinitions(result.rootElement);
|
|
||||||
bpmnModeler.open();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// import XML
|
|
||||||
importWithUnresolvedRefs(bpmnModeler, diagramXML);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* It is possible to populate certain components using API calls to
|
* It is possible to populate certain components using API calls to
|
||||||
* a backend. Here we mock out the API call, but this gives you
|
* a backend. Here we mock out the API call, but this gives you
|
||||||
|
@ -216,8 +188,25 @@ bpmnModeler.on('spiff.callactivity.search', (event) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/* This restores unresolved references that camunda removes */
|
||||||
|
|
||||||
|
bpmnModeler.on('import.parse.complete', event => {
|
||||||
|
const refs = event.references.filter(r => r.property === 'bpmn:loopDataInputRef' || r.property === 'bpmn:loopDataOutputRef');
|
||||||
|
const desc = bpmnModeler._moddle.registry.getEffectiveDescriptor('bpmn:ItemAwareElement');
|
||||||
|
refs.forEach(ref => {
|
||||||
|
const props = {
|
||||||
|
id: ref.id,
|
||||||
|
name: ref.id ? typeof(ref.name) === 'undefined': ref.name,
|
||||||
|
};
|
||||||
|
let elem = bpmnModeler._moddle.create(desc, props);
|
||||||
|
elem.$parent = ref.element;
|
||||||
|
ref.element.set(ref.property, elem);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
bpmnModeler.importXML(diagramXML).then(() => {});
|
||||||
|
|
||||||
// This handles the download and upload buttons - it isn't specific to
|
// This handles the download and upload buttons - it isn't specific to
|
||||||
// the BPMN modeler or these extensions, just a quick way to allow you to
|
// the BPMN modeler or these extensions, just a quick way to allow you to
|
||||||
// create and save files, so keeping it outside the example.
|
// create and save files, so keeping it outside the example.
|
||||||
setupFileOperations(bpmnModeler, importWithUnresolvedRefs);
|
setupFileOperations(bpmnModeler);
|
||||||
|
|
|
@ -7,7 +7,7 @@ import FileSaver from 'file-saver';
|
||||||
* easily from the editor for testing purposes.
|
* easily from the editor for testing purposes.
|
||||||
* -----------------------------------------
|
* -----------------------------------------
|
||||||
*/
|
*/
|
||||||
export default function setupFileOperations(bpmnModeler, importWithUnresolvedRefs) {
|
export default function setupFileOperations(bpmnModeler) {
|
||||||
/**
|
/**
|
||||||
* Just a quick bit of code so we can save the XML that is output.
|
* Just a quick bit of code so we can save the XML that is output.
|
||||||
* Helps for debugging against other libraries (like SpiffWorkflow)
|
* Helps for debugging against other libraries (like SpiffWorkflow)
|
||||||
|
@ -30,7 +30,7 @@ export default function setupFileOperations(bpmnModeler, importWithUnresolvedRef
|
||||||
*/
|
*/
|
||||||
const uploadBtn = document.getElementById('uploadButton');
|
const uploadBtn = document.getElementById('uploadButton');
|
||||||
uploadBtn.addEventListener('click', (_event) => {
|
uploadBtn.addEventListener('click', (_event) => {
|
||||||
openFile(bpmnModeler, importWithUnresolvedRefs);
|
openFile(bpmnModeler);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ function clickElem(elem) {
|
||||||
elem.dispatchEvent(eventMouse);
|
elem.dispatchEvent(eventMouse);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function openFile(bpmnModeler, importWithUnresolvedRefs) {
|
export function openFile(bpmnModeler) {
|
||||||
const readFile = function readFileCallback(e) {
|
const readFile = function readFileCallback(e) {
|
||||||
const file = e.target.files[0];
|
const file = e.target.files[0];
|
||||||
if (!file) {
|
if (!file) {
|
||||||
|
@ -65,7 +65,7 @@ export function openFile(bpmnModeler, importWithUnresolvedRefs) {
|
||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.onload = function onloadCallback(onloadEvent) {
|
reader.onload = function onloadCallback(onloadEvent) {
|
||||||
const contents = onloadEvent.target.result;
|
const contents = onloadEvent.target.result;
|
||||||
importWithUnresolvedRefs(bpmnModeler, contents);
|
bpmnModeler.importXML(contents);
|
||||||
document.body.removeChild(fileInput);
|
document.body.removeChild(fileInput);
|
||||||
};
|
};
|
||||||
reader.readAsText(file);
|
reader.readAsText(file);
|
||||||
|
|
Loading…
Reference in New Issue