Added button for choosing to validate subflows

This commit is contained in:
frikky
2021-05-19 10:11:42 +02:00
parent 1edca6c5b6
commit 892fc768eb
2 changed files with 125 additions and 80 deletions
+83 -64
View File
@@ -1024,7 +1024,7 @@ func handleWorkflowQueue(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Workflowexecution is aborted because of %s with result %s and status %s"}`, workflowExecution.LastNode, workflowExecution.Result, workflowExecution.Status)))
return
} else {
log.Printf("Continuing even though it's aborted.")
log.Printf("[WARNING] Continuing workflow even though it's aborted (ExitOnError config)")
}
}
@@ -1936,6 +1936,7 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request
}
}
removeTriggers := []string{}
for triggerIndex, trigger := range workflowExecution.Workflow.Triggers {
//log.Printf("[INFO] ID: %s vs %s", trigger.ID, workflowExecution.Start)
if trigger.ID == workflowExecution.Start {
@@ -1976,80 +1977,98 @@ func handleExecution(id string, workflow shuffle.Workflow, request *http.Request
})
} else {
// Replaces trigger with the subflow
if trigger.AppName == "Shuffle Workflow" {
replaceActions := false
workflowAction := ""
for _, param := range trigger.Parameters {
if param.Name == "argument" && !strings.Contains(param.Value, ".#") {
replaceActions = true
}
//if trigger.AppName == "Shuffle Workflow" {
// replaceActions := false
// workflowAction := ""
// for _, param := range trigger.Parameters {
// if param.Name == "argument" && !strings.Contains(param.Value, ".#") {
// replaceActions = true
// }
if param.Name == "startnode" {
workflowAction = param.Value
}
}
// if param.Name == "startnode" {
// workflowAction = param.Value
// }
// }
if replaceActions {
replacementNodes, newBranches, lastnode := shuffle.GetReplacementNodes(ctx, workflowExecution, trigger)
log.Printf("REPLACEMENTS: %d, %d", len(replacementNodes), len(newBranches))
if len(replacementNodes) > 0 {
//workflowExecution.Workflow.Actions = append(workflowExecution.Workflow.Actions, action)
// if replaceActions {
// replacementNodes, newBranches, lastnode := shuffle.GetReplacementNodes(ctx, workflowExecution, trigger, trigger.Label)
// log.Printf("REPLACEMENTS: %d, %d", len(replacementNodes), len(newBranches))
// if len(replacementNodes) > 0 {
// for _, action := range replacementNodes {
// found := false
//lastnode = replacementNodes[0]
// Have to validate in case it's the same workflow and such
for _, action := range replacementNodes {
found := false
for subActionIndex, subaction := range newActions {
if subaction.ID == action.ID {
found = true
//newActions[subActionIndex].Name = action.Name
newActions[subActionIndex].Label = action.Label
break
}
}
// for subActionIndex, subaction := range newActions {
// if subaction.ID == action.ID {
// found = true
// //newActions[subActionIndex].Name = action.Name
// newActions[subActionIndex].Label = action.Label
// break
// }
// }
if !found {
newActions = append(newActions, action)
}
// if !found {
// action.SubAction = true
// newActions = append(newActions, action)
// }
// Check if it's already set to have a value
for resultIndex, result := range defaultResults {
if result.Action.ID == action.ID {
defaultResults = append(defaultResults[:resultIndex], defaultResults[resultIndex+1:]...)
break
// // Check if it's already set to have a value
// for resultIndex, result := range defaultResults {
// if result.Action.ID == action.ID {
// defaultResults = append(defaultResults[:resultIndex], defaultResults[resultIndex+1:]...)
// break
// }
// }
// }
// for _, branch := range newBranches {
// workflowExecution.Workflow.Branches = append(workflowExecution.Workflow.Branches, branch)
// }
// // Append branches:
// // parent -> new inner node (FIRST one)
// for branchIndex, branch := range workflowExecution.Workflow.Branches {
// if branch.DestinationID == trigger.ID {
// log.Printf("REPLACE DESTINATION WITH %s!!", workflowAction)
// workflowExecution.Workflow.Branches[branchIndex].DestinationID = workflowAction
// }
// if branch.SourceID == trigger.ID {
// log.Printf("REPLACE SOURCE WITH LASTNODE %s!!", lastnode)
// workflowExecution.Workflow.Branches[branchIndex].SourceID = lastnode
// }
// }
// // Remove the trigger
// removeTriggers = append(removeTriggers, workflowExecution.Workflow.Triggers[triggerIndex].ID)
// }
// log.Printf("NEW ACTION LENGTH %d, RESULT: %d, Triggers: %d, BRANCHES: %d", len(newActions), len(defaultResults), len(workflowExecution.Workflow.Triggers), len(workflowExecution.Workflow.Branches))
// }
//}
_ = triggerIndex
}
}
}
for _, branch := range newBranches {
workflowExecution.Workflow.Branches = append(workflowExecution.Workflow.Branches, branch)
}
//newTriggers := []shuffle.Trigger{}
//for _, trigger := range workflowExecution.Workflow.Triggers {
// found := false
// for _, triggerId := range removeTriggers {
// if trigger.ID == triggerId {
// found = true
// break
// }
// }
// Append branches:
// parent -> new inner node (FIRST one)
for branchIndex, branch := range workflowExecution.Workflow.Branches {
if branch.DestinationID == trigger.ID {
log.Printf("REPLACE DESTINATION WITH %s!!", workflowAction)
workflowExecution.Workflow.Branches[branchIndex].DestinationID = workflowAction
}
// if found {
// log.Printf("[WARNING] Removed trigger %s during execution", trigger.ID)
// continue
// }
if branch.SourceID == trigger.ID {
log.Printf("REPLACE SOURCE WITH LASTNODE %s!!", lastnode)
workflowExecution.Workflow.Branches[branchIndex].SourceID = lastnode
}
}
// Remove the trigger
workflowExecution.Workflow.Triggers = append(workflowExecution.Workflow.Triggers[:triggerIndex], workflowExecution.Workflow.Triggers[triggerIndex+1:]...)
workflow.Triggers = append(workflow.Triggers[:triggerIndex], workflow.Triggers[triggerIndex+1:]...)
}
log.Printf("NEW ACTION LENGTH %d, RESULT: %d, Triggers: %d", len(newActions), len(defaultResults), len(workflowExecution.Workflow.Triggers))
}
}
}
}
}
// newTriggers = append(newTriggers, trigger)
//}
//workflowExecution.Workflow.Triggers = newTriggers
_ = removeTriggers
if !startFound {
if len(workflowExecution.Start) == 0 && len(workflowExecution.Workflow.Start) > 0 {
+35 -9
View File
@@ -554,9 +554,9 @@ const AngularWorkflow = (props) => {
if (executionData.execution_id === undefined || (responseJson.execution_id === executionData.execution_id && responseJson.results !== undefined && responseJson.results !== null)) {
if (executionData.status !== responseJson.status || executionData.result !== responseJson.result || executionData.results.length !== responseJson.results.length) {
console.log("Updated state with this data:")
console.log(responseJson)
console.log(executionData)
//console.log("Updated state with this data:")
//console.log(responseJson)
//console.log(executionData)
setExecutionData(responseJson)
} else {
console.log("NOT updating state.")
@@ -1731,6 +1731,7 @@ const AngularWorkflow = (props) => {
console.log(tmpapp)
console.log(curaction)
setSelectedApp(tmpapp)
//setSelectedAction(JSON.parse(JSON.stringify(curaction)))
setSelectedAction(curaction)
//return
} else {
@@ -1779,6 +1780,7 @@ const AngularWorkflow = (props) => {
curaction.selectedAuthentication = {}
}
//setSelectedAction(JSON.parse(JSON.stringify(curaction)))
setSelectedApp(curapp)
setSelectedAction(curaction)
@@ -3365,7 +3367,7 @@ const AngularWorkflow = (props) => {
if (data.name !== "User Input" && data.name !== "Shuffle Workflow") {
//workflow.branches.push(newbranch)
//cy.add(edgeToBeAdded)
cy.add(edgeToBeAdded)
}
setWorkflow(workflow)
@@ -3865,7 +3867,7 @@ const AngularWorkflow = (props) => {
}
if (currentnode.data() === undefined) {
console.log("Node doesn't have any data (getParents)! Probably a trigger.")
//console.log("Node doesn't have any data (getParents)! Probably a trigger.")
handled.push(allkeys[key])
results.push({"id": allkeys[key], "type": "TRIGGER"})
} else {
@@ -5037,7 +5039,7 @@ const AngularWorkflow = (props) => {
}
console.log("ACTIONS: ", actionlist)
//console.log("ACTIONS: ", actionlist)
setActionlist(actionlist)
}
@@ -5260,6 +5262,7 @@ const AngularWorkflow = (props) => {
workflow.triggers[selectedTriggerIndex].parameters[1] = {"name": "argument", "value": ""}
workflow.triggers[selectedTriggerIndex].parameters[2] = {"name": "user_apikey", "value": ""}
workflow.triggers[selectedTriggerIndex].parameters[3] = {"name": "startnode", "value": ""}
workflow.triggers[selectedTriggerIndex].parameters[4] = {"name": "check_result", "value": "true"}
console.log("SETTINGS: ", userSettings)
if (userSettings !== undefined && userSettings !== null && userSettings.apikey !== null && userSettings.apikey !== undefined && userSettings.apikey.length > 0) {
@@ -5295,6 +5298,27 @@ const AngularWorkflow = (props) => {
placeholder={selectedTrigger.label}
onChange={selectedTriggerChange}
/>
<FormControlLabel
control={
<Checkbox
checked={workflow.triggers[selectedTriggerIndex].parameters[4] !== undefined && workflow.triggers[selectedTriggerIndex].parameters[4].value === "true"}
onChange={() => {
const newvalue = workflow.triggers[selectedTriggerIndex].parameters[4] === undefined || workflow.triggers[selectedTriggerIndex].parameters[4].value === "false" ? "true" : "false"
workflow.triggers[selectedTriggerIndex].parameters[4] = {
"name": "check_result",
"value": newvalue,
}
setWorkflow(workflow)
setUpdate(Math.random())
}}
color="primary"
value="Wait for results"
/>
}
style={{marginTop: 10}}
label={<div style={{color: "white"}}>Wait for results</div>}
/>
<Divider style={{marginTop: "20px", height: "1px", width: "100%", backgroundColor: "rgb(91, 96, 100)"}}/>
<div style={{flex: "6", marginTop: "20px"}}>
<div>
@@ -5384,7 +5408,7 @@ const AngularWorkflow = (props) => {
fullWidth
onChange={(e) => {
setSubworkflowStartnode(e.target.value)
console.log("WF: ", workflow)
//console.log("WF: ", workflow)
const branchId = uuid.v4()
const newbranch = {
@@ -5418,6 +5442,7 @@ const AngularWorkflow = (props) => {
}
}
if (workflow.id == subworkflow.id) {
const cybranch = {
group: "edges",
source: newbranch.source_id,
@@ -5427,6 +5452,7 @@ const AngularWorkflow = (props) => {
}
cy.add(cybranch)
}
try {
workflow.triggers[selectedTriggerIndex].parameters[3].value = e.target.value.id
@@ -7017,7 +7043,7 @@ const AngularWorkflow = (props) => {
{executionData.status !== undefined && executionData.status.length > 0 ?
<div style={{display: "flex"}}>
<Typography variant="body1">
<b>Status &nbsp;</b>
<b>Status &nbsp;&nbsp;</b>
</Typography>
<Typography variant="body1" color="textSecondary">
{executionData.status}
@@ -7144,7 +7170,7 @@ const AngularWorkflow = (props) => {
}
return (
<div key={index} style={{marginBottom: 40,}} onMouseOver={() => {
<div key={index} style={{marginBottom: 40, border: data.action.sub_action === true ? "1px solid rgba(255,255,255,0.3)" : null, borderRadius: theme.palette.borderRadius,}} onMouseOver={() => {
var currentnode = cy.getElementById(data.action.id)
if (currentnode.length !== 0) {
currentnode.addClass('shuffle-hover-highlight')