diff --git a/frontend/src/Admin.js b/frontend/src/Admin.js index 5d2e8158..a0a1fa74 100644 --- a/frontend/src/Admin.js +++ b/frontend/src/Admin.js @@ -371,7 +371,7 @@ const Admin = (props) => { diff --git a/frontend/src/App.js b/frontend/src/App.js index ac162e47..e40d7660 100644 --- a/frontend/src/App.js +++ b/frontend/src/App.js @@ -42,8 +42,6 @@ var globalUrl = window.location.origin if (window.location.protocol == "http:" && window.location.port === "3000") { globalUrl = "http://192.168.3.6:5001" } -console.log(window.location) -console.log(globalUrl) const surfaceColor = "#27292D" const inputColor = "#383B40" diff --git a/frontend/src/SettingsPage.js b/frontend/src/SettingsPage.js index dad3c89f..f4baa76e 100644 --- a/frontend/src/SettingsPage.js +++ b/frontend/src/SettingsPage.js @@ -3,6 +3,7 @@ import React, {useState, useEffect} from 'react'; import Paper from '@material-ui/core/Paper'; import Button from '@material-ui/core/Button'; import Divider from '@material-ui/core/Divider'; +import {Link} from 'react-router-dom'; import TextField from '@material-ui/core/TextField'; @@ -51,6 +52,7 @@ const Settings = (props) => { const boxStyle = { flex: "1", + color: "white", marginLeft: "10px", marginRight: "10px", paddingLeft: "30px", @@ -181,6 +183,7 @@ const Settings = (props) => {

APIKEY

+ What is the API key used for? { const alert = useAlert() + var upload = "" + const [file, setFile] = React.useState(""); + const [workflows, setWorkflows] = React.useState([]); const [selectedWorkflow, setSelectedWorkflow] = React.useState({}); const [selectedExecution, setSelectedExecution] = React.useState({}); @@ -695,10 +698,8 @@ const Workflows = (props) => { ) } - const setNewWorkflow = () => { - if (newWorkflowName.length === 0) { - return - } + // Can create and set workflows + const setNewWorkflow = (name, description, editingWorkflow, redirect) => { var method = "POST" var extraData = "" @@ -710,12 +711,12 @@ const Workflows = (props) => { workflowdata = editingWorkflow } - workflowdata["name"] = newWorkflowName - workflowdata["description"] = newWorkflowDescription + workflowdata["name"] = name + workflowdata["description"] = description //console.log(workflowdata) //return - fetch(globalUrl+"/api/v1/workflows"+extraData, { + return fetch(globalUrl+"/api/v1/workflows"+extraData, { method: method, headers: { 'Content-Type': 'application/json', @@ -732,17 +733,71 @@ const Workflows = (props) => { return response.json() }) .then((responseJson) => { - if (method === "POST") { + if (method === "POST" && redirect) { window.location.pathname = "/workflows/"+responseJson["id"] + } else if (!redirect) { + // Update :) + getAvailableWorkflows() } else { alert.info("Successfully changed basic info for workflow") } + + return responseJson }) .catch(error => { alert.error(error.toString()) }); } + + const importFiles = (event) => { + const file = event.target.value + if (event.target.files.length > 0) { + for (var key in event.target.files) { + const file = event.target.files[key] + if (file.type !== "application/json") { + //alert.error("File has to contain json.") + continue + } + + const reader = new FileReader() + // Waits for the read + reader.addEventListener('load', (event) => { + var data = reader.result + try { + data = JSON.parse(reader.result) + } catch (e) { + alert.error("Invalid JSON: "+e) + return + } + + // Initialize the workflow itself + const ret = setNewWorkflow(data.name, data.description, {}, false) + .then((response) => { + if (response !== undefined) { + // SET THE FULL THING + data.id = response.id + + // Actually create it + const ret = setNewWorkflow(data.name, data.description, data, false) + .then((response) => { + if (response !== undefined) { + alert.success("Successfully created "+data.name) + } + }) + } + }) + .catch(error => { + alert.error("Import error: "+error.toString()) + }); + }) + + // Actually reads + reader.readAsText(file) + } + } + } + const modalView = modalOpen ? { Cancel -
-
- -
+
+ + + upload = ref} onChange={importFiles} />