added the task stuff back in where it was commented out
This commit is contained in:
parent
2ef22a8bc2
commit
cbbda3a6f2
3 changed files with 131 additions and 131 deletions
|
|
@ -7,10 +7,10 @@ import {
|
|||
TextField
|
||||
} from "@mui/material";
|
||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
import { Field, HarvestPlan, /*Task*/ } from "models";
|
||||
import { Field, HarvestPlan, Task } from "models";
|
||||
import moment from "moment";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useHarvestPlanAPI/*, useTaskAPI*/ } from "providers";
|
||||
import { useHarvestPlanAPI, useTaskAPI } from "providers";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
|
||||
interface Props {
|
||||
|
|
@ -23,22 +23,22 @@ interface Props {
|
|||
export default function DuplicateHarvestPlan(props: Props) {
|
||||
const { open, close, fields, plan } = props;
|
||||
const [newFieldIndex, setNewFieldIndex] = useState(0);
|
||||
//const [planTasks, setPlanTasks] = useState<Task[]>([]);
|
||||
const [planTasks, setPlanTasks] = useState<Task[]>([]);
|
||||
const [title, setTitle] = useState("");
|
||||
const harvestPlanAPI = useHarvestPlanAPI();
|
||||
//const taskAPI = useTaskAPI();
|
||||
const taskAPI = useTaskAPI();
|
||||
const [ready, setReady] = useState(false);
|
||||
|
||||
// const loadTasks = useCallback(() => {
|
||||
// taskAPI.listTasks(50, 0, "asc", "start", plan.key()).then(resp => {
|
||||
// setPlanTasks(resp.data.tasks.map(t => Task.any(t)));
|
||||
// setReady(true);
|
||||
// });
|
||||
// }, [taskAPI, plan]);
|
||||
const loadTasks = useCallback(() => {
|
||||
taskAPI.listTasks(50, 0, "asc", "start", plan.key()).then(resp => {
|
||||
setPlanTasks(resp.data.tasks.map(t => Task.any(t)));
|
||||
setReady(true);
|
||||
});
|
||||
}, [taskAPI, plan]);
|
||||
|
||||
// useEffect(() => {
|
||||
// loadTasks();
|
||||
// }, [loadTasks]);
|
||||
useEffect(() => {
|
||||
loadTasks();
|
||||
}, [loadTasks]);
|
||||
|
||||
const duplicate = () => {
|
||||
let planSettings = HarvestPlan.clone(plan).settings;
|
||||
|
|
@ -48,11 +48,11 @@ export default function DuplicateHarvestPlan(props: Props) {
|
|||
planSettings.title = title;
|
||||
}
|
||||
harvestPlanAPI.addHarvestPlan(planSettings).then(resp => {
|
||||
// let tasks = planTasks;
|
||||
// tasks.forEach(task => {
|
||||
// task.settings.objectKey = resp.data.harvestPlan;
|
||||
// taskAPI.addTask(task.settings);
|
||||
// });
|
||||
let tasks = planTasks;
|
||||
tasks.forEach(task => {
|
||||
task.settings.objectKey = resp.data.harvestPlan;
|
||||
taskAPI.addTask(task.settings);
|
||||
});
|
||||
});
|
||||
close();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -22,12 +22,12 @@ import {
|
|||
import { makeStyles } from "@mui/styles";
|
||||
import ResponsiveDialog from "common/ResponsiveDialog";
|
||||
import { useMobile, useSnackbar } from "hooks";
|
||||
import { Field, HarvestPlan/*, Task*/ } from "models";
|
||||
import { Field, HarvestPlan, Task } from "models";
|
||||
import moment from "moment";
|
||||
import { pond } from "protobuf-ts/pond";
|
||||
import { useHarvestPlanAPI/*, useTaskAPI*/ } from "providers";
|
||||
import { useHarvestPlanAPI, useTaskAPI } from "providers";
|
||||
import React, { useCallback, useEffect, useState } from "react";
|
||||
//import TaskSettings from "tasks/TaskSettings";
|
||||
import TaskSettings from "tasks/TaskSettings";
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
|
|
@ -166,8 +166,8 @@ export default function HarvestSettings(props: Props) {
|
|||
const [activeStep, setActiveStep] = useState(0);
|
||||
const isMobile = useMobile();
|
||||
const classes = useStyles();
|
||||
//const [planTasks, setPlanTasks] = useState<Task[]>([]);
|
||||
//const taskAPI = useTaskAPI();
|
||||
const [planTasks, setPlanTasks] = useState<Task[]>([]);
|
||||
const taskAPI = useTaskAPI();
|
||||
const harvestPlanAPI = useHarvestPlanAPI();
|
||||
const [title, setTitle] = useState("");
|
||||
const [cropType, setCropType] = useState(0);
|
||||
|
|
@ -179,21 +179,21 @@ export default function HarvestSettings(props: Props) {
|
|||
const [price, setPrice] = useState("");
|
||||
const [newTaskDialog, setNewTaskDialog] = useState(false);
|
||||
const [type, setType] = useState("");
|
||||
//const [taskToEdit, setTaskToEdit] = useState<Task>();
|
||||
const [taskToEdit, setTaskToEdit] = useState<Task>();
|
||||
const { openSnack } = useSnackbar();
|
||||
const [deleteOpen, setDeleteOpen] = useState(false);
|
||||
|
||||
// const loadTasks = useCallback(() => {
|
||||
// if (planKey) {
|
||||
// taskAPI.getMultiTasks([planKey]).then(resp => {
|
||||
// setPlanTasks(resp.data.tasks.map(t => Task.any(t)));
|
||||
// });
|
||||
// }
|
||||
// }, [taskAPI, planKey]);
|
||||
const loadTasks = useCallback(() => {
|
||||
if (planKey) {
|
||||
taskAPI.getMultiTasks([planKey]).then(resp => {
|
||||
setPlanTasks(resp.data.tasks.map(t => Task.any(t)));
|
||||
});
|
||||
}
|
||||
}, [taskAPI, planKey]);
|
||||
|
||||
// useEffect(() => {
|
||||
// loadTasks();
|
||||
// }, [loadTasks]);
|
||||
useEffect(() => {
|
||||
loadTasks();
|
||||
}, [loadTasks]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!plan || (plan && plan.permissions.includes(pond.Permission.PERMISSION_WRITE))) {
|
||||
|
|
@ -227,71 +227,71 @@ export default function HarvestSettings(props: Props) {
|
|||
close(reload, updatedPlan);
|
||||
};
|
||||
|
||||
// const showTasks = (type: string) => {
|
||||
// let tasks: Task[] = [];
|
||||
// let costTotal = 0;
|
||||
// let secondaryCostTotal = 0;
|
||||
// planTasks.forEach(task => {
|
||||
// if (task.settings.type === type) {
|
||||
// tasks.push(task);
|
||||
// costTotal += task.cost();
|
||||
// secondaryCostTotal += task.secondaryCost();
|
||||
// }
|
||||
// });
|
||||
const showTasks = (type: string) => {
|
||||
let tasks: Task[] = [];
|
||||
let costTotal = 0;
|
||||
let secondaryCostTotal = 0;
|
||||
planTasks.forEach(task => {
|
||||
if (task.settings.type === type) {
|
||||
tasks.push(task);
|
||||
costTotal += task.cost();
|
||||
secondaryCostTotal += task.secondaryCost();
|
||||
}
|
||||
});
|
||||
|
||||
// let frag = (
|
||||
// <React.Fragment>
|
||||
// <Table>
|
||||
// <TableHead>
|
||||
// <TableRow>
|
||||
// <TableCell>Title</TableCell>
|
||||
// <TableCell>Description</TableCell>
|
||||
// {!isMobile && <TableCell>Material Cost(acre)</TableCell>}
|
||||
// {!isMobile && <TableCell>Equipment Cost(acre)</TableCell>}
|
||||
// <TableCell>Total(acre)</TableCell>
|
||||
// {!isMobile && <TableCell>Start -End</TableCell>}
|
||||
// <TableCell>Edit</TableCell>
|
||||
// </TableRow>
|
||||
// </TableHead>
|
||||
// <TableBody>
|
||||
// {tasks.map((task, i) => (
|
||||
// <TableRow key={i}>
|
||||
// <TableCell>{task.title()}</TableCell>
|
||||
// <TableCell>{task.description()}</TableCell>
|
||||
// {!isMobile && <TableCell>${task.cost().toFixed(2)}</TableCell>}
|
||||
// {!isMobile && <TableCell>${task.secondaryCost().toFixed(2)}</TableCell>}
|
||||
// <TableCell>
|
||||
// ${(Math.round((task.cost() + task.secondaryCost()) * 100) / 100).toFixed(2)}
|
||||
// </TableCell>
|
||||
// {!isMobile && (
|
||||
// <TableCell>
|
||||
// {task.start()} {task.end()}
|
||||
// </TableCell>
|
||||
// )}
|
||||
// <TableCell>
|
||||
// <Button
|
||||
// color="primary"
|
||||
// onClick={() => {
|
||||
// setTaskToEdit(task);
|
||||
// setNewTaskDialog(true);
|
||||
// }}>
|
||||
// Edit
|
||||
// </Button>
|
||||
// </TableCell>
|
||||
// </TableRow>
|
||||
// ))}
|
||||
// </TableBody>
|
||||
// </Table>
|
||||
// <Box>
|
||||
// <Typography>
|
||||
// Total: $
|
||||
// {(Math.round((costTotal + secondaryCostTotal) * field.acres() * 100) / 100).toFixed(2)}
|
||||
// </Typography>
|
||||
// </Box>
|
||||
// </React.Fragment>
|
||||
// );
|
||||
// return frag;
|
||||
// };
|
||||
let frag = (
|
||||
<React.Fragment>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Title</TableCell>
|
||||
<TableCell>Description</TableCell>
|
||||
{!isMobile && <TableCell>Material Cost(acre)</TableCell>}
|
||||
{!isMobile && <TableCell>Equipment Cost(acre)</TableCell>}
|
||||
<TableCell>Total(acre)</TableCell>
|
||||
{!isMobile && <TableCell>Start -End</TableCell>}
|
||||
<TableCell>Edit</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{tasks.map((task, i) => (
|
||||
<TableRow key={i}>
|
||||
<TableCell>{task.title()}</TableCell>
|
||||
<TableCell>{task.description()}</TableCell>
|
||||
{!isMobile && <TableCell>${task.cost().toFixed(2)}</TableCell>}
|
||||
{!isMobile && <TableCell>${task.secondaryCost().toFixed(2)}</TableCell>}
|
||||
<TableCell>
|
||||
${(Math.round((task.cost() + task.secondaryCost()) * 100) / 100).toFixed(2)}
|
||||
</TableCell>
|
||||
{!isMobile && (
|
||||
<TableCell>
|
||||
{task.start()} {task.end()}
|
||||
</TableCell>
|
||||
)}
|
||||
<TableCell>
|
||||
<Button
|
||||
color="primary"
|
||||
onClick={() => {
|
||||
setTaskToEdit(task);
|
||||
setNewTaskDialog(true);
|
||||
}}>
|
||||
Edit
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
<Box>
|
||||
<Typography>
|
||||
Total: $
|
||||
{(Math.round((costTotal + secondaryCostTotal) * field.acres() * 100) / 100).toFixed(2)}
|
||||
</Typography>
|
||||
</Box>
|
||||
</React.Fragment>
|
||||
);
|
||||
return frag;
|
||||
};
|
||||
|
||||
const savePlan = () => {
|
||||
let newPlanSettings = pond.HarvestPlanSettings.create({
|
||||
|
|
@ -326,30 +326,30 @@ export default function HarvestSettings(props: Props) {
|
|||
let postseedEqCost = 0;
|
||||
let harvestEqCost = 0;
|
||||
let fallEqCost = 0;
|
||||
// planTasks.forEach(task => {
|
||||
// switch (task.settings.type) {
|
||||
// case "preseed":
|
||||
// preseedMatCost += task.cost();
|
||||
// preseedEqCost += task.secondaryCost();
|
||||
// break;
|
||||
// case "seed":
|
||||
// seedMatCost += task.cost();
|
||||
// seedEqCost += task.secondaryCost();
|
||||
// break;
|
||||
// case "postseed":
|
||||
// postseedMatCost += task.cost();
|
||||
// postseedEqCost += task.secondaryCost();
|
||||
// break;
|
||||
// case "harvest":
|
||||
// harvestMatCost += task.cost();
|
||||
// harvestEqCost += task.secondaryCost();
|
||||
// break;
|
||||
// default:
|
||||
// fallMatCost += task.cost();
|
||||
// fallEqCost += task.secondaryCost();
|
||||
// break;
|
||||
// }
|
||||
// });
|
||||
planTasks.forEach(task => {
|
||||
switch (task.settings.type) {
|
||||
case "preseed":
|
||||
preseedMatCost += task.cost();
|
||||
preseedEqCost += task.secondaryCost();
|
||||
break;
|
||||
case "seed":
|
||||
seedMatCost += task.cost();
|
||||
seedEqCost += task.secondaryCost();
|
||||
break;
|
||||
case "postseed":
|
||||
postseedMatCost += task.cost();
|
||||
postseedEqCost += task.secondaryCost();
|
||||
break;
|
||||
case "harvest":
|
||||
harvestMatCost += task.cost();
|
||||
harvestEqCost += task.secondaryCost();
|
||||
break;
|
||||
default:
|
||||
fallMatCost += task.cost();
|
||||
fallEqCost += task.secondaryCost();
|
||||
break;
|
||||
}
|
||||
});
|
||||
let tempPlan = plan ?? newPlan;
|
||||
tempPlan.settings.cropType = cropType;
|
||||
tempPlan.settings.field = field.key();
|
||||
|
|
@ -525,7 +525,7 @@ export default function HarvestSettings(props: Props) {
|
|||
Add Crop Activity
|
||||
</Button>
|
||||
<Typography>Planned Activities</Typography>
|
||||
{/* {showTasks("preseed")} */}
|
||||
{showTasks("preseed")}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
@ -542,7 +542,7 @@ export default function HarvestSettings(props: Props) {
|
|||
Add Crop Activity
|
||||
</Button>
|
||||
<Typography>Planned Activities</Typography>
|
||||
{/* {showTasks("seed")} */}
|
||||
{showTasks("seed")}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
@ -559,7 +559,7 @@ export default function HarvestSettings(props: Props) {
|
|||
Add Crop Activity
|
||||
</Button>
|
||||
<Typography>Planned Activities</Typography>
|
||||
{/* {showTasks("postseed")} */}
|
||||
{showTasks("postseed")}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
@ -576,7 +576,7 @@ export default function HarvestSettings(props: Props) {
|
|||
Add Crop Activity
|
||||
</Button>
|
||||
<Typography>Planned Activities</Typography>
|
||||
{/* {showTasks("harvest")} */}
|
||||
{showTasks("harvest")}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
@ -593,7 +593,7 @@ export default function HarvestSettings(props: Props) {
|
|||
Add Crop Activity
|
||||
</Button>
|
||||
<Typography>Planned Activities</Typography>
|
||||
{/* {showTasks("fall")} */}
|
||||
{showTasks("fall")}
|
||||
</Box>
|
||||
);
|
||||
};
|
||||
|
|
@ -706,7 +706,7 @@ export default function HarvestSettings(props: Props) {
|
|||
</DialogActions>
|
||||
</ResponsiveDialog>
|
||||
{deleteDialog()}
|
||||
{/* <TaskSettings
|
||||
<TaskSettings
|
||||
task={taskToEdit}
|
||||
hasCost
|
||||
costTitle="Material Cost(acres)"
|
||||
|
|
@ -722,7 +722,7 @@ export default function HarvestSettings(props: Props) {
|
|||
loadTasks();
|
||||
}
|
||||
}}
|
||||
/> */}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import DisplayDrawer from "common/DisplayDrawer";
|
|||
import HarvestPlanDisplay from "harvestPlan/HarvestPlanDisplay";
|
||||
import { Field, fieldScope, HarvestPlan, teamScope } from "models";
|
||||
import React, { useEffect, useState } from "react";
|
||||
//import TaskViewer from "tasks/TaskViewer";
|
||||
import TaskViewer from "tasks/TaskViewer";
|
||||
import Weather from "weather/weather";
|
||||
import { getThemeType } from "theme";
|
||||
import GrainDescriber from "grain/GrainDescriber";
|
||||
|
|
@ -273,7 +273,7 @@ export default function FieldDrawer(props: Props) {
|
|||
<Weather longitude={field.center().longitude} latitude={field.center().latitude} />
|
||||
</TabPanelMine>
|
||||
<TabPanelMine value={value} index={2}>
|
||||
{/* <TaskViewer drawerView objectKey={field.key()} loadKeys={taskLoadKeys} /> */}
|
||||
<TaskViewer drawerView objectKey={field.key()} loadKeys={taskLoadKeys} />
|
||||
</TabPanelMine>
|
||||
</React.Fragment>
|
||||
);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue