Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unverified Buyer List #186

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
2 changes: 1 addition & 1 deletion models/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ var BuyerSchema = new Schema({
bu_phone: String,
bu_email: String,
bu_payment_terms: String,
bu_verified: {type: Boolean, required: true, default: false},
bu_verified: {type: String, required: true, default: 'Unverified'},
ad_address: {type: Schema.Types.ObjectId, required: true, ref: 'Address'},
ct_comments: [CommentSchema],
in_integrity: Number,
Expand Down
52 changes: 48 additions & 4 deletions public/javascripts/controllers/admin-ctrl.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
angular.module('jasmic.controllers')
.controller('AdministratorCtrl', ['$scope','$mdDialog', '$mdToast','UsersFactory','CropsFactory','SuppliersFactory',
.controller('AdministratorCtrl', ['$scope','$mdDialog', '$mdToast','$window','UsersFactory','CropsFactory','SuppliersFactory',
'UserFactory','CropFactory','SupplierFactory', 'EmailFactory', 'UserProfileFactory', 'ParishesFactory',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matjames007 I encountered an issue after updating a buyer. The screen would turn grey but the dialog box was not seen. In testing the branch, you can remove the $window.scroll line to see if you get encounter this behaviour.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't seen the behaviour described. I also haven't seen the $window.scroll line u mentioned. Could you point me to the file and line number on this branch?

function($scope, $mdDialog, $mdToast, UsersFactory, CropsFactory, SuppliersFactory, UserFactory, CropFactory,
SupplierFactory, EmailFactory, UserProfileFactory, ParishesFactory){
'BuyersListingFactory', 'BuyerFactory',
function($scope, $mdDialog, $mdToast, $window, UsersFactory, CropsFactory, SuppliersFactory, UserFactory, CropFactory,
SupplierFactory, EmailFactory, UserProfileFactory, ParishesFactory, BuyersListingFactory, BuyerFactory){
/**
* Get all users from the database.
*/
Expand Down Expand Up @@ -47,24 +48,38 @@ angular.module('jasmic.controllers')
});
}
getParishes();
/**
* Gets all unverified buyers from the database
*/
getUnverifiedBuyers = function(){
BuyersListingFactory.query({bu_verified: "Unverified"}, function(buyers){
$scope.buyers = buyers;
},function(error){
$scope.buyers = [];
});
}
getUnverifiedBuyers();

$scope.user_obj = {};
$scope.crop_type = {};
$scope.supplier = {};
$scope.buyer = {};
$scope.usertypes = ['Administrator', 'Call Representative'];
$scope.states = ['Approved', 'Pending'];
$scope.buyer_states = ['Unverified', 'Verified'];
/**
* Used to toggle list of records.
* @type {{user: boolean, croptype: boolean, supplier: boolean}}
*/
$scope.hideList = { user: false, croptype: false, supplier: false};
$scope.hideList = { user: false, croptype: false, supplier: false, buyer: false};
/**
* Determines if form to create user must edit a record or create a new record.
* @type {boolean}
*/
$scope.editUser = false;
$scope.editCrop = false;
$scope.editSupplier = false;
$scope.editBuyer = false;
/**
* Displays form specific to each entity i.e. user, crop or supplier.
* @param entity
Expand Down Expand Up @@ -118,6 +133,13 @@ angular.module('jasmic.controllers')
}
getSuppliers();
$scope.hideList.supplier = !$scope.hideList.supplier;
}else if(entity === 'buyer'){
if($scope.editBuyer){
$scope.editBuyer = !$scope.editBuyer;
}
$scope.buyer = {};
getUnverifiedBuyers();
$scope.hideList.buyer = !$scope.hideList.buyer;
}
};
/**
Expand Down Expand Up @@ -182,6 +204,10 @@ angular.module('jasmic.controllers')
$scope.hideList.supplier = !$scope.hideList.supplier;
$scope.supplier = obj;
break;
case 'buyer' : $scope.editBuyer = !$scope.editBuyer;
$scope.hideList.buyer = !$scope.hideList.buyer;
$scope.buyer = obj;
break;
default: showDialog($mdDialog,{statusText: "Error"}, false);
break
}
Expand All @@ -197,6 +223,8 @@ angular.module('jasmic.controllers')
updateCrop();
}else if(type === 'supplier'){
updateSupplier();
}else if(type === 'buyer'){
updateBuyer();
}
};
/**
Expand Down Expand Up @@ -236,6 +264,7 @@ angular.module('jasmic.controllers')
*/
function updateSupplier(){
SupplierFactory.update({id:$scope.supplier._id}, $scope.supplier, function(success){
$window.scrollTo(0,0);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matjames007 here's the reference to the line.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh when u are updating the supplier! not the buyer...lol ok

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@matjames007 actually both! lol..

showDialog($mdDialog, {statusText: 'Supplier Updated!'}, false);
}, function(error){
showDialog($mdDialog, error, false);
Expand All @@ -244,6 +273,21 @@ angular.module('jasmic.controllers')
$scope.hideList.supplier = !$scope.hideList.supplier;
getSuppliers();
}
/**
* Updates a buyer record. Requires admin privileges.
*/
function updateBuyer(){
BuyerFactory.update({id: $scope.buyer._id}, $scope.buyer, function(success){
$window.scrollTo(0,0);
showDialog($mdDialog,{statusText: "Buyer Updated!"}, false);
$scope.buyer = {};
$scope.editBuyer = !$scope.editBuyer;
}, function(error){
showDialog($mdDialog, error, false);
});
$scope.hideList.buyer = !$scope.hideList.buyer;
getUnverifiedBuyers();
}
}]);

/**
Expand Down
4 changes: 2 additions & 2 deletions public/javascripts/controllers/buyer-ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ angular.module('jasmic.controllers')
BuyerTypesListingFactory.query(function(buyertypes) {
$scope.buyerTypes = buyertypes;
}, function(fail) {
//TODO: I need to ensure that I handle these properly
$scoe.buyerTypes = [];
});

ParishesFactory.query({},
function(parishes) {
$scope.parishes = parishes;
},
function(error) {
console.log(error);
$scope.parishes = [];
});

$scope.save = function() {
Expand Down
49 changes: 49 additions & 0 deletions public/partials/admin/buyer_edit.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<md-content layout-padding layout="column">
<div layout="row">
<md-input-container flex>
<label>Buyer Name</label>
<input type="text" ng-model="buyer.bu_buyer_name">
</md-input-container>
<md-input-container flex>
<label>Buyer Type</label>
<input type="text" ng-model="buyer.bt_buyer_type.bt_buyer_type_name">
</md-input-container>
<md-input-container flex>
<label>Contact</label>
<input type="text" ng-model="buyer.bu_phone">
</md-input-container>
</div>

<div layout="row">
<md-input-container flex>
<label>Address 1</label>
<input type="text" ng-model="buyer.ad_address.ad_address1">
</md-input-container>
<md-input-container flex>
<label>Address 2</label>
<input type="text" ng-model="buyer.ad_address.ad_address2">
</md-input-container>
<md-select placeholder="Parish" ng-model="buyer.ad_address.pa_parish" flex>
<md-option ng-repeat="parish in parishes" value={{parish.pa_parish_name}}>{{parish.pa_parish_name}}</md-option>
</md-select>
</div>

<div layout="row">
<md-input-container flex>
<label>Email</label>
<input type="text" ng-model="buyer.bu_email">
</md-input-container>
<md-input-container flex>
<label>Payment Terms</label>
<input type="text" ng-model="buyer.bu_payment_terms">
</md-input-container>
<md-select placeholder="Verified" ng-model="buyer.bu_verified" flex>
<md-option ng-repeat="state in buyer_states" value={{state}}>{{state}}</md-option>
</md-select>
</div>

<md-input-container layout="row" layout-align="center center">
<md-button ng-click="cancel('buyer')">Cancel</md-button>
<md-button ng-click="update('buyer')" ng-if="editBuyer">Update</md-button>
</md-input-container>
</md-content>
2 changes: 1 addition & 1 deletion public/partials/admin/crop_type_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@
<md-button ng-click="save('croptype')" ng-if="!editCrop">Save</md-button>
<md-button ng-click="update('crop')" ng-if="editCrop">Update</md-button>
</md-input-container>
</md-content>
</md-content>
35 changes: 35 additions & 0 deletions public/partials/admin/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,39 @@ <h3 class="{{newUnit ? 'dark':'white'}}">Units</h3>
</div>
</md-card-content>
</md-card>

<md-card class="admin-cards">
<md-card-content class="{{newBuyer ? 'dark':'white'}}">
<div layout="row">
<h3 class="{{newBuyer ? 'dark':'white'}}">Unverified Buyers</h3>
<!-- <div flex class="md-actions edge" layout="row" layout-align="end center">
<md-button ng-click="create('unit')" class="md-fab edge" aria-label="Add New Farm">
<md-icon class="edge" md-svg-icon="/images/ic_add_24px.svg"></md-icon>
</md-button>
</div> -->
</div>
<div>
<table class="table table-hover table-mc-light-blue" ng-if="!hideList.buyer" ng-show="buyers.length > 0">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Parish</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="buyer in buyers" ng-click="selectedElement('buyer',buyer)">
<td>{{buyer.bu_buyer_name}}</td>
<td>{{buyer.bt_buyer_type.bt_buyer_type_name}}</td>
<td>{{buyer.ad_address.pa_parish}}</td>
</tr>
</tbody>
</table>
</div>
<div class="{{editBuyer ?'dark':'white'}}" ng-include="editBuyer ? '/partials/admin/buyer_edit.html': null">

</div>
</md-card-content>
</md-card>

</div>
2 changes: 1 addition & 1 deletion public/partials/buyer_profile_large.html
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ <h2 class="farmerSummary">{{buyer.bu_buyer_name}}</h2>
<md-icon md-svg-icon="/images/ic_verified_user_24px.svg"></md-icon>
<div layout="column">
<br>
{{ buyer.bu_verified ? "Verified" : 'Unverified'}} Buyer
{{ buyer.bu_verified}} Buyer
<div class="label">Verification Status</div>
</div>
</div>
Expand Down
1 change: 0 additions & 1 deletion routes/buyer/buyer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ exports.getBuyers = function(req, res) {
*/
exports.createBuyer = function(req, res) {
if(common.isAuthenticated(req, res)) {
console.log(req.body);
var address = new model.Address(req.body.ad_address);
address.save(function (err) {
if (err) {
Expand Down