2022-06-07 18:16:49 +00:00
|
|
|
import BpmnModeler from 'bpmn-js/lib/Modeler';
|
2022-07-11 17:57:12 +00:00
|
|
|
import diagramXML from '../test/spec/bpmn/diagram.bpmn';
|
2022-06-15 13:51:46 +00:00
|
|
|
import { BpmnPropertiesPanelModule, BpmnPropertiesProviderModule } from 'bpmn-js-properties-panel';
|
2022-07-07 15:20:43 +00:00
|
|
|
import FileSaver from 'file-saver';
|
2022-07-08 14:30:21 +00:00
|
|
|
import spiffworkflow from './spiffworkflow';
|
2022-06-15 19:13:35 +00:00
|
|
|
|
2022-06-15 13:51:46 +00:00
|
|
|
const modelerEl = document.getElementById('modeler');
|
|
|
|
const panelEl = document.getElementById('panel');
|
2022-06-27 21:29:24 +00:00
|
|
|
const spiffModdleExtension = require('./spiffworkflow/moddle/spiffworkflow.json');
|
|
|
|
|
2022-08-04 20:38:40 +00:00
|
|
|
let bpmnModeler;
|
|
|
|
|
2022-06-07 18:16:49 +00:00
|
|
|
// create modeler
|
2022-08-04 19:57:15 +00:00
|
|
|
try {
|
2022-08-04 20:38:40 +00:00
|
|
|
bpmnModeler = new BpmnModeler({
|
2022-08-04 19:57:15 +00:00
|
|
|
container: modelerEl,
|
|
|
|
propertiesPanel: {
|
|
|
|
parent: panelEl
|
|
|
|
},
|
|
|
|
additionalModules: [
|
|
|
|
spiffworkflow,
|
|
|
|
BpmnPropertiesPanelModule,
|
|
|
|
BpmnPropertiesProviderModule,
|
|
|
|
],
|
|
|
|
moddleExtensions: {
|
|
|
|
spiffworkflowModdle: spiffModdleExtension
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
if (error.constructor.name === 'AggregateError') {
|
|
|
|
console.log(error.message);
|
|
|
|
console.log(error.name);
|
|
|
|
console.log(error.errors);
|
|
|
|
}
|
2022-08-04 20:38:40 +00:00
|
|
|
throw error;
|
2022-08-04 19:57:15 +00:00
|
|
|
}
|
2022-06-21 21:04:24 +00:00
|
|
|
|
2022-08-04 20:38:40 +00:00
|
|
|
// import XML
|
|
|
|
bpmnModeler.importXML(diagramXML).then(() => {});
|
|
|
|
|
|
|
|
|
2022-07-11 17:57:12 +00:00
|
|
|
|
|
|
|
/** ****************************************
|
|
|
|
* Below are a few helper methods so we can upload and download files
|
|
|
|
* easily from the editor for testing purposes.
|
|
|
|
* -----------------------------------------
|
|
|
|
*/
|
|
|
|
|
2022-06-21 21:04:24 +00:00
|
|
|
/**
|
|
|
|
* Just a quick bit of code so we can save the XML that is output.
|
|
|
|
* Helps for debugging against other libraries (like SpiffWorkflow)
|
|
|
|
*/
|
|
|
|
let btn = document.getElementById('downloadButton');
|
|
|
|
btn.addEventListener('click', event => {
|
|
|
|
saveXML();
|
|
|
|
});
|
|
|
|
async function saveXML() {
|
|
|
|
const { xml } = await bpmnModeler.saveXML({ format: true });
|
|
|
|
const blob = new Blob([ xml ], { type: 'text/xml' });
|
|
|
|
FileSaver.saveAs(blob, 'diagram.bpmn');
|
|
|
|
}
|
|
|
|
|
2022-07-11 17:57:12 +00:00
|
|
|
/**
|
|
|
|
* Just a quick bit of code so we can open a local XML file
|
|
|
|
* Helps for debugging against other libraries (like SpiffWorkflow)
|
|
|
|
*/
|
|
|
|
let uploadBtn = document.getElementById('uploadButton');
|
|
|
|
uploadBtn.addEventListener('click', event => {
|
|
|
|
openFile(displayFile);
|
|
|
|
});
|
2022-06-21 21:04:24 +00:00
|
|
|
|
2022-07-11 17:57:12 +00:00
|
|
|
function clickElem(elem) {
|
|
|
|
var eventMouse = document.createEvent('MouseEvents');
|
|
|
|
eventMouse.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
|
|
|
|
elem.dispatchEvent(eventMouse);
|
|
|
|
}
|
2022-06-21 21:04:24 +00:00
|
|
|
|
2022-07-11 17:57:12 +00:00
|
|
|
function displayFile(contents) {
|
|
|
|
bpmnModeler.importXML(contents).then(() => {});
|
|
|
|
}
|
2022-06-21 21:04:24 +00:00
|
|
|
|
2022-07-11 17:57:12 +00:00
|
|
|
export function openFile(func) {
|
|
|
|
let readFile = function(e) {
|
|
|
|
var file = e.target.files[0];
|
|
|
|
if (!file) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
var reader = new FileReader();
|
|
|
|
reader.onload = function(e) {
|
|
|
|
var contents = e.target.result;
|
|
|
|
fileInput.func(contents);
|
|
|
|
document.body.removeChild(fileInput);
|
|
|
|
};
|
|
|
|
reader.readAsText(file);
|
|
|
|
};
|
|
|
|
let fileInput = document.createElement('input');
|
|
|
|
fileInput.type = 'file';
|
|
|
|
fileInput.style.display = 'none';
|
|
|
|
fileInput.onchange = readFile;
|
|
|
|
fileInput.func = func;
|
|
|
|
document.body.appendChild(fileInput);
|
|
|
|
clickElem(fileInput);
|
|
|
|
}
|
2022-06-21 21:04:24 +00:00
|
|
|
|