Skip to content

Commit

Permalink
I think I've stripped out the rogue changes that were in my last comm…
Browse files Browse the repository at this point in the history
…it from this one. Same supplier edit functionality as before.
  • Loading branch information
Nick Williams committed Aug 17, 2015
1 parent e24934d commit 3275cfa
Show file tree
Hide file tree
Showing 10 changed files with 176 additions and 32 deletions.
17 changes: 6 additions & 11 deletions public/javascripts/controllers/demand-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ angular.module('jasmic.controllers')
}
}
])
.controller('DemandProfileCtrl', ['$scope','$mdToast','$location', '$mdDialog','$routeParams', 'DemandFactory',
'DemandMatchFactory', 'UserProfileFactory', 'TransactionFactory', 'ReportFactory', 'ReportsFactory',
function ($scope, $mdToast, $location, $mdDialog, $routeParams, DemandFactory, DemandMatchFactory,
UserProfileFactory, TransactionFactory, ReportFactory, ReportsFactory) {
.controller('DemandProfileCtrl', ['$scope','$mdToast','$location','$routeParams', 'DemandFactory',
'DemandMatchFactory', 'UserProfileFactory', 'TransactionFactory',
function ($scope, $mdToast, $location, $routeParams, DemandFactory, DemandMatchFactory,
UserProfileFactory, TransactionFactory) {
/**
* Display user profile based on authenticated
* session information.
Expand All @@ -44,17 +44,13 @@ angular.module('jasmic.controllers')
$scope.user = user;
});



/**
* Lookup Demand information based on ID supplied in the URL.
*/
DemandFactory.show({id:$routeParams.id},
function(demand) {
DemandFactory.show({id:$routeParams.id}, function(demand) {
$scope.demand = demand;
$scope.selectedDemand = demand;
lookupDemandMatches();
lookupReports();
},
function(error) {
$scope.demand = {};
Expand All @@ -68,7 +64,7 @@ angular.module('jasmic.controllers')
$scope.downloadPDF = function() {
//create transaction(s)
if($scope.m_commodities.length > 0) {
//createTransactions();
createTransactions();
} else {
$mdToast.show($mdToast.simple().position('top right').content('No Supplies Selected!'));
}
Expand Down Expand Up @@ -118,7 +114,6 @@ angular.module('jasmic.controllers')
* @param commodity
*/
$scope.checked = function(commodity) {
// console.log(commodity);
var sum = 0;
$scope.combinedSuppyValue = 0;
for(var i in $scope.m_commodities) {
Expand Down
31 changes: 29 additions & 2 deletions public/javascripts/controllers/farmer-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
'UnitsFactory', 'CommodityFactory','CommoditiesFactory', 'DistrictsFactory', 'FarmerMembershipsFactory','CommodityEditFactory',
function ($scope, $location, $routeParams, $mdDialog, OpenTransactionsFactory, TransactionsFactory,
FarmerFactory, ParishesFactory, FarmerFarmFactory, CropsFactory, UnitsFactory,
CommodityFactory, CommoditiesFactory, DistrictsFactory, FarmerMembershipsFactory) {
CommodityFactory, CommoditiesFactory, DistrictsFactory, FarmerMembershipsFactory, CommodityEditFactory) {
/**
* First query for the farmer based on the id supplied in the parameters,
* then query for the transactions this farmer has been involved in.
Expand Down Expand Up @@ -143,8 +143,35 @@ angular.module('jasmic.controllers')
$scope.commodity.co_availability_date= moment().toDate();
$scope.commodity.co_until = moment().add(7, 'days').toDate();
};

$scope.editCommodityItem = function(arrayindex) {

$scope.editCommodity = !$scope.editCommodity;
$scope.commodity = $scope.commodities[arrayindex];
$scope.commodity.co_availability_date= moment().toDate();
$scope.commodity.co_until = moment().add(7, 'days').toDate();

};

$scope.updateCommodity = function(arrayindex) {

CommodityEditFactory.update({id:$scope.commodities[arrayindex].fa_farmer._id, commodity_id:$scope.commodity._id}, $scope.commodity, function(success) {

console.log("Success");

$scope.editCommodity = false;

}, function (error) {

console.log("Error");

});

}

$scope.newCommodity = false;
$scope.newFarm = false;
$scope.editCommodity = false;

$scope.commodity = {};
var selectedCrop;
Expand Down
6 changes: 6 additions & 0 deletions public/javascripts/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ services.factory('CommodityFactory', function($resource) {
})
});

services.factory('CommodityEditFactory', function($resource){
return $resource('farmer/:id/commodity/:commodity_id', {}, {
update: { method: 'PUT', params: {id: '@id', commodity_id: '@commodity_id'} },
});
});

/**
* Adds a new Demand and associates it with a buyer
*/
Expand Down
57 changes: 57 additions & 0 deletions public/partials/commodity_edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<div>
<md-content>

<md-input-container flex>
<label>Crop Name</label><input disabled="disabled" min="0" ng-required="true" ng-model="commodity.cr_crop.cr_crop_name" type="text"/>
</md-input-container>

<div layout-align="center center" layout="row">
<md-input-container flex>
<label>Quantity</label><input min="0" ng-required="true" ng-model="commodity.co_quantity" type="number"/>
</md-input-container>

<md-select ng-required="true" ng-model="commodity.un_quantity_unit" placeholder="Unit">
<md-option ng-value="unit" ng-repeat="unit in units" ng-selected="{{unit.un_unit_name == commodity.un_quantity_unit.un_unit_name}}">{{unit.un_unit_name}}</md-option>
</md-select>
</div>
<div layout-align="center center" layout="row">
<md-input-container flex>
<label>Unit Price</label>
<input ng-required="true" min="0" ng-model="commodity.co_price" type="number"/>
</md-input-container>
per
<md-select ng-required="true" ng-model="commodity.un_price_unit" placeholder="Unit">

<md-option ng-value="unit" ng-repeat="unit in units" ng-selected="{{unit.un_unit_name == commodity.un_price_unit.un_unit_name}}">{{unit.un_unit_name}}</md-option>
</md-select>
</div>

<md-input-container>
<label>Preferred Payment Option(s)</label>
<input ng-model="commodity.co_payment_preference" type="text"/>
</md-input-container>

<div layout="row">

<md-input-container>
<label>Available Date (yyyy-MM-dd)</label>
<input ng-required="true" ng-model="commodity.co_availability_date" type="date"/>
</md-input-container>

<md-input-container>
<label>End Date (yyyy-MM-dd)</label>
<input ng-required="true" ng-model="commodity.co_until" type="date"/>
</md-input-container>
</div>

<md-input-container>
<label>Notes</label>
<input ng-model="commodity.co_notes" type="text"/>
</md-input-container>

<md-input-container layout="row" layout-sm="column" layout-align="center center">
<md-button ng-click="editCommodityItem()">Cancel</md-button>
<md-button ng-click="updateCommodity(0)">Update</md-button>
</md-input-container>
</md-content>
</div>
7 changes: 1 addition & 6 deletions public/partials/demand_profile_large.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ <h2 class="farmerSummary"><a href="/home/#/buyer/{{demand.bu_buyer._id}}"> {{dem
</md-card>

</div>
<div flex="40" layout="column">
<div ng-include="'/partials/transaction_cart.html'">
</div>
<div ng-include="'/partials/report_listing_small.html'">
</div>
<div ng-include="'/partials/transaction_cart.html'" layout="column" flex="40">
</div>

</md-content>
</ui-view>
9 changes: 9 additions & 0 deletions public/partials/farmer_profile_large.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,16 @@ <h3 class="{{newCommodity ? 'dark':'white'}}">Supplies</h3>
<md-icon class="edge" md-svg-icon="/images/ic_add_24px.svg"></md-icon>
</md-button>
</div>

</div>

<div ng-include="newCommodity ? '/partials/commodity_new.html':null">

</div>

<div ng-include="editCommodity ? '/partials/commodity_edit.html':null">

</div>
</md-card-content>
<md-card-content>
<div class="farmerInfo" layout-padding layout="column" ng-repeat="commodity in commodities">
Expand Down Expand Up @@ -202,6 +208,9 @@ <h3 class="{{newCommodity ? 'dark':'white'}}">Supplies</h3>
{{commodity.co_notes}}
<label>Notes</label>
</div>

<button ng-click="editCommodityItem(0)">Edit</button>

</div>
</div>
</md-card-content>
Expand Down
2 changes: 1 addition & 1 deletion public/partials/transaction_cart.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<h4>Share with Buyer</h4>
<span flex></span>
<md-button class="md-icon-button" aria-label="Print">
<md-icon class="scale" md-svg-icon="/images/icons/icons_print.svg" ng-click="createReport();"></md-icon>
<md-icon class="scale" md-svg-icon="/images/icons/icons_print.svg"></md-icon>
<md-tooltip>Print</md-tooltip>
</md-button>
<md-button class="md-icon-button" aria-label="Download">
Expand Down
20 changes: 20 additions & 0 deletions routes/crop/crop-routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* Created by matjames007 on 5/14/15.
*/
var express = require('express');
var Crop = require('./crop');
var router = express.Router();

dummyfunction = function(req, res) {
res.send("Not Implemented");
};

/**
* End Points relevant to Crop
*/
router.get('/crops', Crop.findCrops);
router.post('/crops', Crop.batchUpdate);
router.post('/crop', Crop.createCrop);
router.put('/crop/:id', Crop.updateCropById);

module.exports = router;
56 changes: 45 additions & 11 deletions routes/farmer/farmer.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,16 +230,6 @@ exports.getCommodities = function(req, res) {
}
};

/**
* Intended to be able to edit the commodity based on farmer's id
* @param req
* @param res
*/
exports.editCommodity = function(req, res) {
res.statusCode(500);
res.send({error: 'Not Implemented!'});
};

/**
* Function really only requires the farm_id to be in the parameter
* and does a query based on only this parameter. The function
Expand Down Expand Up @@ -269,7 +259,7 @@ exports.updateFarmById = function(req, res) {
};

/**
* Allows for a comment to be created based on a given farmer.
* Allows for a comment to be eeated based on a given farmer.
* Requires a id of the farmer to be passed as a parameter in
* the request.
*
Expand Down Expand Up @@ -434,6 +424,50 @@ exports.updateMembership = function(req, res) {
});
}
};
/*
exports.updateCommodity = function(req, res) {
if(common.isAuthenticated(req, res)) {
Commodity.updateById(req.params.commodity_id, req.body, function (err, changes) {
if (err) {
handleDBError(err, res);
} else {
res.send(changes);
}
});
}
};
*/


/**
* Edits a commodity based on commodity's id.
* @param req
* @param res
*/
exports.editCommodity = function(req, res) {
if(common.isAuthenticated(req, res)){
/*Commodity.update({_id:req.params.comID}, req.body, function(err, response){
if(err || response.nModified != 0){
common.handleDBError(err, res);
}else{
res.send(response);
}
});*/

Commodity.findByIdAndUpdate({_id:req.params.commodity_id}, req.body, function (err, changes) {
if (err) {
handleDBError(err, res);
} else {
res.send(changes);
}
});

console.log(req.body);

//res.end();

}
};

/**
* Create New Membership Type. Validation done by DB.
Expand Down
3 changes: 2 additions & 1 deletion routes/farmer/farmer_routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ router.put('/farm/:farm_id', Farmer.updateFarmById);

router.post('/farmer/:id/commodity', Farmer.addCommodity);
router.get('/farmer/:id/commodities', Farmer.getCommodities);
router.put('/farmer/:id/commodity/:comID', Farmer.editCommodity);
router.put('/farmer/:id/commodity/:commodity_id', Farmer.editCommodity);
router.get('/farmers/current_commodities', Farmer.searchCurrentCommodities);

router.get('/commodity/:id/match', Farmer.findCommodityMatch);

/**
* Manipulate info about Membership for a specific farmer
*/
router.post('/membershiptype', Farmer.createMembershipType);
Expand Down

0 comments on commit 3275cfa

Please sign in to comment.