Skip to content

Commit

Permalink
"More changes final"
Browse files Browse the repository at this point in the history
  • Loading branch information
svalenciaaq committed Nov 23, 2020
1 parent 725310e commit 6ffe4b1
Show file tree
Hide file tree
Showing 35 changed files with 597 additions and 156 deletions.
3 changes: 2 additions & 1 deletion Back/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var CropRouter = require('./routes/crop');
var UserRouter = require('./routes/users');
var PlantationRouter = require('./routes/plantation');
var HistoryRouter = require('./routes/history');
var PlanningRouter = require('./routes/planning');
var app = express();

// view engine setup
Expand All @@ -36,7 +37,7 @@ app.use('/crop', CropRouter);
app.use('/user', UserRouter);
app.use('/plantation', PlantationRouter);
app.use('/plant/history', HistoryRouter);

app.use('/planning', PlanningRouter);

// catch 404 and forward to error handler
app.use(function(req, res, next) {
Expand Down
3 changes: 3 additions & 0 deletions Back/controllers/HistoryController.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ var History = require('../model/History')
const controller = {}

controller.add = async (req, res) => {



var newRecord = new History({
description: req.body.description,
date: req.body.date,
Expand Down
152 changes: 152 additions & 0 deletions Back/controllers/PlanningController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
const express = require('express')
var router = express.Router()
var ObjectID = require('mongoose').Types.ObjectId
var Planning = require('../model/Planning.js')




const controller = {}

controller.add = async (req, res) => {

var str = req.body.date;
var split= str.split("-");
var entryDate= new Date(split[0],split[1]-1,split[2]);

console.log(req.body.tratament)
if(req.body.tratament=="irrigation"){
entryDate.setDate(entryDate.getDate()+5);
var mDate = entryDate.getMonth();
var yDate = entryDate.getUTCFullYear();
var dDate = entryDate.getDate();

var mMonth = parseInt(mDate) + 1;

}


if(req.body.tratament=="pruning"){
entryDate.setDate(entryDate.getDate()+3);
var mDate = entryDate.getMonth();
var yDate = entryDate.getUTCFullYear();
var dDate = entryDate.getDate();

var mMonth = parseInt(mDate) + 1;

}

if(req.body.tratament=="cloning"){
entryDate.setDate(entryDate.getDate()+4);
var mDate = entryDate.getMonth();
var yDate = entryDate.getUTCFullYear();
var dDate = entryDate.getDate();

var mMonth = parseInt(mDate) + 1;

}

if(req.body.tratament=="fumigation"){
entryDate.setDate(entryDate.getDate()+6);
var mDate = entryDate.getMonth();
var yDate = entryDate.getUTCFullYear();
var dDate = entryDate.getDate();

var mMonth = parseInt(mDate) + 1;

}



var date= yDate + "-" + mMonth + "-" + dDate;



var newRecord = new Planning({
date: date,
tratament: req.body.tratament,
plant: req.body.plant
})

newRecord.save((err, docs) => {
if (!err) res.send(docs)
else console.log('Error while creating new record : ' + JSON.stringify(err, undefined, 2))
})
}

controller.list = async ( req, res) => {
const planning = await Planning.find({"plant": req.params.id})
.then(planning =>{
res.send(planning)
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving tutorials."
});
});

}





controller.findOne = async (req , res) =>{
Planning.findById(req.params.id)
.then((planning) => {
if (!planning) {
return res.status(404).send({
message: "User not found with id " + req.params.id,
})


}
res.status(200).send(planning);
console.log(planning);
})
.catch((err) => {
return res.status(500).send({
message: "Error retrieving user with id " + req.params.id,
});
});
}
controller.delete = async (req , res) =>{
Planning.findByIdAndRemove(req.params.id, (error, data) => {
if (error) {
return next(error);
} else {
res.status(200).json({
msg: data
})
}
})
}


controller.edit = async (req, res) => {

const id = req.params.id;

Planning.findByIdAndUpdate(id, req.body, { useFindAndModify: false })
.then(data => {
if (!data) {
res.status(404).send({
message: `Cannot update Tutorial with id=${id}. Maybe Tutorial was not found!`
});
} else res.send({ message: "Tutorial was updated successfully." });
})
.catch(err => {
res.status(500).send({
message: "Error updating Tutorial with id=" + id
});
});


}





module.exports = controller;
27 changes: 21 additions & 6 deletions Back/controllers/PlantController.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ controller.add = async (req, res) => {

var y = x + 1;

var url=""


var newRecord = new Plant({
id: y,
type: req.body.type,
date: req.body.date,
picture: req.body.picture,
picture: y,
crop:req.body.crop
})

newRecord.save((err, docs) => {
if (!err) res.send(docs)
else console.log('Error while creating new record : ' + JSON.stringify(err, undefined, 2))
})

alert(y)
}

controller.list = async ( req, res) => {
Expand All @@ -50,11 +53,7 @@ controller.add = async (req, res) => {
});

}






controller.findOne = async (req , res) =>{
Plant.findById(req.params.id)
.then((plant) => {
Expand Down Expand Up @@ -109,6 +108,22 @@ controller.edit = async (req, res) => {
}


controller.searchId = async (req,res) =>{

const plant = await Plant.find({"id": req.params.id})
.then(plant =>{
res.send(plant)
})
.catch(err => {
res.status(500).send({
message:
err.message || "Some error occurred while retrieving tutorials."
});
});

}





Expand Down
18 changes: 18 additions & 0 deletions Back/model/Planning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var mongoose = require('mongoose');
var Schema =mongoose.Schema;


let planning= new Schema({
date:{
type:String
},
tratament:{
type: String
},
plant:{
type:String
},
})


module.exports = mongoose.model('planning', planning);
13 changes: 13 additions & 0 deletions Back/routes/planning.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var express = require('express');
var router = express.Router();
var PlanningController = require("../controllers/PlanningController");


router.get('/list/:id',PlanningController.list);
router.delete('/delete/:id' ,PlanningController.delete);
router.post('/add',PlanningController.add);
router.put('/edit/:id',PlanningController.edit);
router.get('/findOne/:id', PlanningController.findOne);


module.exports = router
2 changes: 1 addition & 1 deletion Back/routes/plant.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ router.delete('/delete/:id' , PlantController.delete);
router.post('/add', PlantController.add);
router.put('/edit/:id', PlantController.edit);
router.get('/findOne/:id', PlantController.findOne);

router.get(`/title/:id`,PlantController.searchId);


module.exports = router
Binary file added harvest-management/public/img/1.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/2.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/3.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/4.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/5.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/6.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/7.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/8.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added harvest-management/public/img/9.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion harvest-management/src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
position:fixed;
left:0px;
bottom:0px;
height:30px;
height:50px;
width:100%;
background:lawngreen;
}
Expand Down
7 changes: 4 additions & 3 deletions harvest-management/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import PlantationList from "./components/plantation/plantation.list";
import PlantationAdd from "./components/plantation/plantation.add";
import plantationEdit from "./components/plantation/plantation.edit";


import PlanningList from "./components/planning/plant.plannig";



Expand Down Expand Up @@ -148,15 +148,16 @@ class App extends Component {
<Route exact path ="/user"component={UserList}/>




<Route exact path ="/plant/planning/:id"component={PlanningList}/>

</Switch>
</div>


<footer id="footer" className="py-2 footer-custom text-white-50 mt-2 navbar-fixed-bottom">
<div className="container text-center">
<small>Copyright &copy; Harvest manangement</small>
<small className="text-white">nothing works better than a harvest management</small>
</div>
</footer>
</div>
Expand Down
25 changes: 21 additions & 4 deletions harvest-management/src/components/History/plant.addhistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Form from "react-bootstrap/Form";
import Button from "react-bootstrap/Button";
import HistoryDateService from "../../services/HistoryService";
import { Link} from "react-router-dom";
import PlanningDateService from "../../services/PlanningService";

class AddHistory extends Component {
constructor(props) {
Expand Down Expand Up @@ -54,6 +55,22 @@ saveHistory(){
.catch(e =>{
console.log(e)
});

PlanningDateService.create(data)
.then(response =>{
this.setState({
date: this.state.date,
tratament: this.state.tratament,
plant: this.props.match.params.id,
});
console.log(response.data);
})
.catch(e =>{
console.log(e)
});



this.redirect()
}

Expand Down Expand Up @@ -186,10 +203,10 @@ handleSubmit(event) {
: "form-control"
} name="tratament" value={this.state.tratament} onChange={this.handleInputChange}>
<option value=""></option>
<option value="Irrigation">Irrigation</option>
<option value="Pruning">Pruning</option>
<option value="cocout">Coconut</option>
<option value="mango">Mango</option>
<option value="irrigation">Irrigation</option>
<option value="pruning">Pruning</option>
<option value="cloning">Cloning</option>
<option value="fumigation">Fumigation</option>
</select>

<div
Expand Down

0 comments on commit 6ffe4b1

Please sign in to comment.