diff --git a/frontend/src/views/AngularWorkflow.jsx b/frontend/src/views/AngularWorkflow.jsx index 638234d5..43571456 100644 --- a/frontend/src/views/AngularWorkflow.jsx +++ b/frontend/src/views/AngularWorkflow.jsx @@ -13,7 +13,7 @@ import NestedMenuItem from "material-ui-nested-menu-item"; import ReactMarkdown from "react-markdown"; import { useAlert } from "react-alert"; import theme from '../theme'; -import { isMobile } from "react-device-detect" +import { isMobile } from "react-device-detect" import aa from 'search-insights' import Drift from "react-driftjs"; @@ -25,9 +25,9 @@ import { InstantSearch, Configure, connectSearchBox, connectHits, Index } from ' import algoliasearch from 'algoliasearch/lite'; import { - Zoom, - Avatar, - Popover, + Zoom, + Avatar, + Popover, TextField, Drawer, Button, @@ -50,31 +50,31 @@ import { IconButton, Menu, Input, - Fade, + Fade, FormGroup, FormControlLabel, Typography, Checkbox, Breadcrumbs, CircularProgress, - SwipeableDrawer, + SwipeableDrawer, Switch, - Chip, - Card, - List, - ListItem, - ListItemText, - ListItemAvatar, - Badge, + Chip, + Card, + List, + ListItem, + ListItemText, + ListItemAvatar, + Badge, } from "@material-ui/core"; import { - AvatarGroup, + AvatarGroup, } from "@mui/material" import { - Folder as FolderIcon, - LibraryBooks as LibraryBooksIcon, + Folder as FolderIcon, + LibraryBooks as LibraryBooksIcon, OpenInNew as OpenInNewIcon, Undo as UndoIcon, GetApp as GetAppIcon, @@ -105,12 +105,12 @@ import { ExpandMore as ExpandMoreIcon, VpnKey as VpnKeyIcon, AddComment as AddCommentIcon, - Edit as EditIcon, + Edit as EditIcon, } from "@material-ui/icons"; import { - Preview as PreviewIcon, - ContentCopy as ContentCopyIcon, + Preview as PreviewIcon, + ContentCopy as ContentCopyIcon, } from '@mui/icons-material'; import Autocomplete from "@material-ui/lab/Autocomplete"; @@ -132,8 +132,9 @@ import ConfigureWorkflow from "../components/ConfigureWorkflow.jsx"; import AuthenticationOauth2 from "../components/Oauth2Auth.jsx"; import ParsedAction from "../components/ParsedAction.jsx"; import PaperComponent from "../components/PaperComponent.jsx" -import ExtraApps from "../components/ExtraApps.jsx" -import EditWorkflow from "../components/EditWorkflow.jsx" +import ExtraApps from "../components/ExtraApps.jsx" +import EditWorkflow from "../components/EditWorkflow.jsx" +import AppStats from "../components/AppStats.jsx"; const surfaceColor = "#27292D"; const inputColor = "#383B40"; @@ -250,15 +251,14 @@ const svgSize = 24; const searchClient = algoliasearch("JNSS5CFDZZ", "db08e40265e2941b9a7d8f644b6e5240") const AngularWorkflow = (defaultprops) => { - const { globalUrl, isLoggedIn, isLoaded, userdata } = defaultprops; + const { globalUrl, isLoggedIn, isLoaded, userdata, data_id } = defaultprops; const referenceUrl = globalUrl + "/api/v1/hooks/"; const alert = useAlert() - let navigate = useNavigate(); - - const params = useParams(); - var props = JSON.parse(JSON.stringify(defaultprops)) - props.match = {} - props.match.params = params + let navigate = useNavigate(); + const params = useParams(); + var props = JSON.parse(JSON.stringify(defaultprops)) + props.match = {} + props.match.params = params const green = "#86c142"; const yellow = "#FECC00"; @@ -286,10 +286,10 @@ const AngularWorkflow = (defaultprops) => { const [creatorProfile, setCreatorProfile] = React.useState({}); const [usecases, setUsecases] = React.useState([]); const [files, setFiles] = React.useState({ - "namespaces": [ - "default", - ] - }); + "namespaces": [ + "default", + ] + }); const [appGroup, setAppGroup] = React.useState([]); const [triggerGroup, setTriggerGroup] = React.useState([]); const [executionText, setExecutionText] = React.useState(""); @@ -303,7 +303,7 @@ const AngularWorkflow = (defaultprops) => { const [history, setHistory] = React.useState([]); const [historyIndex, setHistoryIndex] = React.useState(history.length); - const [variableInfo, setVariableInfo] = React.useState({}) + const [variableInfo, setVariableInfo] = React.useState({}) const [appAuthentication, setAppAuthentication] = React.useState([]); const [variablesModalOpen, setVariablesModalOpen] = React.useState(false); @@ -379,10 +379,11 @@ const AngularWorkflow = (defaultprops) => { const [executionData, setExecutionData] = React.useState({}); const [appsLoaded, setAppsLoaded] = React.useState(false); const [showVideo, setShowVideo] = React.useState(""); - const [editWorkflowModalOpen, setEditWorkflowModalOpen] = React.useState(false); + const [editWorkflowModalOpen, setEditWorkflowModalOpen] = React.useState(false); const [userediting, setUserediting] = React.useState(false) const [lastSaved, setLastSaved] = React.useState(true); + const [selectionOpen, setSelectionOpen] = React.useState(false); // eslint-disable-next-line no-unused-vars const [_, setUpdate] = useState(""); // Used for rendring, don't remove @@ -394,8 +395,8 @@ const AngularWorkflow = (defaultprops) => { // Use states and don't update lol const cloudSyncEnabled = props.userdata !== undefined && - props.userdata.active_org !== null && - props.userdata.active_org !== undefined + props.userdata.active_org !== null && + props.userdata.active_org !== undefined ? props.userdata.active_org.cloud_sync === true : false; const isCloud = @@ -407,8 +408,8 @@ const AngularWorkflow = (defaultprops) => { const classes = useStyles(); const [bodyWidth, bodyHeight] = useWindowSize() - //console.log("Mobile: ", isMobile, bodyWidth, bodyHeight) - const cytoscapeWidth = isMobile ? bodyWidth - leftBarSize : bodyWidth - leftBarSize - 25 + //console.log("Mobile: ", isMobile, bodyWidth, bodyHeight) + const cytoscapeWidth = isMobile ? bodyWidth - leftBarSize : bodyWidth - leftBarSize - 25 const [elements, setElements] = useState([]); @@ -439,16 +440,16 @@ const AngularWorkflow = (defaultprops) => { return response.json(); }) .then((responseJson) => { - if (responseJson.success === true) { - if (responseJson.reason !== undefined && responseJson.reason !== undefined && responseJson.reason.length > 0) { - if (!responseJson.reason.includes("404: Not Found") && responseJson.reason.length > 25) { - selectedApp.documentation = responseJson.reason - setSelectedApp(selectedApp) - setUpdate(Math.random()) - } - } - } - + if (responseJson.success === true) { + if (responseJson.reason !== undefined && responseJson.reason !== undefined && responseJson.reason.length > 0) { + if (!responseJson.reason.includes("404: Not Found") && responseJson.reason.length > 25) { + selectedApp.documentation = responseJson.reason + setSelectedApp(selectedApp) + setUpdate(Math.random()) + } + } + } + }) .catch((error) => { alert.error(error.toString()); @@ -456,19 +457,19 @@ const AngularWorkflow = (defaultprops) => { }; useEffect(() => { - if (authenticationModalOpen === true && selectedAction.app_name !== undefined) { - console.log(`Should get app docs for: ${selectedAction.app_name}`) - //console.log(selectedAction) - //console.log("APP: ", selectedApp) + if (authenticationModalOpen === true && selectedAction.app_name !== undefined) { + console.log(`Should get app docs for: ${selectedAction.app_name}`) + //console.log(selectedAction) + //console.log("APP: ", selectedApp) - if (selectedAction.documentation === undefined || selectedAction.documentation === null || selectedAction.documentation.length === 0) { - // SelectedApp.documentation = Markdown? If so, it works - // - const apptype = selectedApp.generated === false ? "python" : "openapi" - getAppDocs(selectedAction.app_name, apptype, selectedAction.app_version) - } - } - }, [authenticationModalOpen]) + if (selectedAction.documentation === undefined || selectedAction.documentation === null || selectedAction.documentation.length === 0) { + // SelectedApp.documentation = Markdown? If so, it works + // + const apptype = selectedApp.generated === false ? "python" : "openapi" + getAppDocs(selectedAction.app_name, apptype, selectedAction.app_version) + } + } + }, [authenticationModalOpen]) const getAvailableWorkflows = (trigger_index) => { fetch(globalUrl + "/api/v1/workflows", { @@ -492,7 +493,7 @@ const AngularWorkflow = (defaultprops) => { // Sets up subflow trigger with the right info if (trigger_index > -1) { - var baseSubflow = {} + var baseSubflow = {} const trigger = workflow.triggers[trigger_index]; if (trigger.parameters.length >= 3) { for (var key in trigger.parameters) { @@ -501,13 +502,13 @@ const AngularWorkflow = (defaultprops) => { if (param.name === "workflow") { if (param.value === workflow.id) { setSubworkflow(workflow); - baseSubflow = workflow + baseSubflow = workflow } else { const sub = responseJson.find( (data) => data.id === param.value ); if (sub !== undefined && subworkflow.id !== sub.id) { - baseSubflow = sub + baseSubflow = sub setSubworkflow(sub); } } @@ -518,14 +519,14 @@ const AngularWorkflow = (defaultprops) => { param.value !== undefined && param.value !== null ) { - if (Object.getOwnPropertyNames(baseSubflow).length > 0) { - const foundAction = baseSubflow.actions.find(action => action.id === param.value) - if (foundAction !== null && foundAction !== undefined) { - setSubworkflowStartnode(foundAction); - } - } else { - setSubworkflowStartnode(param.value); - } + if (Object.getOwnPropertyNames(baseSubflow).length > 0) { + const foundAction = baseSubflow.actions.find(action => action.id === param.value) + if (foundAction !== null && foundAction !== undefined) { + setSubworkflowStartnode(foundAction); + } + } else { + setSubworkflowStartnode(param.value); + } } } } @@ -644,17 +645,17 @@ const AngularWorkflow = (defaultprops) => { }) .then((responseJson) => { if ( - responseJson.success === true && + responseJson.success === true && (responseJson.apikey === undefined || - responseJson.apikey.length === 0 || - responseJson.apikey === null) + responseJson.apikey.length === 0 || + responseJson.apikey === null) ) { generateApikey(); } - if (responseJson.success === true) { - setUserSettings(responseJson) - } + if (responseJson.success === true) { + setUserSettings(responseJson) + } }) .catch((error) => { console.log("Settings error: ", error); @@ -750,27 +751,27 @@ const AngularWorkflow = (defaultprops) => { }); const newitem = removeParam("execution_id", cursearch); - navigate(curpath + newitem) + navigate(curpath + newitem) //props.history.push(curpath + newitem); } else { - console.log("Couldn't find execution for execution ID. Retrying as user to get ", tmpView) + console.log("Couldn't find execution for execution ID. Retrying as user to get ", tmpView) - //setExecutionRequestStarted(true); - const cur_execution = { - execution_id: tmpView, - //authorization: data.authorization, + //setExecutionRequestStarted(true); + const cur_execution = { + execution_id: tmpView, + //authorization: data.authorization, } setExecutionModalView(1); setExecutionRequest(cur_execution); - start(); + start(); const newitem = removeParam("execution_id", cursearch); - navigate(curpath + newitem) + navigate(curpath + newitem) - setTimeout(() => { - stop() - }, 5000); - } + setTimeout(() => { + stop() + }, 5000); + } } } }) @@ -799,7 +800,7 @@ const AngularWorkflow = (defaultprops) => { return response.json(); }) .then((responseJson) => { - //console.log("RESPONSE: ", responseJson) + //console.log("RESPONSE: ", responseJson) handleUpdateResults(responseJson, executionRequest); }) .catch((error) => { @@ -813,11 +814,11 @@ const AngularWorkflow = (defaultprops) => { fetch( globalUrl + - "/api/v1/workflows/" + - props.match.params.key + - "/executions/" + - executionRequest.execution_id + - "/abort", + "/api/v1/workflows/" + + props.match.params.key + + "/executions/" + + executionRequest.execution_id + + "/abort", { method: "GET", headers: { @@ -847,212 +848,212 @@ const AngularWorkflow = (defaultprops) => { // Loop nodes and find results // Update on every interval? idk - ReactDOM.unstable_batchedUpdates(() => { - if (JSON.stringify(responseJson) !== JSON.stringify(executionData)) { - // FIXME: If another is selected, don't edit.. - // Doesn't work because this is some async garbage - 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 - ) { - setExecutionData(responseJson); - } else { - //console.log("NOT updating state."); - } - } - } + ReactDOM.unstable_batchedUpdates(() => { + if (JSON.stringify(responseJson) !== JSON.stringify(executionData)) { + // FIXME: If another is selected, don't edit.. + // Doesn't work because this is some async garbage + 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 + ) { + setExecutionData(responseJson); + } else { + //console.log("NOT updating state."); + } + } + } - if (responseJson.execution_id !== executionRequest.execution_id) { - cy.elements().removeClass( - "success-highlight failure-highlight executing-highlight" - ); - return; - } + if (responseJson.execution_id !== executionRequest.execution_id) { + cy.elements().removeClass( + "success-highlight failure-highlight executing-highlight" + ); + return; + } - if (responseJson.results !== null && responseJson.results.length > 0) { - for (var key in responseJson.results) { - var item = responseJson.results[key]; - var currentnode = cy.getElementById(item.action.id); - if (currentnode.length === 0) { - continue; - } + if (responseJson.results !== null && responseJson.results.length > 0) { + for (var key in responseJson.results) { + var item = responseJson.results[key]; + var currentnode = cy.getElementById(item.action.id); + if (currentnode.length === 0) { + continue; + } - currentnode = currentnode[0]; - const outgoingEdges = currentnode.outgoers("edge"); - const incomingEdges = currentnode.incomers("edge"); + currentnode = currentnode[0]; + const outgoingEdges = currentnode.outgoers("edge"); + const incomingEdges = currentnode.incomers("edge"); - switch (item.status) { - case "EXECUTING": - currentnode.removeClass("not-executing-highlight"); - currentnode.removeClass("success-highlight"); - currentnode.removeClass("failure-highlight"); - currentnode.removeClass("shuffle-hover-highlight"); - currentnode.removeClass("awaiting-data-highlight"); - incomingEdges.addClass("success-highlight"); - currentnode.addClass("executing-highlight"); - break; - case "SKIPPED": - currentnode.removeClass("not-executing-highlight"); - currentnode.removeClass("success-highlight"); - currentnode.removeClass("failure-highlight"); - currentnode.removeClass("shuffle-hover-highlight"); - currentnode.removeClass("awaiting-data-highlight"); - currentnode.removeClass("executing-highlight"); - currentnode.addClass("skipped-highlight"); - break; - case "WAITING": - currentnode.removeClass("not-executing-highlight"); - currentnode.removeClass("success-highlight"); - currentnode.removeClass("failure-highlight"); - currentnode.removeClass("shuffle-hover-highlight"); - currentnode.removeClass("awaiting-data-highlight"); - currentnode.addClass("executing-highlight"); + switch (item.status) { + case "EXECUTING": + currentnode.removeClass("not-executing-highlight"); + currentnode.removeClass("success-highlight"); + currentnode.removeClass("failure-highlight"); + currentnode.removeClass("shuffle-hover-highlight"); + currentnode.removeClass("awaiting-data-highlight"); + incomingEdges.addClass("success-highlight"); + currentnode.addClass("executing-highlight"); + break; + case "SKIPPED": + currentnode.removeClass("not-executing-highlight"); + currentnode.removeClass("success-highlight"); + currentnode.removeClass("failure-highlight"); + currentnode.removeClass("shuffle-hover-highlight"); + currentnode.removeClass("awaiting-data-highlight"); + currentnode.removeClass("executing-highlight"); + currentnode.addClass("skipped-highlight"); + break; + case "WAITING": + currentnode.removeClass("not-executing-highlight"); + currentnode.removeClass("success-highlight"); + currentnode.removeClass("failure-highlight"); + currentnode.removeClass("shuffle-hover-highlight"); + currentnode.removeClass("awaiting-data-highlight"); + currentnode.addClass("executing-highlight"); - if (!visited.includes(item.action.label)) { - if (executionRunning) { - visited.push(item.action.label); - setVisited(visited); - } - } + if (!visited.includes(item.action.label)) { + if (executionRunning) { + visited.push(item.action.label); + setVisited(visited); + } + } - // FIXME - add outgoing nodes to executing - //const outgoingNodes = outgoingEdges.find().data().target - if (outgoingEdges.length > 0) { - outgoingEdges.addClass("success-highlight"); - } - break; - case "SUCCESS": - currentnode.removeClass("not-executing-highlight"); - currentnode.removeClass("executing-highlight"); - currentnode.removeClass("failure-highlight"); - currentnode.removeClass("shuffle-hover-highlight"); - currentnode.removeClass("awaiting-data-highlight"); - currentnode.addClass("success-highlight"); - incomingEdges.addClass("success-highlight"); - outgoingEdges.addClass("success-highlight"); + // FIXME - add outgoing nodes to executing + //const outgoingNodes = outgoingEdges.find().data().target + if (outgoingEdges.length > 0) { + outgoingEdges.addClass("success-highlight"); + } + break; + case "SUCCESS": + currentnode.removeClass("not-executing-highlight"); + currentnode.removeClass("executing-highlight"); + currentnode.removeClass("failure-highlight"); + currentnode.removeClass("shuffle-hover-highlight"); + currentnode.removeClass("awaiting-data-highlight"); + currentnode.addClass("success-highlight"); + incomingEdges.addClass("success-highlight"); + outgoingEdges.addClass("success-highlight"); - if ( - visited !== undefined && - visited !== null && - !visited.includes(item.action.label) - ) { - if (executionRunning) { - visited.push(item.action.label); - setVisited(visited); - } - } + if ( + visited !== undefined && + visited !== null && + !visited.includes(item.action.label) + ) { + if (executionRunning) { + visited.push(item.action.label); + setVisited(visited); + } + } - // FIXME - add outgoing nodes to executing - //const outgoingNodes = outgoingEdges.find().data().target - if (outgoingEdges.length > 0) { - for (var i = 0; i < outgoingEdges.length; i++) { - const edge = outgoingEdges[i]; - const targetnode = cy.getElementById(edge.data().target); - if ( - targetnode !== undefined && - !targetnode.classes().includes("success-highlight") && - !targetnode.classes().includes("failure-highlight") - ) { - targetnode.removeClass("not-executing-highlight"); - targetnode.removeClass("success-highlight"); - targetnode.removeClass("shuffle-hover-highlight"); - targetnode.removeClass("failure-highlight"); - targetnode.removeClass("awaiting-data-highlight"); - targetnode.addClass("executing-highlight"); - } - } - } - break; - case "FAILURE": - //When status comes as failure, allow user to start workflow execution - if (executionRunning) { - setExecutionRunning(false); - } + // FIXME - add outgoing nodes to executing + //const outgoingNodes = outgoingEdges.find().data().target + if (outgoingEdges.length > 0) { + for (var i = 0; i < outgoingEdges.length; i++) { + const edge = outgoingEdges[i]; + const targetnode = cy.getElementById(edge.data().target); + if ( + targetnode !== undefined && + !targetnode.classes().includes("success-highlight") && + !targetnode.classes().includes("failure-highlight") + ) { + targetnode.removeClass("not-executing-highlight"); + targetnode.removeClass("success-highlight"); + targetnode.removeClass("shuffle-hover-highlight"); + targetnode.removeClass("failure-highlight"); + targetnode.removeClass("awaiting-data-highlight"); + targetnode.addClass("executing-highlight"); + } + } + } + break; + case "FAILURE": + //When status comes as failure, allow user to start workflow execution + if (executionRunning) { + setExecutionRunning(false); + } - currentnode.removeClass("not-executing-highlight"); - currentnode.removeClass("executing-highlight"); - currentnode.removeClass("success-highlight"); - currentnode.removeClass("awaiting-data-highlight"); - currentnode.removeClass("shuffle-hover-highlight"); - currentnode.addClass("failure-highlight"); + currentnode.removeClass("not-executing-highlight"); + currentnode.removeClass("executing-highlight"); + currentnode.removeClass("success-highlight"); + currentnode.removeClass("awaiting-data-highlight"); + currentnode.removeClass("shuffle-hover-highlight"); + currentnode.addClass("failure-highlight"); - if (!visited.includes(item.action.label)) { - if ( - item.action.result !== undefined && - item.action.result !== null && - !item.action.result.includes("failed condition") - ) { - alert.error( - "Error for " + - item.action.label + - " with result " + - item.result - ); - } - visited.push(item.action.label); - setVisited(visited); - } - break; - case "AWAITING_DATA": - currentnode.removeClass("not-executing-highlight"); - currentnode.removeClass("executing-highlight"); - currentnode.removeClass("success-highlight"); - currentnode.removeClass("failure-highlight"); - currentnode.removeClass("shuffle-hover-highlight"); - currentnode.addClass("awaiting-data-highlight"); - break; - default: - console.log("DEFAULT?"); - break; - } - } - } + if (!visited.includes(item.action.label)) { + if ( + item.action.result !== undefined && + item.action.result !== null && + !item.action.result.includes("failed condition") + ) { + alert.error( + "Error for " + + item.action.label + + " with result " + + item.result + ); + } + visited.push(item.action.label); + setVisited(visited); + } + break; + case "AWAITING_DATA": + currentnode.removeClass("not-executing-highlight"); + currentnode.removeClass("executing-highlight"); + currentnode.removeClass("success-highlight"); + currentnode.removeClass("failure-highlight"); + currentnode.removeClass("shuffle-hover-highlight"); + currentnode.addClass("awaiting-data-highlight"); + break; + default: + console.log("DEFAULT?"); + break; + } + } + } - if ( - responseJson.status === "ABORTED" || - responseJson.status === "STOPPED" || - responseJson.status === "FAILURE" || - responseJson.status === "WAITING" - ) { - stop(); + if ( + responseJson.status === "ABORTED" || + responseJson.status === "STOPPED" || + responseJson.status === "FAILURE" || + responseJson.status === "WAITING" + ) { + stop(); - if (executionRunning) { - setExecutionRunning(false); - } + if (executionRunning) { + setExecutionRunning(false); + } - var curelements = cy.elements(); - for (var i = 0; i < curelements.length; i++) { - if (curelements[i].classes().includes("executing-highlight")) { - curelements[i].removeClass("executing-highlight"); - curelements[i].addClass("failure-highlight"); - } - } + var curelements = cy.elements(); + for (var i = 0; i < curelements.length; i++) { + if (curelements[i].classes().includes("executing-highlight")) { + curelements[i].removeClass("executing-highlight"); + curelements[i].addClass("failure-highlight"); + } + } - getWorkflowExecution(props.match.params.key, ""); - } else if (responseJson.status === "FINISHED") { - setExecutionRunning(false); - stop(); - getWorkflowExecution(props.match.params.key, ""); - setUpdate(Math.random()); - } - }) + getWorkflowExecution(props.match.params.key, ""); + } else if (responseJson.status === "FINISHED") { + setExecutionRunning(false); + stop(); + getWorkflowExecution(props.match.params.key, ""); + setUpdate(Math.random()); + } + }) }; - const sendStreamRequest = (body) => { - console.log("Stream not activated yet.") - return + const sendStreamRequest = (body) => { + console.log("Stream not activated yet.") + return - // Session may be important here huh - body.user_id = userdata.id + // Session may be important here huh + body.user_id = userdata.id - fetch(globalUrl + "/api/v1/workflows/" + props.match.params.key + "/stream", { + fetch(globalUrl + "/api/v1/workflows/" + props.match.params.key + "/stream", { method: "POST", headers: { "Content-Type": "application/json", @@ -1061,22 +1062,22 @@ const AngularWorkflow = (defaultprops) => { body: JSON.stringify(body), credentials: "include", }) - .then((response) => { - setSavingState(0); - if (response.status !== 200) { - console.log("Status not 200 for setting workflows :O!"); - } + .then((response) => { + setSavingState(0); + if (response.status !== 200) { + console.log("Status not 200 for setting workflows :O!"); + } - return response.json(); - }) - .then((responseJson) => { - console.log("RESP: ", responseJson) - }) - .catch((error) => { - console.log("Stream send error: ", error.toString()) - //alert.error(error.toString()); - }) - } + return response.json(); + }) + .then((responseJson) => { + console.log("RESP: ", responseJson) + }) + .catch((error) => { + console.log("Stream send error: ", error.toString()) + //alert.error(error.toString()); + }) + } const saveWorkflow = (curworkflow, executionArgument, startNode) => { var success = false; @@ -1087,283 +1088,283 @@ const AngularWorkflow = (defaultprops) => { return; } - setSavingState(2); + setSavingState(2); - // This might not be the right course of action, but seems logical, as items could be running already - // Makes it possible to update with a version in current render - stop(); - var useworkflow = workflow; - if (curworkflow !== undefined) { - useworkflow = curworkflow; - } + // This might not be the right course of action, but seems logical, as items could be running already + // Makes it possible to update with a version in current render + stop(); + var useworkflow = workflow; + if (curworkflow !== undefined) { + useworkflow = curworkflow; + } - var cyelements = cy.elements(); - var newActions = []; - var newTriggers = []; - var newBranches = []; - var newVBranches = []; - var newComments = []; - for (var key in cyelements) { - if (cyelements[key].data === undefined) { - continue; - } + var cyelements = cy.elements(); + var newActions = []; + var newTriggers = []; + var newBranches = []; + var newVBranches = []; + var newComments = []; + for (var key in cyelements) { + if (cyelements[key].data === undefined) { + continue; + } - var type = cyelements[key].data()["type"]; - if (type === undefined) { - if ( - cyelements[key].data().source === undefined || - cyelements[key].data().target === undefined - ) { - continue; - } + var type = cyelements[key].data()["type"]; + if (type === undefined) { + if ( + cyelements[key].data().source === undefined || + cyelements[key].data().target === undefined + ) { + continue; + } - var parsedElement = { - id: cyelements[key].data().id, - source_id: cyelements[key].data().source, - destination_id: cyelements[key].data().target, - conditions: cyelements[key].data().conditions, - decorator: cyelements[key].data().decorator, - }; + var parsedElement = { + id: cyelements[key].data().id, + source_id: cyelements[key].data().source, + destination_id: cyelements[key].data().target, + conditions: cyelements[key].data().conditions, + decorator: cyelements[key].data().decorator, + }; - if (parsedElement.decorator) { - newVBranches.push(parsedElement); - } else { - newBranches.push(parsedElement); - } - } else { - if (type === "ACTION") { - const cyelement = cyelements[key].data(); - const elementid = - cyelement.id === undefined || cyelement.id === null - ? cyelement["_id"] - : cyelement.id; + if (parsedElement.decorator) { + newVBranches.push(parsedElement); + } else { + newBranches.push(parsedElement); + } + } else { + if (type === "ACTION") { + const cyelement = cyelements[key].data(); + const elementid = + cyelement.id === undefined || cyelement.id === null + ? cyelement["_id"] + : cyelement.id; - var curworkflowAction = useworkflow.actions.find( - (a) => - a !== undefined && - (a["id"] === elementid || a["_id"] === elementid) - ); - if (curworkflowAction === undefined) { - curworkflowAction = cyelements[key].data(); - } + var curworkflowAction = useworkflow.actions.find( + (a) => + a !== undefined && + (a["id"] === elementid || a["_id"] === elementid) + ); + if (curworkflowAction === undefined) { + curworkflowAction = cyelements[key].data(); + } - curworkflowAction.position = cyelements[key].position(); + curworkflowAction.position = cyelements[key].position(); - // workaround to fix some edgecases - if ( - curworkflowAction.parameters === "" || - curworkflowAction.parameters === null - ) { - curworkflowAction.parameters = []; - } + // workaround to fix some edgecases + if ( + curworkflowAction.parameters === "" || + curworkflowAction.parameters === null + ) { + curworkflowAction.parameters = []; + } - if ( - curworkflowAction.example === undefined || - curworkflowAction.example === "" || - curworkflowAction.example === null - ) { - if (cyelements[key].data().example !== undefined) { - curworkflowAction.example = cyelements[key].data().example; - } - } + if ( + curworkflowAction.example === undefined || + curworkflowAction.example === "" || + curworkflowAction.example === null + ) { + if (cyelements[key].data().example !== undefined) { + curworkflowAction.example = cyelements[key].data().example; + } + } - // Override just in this place - curworkflowAction.errors = []; - curworkflowAction.isValid = true; + // Override just in this place + curworkflowAction.errors = []; + curworkflowAction.isValid = true; - // Cleans up OpenAPI items - var newparams = []; - for (var key in curworkflowAction.parameters) { - const thisitem = curworkflowAction.parameters[key]; - if (thisitem.name.startsWith("${") && thisitem.name.endsWith("}")) { - continue; - } + // Cleans up OpenAPI items + var newparams = []; + for (var key in curworkflowAction.parameters) { + const thisitem = curworkflowAction.parameters[key]; + if (thisitem.name.startsWith("${") && thisitem.name.endsWith("}")) { + continue; + } - newparams.push(thisitem); - } + newparams.push(thisitem); + } - curworkflowAction.parameters = newparams; - newActions.push(curworkflowAction); - } else if (type === "TRIGGER") { - if (useworkflow.triggers === undefined || useworkflow.triggers === null) { - useworkflow.triggers = []; - } + curworkflowAction.parameters = newparams; + newActions.push(curworkflowAction); + } else if (type === "TRIGGER") { + if (useworkflow.triggers === undefined || useworkflow.triggers === null) { + useworkflow.triggers = []; + } - var curworkflowTrigger = useworkflow.triggers.find( - (a) => a.id === cyelements[key].data()["id"] - ); - if (curworkflowTrigger === undefined) { - curworkflowTrigger = cyelements[key].data(); - } + var curworkflowTrigger = useworkflow.triggers.find( + (a) => a.id === cyelements[key].data()["id"] + ); + if (curworkflowTrigger === undefined) { + curworkflowTrigger = cyelements[key].data(); + } - curworkflowTrigger.position = cyelements[key].position(); - if (curworkflowTrigger.canConnect === false) { - continue - } + curworkflowTrigger.position = cyelements[key].position(); + if (curworkflowTrigger.canConnect === false) { + continue + } - newTriggers.push(curworkflowTrigger); - } else if (type === "COMMENT") { - if (useworkflow.comments === undefined || useworkflow.comments === null) { - useworkflow.comments = []; - } + newTriggers.push(curworkflowTrigger); + } else if (type === "COMMENT") { + if (useworkflow.comments === undefined || useworkflow.comments === null) { + useworkflow.comments = []; + } - var curworkflowComment = useworkflow.comments.find( - (a) => a.id === cyelements[key].data()["id"] - ) + var curworkflowComment = useworkflow.comments.find( + (a) => a.id === cyelements[key].data()["id"] + ) - if (curworkflowComment === undefined) { - curworkflowComment = cyelements[key].data(); - try { - curworkflowComment.position.x = parseInt(curworkflowComment.position.x) - } catch (e) { - console.log("Failed to parse position Y of comment: ", curworkflowComment.position.x) - } + if (curworkflowComment === undefined) { + curworkflowComment = cyelements[key].data(); + try { + curworkflowComment.position.x = parseInt(curworkflowComment.position.x) + } catch (e) { + console.log("Failed to parse position Y of comment: ", curworkflowComment.position.x) + } - try { - curworkflowComment.position.y = parseInt(curworkflowComment.position.y) - } catch (e) { - console.log("Failed to parse position Y of comment: ", curworkflowComment.position.y) - } - } + try { + curworkflowComment.position.y = parseInt(curworkflowComment.position.y) + } catch (e) { + console.log("Failed to parse position Y of comment: ", curworkflowComment.position.y) + } + } - const parsedHeight = parseInt(curworkflowComment["height"]) - if (!isNaN(parsedHeight)) { - curworkflowComment.height = parsedHeight - } else { - curworkflowComment.width = 150 - } + const parsedHeight = parseInt(curworkflowComment["height"]) + if (!isNaN(parsedHeight)) { + curworkflowComment.height = parsedHeight + } else { + curworkflowComment.width = 150 + } - const parsedWidth = parseInt(curworkflowComment["width"]) - if (!isNaN(parsedWidth)) { - curworkflowComment.width = parsedWidth - } else { - curworkflowComment.width = 200 - } + const parsedWidth = parseInt(curworkflowComment["width"]) + if (!isNaN(parsedWidth)) { + curworkflowComment.width = parsedWidth + } else { + curworkflowComment.width = 200 + } - curworkflowComment.position = cyelements[key].position(); - //console.log(curworkflowComment) + curworkflowComment.position = cyelements[key].position(); + //console.log(curworkflowComment) - newComments.push(curworkflowComment); - } else { - alert.info("No handler for type: " + type); - } - } - } + newComments.push(curworkflowComment); + } else { + alert.info("No handler for type: " + type); + } + } + } - if (userediting === true) { - useworkflow.user_editing = true - } + if (userediting === true) { + useworkflow.user_editing = true + } - useworkflow.actions = newActions; - useworkflow.triggers = newTriggers; - useworkflow.branches = newBranches; - useworkflow.comments = newComments; - useworkflow.visual_branches = newVBranches; + useworkflow.actions = newActions; + useworkflow.triggers = newTriggers; + useworkflow.branches = newBranches; + useworkflow.comments = newComments; + useworkflow.visual_branches = newVBranches; - // Errors are backend defined - useworkflow.errors = []; - useworkflow.previously_saved = true; + // Errors are backend defined + useworkflow.errors = []; + useworkflow.previously_saved = true; - if (cy !== undefined) { - // scale: 0.3, - // bg: "#27292d", - const cyImageData = cy.png({ - output: "base64uri", - maxWidth: 480, - maxHeight: 270, - }) + if (cy !== undefined) { + // scale: 0.3, + // bg: "#27292d", + const cyImageData = cy.png({ + output: "base64uri", + maxWidth: 480, + maxHeight: 270, + }) - if (cyImageData !== undefined && cyImageData !== null && cyImageData.length > 0) { - useworkflow.image = cyImageData - } - } + if (cyImageData !== undefined && cyImageData !== null && cyImageData.length > 0) { + useworkflow.image = cyImageData + } + } - setLastSaved(true); - fetch(globalUrl + "/api/v1/workflows/" + props.match.params.key, { - method: "PUT", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - body: JSON.stringify(useworkflow), - credentials: "include", - }) - .then((response) => { - setSavingState(0); - if (response.status !== 200) { - console.log("Status not 200 for setting workflows :O!"); - } + setLastSaved(true); + fetch(globalUrl + "/api/v1/workflows/" + props.match.params.key, { + method: "PUT", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + body: JSON.stringify(useworkflow), + credentials: "include", + }) + .then((response) => { + setSavingState(0); + if (response.status !== 200) { + console.log("Status not 200 for setting workflows :O!"); + } - return response.json(); - }) - .then((responseJson) => { - if (executionArgument !== undefined && startNode !== undefined) { - //console.log("Running execution AFTER saving"); - executeWorkflow(executionArgument, startNode, true); - return; - } + return response.json(); + }) + .then((responseJson) => { + if (executionArgument !== undefined && startNode !== undefined) { + //console.log("Running execution AFTER saving"); + executeWorkflow(executionArgument, startNode, true); + return; + } - if (!responseJson.success) { - console.log(responseJson); - if (responseJson.reason !== undefined && responseJson.reason !== null) { - alert.error("Failed to save: " + responseJson.reason); - } else { - alert.error("Failed to save. Please contact your support@shuffler.io or your local admin if this is unexpected.") - } - } else { + if (!responseJson.success) { + console.log(responseJson); + if (responseJson.reason !== undefined && responseJson.reason !== null) { + alert.error("Failed to save: " + responseJson.reason); + } else { + alert.error("Failed to save. Please contact your support@shuffler.io or your local admin if this is unexpected.") + } + } else { - sendStreamRequest({ - "item": "workflow", - "type": "save", - "id": workflow.id, - }) + sendStreamRequest({ + "item": "workflow", + "type": "save", + "id": workflow.id, + }) - if ( - responseJson.new_id !== undefined && - responseJson.new_id !== null - ) { - window.location.pathname = "/workflows/" + responseJson.new_id; - } + if ( + responseJson.new_id !== undefined && + responseJson.new_id !== null + ) { + window.location.pathname = "/workflows/" + responseJson.new_id; + } - success = true; - if (responseJson.errors !== undefined) { - workflow.errors = responseJson.errors; - if (responseJson.errors.length === 0) { - workflow.isValid = true; - workflow.is_valid = true; + success = true; + if (responseJson.errors !== undefined) { + workflow.errors = responseJson.errors; + if (responseJson.errors.length === 0) { + workflow.isValid = true; + workflow.is_valid = true; - const cyelements = cy.elements(); - - for (var i = 0; i < cyelements.length; i++) { - //cyelements[i].removeStyle(); - cyelements[i].data().is_valid = true; - cyelements[i].data().errors = []; - } + const cyelements = cy.elements(); - for (var key in workflow.actions) { - workflow.actions[key].is_valid = true; - workflow.actions[key].errors = []; - } - } + for (var i = 0; i < cyelements.length; i++) { + //cyelements[i].removeStyle(); + cyelements[i].data().is_valid = true; + cyelements[i].data().errors = []; + } - for (var key in workflow.errors) { - //alert.info(workflow.errors[key]); - } + for (var key in workflow.actions) { + workflow.actions[key].is_valid = true; + workflow.actions[key].errors = []; + } + } - setWorkflow(workflow); - } + for (var key in workflow.errors) { + //alert.info(workflow.errors[key]); + } - setSavingState(1); - setTimeout(() => { - setSavingState(0); - }, 1500); - } - }) - .catch((error) => { - setSavingState(0); - //alert.error(error.toString()); - console.log("Save workflow error: ", error.toString()); - }); + setWorkflow(workflow); + } + + setSavingState(1); + setTimeout(() => { + setSavingState(0); + }, 1500); + } + }) + .catch((error) => { + setSavingState(0); + //alert.error(error.toString()); + console.log("Save workflow error: ", error.toString()); + }); return success; }; @@ -1396,103 +1397,103 @@ const AngularWorkflow = (defaultprops) => { }; const executeWorkflow = (executionArgument, startNode, hasSaved) => { - ReactDOM.unstable_batchedUpdates(() => { - if (hasSaved === false) { - setExecutionRequestStarted(true); - saveWorkflow(workflow, executionArgument, startNode); - console.log("FIXME: Might have forgotten to save before executing."); - return; - } + ReactDOM.unstable_batchedUpdates(() => { + if (hasSaved === false) { + setExecutionRequestStarted(true); + saveWorkflow(workflow, executionArgument, startNode); + console.log("FIXME: Might have forgotten to save before executing."); + return; + } - if (workflow.public) { - alert.info("Save it to get a new version"); - } + if (workflow.public) { + alert.info("Save it to get a new version"); + } - var returncheck = monitorUpdates(); - if (!returncheck) { - alert.error("No startnode set."); - return; - } + var returncheck = monitorUpdates(); + if (!returncheck) { + alert.error("No startnode set."); + return; + } - setVisited([]) - setExecutionRequest({}) - stop() + setVisited([]) + setExecutionRequest({}) + stop() - var curelements = cy.elements(); - for (var i = 0; i < curelements.length; i++) { - curelements[i].addClass("not-executing-highlight"); - } + var curelements = cy.elements(); + for (var i = 0; i < curelements.length; i++) { + curelements[i].addClass("not-executing-highlight"); + } - const data = { execution_argument: executionArgument, start: startNode }; - fetch( - globalUrl + "/api/v1/workflows/" + props.match.params.key + "/execute", - { - method: "POST", - headers: { - "Content-Type": "application/json", - Accept: "application/json", - }, - credentials: "include", - body: JSON.stringify(data), - } - ) - .then((response) => { - setExecutionRequestStarted(false) - if (response.status !== 200) { - console.log("Status not 200 for WORKFLOW EXECUTION :O!"); - } + const data = { execution_argument: executionArgument, start: startNode }; + fetch( + globalUrl + "/api/v1/workflows/" + props.match.params.key + "/execute", + { + method: "POST", + headers: { + "Content-Type": "application/json", + Accept: "application/json", + }, + credentials: "include", + body: JSON.stringify(data), + } + ) + .then((response) => { + setExecutionRequestStarted(false) + if (response.status !== 200) { + console.log("Status not 200 for WORKFLOW EXECUTION :O!"); + } - return response.json(); - }) - .then((responseJson) => { - if (!responseJson.success) { - alert.error("Failed to start: " + responseJson.reason); - setExecutionRunning(false); - setExecutionRequestStarted(false); - stop(); + return response.json(); + }) + .then((responseJson) => { + if (!responseJson.success) { + alert.error("Failed to start: " + responseJson.reason); + setExecutionRunning(false); + setExecutionRequestStarted(false); + stop(); - for (var i = 0; i < curelements.length; i++) { - curelements[i].removeClass("not-executing-highlight"); - } - return; - } else { - setExecutionRunning(true); - setExecutionRequestStarted(false); - } + for (var i = 0; i < curelements.length; i++) { + curelements[i].removeClass("not-executing-highlight"); + } + return; + } else { + setExecutionRunning(true); + setExecutionRequestStarted(false); + } - if ( - responseJson.execution_id === "" || - responseJson.execution_id === undefined || - responseJson.authorization === "" || - responseJson.authorization === undefined - ) { - alert.error("Something went wrong during execution startup"); - console.log("BAD RESPONSE FOR EXECUTION: ", responseJson); - setExecutionRunning(false); - setExecutionRequestStarted(false); - stop(); + if ( + responseJson.execution_id === "" || + responseJson.execution_id === undefined || + responseJson.authorization === "" || + responseJson.authorization === undefined + ) { + alert.error("Something went wrong during execution startup"); + console.log("BAD RESPONSE FOR EXECUTION: ", responseJson); + setExecutionRunning(false); + setExecutionRequestStarted(false); + stop(); - for (var i = 0; i < curelements.length; i++) { - curelements[i].removeClass("not-executing-highlight"); - } - return; - } + for (var i = 0; i < curelements.length; i++) { + curelements[i].removeClass("not-executing-highlight"); + } + return; + } - setExecutionRequest({ - execution_id: responseJson.execution_id, - authorization: responseJson.authorization, - }); - setExecutionData({}); - setExecutionModalOpen(true); - setExecutionModalView(1); - start(); - }) - .catch((error) => { - //alert.error(error.toString()); - setExecutionRequestStarted(false) - console.log("Execute workflow err: ", error.toString()); - }); - }) + setExecutionRequest({ + execution_id: responseJson.execution_id, + authorization: responseJson.authorization, + }); + setExecutionData({}); + setExecutionModalOpen(true); + setExecutionModalView(1); + start(); + }) + .catch((error) => { + //alert.error(error.toString()); + setExecutionRequestStarted(false) + console.log("Execute workflow err: ", error.toString()); + }); + }) }; // This can be used to only show prioritzed ones later @@ -1584,7 +1585,7 @@ const AngularWorkflow = (defaultprops) => { } if (appUpdates === true) { - console.log("Closing auth modal: Success") + console.log("Closing auth modal: Success") setAuthenticationModalOpen(false); setSelectedAction(selectedAction); @@ -1592,7 +1593,7 @@ const AngularWorkflow = (defaultprops) => { saveWorkflow(workflow); alert.info("Added and updated authentication!"); } else { - console.log("Closing auth modal? FAIL") + console.log("Closing auth modal? FAIL") alert.error("Failed to find new authentication. See details in Oauth2 popup window where auth was attempted."); } @@ -1621,7 +1622,7 @@ const AngularWorkflow = (defaultprops) => { credentials: "include", }) .then((response) => { - setAppsLoaded(true) + setAppsLoaded(true) if (response.status !== 200) { console.log("Status not 200 for apps :O!"); } @@ -1629,25 +1630,25 @@ const AngularWorkflow = (defaultprops) => { return response.json(); }) .then((responseJson) => { - if (responseJson === null) { - console.log("No response") - const pretend_apps = [{ - "name": "TBD", - "app_name": "TBD", - "app_version": "TBD", - "description": "TBD", - "version": "TBD", - "large_image": "", - }] - setApps(pretend_apps) - setFilteredApps(pretend_apps) + if (responseJson === null) { + console.log("No response") + const pretend_apps = [{ + "name": "TBD", + "app_name": "TBD", + "app_version": "TBD", + "description": "TBD", + "version": "TBD", + "large_image": "", + }] + setApps(pretend_apps) + setFilteredApps(pretend_apps) setPrioritizedApps(pretend_apps); - return - } + return + } - if (responseJson.success === false) { - return - } + if (responseJson.success === false) { + return + } // FIXME - handle versions on left bar //handleAppVersioning(responseJson) @@ -1672,25 +1673,25 @@ const AngularWorkflow = (defaultprops) => { // ) //); - var tmpFiltered = responseJson.filter((app) => !internalIds.includes(app.name)) - //tmpFiltered = sortByKey(tmpFiltered, "activated") + var tmpFiltered = responseJson.filter((app) => !internalIds.includes(app.name)) + //tmpFiltered = sortByKey(tmpFiltered, "activated") setFilteredApps(tmpFiltered) - //!(!app.activated && app.generated) + //!(!app.activated && app.generated) setPrioritizedApps( responseJson.filter((app) => internalIds.includes(app.name)) ); } }) .catch((error) => { - setAppsLoaded(true) + setAppsLoaded(true) //alert.error("App loading error: "+error.toString()); - console.log("App loading error: "+error.toString()); + console.log("App loading error: " + error.toString()); }); }; - // Searhc by username, userId, workflow, appId should all work - const getUserProfile = (username, rerun) => { + // Searhc by username, userId, workflow, appId should all work + const getUserProfile = (username, rerun) => { fetch(`${globalUrl}/api/v1/users/creators/${username}`, { method: "GET", headers: { @@ -1699,35 +1700,35 @@ const AngularWorkflow = (defaultprops) => { }, credentials: "include", }) - .then((response) => { - if (response.status !== 200) { - console.log("Status not 200 for WORKFLOW EXECUTION :O!"); - } + .then((response) => { + if (response.status !== 200) { + console.log("Status not 200 for WORKFLOW EXECUTION :O!"); + } - return response.json(); - }) - .then((responseJson) => { - if (responseJson.success !== false) { - console.log("Found creator: ", responseJson) - setCreatorProfile(responseJson) - } else { - console.log("Couldn't find the creator profile (rerun?): ", responseJson, rerun) - // If the current user is any of the Shuffle Creators - // AND the workflow doesn't have an owner: allow editing. - // else: Allow suggestions? - //console.log("User: ", userdata) - //if (rerun !== true) { - // getUserProfile(userdata.id, true) - //} - } - }) - .catch((error) => { - console.log("Get userprofile error: ", error); - }) + return response.json(); + }) + .then((responseJson) => { + if (responseJson.success !== false) { + console.log("Found creator: ", responseJson) + setCreatorProfile(responseJson) + } else { + console.log("Couldn't find the creator profile (rerun?): ", responseJson, rerun) + // If the current user is any of the Shuffle Creators + // AND the workflow doesn't have an owner: allow editing. + // else: Allow suggestions? + //console.log("User: ", userdata) + //if (rerun !== true) { + // getUserProfile(userdata.id, true) + //} + } + }) + .catch((error) => { + console.log("Get userprofile error: ", error); + }) } - const getFiles = () => { + const getFiles = () => { fetch(globalUrl + "/api/v1/files", { method: "GET", headers: { @@ -1748,9 +1749,11 @@ const AngularWorkflow = (defaultprops) => { if (responseJson.files !== undefined && responseJson.files !== null) { setFiles(responseJson); } else { - setFiles({"namespaces": [ - "default" - ]}); + setFiles({ + "namespaces": [ + "default" + ] + }); } if ( @@ -1802,46 +1805,46 @@ const AngularWorkflow = (defaultprops) => { if (responseJson.public) { //alert.info("This workflow is public. Save the workflow to use it in your organization."); - - setAuthLoaded(true) - console.log("RESP: ", responseJson) - if (Object.getOwnPropertyNames(creatorProfile).length === 0) { - //getUserProfile("frikky") - getUserProfile(responseJson.id, false) - } - //{appGroup.map((data, index) => { - //const [appGroup, setAppGroup] = React.useState([]); - var appsFound = [] - for (var key in responseJson.actions) { - const parsedAction = responseJson.actions[key] - if (parsedAction.large_image === undefined || parsedAction.large_image === null || parsedAction.large_image === "") { - continue - } - if (appsFound.findIndex(data => data.app_name === parsedAction.app_name) < 0){ - appsFound.push(parsedAction) - } - } + setAuthLoaded(true) + console.log("RESP: ", responseJson) + if (Object.getOwnPropertyNames(creatorProfile).length === 0) { + //getUserProfile("frikky") + getUserProfile(responseJson.id, false) + } - setAppGroup(appsFound) + //{appGroup.map((data, index) => { + //const [appGroup, setAppGroup] = React.useState([]); + var appsFound = [] + for (var key in responseJson.actions) { + const parsedAction = responseJson.actions[key] + if (parsedAction.large_image === undefined || parsedAction.large_image === null || parsedAction.large_image === "") { + continue + } + if (appsFound.findIndex(data => data.app_name === parsedAction.app_name) < 0) { + appsFound.push(parsedAction) + } + } - appsFound = [] - for (var key in responseJson.triggers) { - const parsedAction = responseJson.triggers[key] - if (appsFound.findIndex(data => data.app_name === parsedAction.app_name) < 0){ - appsFound.push(parsedAction) - } - } + setAppGroup(appsFound) - setTriggerGroup(appsFound) - } else { - getAppAuthentication(); - getEnvironments(); - getWorkflowExecution(props.match.params.key, ""); - getAvailableWorkflows(-1); - getSettings(); - getFiles() - } + appsFound = [] + for (var key in responseJson.triggers) { + const parsedAction = responseJson.triggers[key] + if (appsFound.findIndex(data => data.app_name === parsedAction.app_name) < 0) { + appsFound.push(parsedAction) + } + } + + setTriggerGroup(appsFound) + } else { + getAppAuthentication(); + getEnvironments(); + getWorkflowExecution(props.match.params.key, ""); + getAvailableWorkflows(-1); + getSettings(); + getFiles() + } // Appends SUBFLOWS. Does NOT run during normal grabbing of workflows. if (sourcenode.id !== undefined) { @@ -1867,9 +1870,9 @@ const AngularWorkflow = (defaultprops) => { node.data = action; - node.data.canConnect = false - node.data.is_valid = true - node.data.isValid = true + node.data.canConnect = false + node.data.is_valid = true + node.data.isValid = true node.data._id = action["id"]; node.data.type = "ACTION"; node.data.source_workflow = responseJson.id; @@ -1877,10 +1880,10 @@ const AngularWorkflow = (defaultprops) => { nodefound = true; } - if (responseJson.public) { - node.data.is_valid = true - node.is_valid = true - } + if (responseJson.public) { + node.data.is_valid = true + node.is_valid = true + } var example = ""; if ( @@ -1895,27 +1898,27 @@ const AngularWorkflow = (defaultprops) => { return node; }); - var triggers = responseJson.triggers.map((trigger) => { - const node = {}; - - console.log("Only add workflow: ", trigger.app_name) - if (trigger.app_name !== "Shuffle Workflow" && trigger.app_name !== "User Input") { - return null - } + var triggers = responseJson.triggers.map((trigger) => { + const node = {}; - node.position = trigger.position; - node.data = trigger; + console.log("Only add workflow: ", trigger.app_name) + if (trigger.app_name !== "Shuffle Workflow" && trigger.app_name !== "User Input") { + return null + } - node.data.canConnect = false - node.data.id = trigger["id"]; - node.data._id = trigger["id"]; - node.data.type = "TRIGGER"; + node.position = trigger.position; + node.data = trigger; - return node; - }); + node.data.canConnect = false + node.data.id = trigger["id"]; + node.data._id = trigger["id"]; + node.data.type = "TRIGGER"; + + return node; + }); triggers = triggers.filter((trigger) => trigger !== null); - const insertedNodes = [].concat(actions, triggers); + const insertedNodes = [].concat(actions, triggers); var edges = responseJson.branches.map((branch, index) => { const edge = {}; var conditions = responseJson.branches[index].conditions; @@ -1957,10 +1960,10 @@ const AngularWorkflow = (defaultprops) => { source_workflow: responseJson.id, }; - if (responseJson.public) { - edge.data.is_valid = true - edge.is_valid = true - } + if (responseJson.public) { + edge.data.is_valid = true + edge.is_valid = true + } return edge; }); @@ -2002,7 +2005,7 @@ const AngularWorkflow = (defaultprops) => { responseJson.errors !== undefined || responseJson.errors !== null || responseJson.errors !== // what - responseJson.errors.length > 0 + responseJson.errors.length > 0 ) { setConfigureWorkflowModalOpen(true); } @@ -2018,162 +2021,162 @@ const AngularWorkflow = (defaultprops) => { const onUnselect = (event) => { const nodedata = event.target.data(); console.log("UNSELECT: ", nodedata); - //if (nodedata.type === "ACTION") { - // setLastSelected(nodedata) - //} - // + //if (nodedata.type === "ACTION") { + // setLastSelected(nodedata) + //} + // - // Wait for new node to possibly be selected - //setTimeout(() => { - const typeIds = cy.elements('node:selected').jsons(); - for (var idkey in typeIds) { - const item = typeIds[idkey] - if (item.data.isButton === true) { - //console.log("Reselect old node & return - or just return?") - - if (item.data.buttonType === "delete" && item.data.attachedTo === nodedata.id) { - //console.log("delete of same node!") - } - return - } - } + // Wait for new node to possibly be selected + //setTimeout(() => { + const typeIds = cy.elements('node:selected').jsons(); + for (var idkey in typeIds) { + const item = typeIds[idkey] + if (item.data.isButton === true) { + //console.log("Reselect old node & return - or just return?") - // Unselecting all - //cy.elements().unselect() + if (item.data.buttonType === "delete" && item.data.attachedTo === nodedata.id) { + //console.log("delete of same node!") + } + return + } + } - //if (nodedata.app_name === undefined && nodedata.source === undefined) { - // return; - //} - //event.target.removeClass("selected"); - // + // Unselecting all + //cy.elements().unselect() + + //if (nodedata.app_name === undefined && nodedata.source === undefined) { + // return; + //} + //event.target.removeClass("selected"); + // - //// If button is clicked, select current node + //// If button is clicked, select current node - // Attempt at rewrite of name in other actions in following nodes. - // Should probably be done in the onBlur for the textfield instead - /* - if (event.target.data().type === "ACTION") { - const nodeaction = event.target.data() - const curaction = workflow.actions.find(a => a.id === nodeaction.id) - console.log("workflowaction: ", curaction) - console.log("nodeaction: ", nodeaction) - if (nodeaction.label !== curaction.label) { - console.log("BEACH!") + // Attempt at rewrite of name in other actions in following nodes. + // Should probably be done in the onBlur for the textfield instead + /* + if (event.target.data().type === "ACTION") { + const nodeaction = event.target.data() + const curaction = workflow.actions.find(a => a.id === nodeaction.id) + console.log("workflowaction: ", curaction) + console.log("nodeaction: ", nodeaction) + if (nodeaction.label !== curaction.label) { + console.log("BEACH!") - var params = [] - const fixedName = "$"+curaction.label.toLowerCase().replace(" ", "_") - for (var actionkey in workflow.actions) { - if (workflow.actions[actionkey].id === curaction.id) { - continue - } + var params = [] + const fixedName = "$"+curaction.label.toLowerCase().replace(" ", "_") + for (var actionkey in workflow.actions) { + if (workflow.actions[actionkey].id === curaction.id) { + continue + } - for (var paramkey in workflow.actions[actionkey].parameters) { - const param = workflow.actions[actionkey].parameters[paramkey] - if (param.value === null || param.value === undefined || !param.value.includes("$")) { - continue - } + for (var paramkey in workflow.actions[actionkey].parameters) { + const param = workflow.actions[actionkey].parameters[paramkey] + if (param.value === null || param.value === undefined || !param.value.includes("$")) { + continue + } - const innername = param.value.toLowerCase().replace(" ", "_") - if (innername.includes(fixedName)) { - //workflow.actions[actionkey].parameters[paramkey].replace( - //console.log("FOUND!: ", innername) - } - } - } - } - } - */ + const innername = param.value.toLowerCase().replace(" ", "_") + if (innername.includes(fixedName)) { + //workflow.actions[actionkey].parameters[paramkey].replace( + //console.log("FOUND!: ", innername) + } + } + } + } + } + */ - //cy.removeListener("select"); - //cy.on("select", "node", (e) => onNodeSelect(e, appAuthentication)); - //cy.on("select", "edge", (e) => onEdgeSelect(e)); + //cy.removeListener("select"); + //cy.on("select", "node", (e) => onNodeSelect(e, appAuthentication)); + //cy.on("select", "edge", (e) => onEdgeSelect(e)); - // FIXME - check if they have value before overriding like this for no reason. - // Would save a lot of time (400~ ms -> 30ms) - //console.log("ACTION: ", selectedAction) - //console.log("APP: ", selectedApp) + // FIXME - check if they have value before overriding like this for no reason. + // Would save a lot of time (400~ ms -> 30ms) + //console.log("ACTION: ", selectedAction) + //console.log("APP: ", selectedApp) - ReactDOM.unstable_batchedUpdates(() => { - setSelectedAction({}); - setSelectedApp({}); - setSelectedTrigger({}); - setSelectedComment({}) - setSelectedEdge({}); + ReactDOM.unstable_batchedUpdates(() => { + setSelectedAction({}); + setSelectedApp({}); + setSelectedTrigger({}); + setSelectedComment({}) + setSelectedEdge({}); - setSelectedEdge({}) - setSelectedActionEnvironment({}) - setTriggerAuthentication({}) - setSelectedTriggerIndex(-1) - setTriggerFolders([]) - setSubworkflow({}) - setLocalFirstrequest(true) + setSelectedEdge({}) + setSelectedActionEnvironment({}) + setTriggerAuthentication({}) + setSelectedTriggerIndex(-1) + setTriggerFolders([]) + setSubworkflow({}) + setLocalFirstrequest(true) - // Can be used for right side view - setRightSideBarOpen(false); - setScrollConfig({ - top: 0, - left: 0, - selected: "", - }); - //console.timeEnd("UNSELECT"); - }) + // Can be used for right side view + setRightSideBarOpen(false); + setScrollConfig({ + top: 0, + left: 0, + selected: "", + }); + //console.timeEnd("UNSELECT"); + }) - sendStreamRequest({ - "item": "node", - "type": "unselect", - "userid": userdata.id, - }) - //}, 150) + sendStreamRequest({ + "item": "node", + "type": "unselect", + "userid": userdata.id, + }) + //}, 150) }; const onEdgeSelect = (event) => { - ReactDOM.unstable_batchedUpdates(() => { - setRightSideBarOpen(true); - setLastSaved(false); + ReactDOM.unstable_batchedUpdates(() => { + setRightSideBarOpen(true); + setLastSaved(false); - /* - // Used to not be able to edit trigger-based branches. - const triggercheck = workflow.triggers.find(trigger => trigger.id === event.target.data()["source"]) - if (triggercheck === undefined) { - */ - if ( - event.target.data("type") !== "COMMENT" && - event.target.data().decorator - ) { - alert.info("This edge can't be edited."); - } else { - //console.log("DATA: ", event.target.data()) - const destinationId = event.target.data("target"); - //console.log("DATA: ", event.target.data()) - const curaction = workflow.actions.find((a) => a.id === destinationId); - //console.log("ACTION: ", curaction) - if (curaction !== undefined && curaction !== null) { - if ( - curaction.app_name === "Shuffle Tools" && - curaction.name === "router" - ) { - alert.info("Router action can't have incoming conditions"); - event.target.unselect(); - return; - } - } + /* + // Used to not be able to edit trigger-based branches. + const triggercheck = workflow.triggers.find(trigger => trigger.id === event.target.data()["source"]) + if (triggercheck === undefined) { + */ + if ( + event.target.data("type") !== "COMMENT" && + event.target.data().decorator + ) { + alert.info("This edge can't be edited."); + } else { + //console.log("DATA: ", event.target.data()) + const destinationId = event.target.data("target"); + //console.log("DATA: ", event.target.data()) + const curaction = workflow.actions.find((a) => a.id === destinationId); + //console.log("ACTION: ", curaction) + if (curaction !== undefined && curaction !== null) { + if ( + curaction.app_name === "Shuffle Tools" && + curaction.name === "router" + ) { + alert.info("Router action can't have incoming conditions"); + event.target.unselect(); + return; + } + } - setSelectedEdgeIndex( - workflow.branches.findIndex( - (data) => data.id === event.target.data()["id"] - ) - ); - setSelectedEdge(event.target.data()); - } + setSelectedEdgeIndex( + workflow.branches.findIndex( + (data) => data.id === event.target.data()["id"] + ) + ); + setSelectedEdge(event.target.data()); + } - setSelectedAction({}); - setSelectedTrigger({}); - }) + setSelectedAction({}); + setSelectedTrigger({}); + }) }; // Comparing locations between nodes and setting views @@ -2195,9 +2198,9 @@ const AngularWorkflow = (defaultprops) => { return; } - if (nodedata.parameters === undefined) { - return - } + if (nodedata.parameters === undefined) { + return + } const workflow_id = nodedata.parameters.find( (param) => param.name === "workflow" @@ -2233,26 +2236,26 @@ const AngularWorkflow = (defaultprops) => { return; } - const connected = event.target.connectedEdges().jsons() - for (var key in connected) { - const edge = connected[key] - //console.log("EDGE:", edge) + const connected = event.target.connectedEdges().jsons() + for (var key in connected) { + const edge = connected[key] + //console.log("EDGE:", edge) - //const edge = edgeBase.json() + //const edge = edgeBase.json() const sourcenode = cy.getElementById(edge.data.source) const destinationnode = cy.getElementById(edge.data.target) - if (sourcenode === undefined || sourcenode === null || destinationnode === undefined || destinationnode === null) { - continue - } + if (sourcenode === undefined || sourcenode === null || destinationnode === undefined || destinationnode === null) { + continue + } - const edgeCurve = calculateEdgeCurve(sourcenode.position(), destinationnode.position()) + const edgeCurve = calculateEdgeCurve(sourcenode.position(), destinationnode.position()) const currentedge = cy.getElementById(edge.data.id) - if (currentedge !== undefined && currentedge !== null) { - currentedge.style('control-point-distance', edgeCurve.distance) - currentedge.style('control-point-weight', edgeCurve.weight) - } - } + if (currentedge !== undefined && currentedge !== null) { + currentedge.style('control-point-distance', edgeCurve.distance) + currentedge.style('control-point-weight', edgeCurve.weight) + } + } if (styledElements.length === 1) { console.log( @@ -2274,18 +2277,18 @@ const AngularWorkflow = (defaultprops) => { if (curElement !== null && curElement !== undefined) { curElement.style.border = curElement.style.original_border; var newValue = "$" + nodedata.label.toLowerCase().replaceAll(" ", "_"); - if (nodedata.type === "TRIGGER") { - if (nodedata.trigger_type === "WEBHOOK" || nodedata.trigger_type === "SCHEDULE" || nodedata.trigger_type === "EMAIL") { - var newValue = "$exec" - } - } + if (nodedata.type === "TRIGGER") { + if (nodedata.trigger_type === "WEBHOOK" || nodedata.trigger_type === "SCHEDULE" || nodedata.trigger_type === "EMAIL") { + var newValue = "$exec" + } + } var paramname = ""; var idnumber = -1; if (curElement.id.startsWith("rightside_field_")) { console.log("FOUND FIELD WITH NUMBER: ", curElement.id); - // Find exact position to put the text + // Find exact position to put the text const idsplit = curElement.id.split("_"); console.log(idsplit); @@ -2378,22 +2381,22 @@ const AngularWorkflow = (defaultprops) => { y: 0, }; - sendStreamRequest({ - "item": "node", - "type": "move", - "id": nodedata.id, - "location": { - "x": event.target.position("x"), - "y": event.target.position("y"), - } - }) + sendStreamRequest({ + "item": "node", + "type": "move", + "id": nodedata.id, + "location": { + "x": event.target.position("x"), + "y": event.target.position("y"), + } + }) }; const onNodeDrag = (event, selectedAction) => { const nodedata = event.target.data(); if (nodedata.finished === false) { - console.log("NOT FINISHED - ADD EXAMPLE BRANCHES TO CLOSEST!!") - return + console.log("NOT FINISHED - ADD EXAMPLE BRANCHES TO CLOSEST!!") + return } if (nodedata.app_name !== undefined) { @@ -2404,28 +2407,28 @@ const AngularWorkflow = (defaultprops) => { cy.getElementById(currentNode.data.id).remove(); } - // Calculate location - //currentNode.position.x > - //if (nodedata.position.x > 0 && nodedata.position.y > 0) { - // console.log("Positive both") - //} + // Calculate location + //currentNode.position.x > + //if (nodedata.position.x > 0 && nodedata.position.y > 0) { + // console.log("Positive both") + //} - //console.log(currentNode.position) - //console.log(nodedata.position) + //console.log(currentNode.position) + //console.log(nodedata.position) } } else { //console.log("No appid? ", nodedata) } - if (nodedata.buttonType === "edgehandler") { - console.log("Enable edgehandler!") - console.log("Find parent: ", nodedata.attachedTo) - const parentNode = cy.getElementById(nodedata.attachedTo); - if (parentNode !== null && parentNode !== undefined) { - console.log("Start parentnode tracking!") - //cy.edgehandles().start(parentNode) - } - } + if (nodedata.buttonType === "edgehandler") { + console.log("Enable edgehandler!") + console.log("Find parent: ", nodedata.attachedTo) + const parentNode = cy.getElementById(nodedata.attachedTo); + if (parentNode !== null && parentNode !== undefined) { + console.log("Start parentnode tracking!") + //cy.edgehandles().start(parentNode) + } + } if (nodedata.id === selectedAction.id) { return; @@ -2434,20 +2437,20 @@ const AngularWorkflow = (defaultprops) => { /* - // Tried looking for the closest node by position. aStar path not working entirely. - console.log("NODE: ", event.target) - const closestNode = cy.elements().aStar({ - root: nodedata.id, - goal: 'node', - directed: false, - }) + // Tried looking for the closest node by position. aStar path not working entirely. + console.log("NODE: ", event.target) + const closestNode = cy.elements().aStar({ + root: nodedata.id, + goal: 'node', + directed: false, + }) - if (closestNode.found) { - console.log("No closest node found for: ", nodedata.id) - } else { - console.log("Closest: ", closestNode) - } - */ + if (closestNode.found) { + console.log("No closest node found for: ", nodedata.id) + } else { + console.log("Closest: ", closestNode) + } + */ if ( originalLocation.x === 0 && @@ -2517,481 +2520,481 @@ const AngularWorkflow = (defaultprops) => { if (!lastSaved) { return unloadText; } else { - if (workflow.public === false) { - //document.removeEventListener("mousemove", onMouseUpdate, true); - document.removeEventListener("keydown", handleKeyDown, true); - document.removeEventListener("paste", handlePaste, true); - } - } + if (workflow.public === false) { + //document.removeEventListener("mousemove", onMouseUpdate, true); + document.removeEventListener("keydown", handleKeyDown, true); + document.removeEventListener("paste", handlePaste, true); + } + } }); // Nodeselectbatching: // https://stackoverflow.com/questions/16677856/cy-onselect-callback-only-once - // onNodeClick + // onNodeClick const onNodeSelect = (event, newAppAuth) => { - // Otherwise everything is SUPER slow - ReactDOM.unstable_batchedUpdates(() => { - const data = event.target.data(); - if (data.isButton) { - if (data.buttonType === "delete") { - const parentNode = cy.getElementById(data.attachedTo); - if (parentNode !== null && parentNode !== undefined) { - removeNode(data.attachedTo) - //parentNode.remove() - } + // Otherwise everything is SUPER slow + ReactDOM.unstable_batchedUpdates(() => { + const data = event.target.data(); + if (data.isButton) { + if (data.buttonType === "delete") { + const parentNode = cy.getElementById(data.attachedTo); + if (parentNode !== null && parentNode !== undefined) { + removeNode(data.attachedTo) + //parentNode.remove() + } - return - } else if (data.buttonType === "set_startnode" && data.type !== "TRIGGER") { - const parentNode = cy.getElementById(data.attachedTo); - if (parentNode !== null && parentNode !== undefined) { - var oldstartnode = cy.getElementById(workflow.start); - if ( - oldstartnode !== null && - oldstartnode !== undefined && - oldstartnode.length > 0 - ) { - try { - oldstartnode[0].data("isStartNode", false); - } catch (e) { - console.log("Startnode error: ", e); - } - } + return + } else if (data.buttonType === "set_startnode" && data.type !== "TRIGGER") { + const parentNode = cy.getElementById(data.attachedTo); + if (parentNode !== null && parentNode !== undefined) { + var oldstartnode = cy.getElementById(workflow.start); + if ( + oldstartnode !== null && + oldstartnode !== undefined && + oldstartnode.length > 0 + ) { + try { + oldstartnode[0].data("isStartNode", false); + } catch (e) { + console.log("Startnode error: ", e); + } + } - workflow.start = parentNode.data("id"); - setLastSaved(false); - parentNode.data("isStartNode", true); - } - - //event.target.unselect(); - setRightSideBarOpen(true); - return + workflow.start = parentNode.data("id"); + setLastSaved(false); + parentNode.data("isStartNode", true); + } - } else if (data.buttonType === "copy") { - console.log("COPY!"); + //event.target.unselect(); + setRightSideBarOpen(true); + return - // 1. Find parent - // 2. Find branches for parent - // 3. Make a new node that's moved a little bit - const parentNode = cy.getElementById(data.attachedTo); - if (parentNode !== null && parentNode !== undefined) { - var newNodeData = JSON.parse(JSON.stringify(parentNode.data())); - newNodeData.id = uuidv4(); - if (newNodeData.position !== undefined) { - newNodeData.position = { - x: newNodeData.position.x + 100, - y: newNodeData.position.y + 100, - }; - } + } else if (data.buttonType === "copy") { + console.log("COPY!"); - newNodeData.isStartNode = false; - newNodeData.errors = []; - newNodeData.is_valid = true; - newNodeData.isValid = true; - newNodeData.label = parentNode.data("label") + "_copy"; + // 1. Find parent + // 2. Find branches for parent + // 3. Make a new node that's moved a little bit + const parentNode = cy.getElementById(data.attachedTo); + if (parentNode !== null && parentNode !== undefined) { + var newNodeData = JSON.parse(JSON.stringify(parentNode.data())); + newNodeData.id = uuidv4(); + if (newNodeData.position !== undefined) { + newNodeData.position = { + x: newNodeData.position.x + 100, + y: newNodeData.position.y + 100, + }; + } - cy.add({ - group: "nodes", - data: newNodeData, - position: newNodeData.position, - }); + newNodeData.isStartNode = false; + newNodeData.errors = []; + newNodeData.is_valid = true; + newNodeData.isValid = true; + newNodeData.label = parentNode.data("label") + "_copy"; - // Readding the icon after moving the node - if ( - newNodeData.app_name !== "Testing" || - newNodeData.app_name !== "Shuffle Workflow" - ) { - } else { - const iconInfo = GetIconInfo(newNodeData); - const svg_pin = ``; - const svgpin_Url = encodeURI("data:image/svg+xml;utf-8," + svg_pin); + cy.add({ + group: "nodes", + data: newNodeData, + position: newNodeData.position, + }); - const offset = newNodeData.isStartNode ? 36 : 44; - const decoratorNode = { - position: { - x: newNodeData.position.x + offset, - y: newNodeData.position.y + offset, - }, - locked: true, - data: { - isDescriptor: true, - isValid: true, - is_valid: true, - label: "", - image: svgpin_Url, - imageColor: iconInfo.iconBackgroundColor, - attachedTo: newNodeData.id, - }, - }; + // Readding the icon after moving the node + if ( + newNodeData.app_name !== "Testing" || + newNodeData.app_name !== "Shuffle Workflow" + ) { + } else { + const iconInfo = GetIconInfo(newNodeData); + const svg_pin = ``; + const svgpin_Url = encodeURI("data:image/svg+xml;utf-8," + svg_pin); - cy.add(decoratorNode).unselectify(); - } + const offset = newNodeData.isStartNode ? 36 : 44; + const decoratorNode = { + position: { + x: newNodeData.position.x + offset, + y: newNodeData.position.y + offset, + }, + locked: true, + data: { + isDescriptor: true, + isValid: true, + is_valid: true, + label: "", + image: svgpin_Url, + imageColor: iconInfo.iconBackgroundColor, + attachedTo: newNodeData.id, + }, + }; - workflow.actions.push(newNodeData); + cy.add(decoratorNode).unselectify(); + } - const sourcebranches = workflow.branches.filter( - (foundbranch) => foundbranch.source_id === parentNode.data("id") - ); - const destinationbranches = workflow.branches.filter( - (foundbranch) => - foundbranch.destination_id === parentNode.data("id") - ); + workflow.actions.push(newNodeData); - for (var key in sourcebranches) { - var newbranch = JSON.parse(JSON.stringify(sourcebranches[key])); - newbranch.id = uuidv4(); - newbranch.source_id = newNodeData.id; + const sourcebranches = workflow.branches.filter( + (foundbranch) => foundbranch.source_id === parentNode.data("id") + ); + const destinationbranches = workflow.branches.filter( + (foundbranch) => + foundbranch.destination_id === parentNode.data("id") + ); - newbranch._id = newbranch.id; - newbranch.source = newbranch.source_id; - newbranch.target = newbranch.destination_id; - cy.add({ - group: "edges", - data: newbranch, - }); - } + for (var key in sourcebranches) { + var newbranch = JSON.parse(JSON.stringify(sourcebranches[key])); + newbranch.id = uuidv4(); + newbranch.source_id = newNodeData.id; - for (var key in destinationbranches) { - var newbranch = JSON.parse( - JSON.stringify(destinationbranches[key]) - ); - newbranch.id = uuidv4(); - newbranch.destination_id = newNodeData.id; + newbranch._id = newbranch.id; + newbranch.source = newbranch.source_id; + newbranch.target = newbranch.destination_id; + cy.add({ + group: "edges", + data: newbranch, + }); + } - newbranch._id = newbranch.id; - newbranch.source = newbranch.source_id; - newbranch.target = newbranch.destination_id; - cy.add({ - group: "edges", - data: newbranch, - }); - } + for (var key in destinationbranches) { + var newbranch = JSON.parse( + JSON.stringify(destinationbranches[key]) + ); + newbranch.id = uuidv4(); + newbranch.destination_id = newNodeData.id; - //event.target.unselect(); - return - } - } + newbranch._id = newbranch.id; + newbranch.source = newbranch.source_id; + newbranch.target = newbranch.destination_id; + cy.add({ + group: "edges", + data: newbranch, + }); + } - return; - } else if (data.isDescriptor) { - console.log("Can't select descriptor"); - event.target.unselect(); - return; - } + //event.target.unselect(); + return + } + } - if (data.type === "ACTION") { - setSelectedComment({}) - //var curaction = JSON.parse(JSON.stringify(data)) - // FIXME: Trust it to just work? - //event.target.data() - var curaction = workflow.actions.find((a) => a.id === data.id) - if (!curaction || curaction === undefined) { - console.log("NOT FOUND DATA: ", event.target.data()) - if (data.id !== undefined && data.app_name !== undefined) { - workflow.actions.push(data) - setWorkflow(workflow) - curaction = data - } else { - if (workflow.public !== true) { - alert.error("Action not found. Please remake it."); - } + return; + } else if (data.isDescriptor) { + console.log("Can't select descriptor"); + event.target.unselect(); + return; + } - event.target.remove(); - return; - } - } + if (data.type === "ACTION") { + setSelectedComment({}) + //var curaction = JSON.parse(JSON.stringify(data)) + // FIXME: Trust it to just work? + //event.target.data() + var curaction = workflow.actions.find((a) => a.id === data.id) + if (!curaction || curaction === undefined) { + console.log("NOT FOUND DATA: ", event.target.data()) + if (data.id !== undefined && data.app_name !== undefined) { + workflow.actions.push(data) + setWorkflow(workflow) + curaction = data + } else { + if (workflow.public !== true) { + alert.error("Action not found. Please remake it."); + } - //var newapps = JSON.parse(JSON.stringify(apps)) - var newapps = apps - if (apps === null || apps === undefined || apps.length === 0) { - newapps = filteredApps - } + event.target.remove(); + return; + } + } - // Check ID first, then names etc - // That way it always selects the right IF it exists - var curapp = newapps.find((a) => - a.id === curaction.app_id - ) + //var newapps = JSON.parse(JSON.stringify(apps)) + var newapps = apps + if (apps === null || apps === undefined || apps.length === 0) { + newapps = filteredApps + } - if (curapp === undefined || curapp === null) { - console.log("Couldn't find ID - checking with name & version") + // Check ID first, then names etc + // That way it always selects the right IF it exists + var curapp = newapps.find((a) => + a.id === curaction.app_id + ) - curapp = newapps.find((a) => - a.name === curaction.app_name && - (a.app_version === curaction.app_version || - (a.loop_versions !== null && - a.loop_versions.includes(curaction.app_version))) - ) - } + if (curapp === undefined || curapp === null) { + console.log("Couldn't find ID - checking with name & version") - if (curaction.template === true) { - //newapps. - const parsedname = curaction.name.replaceAll(" ", "_").toLowerCase() - console.log("FIND AN ACTION AMONG THE APPS THAT MATCHES NAME: ", parsedname) + curapp = newapps.find((a) => + a.name === curaction.app_name && + (a.app_version === curaction.app_version || + (a.loop_versions !== null && + a.loop_versions.includes(curaction.app_version))) + ) + } - curaction.matching_actions = [] - for (var key in newapps) { - for (var subkey in newapps[key].actions) { - const tmpaction = newapps[key].actions[subkey] - if (tmpaction.name.replaceAll(" ", "_").toLowerCase() === parsedname) { - console.log("MATCH!: ", newapps[key]) - curaction.matching_actions.push({ - "app_name": newapps[key].name, - "app_version": newapps[key].app_version, - "app_id": newapps[key].id, - "action": tmpaction, - "large_image": newapps[key].large_image, - "app_index": key, - "action_index": subkey, - }) - } - } - } - } + if (curaction.template === true) { + //newapps. + const parsedname = curaction.name.replaceAll(" ", "_").toLowerCase() + console.log("FIND AN ACTION AMONG THE APPS THAT MATCHES NAME: ", parsedname) - if (!curapp || curapp === undefined) { - console.log("APPS - couldn't find it: ", newapps) - //alert.error(`App ${curaction.app_name}:${curaction.app_version} not found. Is it activated?`); + curaction.matching_actions = [] + for (var key in newapps) { + for (var subkey in newapps[key].actions) { + const tmpaction = newapps[key].actions[subkey] + if (tmpaction.name.replaceAll(" ", "_").toLowerCase() === parsedname) { + console.log("MATCH!: ", newapps[key]) + curaction.matching_actions.push({ + "app_name": newapps[key].name, + "app_version": newapps[key].app_version, + "app_id": newapps[key].id, + "action": tmpaction, + "large_image": newapps[key].large_image, + "app_index": key, + "action_index": subkey, + }) + } + } + } + } - const tmpapp = { - name: curaction.app_name, - app_name: curaction.app_name, - app_version: curaction.app_version, - id: curaction.app_id, - actions: [curaction], - }; + if (!curapp || curapp === undefined) { + console.log("APPS - couldn't find it: ", newapps) + //alert.error(`App ${curaction.app_name}:${curaction.app_version} not found. Is it activated?`); - setSelectedApp(tmpapp); - setSelectedAction(curaction); - } else { - //if (curapp.id !== curaction.id) { - // curaction.app_id = curapp.id - // //.valueOf() - //} - curaction.app_id = curapp.id + const tmpapp = { + name: curaction.app_name, + app_name: curaction.app_name, + app_version: curaction.app_version, + id: curaction.app_id, + actions: [curaction], + }; - setAuthenticationType( - curapp.authentication.type === "oauth2" && curapp.authentication.redirect_uri !== undefined && curapp.authentication.redirect_uri !== null ? { - type: "oauth2", - redirect_uri: curapp.authentication.redirect_uri, - refresh_uri: curapp.authentication.refresh_uri, - token_uri: curapp.authentication.token_uri, - scope: curapp.authentication.scope, - client_id: curapp.authentication.client_id, - client_secret: curapp.authentication.client_secret, - } : { - type: "", - } - ) + setSelectedApp(tmpapp); + setSelectedAction(curaction); + } else { + //if (curapp.id !== curaction.id) { + // curaction.app_id = curapp.id + // //.valueOf() + //} + curaction.app_id = curapp.id - const requiresAuth = curapp.authentication.required; //&& ((curapp.authentication.parameters !== undefined && curapp.authentication.parameters !== null) || (curapp.authentication.type === "oauth2" && curapp.authentication.redirect_uri !== undefined && curapp.authentication.redirect_uri !== null)) - setRequiresAuthentication(requiresAuth); - if (curapp.authentication.required) { - //console.log("App requires auth.") - // Setup auth here :) - const authenticationOptions = []; - var findAuthId = ""; - if ( - curaction.authentication_id !== null && - curaction.authentication_id !== undefined && - curaction.authentication_id.length > 0 - ) { - findAuthId = curaction.authentication_id; - } + setAuthenticationType( + curapp.authentication.type === "oauth2" && curapp.authentication.redirect_uri !== undefined && curapp.authentication.redirect_uri !== null ? { + type: "oauth2", + redirect_uri: curapp.authentication.redirect_uri, + refresh_uri: curapp.authentication.refresh_uri, + token_uri: curapp.authentication.token_uri, + scope: curapp.authentication.scope, + client_id: curapp.authentication.client_id, + client_secret: curapp.authentication.client_secret, + } : { + type: "", + } + ) - const tmpAuth = JSON.parse(JSON.stringify(newAppAuth)); - //var tmpAuth = newAppAuth + const requiresAuth = curapp.authentication.required; //&& ((curapp.authentication.parameters !== undefined && curapp.authentication.parameters !== null) || (curapp.authentication.type === "oauth2" && curapp.authentication.redirect_uri !== undefined && curapp.authentication.redirect_uri !== null)) + setRequiresAuthentication(requiresAuth); + if (curapp.authentication.required) { + //console.log("App requires auth.") + // Setup auth here :) + const authenticationOptions = []; + var findAuthId = ""; + if ( + curaction.authentication_id !== null && + curaction.authentication_id !== undefined && + curaction.authentication_id.length > 0 + ) { + findAuthId = curaction.authentication_id; + } - for (var key in tmpAuth) { - var item = tmpAuth[key]; + const tmpAuth = JSON.parse(JSON.stringify(newAppAuth)); + //var tmpAuth = newAppAuth - const newfields = {}; - for (var filterkey in item.fields) { - newfields[item.fields[filterkey].key] = item.fields[filterkey].value; - } + for (var key in tmpAuth) { + var item = tmpAuth[key]; - item.fields = newfields; - if (item.app.name === curapp.name) { - authenticationOptions.push(item); - if (item.id === findAuthId) { - curaction.selectedAuthentication = item; - } - } - } + const newfields = {}; + for (var filterkey in item.fields) { + newfields[item.fields[filterkey].key] = item.fields[filterkey].value; + } - curaction.authentication = authenticationOptions; - if ( - curaction.selectedAuthentication === null || - curaction.selectedAuthentication === undefined || - curaction.selectedAuthentication.length === "" - ) { - curaction.selectedAuthentication = {}; - } - } else { - curaction.authentication = []; - curaction.authentication_id = ""; - curaction.selectedAuthentication = {}; - } + item.fields = newfields; + if (item.app.name === curapp.name) { + authenticationOptions.push(item); + if (item.id === findAuthId) { + curaction.selectedAuthentication = item; + } + } + } - if ( - curaction.parameters !== undefined && - curaction.parameters !== null && - curaction.parameters.length > 0 - ) { - for (var key in curaction.parameters) { - if ( - curaction.parameters[key].options !== undefined && - curaction.parameters[key].options !== null && - curaction.parameters[key].options.length > 0 && - curaction.parameters[key].value === "" - ) { - curaction.parameters[key].value = curaction.parameters[key].options[0]; - } - } - } else { - console.log("Should check APP if it has the same params as ACTION") - for (var key in curapp.actions) { - const tmpaction = curapp.actions[key] - if (tmpaction.name === curaction.name) { - console.log("Found action - needs change?", tmpaction) - if (tmpaction.parameters !== undefined && tmpaction.parameters !== null && tmpaction.parameters.length > 0) { - curaction.parameters = JSON.parse(JSON.stringify(tmpaction.parameters)) - } - break - } - } - } + curaction.authentication = authenticationOptions; + if ( + curaction.selectedAuthentication === null || + curaction.selectedAuthentication === undefined || + curaction.selectedAuthentication.length === "" + ) { + curaction.selectedAuthentication = {}; + } + } else { + curaction.authentication = []; + curaction.authentication_id = ""; + curaction.selectedAuthentication = {}; + } - console.log("ACTION CLICK: ", curaction) - setSelectedApp(curapp); - setSelectedAction(curaction); + if ( + curaction.parameters !== undefined && + curaction.parameters !== null && + curaction.parameters.length > 0 + ) { + for (var key in curaction.parameters) { + if ( + curaction.parameters[key].options !== undefined && + curaction.parameters[key].options !== null && + curaction.parameters[key].options.length > 0 && + curaction.parameters[key].value === "" + ) { + curaction.parameters[key].value = curaction.parameters[key].options[0]; + } + } + } else { + console.log("Should check APP if it has the same params as ACTION") + for (var key in curapp.actions) { + const tmpaction = curapp.actions[key] + if (tmpaction.name === curaction.name) { + console.log("Found action - needs change?", tmpaction) + if (tmpaction.parameters !== undefined && tmpaction.parameters !== null && tmpaction.parameters.length > 0) { + curaction.parameters = JSON.parse(JSON.stringify(tmpaction.parameters)) + } + break + } + } + } - cy.removeListener("drag"); - cy.removeListener("free"); - cy.on("drag", "node", (e) => onNodeDrag(e, curaction)); - cy.on("free", "node", (e) => onNodeDragStop(e, curaction)); - } + console.log("ACTION CLICK: ", curaction) + setSelectedApp(curapp); + setSelectedAction(curaction); - if (environments !== undefined && environments !== null && (typeof environments === "array" || typeof environments === "object")) { - var parsedenv = environments - //if (typeof environments === "object") { - // parsedenv = [environments] - //} + cy.removeListener("drag"); + cy.removeListener("free"); + cy.on("drag", "node", (e) => onNodeDrag(e, curaction)); + cy.on("free", "node", (e) => onNodeDragStop(e, curaction)); + } - const envs = parsedenv.find((a) => a.Name === curaction.environment); - var env = environments[defaultEnvironmentIndex] - if (envs !== undefined && envs !== null) { - env = envs - } + if (environments !== undefined && environments !== null && (typeof environments === "array" || typeof environments === "object")) { + var parsedenv = environments + //if (typeof environments === "object") { + // parsedenv = [environments] + //} - setSelectedActionEnvironment(env); - } - } else if (data.type === "TRIGGER") { - setSelectedComment({}) - if (workflow.triggers === null) { - workflow.triggers = [] - } + const envs = parsedenv.find((a) => a.Name === curaction.environment); + var env = environments[defaultEnvironmentIndex] + if (envs !== undefined && envs !== null) { + env = envs + } - var trigger_index = workflow.triggers.findIndex( - (a) => a.id === data.id - ); + setSelectedActionEnvironment(env); + } + } else if (data.type === "TRIGGER") { + setSelectedComment({}) + if (workflow.triggers === null) { + workflow.triggers = [] + } - //console.log("Trigger: ", data, trigger_index) - if (trigger_index === -1) { - workflow.triggers.push(data) - trigger_index = workflow.triggers.length-1 - setWorkflow(workflow) - } + var trigger_index = workflow.triggers.findIndex( + (a) => a.id === data.id + ); - //console.log("Trigger2: ", data, trigger_index) - //if (data.id !== undefined && data.app_name !== undefined) { - // //newapps.push(data) - // workflow.actions.push(data) - // curaction = data - //} else { - // alert.error("Action not found. Please remake it."); - // event.target.remove(); - // return; - //} + //console.log("Trigger: ", data, trigger_index) + if (trigger_index === -1) { + workflow.triggers.push(data) + trigger_index = workflow.triggers.length - 1 + setWorkflow(workflow) + } - if (data.app_name === "Shuffle Workflow") { - getAvailableWorkflows(trigger_index); - getSettings(); - } else if (data.app_name === "Webhook") { - if (workflow.triggers[trigger_index].parameters !== undefined) { - workflow.triggers[trigger_index].parameters[0] = { - name: "url", - value: referenceUrl + "webhook_" + workflow.triggers[trigger_index].id, - }; - } - } + //console.log("Trigger2: ", data, trigger_index) + //if (data.id !== undefined && data.app_name !== undefined) { + // //newapps.push(data) + // workflow.actions.push(data) + // curaction = data + //} else { + // alert.error("Action not found. Please remake it."); + // event.target.remove(); + // return; + //} - console.log("DATA: ", data) - setSelectedTriggerIndex(trigger_index); - setSelectedTrigger(data); - setSelectedActionEnvironment(data.env); - } else if (data.type === "COMMENT") { - setSelectedComment(data); - } else { - alert.error("Can't handle " + data.type); - return; - } + if (data.app_name === "Shuffle Workflow") { + getAvailableWorkflows(trigger_index); + getSettings(); + } else if (data.app_name === "Webhook") { + if (workflow.triggers[trigger_index].parameters !== undefined && workflow.triggers[trigger_index].parameters !== null && workflow.triggers[trigger_index].parameters.length > 0) { + workflow.triggers[trigger_index].parameters[0] = { + name: "url", + value: referenceUrl + "webhook_" + workflow.triggers[trigger_index].id, + }; + } + } - setRightSideBarOpen(true); - setLastSaved(false); - setScrollConfig({ - top: 0, - left: 0, - selected: "", - }); + console.log("DATA: ", data) + setSelectedTriggerIndex(trigger_index); + setSelectedTrigger(data); + setSelectedActionEnvironment(data.env); + } else if (data.type === "COMMENT") { + setSelectedComment(data); + } else { + alert.error("Can't handle " + data.type); + return; + } - console.log("DOne in the node update") - - sendStreamRequest({ - "item": "node", - "type": "select", - "id": data.id, - "userid": userdata.id, - "location": { - "x": event.target.position("x"), - "y": event.target.position("y"), - } - }) + setRightSideBarOpen(true); + setLastSaved(false); + setScrollConfig({ + top: 0, + left: 0, + selected: "", + }); - }) + console.log("DOne in the node update") + + sendStreamRequest({ + "item": "node", + "type": "select", + "id": data.id, + "userid": userdata.id, + "location": { + "x": event.target.position("x"), + "y": event.target.position("y"), + } + }) + + }) } - const activateApp = (appid, refresh) => { - fetch(globalUrl+"/api/v1/apps/"+appid+"/activate", { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'Accept': 'application/json', - }, - credentials: "include", + const activateApp = (appid, refresh) => { + fetch(globalUrl + "/api/v1/apps/" + appid + "/activate", { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Accept': 'application/json', + }, + credentials: "include", }) - .then((response) => { - if (response.status !== 200) { - console.log("Failed to activate") - } + .then((response) => { + if (response.status !== 200) { + console.log("Failed to activate") + } - return response.json() - }) - .then((responseJson) => { - if (responseJson.success === false) { - alert.error("Failed to activate the app") - } else { - alert.success("App activated for your organization! Refresh the page to use the app.") + return response.json() + }) + .then((responseJson) => { + if (responseJson.success === false) { + alert.error("Failed to activate the app") + } else { + alert.success("App activated for your organization! Refresh the page to use the app.") - if (refresh === true) { - getApps() - } - } - }) - .catch(error => { - //alert.error(error.toString()) - console.log("Activate app error: ", error.toString()) - }); - } + if (refresh === true) { + getApps() + } + } + }) + .catch(error => { + //alert.error(error.toString()) + console.log("Activate app error: ", error.toString()) + }); + } const GetExampleResult = (item) => { var exampledata = item.example === undefined ? "" : item.example; @@ -3054,12 +3057,12 @@ const AngularWorkflow = (defaultprops) => { // Finds the FIRST json only if (jsonvalid) { - try { - exampledata = JSON.parse(foundResult.result) - } catch (e) { - console.log("Result: ", exampledata) + try { + exampledata = JSON.parse(foundResult.result) + } catch (e) { + console.log("Result: ", exampledata) - } + } break; } @@ -3078,8 +3081,8 @@ const AngularWorkflow = (defaultprops) => { return ""; } - //console.log("NOT REPLACING ON PURPOSE!!") - //return "" + //console.log("NOT REPLACING ON PURPOSE!!") + //return "" // Basically just a stupid if-else :) const synonyms = { @@ -3115,7 +3118,7 @@ const AngularWorkflow = (defaultprops) => { "value", "item", ], - tags: ["tags", "taxonomies"], + tags: ["tags", "taxonomies"], }; // 1. Find the right synonym @@ -3187,8 +3190,8 @@ const AngularWorkflow = (defaultprops) => { // Takes an action as input, then runs through and updates the relevant fields // based on previous actions' - // Uses lots of synonyms - // autocomplete + // Uses lots of synonyms + // autocomplete const RunAutocompleter = (dstdata) => { // **PS: The right action should already be set here** // 1. Check execution argument @@ -3202,15 +3205,15 @@ const AngularWorkflow = (defaultprops) => { continue } - if (param.options !== undefined && param.options !== null && param.options.length > 0) { - continue - } + if (param.options !== undefined && param.options !== null && param.options.length > 0) { + continue + } const paramname = param.name.toLowerCase().trim().replaceAll("_", " "); const foundresult = GetParamMatch(paramname, exampledata, ""); if (foundresult.length > 0) { - console.log("FOUND ReS for field: ", dstdata.parameters[paramkey].name, foundresult) + console.log("FOUND ReS for field: ", dstdata.parameters[paramkey].name, foundresult) if (dstdata.parameters[paramkey].value.length === 0) { dstdata.parameters[paramkey].value = `$${parentlabel}${foundresult}`; dstdata.parameters[paramkey].autocompleted = true @@ -3238,9 +3241,9 @@ const AngularWorkflow = (defaultprops) => { continue } - if (param.options !== undefined && param.options !== null && param.options.length > 0) { - continue - } + if (param.options !== undefined && param.options !== null && param.options.length > 0) { + continue + } const paramname = param.name .toLowerCase() @@ -3251,7 +3254,7 @@ const AngularWorkflow = (defaultprops) => { if (foundresult.length > 0) { if (dstdata.parameters[paramkey].value.length === 0) { dstdata.parameters[paramkey].value = `$${parentlabel}${foundresult}`; - dstdata.parameters[paramkey].autocompleted = true + dstdata.parameters[paramkey].autocompleted = true } else { //dstdata.parameters[paramkey].value = `$${parentlabel}${foundresult}`; } @@ -3269,58 +3272,58 @@ const AngularWorkflow = (defaultprops) => { setLastSaved(false); const edge = event.target.data(); - console.log("edge added: ", edge) - if (edge.source === undefined && edge.target === undefined) { - return - } + console.log("edge added: ", edge) + if (edge.source === undefined && edge.target === undefined) { + return + } - if (edge.readded === true) { - console.log("Readded edge - stopping") + if (edge.readded === true) { + console.log("Readded edge - stopping") - event.target.data("readded", false) - return - } + event.target.data("readded", false) + return + } - const sourcenode = cy.getElementById(edge.source) - const destinationnode = cy.getElementById(edge.target) - if (sourcenode === undefined || sourcenode === null || destinationnode === undefined || destinationnode === null) { - } else { - console.log("Edge added: Is it a trigger? If so, check if it already has a branch and remove it: ", sourcenode.data()) - if (sourcenode.data("type") === "TRIGGER") { - if (sourcenode.data("app_name") !== "Shuffle Workflow" && sourcenode.data("app_name") !== "User Input") { - setTimeout(() => { - const alledges = cy.edges().jsons() - console.log("edges: ", alledges, edge) - var targetedge = alledges.findIndex( - (data) => data.data.source === edge.source && data.data.id !== edge.id - ) + const sourcenode = cy.getElementById(edge.source) + const destinationnode = cy.getElementById(edge.target) + if (sourcenode === undefined || sourcenode === null || destinationnode === undefined || destinationnode === null) { + } else { + console.log("Edge added: Is it a trigger? If so, check if it already has a branch and remove it: ", sourcenode.data()) + if (sourcenode.data("type") === "TRIGGER") { + if (sourcenode.data("app_name") !== "Shuffle Workflow" && sourcenode.data("app_name") !== "User Input") { + setTimeout(() => { + const alledges = cy.edges().jsons() + console.log("edges: ", alledges, edge) + var targetedge = alledges.findIndex( + (data) => data.data.source === edge.source && data.data.id !== edge.id + ) - console.log("Node: ", targetedge) - if (targetedge !== -1) { - event.target.remove() + console.log("Node: ", targetedge) + if (targetedge !== -1) { + event.target.remove() - //console.log("Found branch already!") - alert.info("Triggers can have exactly one target node") - return - - - // name: "Shuffle Workflow", - // name: "User Input", - } else { - console.log("Node doesn't already have one") - } - }, 50) - } - } + //console.log("Found branch already!") + alert.info("Triggers can have exactly one target node") + return - const edgeCurve = calculateEdgeCurve(sourcenode.position(), destinationnode.position()) - const currentedge = cy.getElementById(edge.id) - if (currentedge !== undefined && currentedge !== null) { - currentedge.style('control-point-distance', edgeCurve.distance) - currentedge.style('control-point-weight', edgeCurve.weight) - } - } + // name: "Shuffle Workflow", + // name: "User Input", + } else { + console.log("Node doesn't already have one") + } + }, 50) + } + } + + const edgeCurve = calculateEdgeCurve(sourcenode.position(), destinationnode.position()) + const currentedge = cy.getElementById(edge.id) + if (currentedge !== undefined && currentedge !== null) { + currentedge.style('control-point-distance', edgeCurve.distance) + currentedge.style('control-point-weight', edgeCurve.weight) + } + + } var targetnode = workflow.triggers.findIndex( @@ -3338,14 +3341,14 @@ const AngularWorkflow = (defaultprops) => { } } - const eventTarget = event.target.target() - console.log("BUTTON ADDED! Find parent from: ", eventTarget) + const eventTarget = event.target.target() + console.log("BUTTON ADDED! Find parent from: ", eventTarget) if (eventTarget.data("isButton") === true) { - const parentNode = cy.getElementById(eventTarget.data("attachedTo")) - event.target.remove() - console.log("Setting it to parentnode: ", parentNode.data()) - if (parentNode !== undefined && parentNode !== null) { - //event.target.data("target", eventTarget.data("attachedTo")) + const parentNode = cy.getElementById(eventTarget.data("attachedTo")) + event.target.remove() + console.log("Setting it to parentnode: ", parentNode.data()) + if (parentNode !== undefined && parentNode !== null) { + //event.target.data("target", eventTarget.data("attachedTo")) const newEdgeUuid = uuidv4() const newcybranch = { @@ -3362,14 +3365,14 @@ const AngularWorkflow = (defaultprops) => { } cy.add(edgeToBeAdded); - } - } + } + } if ( eventTarget.data("isDescriptor") === true || - eventTarget.data("type") === "COMMENT" + eventTarget.data("type") === "COMMENT" ) { - console.log("Removing because of descriptor or comment") + console.log("Removing because of descriptor or comment") event.target.remove(); return; } @@ -3404,13 +3407,13 @@ const AngularWorkflow = (defaultprops) => { (data) => data.id === edge.source ); if (targetnode === -1) { - if (targetnode.type !== "TRIGGER") { - alert.error("Can't make arrow to starting node"); - event.target.remove(); - break; - } - - found = true; + if (targetnode.type !== "TRIGGER") { + alert.error("Can't make arrow to starting node"); + event.target.remove(); + break; + } + + found = true; } } else if (edge.source === workflow.branches[key].source_id) { // FIXME: Verify multi-target for triggers @@ -3430,18 +3433,18 @@ const AngularWorkflow = (defaultprops) => { // Find the targetnode and check if its a trigger // FIXME - do this for both actions and other types? /* - targetnode = workflow.triggers.findIndex(data => data.id === edge.target) - if (targetnode !== -1) { - console.log("TARGETNODE: ", targetnode) - if (workflow.triggers[targetnode].app_name === "User Input" || workflow.triggers[targetnode].app_name === "Shuffle Workflow") { - } else { - alert.error("Can't have triggers as target of branch") - event.target.remove() - found = true - break - } - } - */ + targetnode = workflow.triggers.findIndex(data => data.id === edge.target) + if (targetnode !== -1) { + console.log("TARGETNODE: ", targetnode) + if (workflow.triggers[targetnode].app_name === "User Input" || workflow.triggers[targetnode].app_name === "Shuffle Workflow") { + } else { + alert.error("Can't have triggers as target of branch") + event.target.remove() + found = true + break + } + } + */ } } @@ -3489,21 +3492,21 @@ const AngularWorkflow = (defaultprops) => { const node = event.target; const nodedata = event.target.data(); - if (Object.keys(nodedata).length === 1) { - console.log("Check if another node actually exists before adding") - } + if (Object.keys(nodedata).length === 1) { + console.log("Check if another node actually exists before adding") + } if (nodedata.finished === false || (nodedata.id !== undefined && nodedata.is_valid === undefined) ) { - //if (nodedata.app_id === undefined) { - //console.log("Returning because node is not valid: ", nodedata) + //if (nodedata.app_id === undefined) { + //console.log("Returning because node is not valid: ", nodedata) return; } - // DONT MOVE THIS LINE RIGHT HERE v + // DONT MOVE THIS LINE RIGHT HERE v setLastSaved(false) - // Dont move the line above. May break stuff. + // Dont move the line above. May break stuff. if (node.isNode() && cy.nodes().size() === 1) { @@ -3511,7 +3514,7 @@ const AngularWorkflow = (defaultprops) => { nodedata.isStartNode = true; } else { if (workflow.actions === null) { - console.log("Returning because node has no value") + console.log("Returning because node has no value") return; } @@ -3525,13 +3528,13 @@ const AngularWorkflow = (defaultprops) => { } if (nodedata.type === "ACTION") { - /* - var curaction = workflow.actions.find((a) => a.id === nodedata.id); - if (curaction === null || curaction === undefined) { - alert.error("Node not found. Please remake it.") - event.target.remove(); - } - */ + /* + var curaction = workflow.actions.find((a) => a.id === nodedata.id); + if (curaction === null || curaction === undefined) { + alert.error("Node not found. Please remake it.") + event.target.remove(); + } + */ if ( workflow.actions.length === 1 && workflow.actions[0].id === workflow.start @@ -3586,11 +3589,11 @@ const AngularWorkflow = (defaultprops) => { ); newparam.id = uuidv4(); - if (newparam.value === undefined || newparam.value === null) { - newparam.value = ""; - } else { - newparam.value = newparam.value; - } + if (newparam.value === undefined || newparam.value === null) { + newparam.value = ""; + } else { + newparam.value = newparam.value; + } newparameters.push(newparam); } @@ -3670,42 +3673,42 @@ const AngularWorkflow = (defaultprops) => { return; } - // Check if the source is trigger and can start - console.log("Removed: ", edge.data()) + // Check if the source is trigger and can start + console.log("Removed: ", edge.data()) const allNodes = cy.nodes().jsons() - for (var key in allNodes) { - const curnode = allNodes[key] - if (curnode.data.type !== "TRIGGER") { - continue - } + for (var key in allNodes) { + const curnode = allNodes[key] + if (curnode.data.type !== "TRIGGER") { + continue + } - if (curnode.data.id === edge.data("source")) { - console.log("Found matching trigger source: ", curnode) - if (curnode.data.app_name !== "Shuffle Workflow" && curnode.data.app_name !== "User Input") { - // If it's started, READD the edge - if (curnode.data.status === "running") { - console.log("Edge is running - readd it: ", edge.data()) - - // Just making sure it's not running infinitely - var newdata = edge.data() - newdata.readded = true + if (curnode.data.id === edge.data("source")) { + console.log("Found matching trigger source: ", curnode) + if (curnode.data.app_name !== "Shuffle Workflow" && curnode.data.app_name !== "User Input") { + // If it's started, READD the edge + if (curnode.data.status === "running") { + console.log("Edge is running - readd it: ", edge.data()) - try { - cy.add({ - group: "edges", - data: newdata, - }) + // Just making sure it's not running infinitely + var newdata = edge.data() + newdata.readded = true - alert.error("You must STOP the trigger before deleting its branches") - } catch (e) { - console.log("Failed re-adding edge: ", e) - } - } + try { + cy.add({ + group: "edges", + data: newdata, + }) - //status: "uninitialized", - } - } - } + alert.error("You must STOP the trigger before deleting its branches") + } catch (e) { + console.log("Failed re-adding edge: ", e) + } + } + + //status: "uninitialized", + } + } + } workflow.branches = workflow.branches.filter( (a) => a.id !== edge.data().id @@ -3778,7 +3781,7 @@ const AngularWorkflow = (defaultprops) => { data: data, }) - //console.log("REMOVED: ", data) + //console.log("REMOVED: ", data) setHistory(history); setHistoryIndex(history.length); } @@ -3831,15 +3834,15 @@ const AngularWorkflow = (defaultprops) => { } } - if ( - event.target !== undefined && - event.target !== null - ) { - if (event.target.localName !== "body") { - console.log("Skipping because body is not targeted") - return; - } - } + if ( + event.target !== undefined && + event.target !== null + ) { + if (event.target.localName !== "body") { + console.log("Skipping because body is not targeted") + return; + } + } console.log("CTRL+C"); if (cy !== undefined) { @@ -3871,21 +3874,21 @@ const AngularWorkflow = (defaultprops) => { //console.log("CTRL+V") // The below parts are handled in the function handlePaste() /* - const clipboard = navigator.clipboard - if (clipboard === undefined || window === undefined || window === null) { - alert.error("Can only use cliboard over HTTPS (port 3443)") - return - } + const clipboard = navigator.clipboard + if (clipboard === undefined || window === undefined || window === null) { + alert.error("Can only use cliboard over HTTPS (port 3443)") + return + } - console.log("CLIPBOARD: ", window.clipboardData) - const pastedData = window.clipboardData.getData('Text'); - console.log("PASTED: ", pastedData) + console.log("CLIPBOARD: ", window.clipboardData) + const pastedData = window.clipboardData.getData('Text'); + console.log("PASTED: ", pastedData) - - //var tmpAuth = JSON.parse(JSON.stringify(appAuthentication)) - var jsonvalid = true - var parsedjson = [] - */ + + //var tmpAuth = JSON.parse(JSON.stringify(appAuthentication)) + var jsonvalid = true + var parsedjson = [] + */ } break; case 88: @@ -3920,10 +3923,10 @@ const AngularWorkflow = (defaultprops) => { //console.log("Skipping because body is not targeted") return; } - } - - //console.log("PATH2: ", event.target) - if ( + } + + //console.log("PATH2: ", event.target) + if ( event.target !== undefined && event.target !== null ) { @@ -3931,7 +3934,7 @@ const AngularWorkflow = (defaultprops) => { //console.log("Skipping because body is not targeted") return; } - } + } event.preventDefault(); @@ -3948,7 +3951,7 @@ const AngularWorkflow = (defaultprops) => { for (var key in parsedjson) { const item = parsedjson[key]; console.log("Adding: ", item); - item.data.id = uuidv4() + item.data.id = uuidv4() cy.add({ group: item.group, @@ -4017,16 +4020,16 @@ const AngularWorkflow = (defaultprops) => { } } - // FIXME: Don't allow multiple in cloud yet. Cloud -> Onprem isn't stable. - if (isCloud) { - if (responseJson !== undefined && responseJson !== null && responseJson.length > 0) { - setEnvironments(responseJson); - } else { - setEnvironments([{ Name: "Cloud", Type: "cloud" }]); - } - } else { - setEnvironments(responseJson); - } + // FIXME: Don't allow multiple in cloud yet. Cloud -> Onprem isn't stable. + if (isCloud) { + if (responseJson !== undefined && responseJson !== null && responseJson.length > 0) { + setEnvironments(responseJson); + } else { + setEnvironments([{ Name: "Cloud", Type: "cloud" }]); + } + } else { + setEnvironments(responseJson); + } }) .catch((error) => { //alert.error(error.toString()); @@ -4063,29 +4066,29 @@ const AngularWorkflow = (defaultprops) => { } } - const cytoscapeElement = document.getElementById("cytoscape_view") - if (cytoscapeElement !== undefined && cytoscapeElement !== null) { - cytoscapeElement.style.cursor = "default" - } + const cytoscapeElement = document.getElementById("cytoscape_view") + if (cytoscapeElement !== undefined && cytoscapeElement !== null) { + cytoscapeElement.style.cursor = "default" + } - // Skipping node editing if it's the selected one - if (cy !== undefined) { - const typeIds = cy.elements('node:selected').jsons(); - for (var idkey in typeIds) { - const item = typeIds[idkey] - if (item.data.id === nodedata.id) { - return - } - } - } - //if (nodedata.id === selectedAction.id || nodedata.id === selectedTrigger.id) { - // return - //} + // Skipping node editing if it's the selected one + if (cy !== undefined) { + const typeIds = cy.elements('node:selected').jsons(); + for (var idkey in typeIds) { + const item = typeIds[idkey] + if (item.data.id === nodedata.id) { + return + } + } + } + //if (nodedata.id === selectedAction.id || nodedata.id === selectedTrigger.id) { + // return + //} var parsedStyle = { "border-width": "1px", "font-size": "18px", - //"cursor": "default", + //"cursor": "default", } if ((nodedata.app_name === "Testing" || nodedata.app_name === "Shuffle Tools") && !nodedata.isStartNode) { @@ -4195,7 +4198,7 @@ const AngularWorkflow = (defaultprops) => { }); }; - const addSuggestionButtons = (event) => { + const addSuggestionButtons = (event) => { var parentNode = cy.$("#" + event.target.data("id")); if (parentNode.data("isButton") || parentNode.data("buttonId")) return; @@ -4205,31 +4208,31 @@ const AngularWorkflow = (defaultprops) => { parentNode.data("circleId", circleId); - var appid = "1234" - var suggestions = [{ - app_name: "TheHive", - app_version: "1.1.0", - app_id: appid, - sharing: false, - private_id: false, - isStartNode: false, - label: "Suggestion 1", - large_image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK4AAACuCAYAAACvDDbuAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH5AgXDjM6hEZGWwAAD+lJREFUeNrtXb/vJTcRH7/v3iVBCqRBiCAQAtHwq4AWRElHwX8AoqbmXwDRpiH/QyQkGoogUSAhKIKUAE1IdSRSREhQQk7c3XtD8X55vePxjNfe3bk3H+nu+96uPf54POtnj8fe8OQX30JwOIxhtzYBh6MGOsPF0z9p2iWwpd8LjX6W5vWUYaiqlBuvLT5b5TQDPlRwmMSAABBg+kCer+XuAeQf4tL9tAxJ/hIfZGSm8rhyEfjytfxr9FeSX+KjvVfipNVpWlaPNhsAEPCS7Ao8FYnRlbO4ksLnjiSQvIanv4FNjwJ5pXIlMq6MQpIqqPnQKQKbjuPDtZlG55o6UHXWtVncZZTbbNBVB1P5dJYguCbJJ1WjOG8PVOioSm5HPrVt1rwuyN+K+PSZnNV1M/MmEFubfFjjU9tmK9XBJ2cOk3DDdZiEG67DJOrGuA7HyvAe12ESAxa73KPrN1z8gUikCCdvcD5NXnpQpA8nNhh9m5Yn4ZMrV8dHV/8a/dRA0x419a3lI9GBtM2GcrGYFXRNUU5TyluTOpdXwqeUt6YOpby9DUTLZylOcRlzdBTf2yV3ZBFOmKSHQh5KpjSSSpqG4s6VkUubqw8W8knTSnWk0Y+2jF5tlmuDUloJn6T8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ESw3UPd8gPtrh7JeTyXvZGn0KD0jSlMms5Sfhw92vkUvXT5tPWt3WbSfjMsSFl3ujlJdy+4xkjnFze+PWrNWXWclqaT6t82vq2bjMJnzk2pMzrQwWHSbjhOkzCDdchxpZchpezwySQvHhiyVMLevPRctXwqeWmfcv5GaVTGKRy557YIHnhpETeoCl05grhbPlL89HK1vCp5darvZbgo+XEwYcKDpNww3WYxC6/U5PY5oun66MzPHH8L05PpqHKghn+TpjyictkZQLPh4u6yeknvXeWU+JD6TDHJ/cbn93Bi8nnDKdJm8EG2+zIZwBudlbjUOYOpj1frClPwyf3OZuXuaEx3lgWZixKxIfZ911rvJO65PRFVmZjbYY+VHDYhBuuwyTccB0mcdkB0cr5z70pW/pm7Bo+LesgqUsrPjVye9WXkqld8FiizRCi6LBWjmTRPGGG/JZ5ejvoa1ai1qwvlWarbeZDBYdJuOE6TKKP4W7xJdFb4+R8ZvH5P852gxhpwOZ9AAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIwLTA4LTIzVDE0OjUyOjAwKzAyOjAwetRgVgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMC0wOC0yM1QxNDo1MTo1OCswMjowMJuxI+oAAAAASUVORK5CYII=", - finished: false, - is_valid: true, - isSuggestion: true, - attachedTo: event.target.data("id"), - }] + var appid = "1234" + var suggestions = [{ + app_name: "TheHive", + app_version: "1.1.0", + app_id: appid, + sharing: false, + private_id: false, + isStartNode: false, + label: "Suggestion 1", + large_image: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAK4AAACuCAYAAACvDDbuAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABmJLR0QA/wD/AP+gvaeTAAAAB3RJTUUH5AgXDjM6hEZGWwAAD+lJREFUeNrtXb/vJTcRH7/v3iVBCqRBiCAQAtHwq4AWRElHwX8AoqbmXwDRpiH/QyQkGoogUSAhKIKUAE1IdSRSREhQQk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lOmNyZWF0ZQAyMDIwLTA4LTIzVDE0OjUyOjAwKzAyOjAwetRgVgAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMC0wOC0yM1QxNDo1MTo1OCswMjowMJuxI+oAAAAASUVORK5CYII=", + finished: false, + is_valid: true, + isSuggestion: true, + attachedTo: event.target.data("id"), + }] //isButton: true, cy.add({ group: "nodes", data: suggestions[0], - position: { x: px, y: py }, + position: { x: px, y: py }, locked: true, }); - //suggestions[0].id = uuidv4() + //suggestions[0].id = uuidv4() //cy.add({ // group: "nodes", // data: suggestions[0], @@ -4313,14 +4316,14 @@ const AngularWorkflow = (defaultprops) => { const nodedata = event.target.data(); if (nodedata.finished === false) { - console.log("NODE: ", nodedata) + console.log("NODE: ", nodedata) return; } - const cytoscapeElement = document.getElementById("cytoscape_view") - if (cytoscapeElement !== undefined && cytoscapeElement !== null) { - cytoscapeElement.style.cursor = "pointer" - } + const cytoscapeElement = document.getElementById("cytoscape_view") + if (cytoscapeElement !== undefined && cytoscapeElement !== null) { + cytoscapeElement.style.cursor = "pointer" + } //var parentNode = cy.$("#" + event.target.data("id")); //if (parentNode.data("isButton") || parentNode.data("buttonId")) return; @@ -4356,18 +4359,18 @@ const AngularWorkflow = (defaultprops) => { if (!found) { addDeleteButton(event); - if (nodedata.type === "TRIGGER") { - if (nodedata.trigger_type === "SUBFLOW" || nodedata.trigger_type === "USERINPUT") { - addCopyButton(event); - } - } else { - addCopyButton(event); - addStartnodeButton(event); - } + if (nodedata.type === "TRIGGER") { + if (nodedata.trigger_type === "SUBFLOW" || nodedata.trigger_type === "USERINPUT") { + addCopyButton(event); + } + } else { + addCopyButton(event); + addStartnodeButton(event); + } - // autocomplete - // right click - // suggestions + // autocomplete + // right click + // suggestions //addSuggestionButtons(event); } } @@ -4376,55 +4379,55 @@ const AngularWorkflow = (defaultprops) => { "border-width": "7px", "border-opacity": ".7", "font-size": "25px", - //"cursor": "pointer", + //"cursor": "pointer", } - const typeIds = cy.elements('node:selected').jsons(); - for (var idkey in typeIds) { - const item = typeIds[idkey] - if (item.data.id === nodedata.id) { - //console.log("items: ", item.data.id, nodedata.id) - parsedStyle["border-width"] = "12px" - break - } - } + const typeIds = cy.elements('node:selected').jsons(); + for (var idkey in typeIds) { + const item = typeIds[idkey] + if (item.data.id === nodedata.id) { + //console.log("items: ", item.data.id, nodedata.id) + parsedStyle["border-width"] = "12px" + break + } + } if (nodedata.type !== "COMMENT") { parsedStyle.color = "white"; - //if (!event.target.data("isButton") && !event.target.data("buttonId")) { - // const px = event.target.position("x") - 0; - // const py = event.target.position("y") - 50; - // const circleId = (newNodeId = uuidv4()); + //if (!event.target.data("isButton") && !event.target.data("buttonId")) { + // const px = event.target.position("x") - 0; + // const py = event.target.position("y") - 50; + // const circleId = (newNodeId = uuidv4()); - // console.log("Got px, py: ", px, py) - // - // cy.add({ - // group: "nodes", - // data: { - // weight: 30, - // id: circleId, - // isButton: true, - // attachedTo: event.target.data("id"), - // buttonType: "edgehandler", - // is_valid: true, - // }, - // position: { x: px, y: py }, - // locked: true, - // }) - //} + // console.log("Got px, py: ", px, py) + // + // cy.add({ + // group: "nodes", + // data: { + // weight: 30, + // id: circleId, + // isButton: true, + // attachedTo: event.target.data("id"), + // buttonType: "edgehandler", + // is_valid: true, + // }, + // position: { x: px, y: py }, + // locked: true, + // }) + //} } - if (event.target !== undefined && event.target !== null) { - event.target.animate( - { - style: parsedStyle, - }, - { - duration: animationDuration, - } - ); - } + if (event.target !== undefined && event.target !== null) { + event.target.animate( + { + style: parsedStyle, + }, + { + duration: animationDuration, + } + ); + } const outgoingEdges = event.target.outgoers("edge"); const incomingEdges = event.target.incomers("edge"); @@ -4448,10 +4451,10 @@ const AngularWorkflow = (defaultprops) => { return; } - const cytoscapeElement = document.getElementById("cytoscape_view") - if (cytoscapeElement !== undefined && cytoscapeElement !== null) { - cytoscapeElement.style.cursor = "default" - } + const cytoscapeElement = document.getElementById("cytoscape_view") + if (cytoscapeElement !== undefined && cytoscapeElement !== null) { + cytoscapeElement.style.cursor = "default" + } //event.target.removeStyle(); }; @@ -4467,10 +4470,10 @@ const AngularWorkflow = (defaultprops) => { return; } - const cytoscapeElement = document.getElementById("cytoscape_view") - if (cytoscapeElement !== undefined && cytoscapeElement !== null) { - cytoscapeElement.style.cursor = "pointer" - } + const cytoscapeElement = document.getElementById("cytoscape_view") + if (cytoscapeElement !== undefined && cytoscapeElement !== null) { + cytoscapeElement.style.cursor = "pointer" + } //const sourcecolor = cy // .getElementById(event.target.data("source")) @@ -4479,112 +4482,112 @@ const AngularWorkflow = (defaultprops) => { // .getElementById(event.target.data("target")) // .style("border-color"); - ////console.log(sourcecolor, targetcolor) + ////console.log(sourcecolor, targetcolor) //if ( // sourcecolor !== null && // sourcecolor !== undefined && // targetcolor !== null && // targetcolor !== undefined && - // !sourcecolor.includes("rgb") && - // !targetcolor.includes("rgb") + // !sourcecolor.includes("rgb") && + // !targetcolor.includes("rgb") //) { - // console.log(sourcecolor) - // console.log(targetcolor) + // console.log(sourcecolor) + // console.log(targetcolor) - // if (event.target !== null && event.target.value !== null) { - // event.target.animate({ - // style: { - // "target-arrow-color": targetcolor, - // "line-fill": "linear-gradient", - // "line-gradient-stop-colors": [sourcecolor, targetcolor], - // "line-gradient-stop-positions": [0, 1], - // }, - // duration: animationDuration, - // }) - // } else { - // event.target.animate({ - // style: { - // "target-arrow-color": targetcolor, - // "line-fill": "linear-gradient", + // if (event.target !== null && event.target.value !== null) { + // event.target.animate({ + // style: { + // "target-arrow-color": targetcolor, + // "line-fill": "linear-gradient", + // "line-gradient-stop-colors": [sourcecolor, targetcolor], + // "line-gradient-stop-positions": [0, 1], + // }, + // duration: animationDuration, + // }) + // } else { + // event.target.animate({ + // style: { + // "target-arrow-color": targetcolor, + // "line-fill": "linear-gradient", // "line-gradient-stop-colors": ["#41dcab", "#41dcab"], - // "line-gradient-stop-positions": [0, 1], - // }, - // duration: animationDuration, - // }) + // "line-gradient-stop-positions": [0, 1], + // }, + // duration: animationDuration, + // }) - // } + // } //} - if (event.target !== undefined && event.target !== null) { - //const targetcolor = "#66a8b1" - //const parsedStyle = { + if (event.target !== undefined && event.target !== null) { + //const targetcolor = "#66a8b1" + //const parsedStyle = { // "width": "10px", - // "font-size": "18px", + // "font-size": "18px", // "target-arrow-color": "#66a8b1", - // "color": "#66a8b1", - //} + // "color": "#66a8b1", + //} - //event.target.addClass("shuffle-hover-highlight"); + //event.target.addClass("shuffle-hover-highlight"); - //console.log("Style1: ", event.target) - //console.log("Style: ", event.target.style()) + //console.log("Style1: ", event.target) + //console.log("Style: ", event.target.style()) - //event.target.animate( - // { - // style: parsedStyle, - // }, - // { - // duration: animationDuration, - // } - //) - } + //event.target.animate( + // { + // style: parsedStyle, + // }, + // { + // duration: animationDuration, + // } + //) + } } - // Calculates how a trigger should curve - // Thanks to: - // https://codepen.io/guillaumethomas/pen/xxbbBKO - const calculateEdgeCurve = (sourcenodePosition, destinationnodePosition) => { - const xParsed = destinationnodePosition.x - sourcenodePosition.x - const yParsed = destinationnodePosition.y - sourcenodePosition.y + // Calculates how a trigger should curve + // Thanks to: + // https://codepen.io/guillaumethomas/pen/xxbbBKO + const calculateEdgeCurve = (sourcenodePosition, destinationnodePosition) => { + const xParsed = destinationnodePosition.x - sourcenodePosition.x + const yParsed = destinationnodePosition.y - sourcenodePosition.y - const z = Math.sqrt(xParsed * xParsed + yParsed * yParsed); - const costheta = xParsed / z; - const alpha = 0.25; - var controlPointDistance = [-alpha * yParsed * costheta, alpha * yParsed * costheta]; - var controlPointWeight = [alpha, 1-alpha] + const z = Math.sqrt(xParsed * xParsed + yParsed * yParsed); + const costheta = xParsed / z; + const alpha = 0.25; + var controlPointDistance = [-alpha * yParsed * costheta, alpha * yParsed * costheta]; + var controlPointWeight = [alpha, 1 - alpha] - //'control-point-weight': ['0.33', '0.66'], - //var controlPointWeight = ["0.33", "0.66"] - //var controlPointDistance = ["33%", "-66%"] - //var controlPointWeight = ["0.00", "1.00"] - /* - if (yParsed !== 0) { - //const degreeFound = Math.atan2(xParsed / yParsed) - const degreeFound = Math.atan2(xParsed, yParsed) * 180 / Math.PI + //'control-point-weight': ['0.33', '0.66'], + //var controlPointWeight = ["0.33", "0.66"] + //var controlPointDistance = ["33%", "-66%"] + //var controlPointWeight = ["0.00", "1.00"] + /* + if (yParsed !== 0) { + //const degreeFound = Math.atan2(xParsed / yParsed) + const degreeFound = Math.atan2(xParsed, yParsed) * 180 / Math.PI - if (degreeFound > 90 && degreeFound < 180) { - console.log("TOPRIGHT") - } else if (degreeFound < 90 && degreeFound > 0) { - console.log("BOTTOMRIGHT") - } else if (degreeFound < 0 && degreeFound > -90) { - console.log("BOTTOMLEFT") - //controlPointWeight = ["0.20", "0.80"] - //controlPointWeight = "0.7" - //controlPointDistance = "50%" + if (degreeFound > 90 && degreeFound < 180) { + console.log("TOPRIGHT") + } else if (degreeFound < 90 && degreeFound > 0) { + console.log("BOTTOMRIGHT") + } else if (degreeFound < 0 && degreeFound > -90) { + console.log("BOTTOMLEFT") + //controlPointWeight = ["0.20", "0.80"] + //controlPointWeight = "0.7" + //controlPointDistance = "50%" - } else if (degreeFound < -90 && degreeFound > -180) { - console.log("TOPLEFT") - } else { - console.log("STRAIGHT!") - } - } - */ + } else if (degreeFound < -90 && degreeFound > -180) { + console.log("TOPLEFT") + } else { + console.log("STRAIGHT!") + } + } + */ - return { - "distance": controlPointDistance, - "weight": controlPointWeight, - } - } + return { + "distance": controlPointDistance, + "weight": controlPointWeight, + } + } const setupGraph = () => { const actions = workflow.actions.map((action) => { @@ -4616,10 +4619,10 @@ const AngularWorkflow = (defaultprops) => { node.data.type = "ACTION"; node.isStartNode = action["id"] === workflow.start; - if (workflow.public === true) { - node.data.is_valid = true - node.is_valid = true - } + if (workflow.public === true) { + node.data.is_valid = true + node.is_valid = true + } var example = ""; if ( @@ -4728,28 +4731,28 @@ const AngularWorkflow = (defaultprops) => { }; // This is an attempt at prettier edges. The numbers are weird to work with. - // Bezier curves - //http://manual.graphspace.org/projects/graphspace-python/en/latest/demos/edge-types.html - var sourcenode = actions.find(node => node.data._id === branch.source_id || node.data.id === branch.source_id) - var destinationnode = actions.find(node => node.data._id === branch.destination_id || node.data.id === branch.destination_id) + // Bezier curves + //http://manual.graphspace.org/projects/graphspace-python/en/latest/demos/edge-types.html + var sourcenode = actions.find(node => node.data._id === branch.source_id || node.data.id === branch.source_id) + var destinationnode = actions.find(node => node.data._id === branch.destination_id || node.data.id === branch.destination_id) - if (sourcenode === undefined) { - sourcenode = triggers.find(node => node.data._id === branch.source_id || node.data.id === branch.source_id) - } + if (sourcenode === undefined) { + sourcenode = triggers.find(node => node.data._id === branch.source_id || node.data.id === branch.source_id) + } - if (destinationnode === undefined) { - destinationnode = triggers.find(node => node.data._id === branch.destination_id || node.data.id === branch.destination_id) - } + if (destinationnode === undefined) { + destinationnode = triggers.find(node => node.data._id === branch.destination_id || node.data.id === branch.destination_id) + } - if (sourcenode !== undefined && destinationnode !== undefined && branch.source_id !== branch.destination_id) { - const edgeCurve = calculateEdgeCurve(sourcenode.position, destinationnode.position) - edge.style = { - 'control-point-distance': edgeCurve.distance, - 'control-point-weight': edgeCurve.weight, - } - } else { - console.log("FAILED node curve handling") - } + if (sourcenode !== undefined && destinationnode !== undefined && branch.source_id !== branch.destination_id) { + const edgeCurve = calculateEdgeCurve(sourcenode.position, destinationnode.position) + edge.style = { + 'control-point-distance': edgeCurve.distance, + 'control-point-weight': edgeCurve.weight, + } + } else { + console.log("FAILED node curve handling") + } return edge; }); @@ -4817,13 +4820,13 @@ const AngularWorkflow = (defaultprops) => { const removeNode = (nodeId) => { const selectedNode = cy.getElementById(nodeId); if (selectedNode.data() === undefined) { - console.log("No node to remove") + console.log("No node to remove") return; } - //console.log("Removing node: ", selectedNode.data("id"), "Action: ", selectedAction.id) + //console.log("Removing node: ", selectedNode.data("id"), "Action: ", selectedAction.id) - // Get selected node + // Get selected node if (selectedNode.data().type === "TRIGGER") { console.log("Should remove trigger!"); @@ -4844,45 +4847,45 @@ const AngularWorkflow = (defaultprops) => { } } - //if (selectedNode.data("id") === selectedAction.id) { - // setSelectedApp({}); - // setSelectedAction({}); + //if (selectedNode.data("id") === selectedAction.id) { + // setSelectedApp({}); + // setSelectedAction({}); //setSelectedTrigger({}); //setSelectedTriggerIndex({}); - //} - const parsedSelection = cy.$(":selected"); + //} + const parsedSelection = cy.$(":selected"); if (selectedNode.data().decorator === true && selectedNode.data("type") !== "COMMENT") { alert.info("This node can't be deleted."); } else { selectedNode.remove(); } - // An attempt at NOT unselecting when removing - /* - setTimeout(() => { - if (parsedSelection.data() !== undefined) { - if (parsedSelection.data("id") !== selectedNode.data("id")) { - console.log("SHOULD SELECT SINCE ID IS DIFFERENT") + // An attempt at NOT unselecting when removing + /* + setTimeout(() => { + if (parsedSelection.data() !== undefined) { + if (parsedSelection.data("id") !== selectedNode.data("id")) { + console.log("SHOULD SELECT SINCE ID IS DIFFERENT") - parsedSelection.select() - } - } + parsedSelection.select() + } + } - console.log("Parsed: ", parsedSelection.data("id"), selectedNode.data("id")) - }, 2500) - */ + console.log("Parsed: ", parsedSelection.data("id"), selectedNode.data("id")) + }, 2500) + */ }; - if (isLoaded && setupSent === false) { - setSetupSent(true) + if (isLoaded && setupSent === false) { + setSetupSent(true) - sendStreamRequest({ - "item": "workflow", - "type": "enter", - "userid": userdata.id, - }) - } + sendStreamRequest({ + "item": "workflow", + "type": "enter", + "userid": userdata.id, + }) + } const fetchUsecases = () => { fetch(globalUrl + "/api/v1/workflows/usecases", { @@ -4893,201 +4896,201 @@ const AngularWorkflow = (defaultprops) => { }, credentials: "include", }) - .then((response) => { - if (response.status !== 200) { - console.log("Status not 200 for usecases"); - } + .then((response) => { + if (response.status !== 200) { + console.log("Status not 200 for usecases"); + } - return response.json(); - }) - .then((responseJson) => { - if (responseJson.success !== false) { - console.log("Usecases: ", usecases) - setUsecases(responseJson) - } else { - } - }) - .catch((error) => { - //alert.error("ERROR: " + error.toString()); - console.log("ERROR getting usecases: " + error.toString()); - }) + return response.json(); + }) + .then((responseJson) => { + if (responseJson.success !== false) { + console.log("Usecases: ", usecases) + setUsecases(responseJson) + } else { + } + }) + .catch((error) => { + //alert.error("ERROR: " + error.toString()); + console.log("ERROR getting usecases: " + error.toString()); + }) } // eslint-disable-next-line react-hooks/exhaustive-deps //useEffect(() => { - if (firstrequest) { - setFirstrequest(false); - getWorkflow(props.match.params.key, {}); - getApps(); - fetchUsecases() + if (firstrequest) { + setFirstrequest(false); + getWorkflow(props.match.params.key, {}); + getApps(); + fetchUsecases() - const cursearch = - typeof window === "undefined" || window.location === undefined - ? "" - : window.location.search; + const cursearch = + typeof window === "undefined" || window.location === undefined + ? "" + : window.location.search; - // FIXME: Don't check specific one here - const tmpExec = new URLSearchParams(cursearch).get("execution_highlight"); - if ( - tmpExec !== undefined && - tmpExec !== null && - tmpExec === "executions" - ) { - setExecutionModalOpen(true) - const newitem = removeParam("execution_highlight", cursearch); - navigate(curpath + newitem) - //props.history.push(curpath + newitem); - } - - const tmpView = new URLSearchParams(cursearch).get("view"); - if ( - tmpView !== undefined && - tmpView !== null && - tmpView === "executions" - ) { - setExecutionModalOpen(true); - - const newitem = removeParam("view", cursearch); - navigate(curpath + newitem) - //navigate(`?execution_highlight=${parsed_url}`) - //props.history.push(curpath + newitem); - } - return; - } - - // App length necessary cus of cy initialization + // FIXME: Don't check specific one here + const tmpExec = new URLSearchParams(cursearch).get("execution_highlight"); if ( - // First load - gets the workflow - elements.length === 0 && - workflow.actions !== undefined && - !graphSetup && - Object.getOwnPropertyNames(workflow).length > 0 + tmpExec !== undefined && + tmpExec !== null && + tmpExec === "executions" ) { - - setGraphSetup(true); - setupGraph(); - console.log("In graph setup") - - // 2nd load - configures cytoscape - } else if (!established && cy !== undefined && ((apps !== null && apps !== undefined && apps.length > 0) || workflow.public === true) && Object.getOwnPropertyNames(workflow).length > 0 && authLoaded) { - - console.log("In POST graph setup!") - - - //This part has to load LAST, as it's kind of not async. - //This means we need everything else to happen first. - - setEstablished(true); - // Validate if the node is just a node lol - - console.log("CY grid: ", cy.gridGuide) - - // https://www.npmjs.com/package/cytoscape-grid-guide - // - if (cy.gridGuide !== undefined) { - cy.gridGuide({ - gridSpacing: 30, - guidelinesStyle: { - strokeStyle: "#8b7d6b", // color of geometric guidelines - geometricGuidelineRange: 400, // range of geometric guidelines - range: 100, // max range of distribution guidelines - minDistRange: 10, // min range for distribution guidelines - distGuidelineOffset: 10, // shift amount of distribution guidelines - horizontalDistColor: "#ff0000", // color of horizontal distribution alignment - verticalDistColor: "#00ff00", // color of vertical distribution alignment - initPosAlignmentColor: "#0000ff", // color of alignment to initial mouse location - lineDash: [0, 0], // line style of geometric guidelines - horizontalDistLine: [0, 0], // line style of horizontal distribution guidelines - verticalDistLine: [0, 0], // line style of vertical distribution guidelines - initPosAlignmentLine: [0, 0], // line style of alignment to initial mouse position - } - }) - } else { - console.log("ERROR: Failed to render grid as it's unitialized") - } - - if (cy.edgehandles !== undefined) { - console.log("Inside edgehandles") - cy.edgehandles({ - handleNodes: (el) => { - console.log("in handlenodes") - - if (el.isNode() && - !el.data("isButton") && - !el.data("isDescriptor") && - !el.data("isSuggestion") && - el.data("type") !== "COMMENT") { - return true - } - - return false - }, - preview: false, - toggleOffOnLeave: true, - loopAllowed: function (node) { - return false; - }, - }); - - //cy.edgehandles({ - // preview: false, - //}) - - //cy.edgehandles().enable() - } else { - console.log("ERROR: Failed to initialize edgehandler") - } - // preview: true, - - cy.fit(null, 200); - - cy.on("boxselect", "node", (e) => { - if (e.target.data("isButton") || e.target.data("isDescriptor") || e.target.data("isSuggestion")) { - e.target.unselect(); - } - - e.target.addClass("selected"); - }); - - cy.on("boxstart", (e) => { - console.log("START"); - cy.removeListener("select"); - }); - - cy.on("boxend", (e) => { - console.log("END: ", cy) - var cydata = cy.$(":selected").jsons(); - if (cydata !== undefined && cydata !== null && cydata.length > 0) { - alert.success(`Selected ${cydata.length} element(s). CTRL+C to copy them.`); - } - }); - - cy.on("select", "node", (e) => { - onNodeSelect(e, appAuthentication); - }); - cy.on("select", "edge", (e) => onEdgeSelect(e)); - - cy.on("unselect", (e) => onUnselect(e)); - - cy.on("add", "node", (e) => onNodeAdded(e)); - cy.on("add", "edge", (e) => onEdgeAdded(e)); - cy.on("remove", "node", (e) => onNodeRemoved(e)); - cy.on("remove", "edge", (e) => onEdgeRemoved(e)); - - cy.on("mouseover", "edge", (e) => onEdgeHover(e)); - cy.on("mouseout", "edge", (e) => onEdgeHoverOut(e)); - cy.on("mouseover", "node", (e) => onNodeHover(e)); - cy.on("mouseout", "node", (e) => onNodeHoverOut(e)); - - // Handles dragging - cy.on("drag", "node", (e) => onNodeDrag(e, selectedAction)); - cy.on("free", "node", (e) => onNodeDragStop(e, selectedAction)); - - cy.on("cxttap", "node", (e) => onCtxTap(e)); - - document.title = "Workflow - " + workflow.name; - registerKeys(); + setExecutionModalOpen(true) + const newitem = removeParam("execution_highlight", cursearch); + navigate(curpath + newitem) + //props.history.push(curpath + newitem); } + + const tmpView = new URLSearchParams(cursearch).get("view"); + if ( + tmpView !== undefined && + tmpView !== null && + tmpView === "executions" + ) { + setExecutionModalOpen(true); + + const newitem = removeParam("view", cursearch); + navigate(curpath + newitem) + //navigate(`?execution_highlight=${parsed_url}`) + //props.history.push(curpath + newitem); + } + return; + } + + // App length necessary cus of cy initialization + if ( + // First load - gets the workflow + elements.length === 0 && + workflow.actions !== undefined && + !graphSetup && + Object.getOwnPropertyNames(workflow).length > 0 + ) { + + setGraphSetup(true); + setupGraph(); + console.log("In graph setup") + + // 2nd load - configures cytoscape + } else if (!established && cy !== undefined && ((apps !== null && apps !== undefined && apps.length > 0) || workflow.public === true) && Object.getOwnPropertyNames(workflow).length > 0 && authLoaded) { + + console.log("In POST graph setup!") + + + //This part has to load LAST, as it's kind of not async. + //This means we need everything else to happen first. + + setEstablished(true); + // Validate if the node is just a node lol + + console.log("CY grid: ", cy.gridGuide) + + // https://www.npmjs.com/package/cytoscape-grid-guide + // + if (cy.gridGuide !== undefined) { + cy.gridGuide({ + gridSpacing: 30, + guidelinesStyle: { + strokeStyle: "#8b7d6b", // color of geometric guidelines + geometricGuidelineRange: 400, // range of geometric guidelines + range: 100, // max range of distribution guidelines + minDistRange: 10, // min range for distribution guidelines + distGuidelineOffset: 10, // shift amount of distribution guidelines + horizontalDistColor: "#ff0000", // color of horizontal distribution alignment + verticalDistColor: "#00ff00", // color of vertical distribution alignment + initPosAlignmentColor: "#0000ff", // color of alignment to initial mouse location + lineDash: [0, 0], // line style of geometric guidelines + horizontalDistLine: [0, 0], // line style of horizontal distribution guidelines + verticalDistLine: [0, 0], // line style of vertical distribution guidelines + initPosAlignmentLine: [0, 0], // line style of alignment to initial mouse position + } + }) + } else { + console.log("ERROR: Failed to render grid as it's unitialized") + } + + if (cy.edgehandles !== undefined) { + console.log("Inside edgehandles") + cy.edgehandles({ + handleNodes: (el) => { + console.log("in handlenodes") + + if (el.isNode() && + !el.data("isButton") && + !el.data("isDescriptor") && + !el.data("isSuggestion") && + el.data("type") !== "COMMENT") { + return true + } + + return false + }, + preview: false, + toggleOffOnLeave: true, + loopAllowed: function (node) { + return false; + }, + }); + + //cy.edgehandles({ + // preview: false, + //}) + + //cy.edgehandles().enable() + } else { + console.log("ERROR: Failed to initialize edgehandler") + } + // preview: true, + + cy.fit(null, 200); + + cy.on("boxselect", "node", (e) => { + if (e.target.data("isButton") || e.target.data("isDescriptor") || e.target.data("isSuggestion")) { + e.target.unselect(); + } + + e.target.addClass("selected"); + }); + + cy.on("boxstart", (e) => { + console.log("START"); + cy.removeListener("select"); + }); + + cy.on("boxend", (e) => { + console.log("END: ", cy) + var cydata = cy.$(":selected").jsons(); + if (cydata !== undefined && cydata !== null && cydata.length > 0) { + alert.success(`Selected ${cydata.length} element(s). CTRL+C to copy them.`); + } + }); + + cy.on("select", "node", (e) => { + onNodeSelect(e, appAuthentication); + }); + cy.on("select", "edge", (e) => onEdgeSelect(e)); + + cy.on("unselect", (e) => onUnselect(e)); + + cy.on("add", "node", (e) => onNodeAdded(e)); + cy.on("add", "edge", (e) => onEdgeAdded(e)); + cy.on("remove", "node", (e) => onNodeRemoved(e)); + cy.on("remove", "edge", (e) => onEdgeRemoved(e)); + + cy.on("mouseover", "edge", (e) => onEdgeHover(e)); + cy.on("mouseout", "edge", (e) => onEdgeHoverOut(e)); + cy.on("mouseover", "node", (e) => onNodeHover(e)); + cy.on("mouseout", "node", (e) => onNodeHoverOut(e)); + + // Handles dragging + cy.on("drag", "node", (e) => onNodeDrag(e, selectedAction)); + cy.on("free", "node", (e) => onNodeDragStop(e, selectedAction)); + + cy.on("cxttap", "node", (e) => onCtxTap(e)); + + document.title = "Workflow - " + workflow.name; + registerKeys(); + } //}) const stopSchedule = (trigger, triggerindex) => { @@ -5137,16 +5140,16 @@ const AngularWorkflow = (defaultprops) => { return; } - var mappedStartnode = "" - const alledges = cy.edges().jsons() - for (var key in alledges) { - const tmp = alledges[key] - console.log("TMP: ", tmp, tmp.data.source) - if (tmp.data.source === trigger.id) { - mappedStartnode = tmp.data.target - break - } - } + var mappedStartnode = "" + const alledges = cy.edges().jsons() + for (var key in alledges) { + const tmp = alledges[key] + console.log("TMP: ", tmp, tmp.data.source) + if (tmp.data.source === trigger.id) { + mappedStartnode = tmp.data.target + break + } + } alert.info("Creating schedule with name " + trigger.name); const data = { @@ -5155,7 +5158,7 @@ const AngularWorkflow = (defaultprops) => { execution_argument: workflow.triggers[triggerindex].parameters[1].value, environment: workflow.triggers[triggerindex].environment, id: trigger.id, - start: mappedStartnode, + start: mappedStartnode, } fetch( @@ -5201,8 +5204,8 @@ const AngularWorkflow = (defaultprops) => { marginRight: 5, display: "flex", flexDirection: "column", - minHeight: isMobile ? bodyHeight-appBarSize*4 : "100%", - maxHeight: isMobile ? bodyHeight-appBarSize*4 : "100%", + minHeight: isMobile ? bodyHeight - appBarSize * 4 : "100%", + maxHeight: isMobile ? bodyHeight - appBarSize * 4 : "100%", }; const paperAppStyle = { @@ -5242,9 +5245,9 @@ const AngularWorkflow = (defaultprops) => { const deleteVariable = (variableIndex) => { //console.log("Delete:", variableName); - if (workflow.workflow_variables !== undefined && workflow.workflow_variables !== null && workflow.workflow_variables.length > variableIndex) { - workflow.workflow_variables.splice(variableIndex, 1) - } + if (workflow.workflow_variables !== undefined && workflow.workflow_variables !== null && workflow.workflow_variables.length > variableIndex) { + workflow.workflow_variables.splice(variableIndex, 1) + } //workflow.workflow_variables = workflow.workflow_variables.filter( // (data) => data.name !== variableName @@ -5253,9 +5256,9 @@ const AngularWorkflow = (defaultprops) => { }; const deleteExecutionVariable = (variableIndex) => { - if (workflow.execution_variables !== undefined && workflow.execution_variables !== null && workflow.execution_variables.length > variableIndex) { - workflow.execution_variables.splice(variableIndex, 1) - } + if (workflow.execution_variables !== undefined && workflow.execution_variables !== null && workflow.execution_variables.length > variableIndex) { + workflow.execution_variables.splice(variableIndex, 1) + } //workflow.execution_variables = workflow.execution_variables.filter( // (data) => data.name !== variableName @@ -5287,103 +5290,103 @@ const AngularWorkflow = (defaultprops) => { {workflow.workflow_variables === null ? null : workflow.workflow_variables.map((variable, index) => { - return ( -