import React, { useEffect} from 'react'; import Paper from '@material-ui/core/Paper'; import Grid from '@material-ui/core/Grid'; import ButtonBase from '@material-ui/core/ButtonBase'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import Button from '@material-ui/core/Button'; //import Breadcrumbs from '@material-ui/core/Breadcrumbs'; const Schedules = (props) => { const { globalUrl } = props; //const [schedules, setSchedules] = React.useState(scheduledata); const [schedules, setSchedules] = React.useState({}); const getAvailableSchedules = () => { fetch(globalUrl+"/api/v1/schedules", { method: 'GET', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, }) .then((response) => response.json()) .then((responseJson) => { setSchedules(responseJson) }) .catch(error => { console.log(error) }); } // FIXME - add automated redirection, as empty apps look horrible currently const newSchedule = () => { fetch(globalUrl+"/api/v1/schedules/new", { method: "POST", headers: {"content-type": "application/json"}, body: JSON.stringify(), }) .then((response) => response.json()) .then((responseJson) => { console.log(responseJson) setSchedules({}) }) .catch(error => { console.log(error) }); } const deleteSchedule = (id) => { if (id === undefined) { return } fetch(globalUrl+"/api/v1/schedules/"+id+"/delete", { method: 'DELETE', headers: { 'Content-Type': 'application/json', 'Accept': 'application/json', }, }) .then((response) => response.json()) .then((responseJson) => { setSchedules({}) }) .catch(error => { console.log(error) }); } // FIXME - use this? //const getNewScheduleInfo = () => { // fetch(globalUrl+"/api/v1/schedules", { // method: 'GET', // headers: { // 'Content-Type': 'application/json', // 'Accept': 'application/json', // }, // }) // .then((response) => response.json()) // .then((responseJson) => { // setSchedules(responseJson) // }) // .catch(error => { // console.log(error) // }); //} useEffect(() => { if (Object.getOwnPropertyNames(schedules).length <= 0) { getAvailableSchedules() } }) const bodyDivStyle = { marginLeft: "20px", marginRight: "20px", width: "1350px", minWidth: "1350px", maxWidth: "1350px", } const scheduleApp = (app) => { console.log(app) return(

{app.name}

{app.description}
{app.action}
) } const splitter =
const hrefStyle = { color: "#385f71", textDecoration: "none" } // FIXME - add Schedule modal const schedulePaper = (schedule) => { return(
{scheduleApp(schedule.appinfo.sourceapp)}
ARROW
{scheduleApp(schedule.appinfo.destinationapp)}
{splitter}
) } console.log(schedules) console.log(schedules) console.log(schedules.schedules) const schedulemap = Object.getOwnPropertyNames(schedules).length > 0 && schedules.schedules && schedules.schedules.length > 0 ?
{schedules.schedules.map(data => ( schedulePaper(data) ))}
:
const scheduleView = Object.getOwnPropertyNames(schedules).length > 0 ?
{schedulemap}
: null // Maybe use gridview or something, idk return (
{scheduleView}
) } export default Schedules