const bpmnVisualization = new bpmnvisu.BpmnVisualization({ container: 'bpmn-container' }); const diagrams = new Map([ ['A.4.1', getA_4_1_BpmnDiagram], // vertical diagram ['C.1.0', getC_1_0_BpmnDiagram], ['C.1.1', getC_1_1_BpmnDiagram], // no pool ['C.2.0', getC_2_0_BpmnDiagram], ]); let lastLoadedDiagram; let lastSelectedPool; const notyf = configureToast(); configureBpmnDiagramsDropdown(); configurePoolSelectionButtons(); loadDiagram('C.2.0'); function loadDiagram(diagramName) { console.info('Loading diagram', diagramName); const diagram = diagrams.get(diagramName).call(); bpmnVisualization.load(diagram, { fit: { type: bpmnvisu.FitType.Center, margin: 20 } }); console.info('Diagram loaded'); lastLoadedDiagram = diagramName; lastSelectedPool = ''; registerBpmnElements(); } function configureBpmnDiagramsDropdown() { document.getElementById('dropdown-diagram-choice').innerHTML = [...diagrams].map(([diagramName, ]) => { return `
${lastSelectedPool}
`;
show('pool-selection-info');
show('group-pools-selection-reset');
hide('dropdown-select-pool');
return false;
};
});
show('btn-group-pools-selection');
}
function changePoolsVisibility(pools, poolIdToHighlight) {
console.info('Updating model, pool to highlight:', poolIdToHighlight);
const model = bpmnVisualization.graph.getModel();
// TMP disable collapsing other pools, see https://github.com/process-analytics/bpmn-visualization-examples/pull/306
// const poolSelectionMethod = getRadioGroupValue('poolSelectionMethod');
const poolSelectionMethod = 'hide';
console.info('Selection method:', poolSelectionMethod);
const hideOthers = poolSelectionMethod === 'hide';
const modelChangeFunction = hideOthers ?
// only keep a single visible pool
(cell => {
model.setVisible(cell, cell.id === poolIdToHighlight);
model.setCollapsed(cell, false);
}) :
// collapse other pools
(cell => {
model.setCollapsed(cell, cell.id !== poolIdToHighlight)
model.setVisible(cell, true);
});
model.beginUpdate();
try {
pools.map(pool => model.getCell(pool.id))
.forEach(modelChangeFunction);
} finally {
model.endUpdate();
}
console.info('Model updated');
}
function configurePoolSelectionButtons() {
document.getElementById('dropdown-toggle-select-pool').onclick = function (){
show('dropdown-select-pool');
}
document.getElementById('btn-pools-selection-reset').onclick = function (){
loadDiagram(lastLoadedDiagram);
}
}
function show(elementId) {
document.getElementById(elementId).classList.remove('hidden');
}
function hide(elementId) {
document.getElementById(elementId).classList.add('hidden');
}
// TODO extract in helper to avoid duplication with diagram-fit-on-load getSelectedFitType
function getRadioGroupValue(elementId) {
const radios = document.getElementsByName(elementId);
for (let i = 0, length = radios.length; i < length; i++) {
if (radios[i].checked) {
return radios[i].value;
}
}
}
function configureToast() {
return new Notyf({
position: {
x: 'right',
y: 'top',
},
types: [
{
type: 'success',
duration: 2500,
}
]
});
}
function toast(htmlMessage) {
notyf.success(htmlMessage);
}