2022-06-07 14:16:49 -04:00
|
|
|
import BpmnModeler from 'bpmn-js/lib/Modeler';
|
2022-08-05 14:57:30 -04:00
|
|
|
import {
|
|
|
|
BpmnPropertiesPanelModule,
|
|
|
|
BpmnPropertiesProviderModule,
|
|
|
|
} from 'bpmn-js-properties-panel';
|
2022-10-29 10:36:25 -04:00
|
|
|
import diagramXML from '../test/spec/bpmn/user_form.bpmn';
|
2022-07-08 10:30:21 -04:00
|
|
|
import spiffworkflow from './spiffworkflow';
|
2022-09-20 16:18:59 -04:00
|
|
|
import setupFileOperations from './fileOperations';
|
2022-06-15 15:13:35 -04:00
|
|
|
|
2022-06-15 09:51:46 -04:00
|
|
|
const modelerEl = document.getElementById('modeler');
|
|
|
|
const panelEl = document.getElementById('panel');
|
2022-06-27 17:29:24 -04:00
|
|
|
const spiffModdleExtension = require('./spiffworkflow/moddle/spiffworkflow.json');
|
|
|
|
|
2022-08-04 16:38:40 -04:00
|
|
|
let bpmnModeler;
|
|
|
|
|
2022-09-21 09:10:34 -04:00
|
|
|
/**
|
|
|
|
* This provides an example of how to instantiate a BPMN Modeler configured with
|
|
|
|
* all the extensions and modifications in this application.
|
|
|
|
*/
|
2022-08-04 15:57:15 -04:00
|
|
|
try {
|
2022-08-04 16:38:40 -04:00
|
|
|
bpmnModeler = new BpmnModeler({
|
2022-08-04 15:57:15 -04:00
|
|
|
container: modelerEl,
|
|
|
|
propertiesPanel: {
|
2022-08-05 14:57:30 -04:00
|
|
|
parent: panelEl,
|
2022-08-04 15:57:15 -04:00
|
|
|
},
|
|
|
|
additionalModules: [
|
|
|
|
spiffworkflow,
|
|
|
|
BpmnPropertiesPanelModule,
|
|
|
|
BpmnPropertiesProviderModule,
|
|
|
|
],
|
|
|
|
moddleExtensions: {
|
2022-08-05 14:57:30 -04:00
|
|
|
spiffworkflowModdle: spiffModdleExtension,
|
|
|
|
},
|
2022-08-04 15:57:15 -04:00
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
if (error.constructor.name === 'AggregateError') {
|
|
|
|
console.log(error.message);
|
|
|
|
console.log(error.name);
|
|
|
|
console.log(error.errors);
|
|
|
|
}
|
2022-08-04 16:38:40 -04:00
|
|
|
throw error;
|
2022-08-04 15:57:15 -04:00
|
|
|
}
|
2022-06-21 17:04:24 -04:00
|
|
|
|
2022-08-04 16:38:40 -04:00
|
|
|
// import XML
|
|
|
|
bpmnModeler.importXML(diagramXML).then(() => {});
|
|
|
|
|
2022-07-11 13:57:12 -04:00
|
|
|
/**
|
2022-10-29 10:36:25 -04:00
|
|
|
* It is possible to populate certain components using API calls to
|
2022-09-21 09:10:34 -04:00
|
|
|
* a backend. Here we mock out the API call, but this gives you
|
|
|
|
* a sense of how things might work.
|
|
|
|
*
|
2022-07-11 13:57:12 -04:00
|
|
|
*/
|
2022-09-21 09:10:34 -04:00
|
|
|
bpmnModeler.on('spiff.service_tasks.requested', (event) => {
|
|
|
|
event.eventBus.fire('spiff.service_tasks.returned', {
|
|
|
|
serviceTaskOperators: [
|
|
|
|
{
|
|
|
|
id: 'Chuck Norris Fact Service',
|
|
|
|
parameters: [
|
|
|
|
{
|
|
|
|
id: 'category',
|
|
|
|
type: 'string',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-09-23 14:32:25 -04:00
|
|
|
{
|
|
|
|
id: 'Fact about a Number',
|
|
|
|
parameters: [
|
|
|
|
{
|
|
|
|
id: 'number',
|
|
|
|
type: 'integer',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
2022-09-21 09:10:34 -04:00
|
|
|
],
|
|
|
|
});
|
2022-07-11 13:57:12 -04:00
|
|
|
});
|
2022-06-21 17:04:24 -04:00
|
|
|
|
2022-10-29 10:36:25 -04:00
|
|
|
/**
|
|
|
|
* Python Script authoring is best done in some sort of editor
|
|
|
|
* here is an example that will connect a large CodeMirror editor
|
|
|
|
* to the "Launch Editor" buttons (Script Tasks, and the Pre and Post
|
|
|
|
* scripts on all other tasks.
|
|
|
|
*/
|
|
|
|
const myCodeMirror = CodeMirror(document.getElementById('code_editor'), {
|
|
|
|
lineNumbers: true,
|
|
|
|
mode: 'python',
|
|
|
|
});
|
|
|
|
|
|
|
|
const btn = document.getElementById('saveCode');
|
|
|
|
let event = null;
|
|
|
|
|
|
|
|
bpmnModeler.on('script.editor.launch', (newEvent) => {
|
|
|
|
event = newEvent;
|
|
|
|
myCodeMirror.setValue(event.script);
|
|
|
|
setTimeout(function() {
|
|
|
|
myCodeMirror.refresh();
|
|
|
|
},1); // We have to wait a moment before calling refresh.
|
|
|
|
document.getElementById('code_overlay').style.display = 'block';
|
|
|
|
document.getElementById('code_editor').focus();
|
|
|
|
});
|
|
|
|
|
|
|
|
btn.addEventListener('click', (_event) => {
|
|
|
|
const { scriptType, element } = event;
|
|
|
|
event.eventBus.fire('script.editor.update', { element, scriptType, script: myCodeMirror.getValue()} )
|
|
|
|
document.getElementById('code_overlay').style.display = 'none';
|
|
|
|
});
|
|
|
|
|
2022-09-21 09:10:34 -04:00
|
|
|
// 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
|
2022-10-29 10:36:25 -04:00
|
|
|
// create and save files, so keeping it outside the example.
|
2022-09-20 16:18:59 -04:00
|
|
|
setupFileOperations(bpmnModeler);
|