From ec822e4cde9568a6af0c65fd092611c0ff6eb792 Mon Sep 17 00:00:00 2001 From: Nick Williams Date: Wed, 26 Aug 2015 14:12:28 -0500 Subject: [PATCH] Farm Editing Implementation. --- public/javascripts/controllers/farmer-ctrl.js | 46 ++++++++++++- public/javascripts/services.js | 10 +++ public/partials/farm_edit.html | 56 +++++++++++++++ public/partials/farmer_profile_large.html | 61 ++--------------- public/partials/farms_card.html | 68 +++++++++++++++++++ routes/farmer/farmer.js | 15 +++- 6 files changed, 196 insertions(+), 60 deletions(-) create mode 100644 public/partials/farm_edit.html create mode 100644 public/partials/farms_card.html diff --git a/public/javascripts/controllers/farmer-ctrl.js b/public/javascripts/controllers/farmer-ctrl.js index aa121f9..de51174 100644 --- a/public/javascripts/controllers/farmer-ctrl.js +++ b/public/javascripts/controllers/farmer-ctrl.js @@ -38,10 +38,10 @@ angular.module('jasmic.controllers') */ .controller('FarmerProfileCtrl', ['$scope', '$location', '$routeParams', '$mdDialog', 'OpenTransactionsFactory', 'TransactionsFactory', 'FarmerFactory', 'ParishesFactory', 'FarmerFarmFactory', 'CropsFactory', - 'UnitsFactory', 'CommodityFactory','CommoditiesFactory', 'DistrictsFactory', 'FarmerMembershipsFactory','CommodityEditFactory', + 'UnitsFactory', 'CommodityFactory','CommoditiesFactory', 'DistrictsFactory', 'FarmerMembershipsFactory','CommodityEditFactory', 'FarmEditFactory', function ($scope, $location, $routeParams, $mdDialog, OpenTransactionsFactory, TransactionsFactory, FarmerFactory, ParishesFactory, FarmerFarmFactory, CropsFactory, UnitsFactory, - CommodityFactory, CommoditiesFactory, DistrictsFactory, FarmerMembershipsFactory, CommodityEditFactory) { + CommodityFactory, CommoditiesFactory, DistrictsFactory, FarmerMembershipsFactory, CommodityEditFactory, FarmEditFactory) { /** * First query for the farmer based on the id supplied in the parameters, * then query for the transactions this farmer has been involved in. @@ -118,6 +118,22 @@ angular.module('jasmic.controllers') $scope.newFarm = !$scope.newFarm; }; + /*.updateFarm = function() { + $scope.farm.di_district = selectedDistrict; + FarmerFarmFactory.create({id:$scope.farmer._id}, $scope.farm, function(success) { + $scope.newFarm = !$scope.newFarm; + loadAll(); + }, function(fail) { + console.log(fail); + console.log($scope.farm); + showDialog($mdDialog, fail, true); + }); + };*/ + + $scope.cancelEdit = function() { + $scope.editFarm = !$scope.editFarm; + }; + /** * Necessary to load all parishes in the necessary forms */ @@ -137,6 +153,14 @@ angular.module('jasmic.controllers') $scope.newFarm = !$scope.newFarm; $scope.farm = {}; }; + + $scope.editFarmLocation = function(arrayindex) { + + $scope.editFarm = !$scope.editFarm; + $scope.farm = $scope.farmer.fr_farms[arrayindex]; + + }; + $scope.newCommodityItem = function() { $scope.newCommodity = !$scope.newCommodity; $scope.commodity = {}; @@ -169,6 +193,24 @@ angular.module('jasmic.controllers') } + + $scope.updateFarm = function(arrayindex) { + + FarmEditFactory.update({farm_id:$scope.farm._id}, $scope.farm, function(success) { + + console.log("Success"); + + $scope.editFarm = false; + + }, function (error) { + + console.log("Error"); + + }); + + } + + $scope.newCommodity = false; $scope.newFarm = false; $scope.editCommodity = false; diff --git a/public/javascripts/services.js b/public/javascripts/services.js index b6f3df5..6f9b5db 100644 --- a/public/javascripts/services.js +++ b/public/javascripts/services.js @@ -229,6 +229,16 @@ services.factory('CommodityEditFactory', function($resource){ }); }); +/** + * Updates a farm + */ + +services.factory('FarmEditFactory', function($resource){ + return $resource('farm/:farm_id', {}, { + update: { method: 'PUT', params: {farm_id: '@farm_id'} }, + }); +}); + /** * Adds a new Demand and associates it with a buyer */ diff --git a/public/partials/farm_edit.html b/public/partials/farm_edit.html new file mode 100644 index 0000000..62e03cb --- /dev/null +++ b/public/partials/farm_edit.html @@ -0,0 +1,56 @@ + +
+ + + {{item.di_extension_name}} + {{item.di_district_name == ""? "" : " - " + item.di_district_name}} + + + No matches found for "{{searchText}}". + + + + + + +
+ + + + + + + + +
+ + + + + + + + +
+ + + + + + + + Cancel + Update + +
diff --git a/public/partials/farmer_profile_large.html b/public/partials/farmer_profile_large.html index c88d545..ef7abe7 100644 --- a/public/partials/farmer_profile_large.html +++ b/public/partials/farmer_profile_large.html @@ -98,66 +98,13 @@

{{farmer.fa_first_name}} {{farmer.fa_middle_name}} {{f - -
-

Farms

-
- - - -
-
-
-
-
- -
-
- -
-
- {{farm.fr_name}} -
Farm Name
-
-
-
-
- {{farm.fr_size}} -
Farm Size (Acre)
-
-
-
-
- {{farm.ad_address1}} -
Address 1
-
-
-
-
- -
-
- {{farm.ad_city}} -
City
-
-
-
-
- {{farm.di_district.di_parish_name}} -
Parish
-
-
-
-
- {{farm.di_district.di_extension_name}} - {{farm.di_district.di_district_name}} -
Extension - District
-
-
-
-
+ + + +
diff --git a/public/partials/farms_card.html b/public/partials/farms_card.html new file mode 100644 index 0000000..e6baebf --- /dev/null +++ b/public/partials/farms_card.html @@ -0,0 +1,68 @@ + +
+

Farms

+
+ + + +
+
+
+ +
+ +
+ +
+ +
+ + +
+
+ +
+
+ {{farm.fr_name}} +
Farm Name
+
+
+
+
+ {{farm.fr_size}} +
Farm Size (Acre)
+
+
+
+
+ {{farm.ad_address1}} +
Address 1
+
+
+
+
+ +
+
+ {{farm.ad_city}} +
City
+
+
+
+
+ {{farm.di_district.di_parish_name}} +
Parish
+
+
+
+
+ {{farm.di_district.di_extension_name}} - {{farm.di_district.di_district_name}} +
Extension - District
+
+
+
+
+ + + +
\ No newline at end of file diff --git a/routes/farmer/farmer.js b/routes/farmer/farmer.js index 04669c6..0d314f1 100644 --- a/routes/farmer/farmer.js +++ b/routes/farmer/farmer.js @@ -11,6 +11,7 @@ var model = require('../../models/db'); var common = require('../common/common'); var Commodity = model.Commodity; +var Farm = model.Farm; var Demand = model.Demand; var Branch = model.Branch; var Membership = model.Membership; @@ -242,7 +243,7 @@ exports.getCommodities = function(req, res) { */ exports.updateFarmById = function(req, res) { if(common.isAuthenticated(req, res)) { - model.Farm.update({_id: req.params.farm_id}, req.body, function (err, response) { + /*model.Farm.update({_id: req.params.farm_id}, req.body, function (err, response) { if (err) { handleDBError(err, res); } else { @@ -255,6 +256,18 @@ exports.updateFarmById = function(req, res) { } } }); + */ + + Farm.findByIdAndUpdate({_id:req.params.farm_id}, req.body, function (err, changes) { + if (err) { + handleDBError(err, res); + } else { + res.send(changes); + } + }); + + console.log(req.body); + } };