Skip to content

Commit

Permalink
Merge pull request #50 from mseng10/mongo_db_support
Browse files Browse the repository at this point in the history
Mongo db support
  • Loading branch information
mseng10 authored Feb 17, 2025
2 parents f0b3475 + de4e6a8 commit fbd5d4e
Show file tree
Hide file tree
Showing 87 changed files with 2,458 additions and 1,689 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
.idea/
myenv/

todo.txt
todo.txt

.installed
1 change: 1 addition & 0 deletions client/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
REACT_APP_API_URL=http://localhost:8002
39 changes: 0 additions & 39 deletions client/.eslintrc.json

This file was deleted.

12 changes: 9 additions & 3 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
FROM node:14

WORKDIR /app
COPY package.json package-lock.json ./

COPY package*.json ./

RUN npm install

COPY . .
RUN npm run build
CMD ["npm", "start"]

EXPOSE 3000

CMD ["npm", "start"]
44 changes: 0 additions & 44 deletions client/nginx.conf

This file was deleted.

4 changes: 4 additions & 0 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import SystemUpdate from './pages/system/SystemUpdate';
import TodoCreate from './pages/todo/TodoCreate';
import TodoUpdate from './pages/todo/TodoUpdate';
import MixCreate from './pages/mix/MixCreate';
import MixUpdate from './pages/mix/MixUpdate';
import Stats from './pages/stat/Stats';
import Mixes from './pages/mix/Mixes';

const drawerWidth = 240;

Expand Down Expand Up @@ -156,7 +158,9 @@ function App() {

{/* <Route path="/genera/create" element={<GeneraCreate /> } /> */}

<Route path="/mixes" element={<Mixes />} />
<Route path="/mixes/create" element={<MixCreate /> } />
<Route path="/mixes/:id" element={<MixUpdate /> } />
</Routes>
</Box>
</ThemeProvider>
Expand Down
3 changes: 2 additions & 1 deletion client/src/AppNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,10 @@ function AppNavigation({ window }) {
]},
{ id: 'view', icon: 'view', color: 'primary', subMenu: [
{ id: 'plants', url: '/plants', icon: 'plant', label: 'Plant' },
{ id: 'mixes', url: '/mixes', icon: 'mix', label: 'Mix' },
{ id: 'systems', url: '/systems', icon: 'system', label: 'System' },
]},
{ id: 'alert', url: '/alerts', icon: 'alert', color: 'primary', badgeCount: meta.alert_count, badgeCountColor: "error" },
{ id: 'alert', url: '/alerts', icon: 'alert', color: 'error', badgeCount: meta.alert_count, badgeCountColor: "error" },
{ id: 'todo', url: '/todos', icon: 'todo', color: 'primary', badgeCount: meta.todo_count},
{ id: 'stats', url: '/stats', icon: 'stats', color: 'primary'},
];
Expand Down
25 changes: 14 additions & 11 deletions client/src/api.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
const API_BASE_URL = 'http://127.0.0.1:5000';
const API_BASE_URL = 'http://127.0.0.1:8002';

export const APIS = {
plant: {
getAll: "/plants/",
create: "/plants/",
getOne: "/plants/{id}/",
updateOne: "/plants/{id}/",
deprecateOne: "/plants/{id}/deprecate/",
deleteOne: "/plants/{id}/",
waterMany: "/plants/water/",
deprecateMany: "/plants/deprecate/"
},
Expand All @@ -15,7 +15,7 @@ export const APIS = {
create: "/systems/",
getOne: "/systems/{id}/",
updateOne: "/systems/{id}/",
deprecateOne: "/systems/{id}/deprecate/",
deleteOne: "/systems/{id}/",
plants: "/systems/{id}/plants/",
alerts: "/systems/{id}/alerts/"
},
Expand All @@ -28,11 +28,14 @@ export const APIS = {
},
alert: {
getAll: "/alerts/",
deprecateOne: "/alerts/{id}/deprecate"
deleteOne: "/alerts/{id}/",
deleteOne: "/todos/{id}/",
},
light: {
getAll: "/lights/",
create: "/lights/"
create: "/lights/",
deleteOne: "/todos/{id}/",

},
meta: {
getOne: "/meta/"
Expand All @@ -44,7 +47,7 @@ export const APIS = {
getAll: "/mixes/",
create: "/mixes/",
updateOne: "/mixes/{id}/",
deprecateOne: "/mixes/{id}/deprecate/"
deleteOne: "/todos/{id}/",
},
soil: {
getAll: "/soils/"
Expand All @@ -60,7 +63,8 @@ export const APIS = {
generaCreate: "/genus_types/{id}/tasks/{eid}/"
},
task: {
updateOne: "/todos/{id}/tasks/{eid}/"
resolve: "/todos/{id}/tasks/{eid}/resolve",
unresolve: "/todos/{id}/tasks/{eid}/unresolve"
},
}

Expand Down Expand Up @@ -113,7 +117,7 @@ export const simplePost = (url, model) => {
});
};

/** Wrapper for fetch with error handling and jsonifying. */
/** Wrapper for update handling and jsonifying. */
export const simplePatch = (url, patchModel) => {
return fetch(url, {
method: 'PATCH',
Expand All @@ -129,7 +133,7 @@ export const simplePatch = (url, patchModel) => {
});
};

/** Wrapper for fetch with error handling and jsonifying. */
/** Wrapper for delete handling and jsonifying. */
export const simpleDelete = (url) => {
return fetch(url, {
method: 'DELETE',
Expand All @@ -139,7 +143,6 @@ export const simpleDelete = (url) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}

return response.json();
return "";
});
};
5 changes: 3 additions & 2 deletions client/src/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Plant Phases
export const PHASE_LABELS = {
adult: "Adult",
cutting: "Cutting",
seed: "Seed",
juvy: "Juvy",
adult: "Adult",
leaf: "Leaf",
seed: "Seed",
};

export const CARD_STYLE = {
Expand Down
4 changes: 2 additions & 2 deletions client/src/hooks/useAlerts.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { simpleFetch, simplePost, APIS, apiBuilder } from '../api';
import { simpleFetch, simplePost, APIS, apiBuilder, simpleDelete } from '../api';

export const useAlerts = (initialAlerts = []) => {
const [alerts, setAlerts] = useState(initialAlerts);
Expand All @@ -18,7 +18,7 @@ export const useAlerts = (initialAlerts = []) => {
const resolveAlert = async (id) => {
setIsLoading(true);
setError(null);
simplePost(apiBuilder(APIS.alert.deprecateOne).setId(id).get())
simpleDelete(apiBuilder(APIS.alert.deleteOne).setId(id).get())
.then(() =>
setAlerts(prevAlerts => prevAlerts.filter(alert =>
alert.id !== id
Expand Down
17 changes: 12 additions & 5 deletions client/src/hooks/useMix.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { simpleFetch, simplePost, apiBuilder, APIS } from '../api';
import { simpleFetch, simplePost, apiBuilder, simplePatch, APIS, simpleDelete } from '../api';

export const useMixes = () => {
const [mixes, setMixes] = useState([]);
Expand Down Expand Up @@ -34,7 +34,7 @@ export const useMixes = () => {
const updateMix = async (updatedMix) => {
setIsLoading(true);
setError(null);
simplePost(apiBuilder(APIS.mix.updateOne).setId(updatedMix.id).get(), updatedMix)
simplePatch(apiBuilder(APIS.mix.updateOne).setId(updatedMix.id).get(), updatedMix)
.then(data =>
setMixes(prevMixes => prevMixes.map(mix =>
mix.id === updatedMix.id ? { ...mix, ...data } : mix
Expand All @@ -47,10 +47,10 @@ export const useMixes = () => {
};

/** Deprecate the mix */
const deprecateMix = async (id) => {
const deleteMix = async (id) => {
setIsLoading(true);
setError(null);
simplePost(apiBuilder(APIS.plant.deprecateOne).setId(id).get())
simpleDelete(apiBuilder(APIS.plant.deleteOne).setId(id).get())
.then(() =>
setMixes(prevMixes => prevMixes.filter(mix =>
mix.id !== id
Expand All @@ -62,7 +62,14 @@ export const useMixes = () => {
setIsLoading(false))
};

return { mixes, isLoading, error, setError, createMix, updateMix, deprecateMix };
return { mixes, isLoading, error, setError, createMix, updateMix, deleteMix };
};

export const useSoilParts = (initialParts) => {
const [soilParts, setSoilParts] = useState(initialParts);
const [isLoading, setIsLoading] = useState(true);

return { soilParts, isLoading, setSoilParts, setIsLoading };
};

/** Query a all soil matters. */
Expand Down
1 change: 0 additions & 1 deletion client/src/hooks/usePlants.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ export const usePlants = (initialPlants) => {

/** Update a system with a new version. */
const updatePlant = async (updatedPlant) => {
console.log(updatedPlant);
const id = updatedPlant.id;
setIsLoading(true);
setError(null);
Expand Down
4 changes: 2 additions & 2 deletions client/src/hooks/useSystems.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useState, useEffect } from 'react';
import { simpleFetch, simplePost, simplePatch, apiBuilder, APIS } from '../api';
import { simpleFetch, simplePost, simplePatch, apiBuilder, APIS, simpleDelete } from '../api';

/** Query and api functionality for all systems. */
export const useSystems = () => {
Expand Down Expand Up @@ -42,7 +42,7 @@ export const useSystems = () => {
const deprecateSystem = async (id) => {
setIsLoading(true);
setError(null);
simplePost(apiBuilder(APIS.system.deprecateOne).setId(id).get())
simpleDelete(apiBuilder(APIS.system.deleteOne).setId(id).get())
.then(() =>
setSystems(prevSystems => prevSystems.filter(system =>
system.id !== id
Expand Down
32 changes: 31 additions & 1 deletion client/src/hooks/useTodos.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,35 @@ export const useTasks = (initialTasks) => {
setIsLoading(false))
};

return { tasks, isLoading, error, deprecateTask, updateTask };
const resolveTask = async (todo_id, task_id) => {
setIsLoading(true);
setError(null);
simplePost(apiBuilder(APIS.task.resolve).setId(todo_id).setEmbedId(task_id).get(), null)
.then(data =>
setTasks(prevTasks => prevTasks.map(task =>
task.id === task_id ? { ...task, ...data } : task
)))
.catch(error => {
setError(error);
})
.finally(() =>
setIsLoading(false))
};

const unresolveTask = async (todo_id, task_id) => {
setIsLoading(true);
setError(null);
simplePost(apiBuilder(APIS.task.unresolve).setId(todo_id).setEmbedId(task_id).get(), null)
.then(data =>
setTasks(prevTasks => prevTasks.map(task =>
task.id === task_id ? { ...task, ...data } : task
)))
.catch(error => {
setError(error);
})
.finally(() =>
setIsLoading(false))
};

return { tasks, isLoading, error, deprecateTask, resolveTask, unresolveTask };
};
4 changes: 3 additions & 1 deletion client/src/modals/plant/DeprecatePlantsForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import Checkbox from '@mui/material/Checkbox';
import Divider from '@mui/material/Divider';
import Modal from '@mui/material/Modal';
import { MODAL_STYLE } from '../../constants';
import { useSpecies } from '../../hooks/usePlants';

// Enum for cause of death
const CauseOfDeath = Object.freeze({
Expand All @@ -26,6 +27,7 @@ const DeprecatePlantsForm = ({isOpen, initialPlants, onRequestClose}) => {
const { plants, isLoading, error, setPlants, deprecatePlants } = usePlants(initialPlants);
const [checkedPlants, setCheckedPlants] = useState([]);
const [allChecked, setAllChecked] = useState(true);
const {species} = useSpecies();

const [causeOfDeath, setCauseOfDeath] = useState('');
const [formError, setFormError] = useState(null);
Expand Down Expand Up @@ -152,7 +154,7 @@ const DeprecatePlantsForm = ({isOpen, initialPlants, onRequestClose}) => {
/>
}
>
<ListItemText primary={plant.name} style={{ color: "black" }}/>
<ListItemText primary={species.find(_s => _s.id === plant.species_id)?.name || 'N/A'} style={{ color: "black" }}/>
</ListItem>
<Divider sx={{width: '100%' }} component="li" />
</div>
Expand Down
Loading

0 comments on commit fbd5d4e

Please sign in to comment.