chore: code style

This commit is contained in:
Philipp 2022-01-31 11:18:53 +01:00 committed by Philipp Fromme
parent 99bfdd2fb8
commit 4e531cc9f7
1 changed files with 33 additions and 22 deletions

View File

@ -1,7 +1,13 @@
import { find, forEach, map } from 'min-dash';
import { is } from '../util/ModelUtil';
import {
find,
forEach,
map
} from 'min-dash';
import BpmnTreeWalker from './BpmnTreeWalker';
import { is } from '../util/ModelUtil';
/**
* The importBpmnDiagram result.
@ -70,15 +76,15 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
bpmnDiagram = bpmnDiagram || (definitions.diagrams && definitions.diagrams[0]);
var diagramsToLoad = getDiagramsToLoad(definitions, bpmnDiagram);
var diagramsToImport = getDiagramsToImport(definitions, bpmnDiagram);
if (!diagramsToLoad) {
if (!diagramsToImport) {
throw new Error(translate('no diagram to display'));
}
// traverse BPMN 2.0 document model,
// starting at definitions
forEach(diagramsToLoad, function(diagram) {
forEach(diagramsToImport, function(diagram) {
walker.handleDefinitions(definitions, diagram);
});
@ -118,13 +124,15 @@ export function importBpmnDiagram(diagram, definitions, bpmnDiagram) {
}
/**
* Returns all diagrams in the same hirarchy as the requested Diagram.
* It includes all parent- and subProcess diagrams.
* Returns all diagrams in the same hirarchy as the requested diagram.
* Includes all parent and sub process diagrams.
*
* @param {Array} definitions
* @param {Object} bpmnDiagram
*
* @returns {Array<Object>}
*/
function getDiagramsToLoad(definitions, bpmnDiagram) {
function getDiagramsToImport(definitions, bpmnDiagram) {
if (!bpmnDiagram) {
return;
}
@ -139,10 +147,10 @@ function getDiagramsToLoad(definitions, bpmnDiagram) {
// in case the process is part of a collaboration, the plane references the
// collaboration, not the process
var collaboration;
if (is(rootElement, 'bpmn:Collaboration')) {
collaboration = rootElement;
}
else {
} else {
collaboration = find(definitions.rootElements, function(element) {
if (!is(element, 'bpmn:Collaboration')) {
return;
@ -154,38 +162,38 @@ function getDiagramsToLoad(definitions, bpmnDiagram) {
});
}
var roots = [rootElement];
var rootElements = [ rootElement ];
// all collaboration processes can contain sub-diagrams
if (collaboration) {
roots = map(collaboration.participants, function(participant) {
rootElements = map(collaboration.participants, function(participant) {
return participant.processRef;
});
roots.push(collaboration);
rootElements.push(collaboration);
}
var allChildren = selfAndAllFlowElements(roots);
var allChildren = selfAndAllFlowElements(rootElements);
// if we have multiple diagrams referencing the same element, we
// use the first in the file
var diagramsToLoad = [bpmnDiagram];
var handledElements = [bpmnElement];
var diagramsToImport = [ bpmnDiagram ];
var handledElements = [ bpmnElement ];
forEach(definitions.diagrams, function(diagram) {
var bo = diagram.plane.bpmnElement;
var businessObject = diagram.plane.bpmnElement;
if (
allChildren.indexOf(bo) !== -1 &&
handledElements.indexOf(bo) === -1
allChildren.indexOf(businessObject) !== -1 &&
handledElements.indexOf(businessObject) === -1
) {
diagramsToLoad.push(diagram);
handledElements.push(bo);
diagramsToImport.push(diagram);
handledElements.push(businessObject);
}
});
return diagramsToLoad;
return diagramsToImport;
}
function selfAndAllFlowElements(elements) {
@ -195,7 +203,9 @@ function selfAndAllFlowElements(elements) {
if (!element) {
return;
}
result.push(element);
result = result.concat(selfAndAllFlowElements(element.flowElements));
});
@ -209,6 +219,7 @@ function findRootProcess(element) {
if (is(parent, 'bpmn:Process')) {
return parent;
}
parent = parent.$parent;
}
}