Skip to content

Commit

Permalink
Merge pull request #12 from s4hri/fix/auto_fsm
Browse files Browse the repository at this point in the history
Fixed issue with state transition wrongly triggered when the machine …
  • Loading branch information
ddetommaso authored Oct 17, 2024
2 parents 0d309b2 + 52bdc60 commit ed5218a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/app/plugins/fsm/fsm.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,12 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit, OnDestr
this.fsmGetCurrentProcess().subscribe(reqID => {

this.currentNodeID = currentNode.id;
this.graphy.setFocusToNode(currentNode.id);

const onRunning = () => {
if(this.previousNodeID) {
this.updateNodeState(this.getNodeByID(this.previousNodeID), NodeStatus.INACTIVE);
this.graphy.setFocusToNode(this.previousNodeID);
if(this.previousNodeID == currentNode.id) {
return;
}
this.updateNodeState(currentNode, NodeStatus.RUNNING);
this.graphy.setFocusToNode(currentNode.id);
};

const onDone = () => {
Expand All @@ -98,7 +95,15 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit, OnDestr
this.updateNodeState(reachableNode, NodeStatus.ACTIVE);
}
this.previousNodeID = currentNode.id;
this.graphy.setFocusToNode(currentNode.id);

const existsInTerminalNodes = this.terminalNodes.some(node => node.nodeID === currentNode.id);
if (existsInTerminalNodes) {
for (let node of this.nodes) {
if (node.id !== this.startingNode.nodeID) {
this.updateNodeState(node, NodeStatus.INACTIVE);
}
}
}
};

const onFailed = () => {
Expand All @@ -108,7 +113,6 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit, OnDestr
this.updateNodeState(reachableNode, NodeStatus.ACTIVE);
}
this.previousNodeID = currentNode.id;
this.graphy.setFocusToNode(currentNode.id);
};

const onTimeout = () => {
Expand All @@ -118,7 +122,6 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit, OnDestr
this.updateNodeState(reachableNode, NodeStatus.ACTIVE);
}
this.previousNodeID = currentNode.id;
this.graphy.setFocusToNode(currentNode.id);
};

// Call checkAsyncRequestStatus with the current state passed to onRunning
Expand Down Expand Up @@ -229,7 +232,8 @@ export class FsmComponent extends WidgetBaseComponent implements OnInit, OnDestr
isEdgeActive(edge: InputEdge) {
const targetNode = this.getNodeByID(edge.targetId);
const sourceNode = this.getNodeByID(edge.sourceId);
return sourceNode.data.state !== NodeStatus.INACTIVE && targetNode.data.state === NodeStatus.ACTIVE;
//return sourceNode.data.state !== NodeStatus.INACTIVE && targetNode.data.state === NodeStatus.ACTIVE;
return (sourceNode.data.state !== NodeStatus.INACTIVE && targetNode.data.state === NodeStatus.ACTIVE) || (sourceNode.data.state == NodeStatus.DONE)
}

onNodeClick(selectedNode: InputNode<nodeData>) {
Expand Down

0 comments on commit ed5218a

Please sign in to comment.