Skip to content

Commit

Permalink
Extract the configuration of handlers for the shapes & the edges in o…
Browse files Browse the repository at this point in the history
…ther methods
  • Loading branch information
csouchet committed Feb 14, 2023
1 parent a4e84d7 commit fa2e9f1
Showing 1 changed file with 66 additions and 60 deletions.
126 changes: 66 additions & 60 deletions demo/draw-path/js/path-use-case.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,50 @@ class PathUseCase extends UseCase {

display() {
super.display();

const allShapes = this._getAllShapes();
const allEdges = this._getAllEdges();
this._bpmnElementIds = [...allShapes, ...allEdges].map(shapeOrEdge => shapeOrEdge.bpmnSemantic.id);
const endEventIds = allShapes.filter(shape => shape.bpmnSemantic.kind === bpmnvisu.ShapeBpmnElementKind.EVENT_END).map(endEvent => endEvent.bpmnSemantic.id);

this._configureShapeHandlers(allShapes, endEventIds);
this._configureEdgeHandlers(allEdges, endEventIds);

document.getElementById('btn-reset').onclick = () => {
this._reset();
this._disablePointerOn(endEventIds);
};
}

_getAllShapes() {
return this._bpmnVisualization.bpmnElementsRegistry.getElementsByKinds([
bpmnvisu.ShapeBpmnElementKind.EVENT_END,
bpmnvisu.ShapeBpmnElementKind.EVENT_BOUNDARY,
bpmnvisu.ShapeBpmnElementKind.EVENT_START,
bpmnvisu.ShapeBpmnElementKind.EVENT_INTERMEDIATE_CATCH,
bpmnvisu.ShapeBpmnElementKind.EVENT_INTERMEDIATE_THROW,
bpmnvisu.ShapeBpmnElementKind.CALL_ACTIVITY,
bpmnvisu.ShapeBpmnElementKind.SUB_PROCESS,
bpmnvisu.ShapeBpmnElementKind.TASK,
bpmnvisu.ShapeBpmnElementKind.TASK_BUSINESS_RULE,
bpmnvisu.ShapeBpmnElementKind.TASK_RECEIVE,
bpmnvisu.ShapeBpmnElementKind.TASK_MANUAL,
bpmnvisu.ShapeBpmnElementKind.TASK_SEND,
bpmnvisu.ShapeBpmnElementKind.TASK_SERVICE,
bpmnvisu.ShapeBpmnElementKind.TASK_SCRIPT,
bpmnvisu.ShapeBpmnElementKind.TASK_USER,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_EVENT_BASED,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_EXCLUSIVE,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_INCLUSIVE,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_PARALLEL]);
}

_getAllEdges() {
return this._bpmnVisualization.bpmnElementsRegistry.getElementsByKinds([
bpmnvisu.FlowKind.SEQUENCE_FLOW, bpmnvisu.FlowKind.MESSAGE_FLOW, bpmnvisu.FlowKind.ASSOCIATION_FLOW]);
}

_configureShapeHandlers(allShapes, endEventIds) {
allShapes.forEach(item => {
const currentId = item.bpmnSemantic.id;

Expand Down Expand Up @@ -55,70 +94,37 @@ class PathUseCase extends UseCase {
};
});
this._disablePointerOn(endEventIds);
}

_configureEdgeHandlers(allEdges, endEventIds) {
allEdges.forEach(item => {
const currentId = item.bpmnSemantic.id;

item.htmlElement.onclick = () => {
if (this._state.firstSelectedShape && this._state.secondSelectedShape) {
this._reset();
}

this._doActionOnEdge(currentId, (filteredPath) => {
if (!this._state.firstSelectedShape) {
this._disableAllShapesAndEdgesExcept([filteredPath.sourceId]);
this._highlight(filteredPath.sourceId);
this._state.firstSelectedShape = filteredPath.sourceId;
}
this._highlight([filteredPath.edgeId, filteredPath.targetId]);
this._activatePointerOn(this._bpmnElementIds);
this._disablePointerOn(endEventIds);
this._state.secondSelectedShape = filteredPath.targetId;
this._steps.goToStep3();
});
};
item.htmlElement.onmouseenter = () => {
this._doActionOnEdge(currentId, (filteredPath) => this._displayPossibleNext(filteredPath));
};
item.htmlElement.onmouseleave = () => {
this._doActionOnEdge(currentId, (filteredPath) => this._nonDisplayPossibleNext(filteredPath));
};
}
)
;

document.getElementById('btn-reset').onclick = () => {
this._reset();
this._disablePointerOn(endEventIds);
};
}
const currentId = item.bpmnSemantic.id;

_getAllShapes() {
return this._bpmnVisualization.bpmnElementsRegistry.getElementsByKinds([
bpmnvisu.ShapeBpmnElementKind.EVENT_END,
bpmnvisu.ShapeBpmnElementKind.EVENT_BOUNDARY,
bpmnvisu.ShapeBpmnElementKind.EVENT_START,
bpmnvisu.ShapeBpmnElementKind.EVENT_INTERMEDIATE_CATCH,
bpmnvisu.ShapeBpmnElementKind.EVENT_INTERMEDIATE_THROW,
bpmnvisu.ShapeBpmnElementKind.CALL_ACTIVITY,
bpmnvisu.ShapeBpmnElementKind.SUB_PROCESS,
bpmnvisu.ShapeBpmnElementKind.TASK,
bpmnvisu.ShapeBpmnElementKind.TASK_BUSINESS_RULE,
bpmnvisu.ShapeBpmnElementKind.TASK_RECEIVE,
bpmnvisu.ShapeBpmnElementKind.TASK_MANUAL,
bpmnvisu.ShapeBpmnElementKind.TASK_SEND,
bpmnvisu.ShapeBpmnElementKind.TASK_SERVICE,
bpmnvisu.ShapeBpmnElementKind.TASK_SCRIPT,
bpmnvisu.ShapeBpmnElementKind.TASK_USER,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_EVENT_BASED,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_EXCLUSIVE,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_INCLUSIVE,
bpmnvisu.ShapeBpmnElementKind.GATEWAY_PARALLEL]);
}
item.htmlElement.onclick = () => {
if (this._state.firstSelectedShape && this._state.secondSelectedShape) {
this._reset();
}

_getAllEdges() {
return this._bpmnVisualization.bpmnElementsRegistry.getElementsByKinds([
bpmnvisu.FlowKind.SEQUENCE_FLOW, bpmnvisu.FlowKind.MESSAGE_FLOW, bpmnvisu.FlowKind.ASSOCIATION_FLOW]);
this._doActionOnEdge(currentId, (filteredPath) => {
if (!this._state.firstSelectedShape) {
this._disableAllShapesAndEdgesExcept([filteredPath.sourceId]);
this._highlight(filteredPath.sourceId);
this._state.firstSelectedShape = filteredPath.sourceId;
}
this._highlight([filteredPath.edgeId, filteredPath.targetId]);
this._activatePointerOn(this._bpmnElementIds);
this._disablePointerOn(endEventIds);
this._state.secondSelectedShape = filteredPath.targetId;
this._steps.goToStep3();
});
};
item.htmlElement.onmouseenter = () => {
this._doActionOnEdge(currentId, (filteredPath) => this._displayPossibleNext(filteredPath));
};
item.htmlElement.onmouseleave = () => {
this._doActionOnEdge(currentId, (filteredPath) => this._nonDisplayPossibleNext(filteredPath));
};
});
}

_doActionBeforeSecondShapeSelection(possibleSecondShapeId, action) {
Expand Down

0 comments on commit fa2e9f1

Please sign in to comment.