-
Notifications
You must be signed in to change notification settings - Fork 105
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
Feat(Setting) donor management module #4837
Changes from all commits
e57e5b6
eb49ae4
54abcc2
2e5a533
e9ae3cb
6a6f163
cfd838d
65f4898
9a07f52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
angular.module('bhima.services') | ||
.service('DonationService', DonationService); | ||
|
||
DonationService.$inject = ['PrototypeApiService']; | ||
|
||
/** | ||
* Role Service | ||
* | ||
* A service wrapper for the /donors HTTP endpoint. | ||
* | ||
*/ | ||
function DonationService(Api) { | ||
const service = new Api('/donations/'); | ||
service.stockBalance = stockBalance; | ||
|
||
function stockBalance(id) { | ||
const url = ''.concat(id, '/stock_balance'); | ||
return Api.read.call(service, url); | ||
} | ||
|
||
return service; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
angular.module('bhima.controllers') | ||
.controller('DonorController', DonorController); | ||
|
||
DonorController.$inject = [ | ||
'$uibModal', 'DonorService', 'ModalService', | ||
'NotifyService', 'uiGridConstants', | ||
]; | ||
|
||
function DonorController($uibModal, Donor, Modal, Notify, uiGridConstants) { | ||
const vm = this; | ||
|
||
vm.createUpdateDonorModal = (selectedRole = {}) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this parameter is not related to role may be |
||
$uibModal.open({ | ||
templateUrl : 'modules/donor/modal/createUpdate.html', | ||
controller : 'DonorAddController as DonorAddCtrl', | ||
resolve : { data : () => selectedRole }, | ||
}); | ||
}; | ||
|
||
vm.remove = function remove(id) { | ||
const message = 'FORM.DIALOGS.DELETE_DONOR'; | ||
Modal.confirm(message) | ||
.then(confirmResponse => { | ||
if (!confirmResponse) { | ||
return; | ||
} | ||
Donor.delete(id) | ||
.then(() => { | ||
Notify.success('FORM.INFO.DELETE_SUCCESS'); | ||
load(); | ||
}) | ||
.catch(Notify.handleError); | ||
}); | ||
}; | ||
|
||
function load() { | ||
vm.loading = true; | ||
|
||
Donor.read() | ||
.then(roles => { | ||
vm.gridOptions.data = roles; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}) | ||
.catch(Notify.handleError) | ||
.finally(() => { | ||
vm.loading = false; | ||
}); | ||
} | ||
|
||
const columns = [{ | ||
field : 'display_name', | ||
displayName : 'FORM.LABELS.NAME', | ||
headerCellFilter : 'translate', | ||
}, | ||
{ | ||
field : 'phone', | ||
displayName : 'FORM.LABELS.PHONE', | ||
headerCellFilter : 'translate', | ||
}, | ||
{ | ||
field : 'email', | ||
displayName : 'FORM.LABELS.EMAIL', | ||
headerCellFilter : 'translate', | ||
}, | ||
{ | ||
field : 'address', | ||
displayName : 'FORM.LABELS.ADDRESS', | ||
headerCellFilter : 'translate', | ||
}, | ||
{ | ||
field : 'actions', | ||
enableFiltering : false, | ||
width : 100, | ||
displayName : '', | ||
headerCellFilter : 'translate', | ||
cellTemplate : 'modules/donor/templates/action.cell.html', | ||
}]; | ||
|
||
// ng-click=" | ||
vm.gridOptions = { | ||
appScopeProvider : vm, | ||
enableColumnMenus : false, | ||
columnDefs : columns, | ||
enableSorting : true, | ||
data : [], | ||
fastWatch : true, | ||
flatEntityAccess : true, | ||
onRegisterApi : (gridApi) => { | ||
vm.gridApi = gridApi; | ||
}, | ||
}; | ||
|
||
load(); | ||
/** | ||
* @function toggleInlineFilter | ||
* | ||
* @description | ||
* Switches the inline filter on and off. | ||
*/ | ||
vm.toggleInlineFilter = function toggleInlineFilter() { | ||
vm.gridOptions.enableFiltering = !vm.gridOptions.enableFiltering; | ||
vm.gridApi.core.notifyDataChange(uiGridConstants.dataChange.COLUMN); | ||
}; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<div class="flex-header"> | ||
<div class="bhima-title"> | ||
<ol class="headercrumb"> | ||
<li class="static" translate>TREE.ADMIN</li> | ||
<li class="title" translate>TREE.DONOR</li> | ||
</ol> | ||
|
||
<div class="toolbar"> | ||
<div class="toolbar-item"> | ||
<button class="btn btn-default" ng-click="DonorCtrl.createUpdateDonorModal()" data-method="create"> | ||
<span class="fa fa-plus"></span> | ||
<span translate class="text-capitalize">FORM.LABELS.ADD</span> | ||
</button> | ||
</div> | ||
<bh-filter-toggle on-toggle="DonorCtrl.toggleInlineFilter()"> | ||
</bh-filter-toggle> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<!-- main content --> | ||
<div class="flex-content"> | ||
<div class="container-fluid"> | ||
<div | ||
id="donor-grid" | ||
class="grid-full-height" | ||
ui-grid="DonorCtrl.gridOptions" | ||
ui-grid-auto-resize | ||
ui-grid-resize-columns | ||
ui-grid-move-columns> | ||
|
||
<bh-grid-loading-indicator | ||
loading-state="DonorCtrl.loading" | ||
empty-state="DonorCtrl.gridOptions.data.length === 0"> | ||
</bh-grid-loading-indicator> | ||
</div> | ||
</div> | ||
</div> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
angular.module('bhima.routes') | ||
.config(['$stateProvider', function Provider($stateProvider) { | ||
|
||
$stateProvider.state('donors', { | ||
url : '/donors', | ||
templateUrl : 'modules/donor/donor.html', | ||
controller : 'DonorController as DonorCtrl', | ||
}); | ||
}]); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
angular.module('bhima.services') | ||
.service('DonorService', DonorService); | ||
|
||
DonorService.$inject = ['PrototypeApiService']; | ||
|
||
/** | ||
* Role Service | ||
* | ||
* A service wrapper for the /donors HTTP endpoint. | ||
* | ||
*/ | ||
function DonorService(Api) { | ||
const service = new Api('/donors/'); | ||
return service; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<form name="donorForm" bh-submit="DonorAddCtrl.submit(donorForm)" novalidate> | ||
<div class="modal-header"> | ||
<ol class="headercrumb"> | ||
<li> | ||
<span translate>TREE.DONOR</span> | ||
|
||
<label class="label label-warning text-uppercase" translate> | ||
{{DonorAddCtrl.action}} | ||
</label> | ||
</li> | ||
</ol> | ||
</div> | ||
|
||
<div class="modal-body"> | ||
<div class="row"> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you remove this |
||
<div class="form-group" ng-class="{ 'has-error' : donorForm.display_name.$invalid && donorForm.$submitted }"> | ||
<label class="control-label" translate>FORM.LABELS.NAME</label> | ||
<input type="text" class="form-control col-md-9" name="label" ng-model="DonorAddCtrl.donor.display_name" required> | ||
<div class="help-block" ng-messages="donorForm.label.$error" ng-show="donorForm.$submitted"> | ||
<div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group" ng-class="{ 'has-error' : donorForm.phone.$invalid && donorForm.$submitted }"> | ||
<label class="control-label" translate>FORM.LABELS.PHONE</label> | ||
<input type="tel" class="form-control col-md-9" name="phone" ng-model="DonorAddCtrl.donor.phone"> | ||
<div class="help-block" ng-messages="donorForm.phone.$error" ng-show="donorForm.$submitted"> | ||
<div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="form-group" ng-class="{ 'has-error' : donorForm.email.$invalid && donorForm.$submitted }"> | ||
<label class="control-label" translate>FORM.LABELS.EMAIL</label> | ||
<input type="email" class="form-control col-md-9" name="email" ng-model="DonorAddCtrl.donor.email"> | ||
<div class="help-block" ng-messages="donorForm.email.$error" ng-show="donorForm.$submitted"> | ||
<div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
</div> | ||
</div> | ||
|
||
|
||
<div class="form-group" ng-class="{ 'has-error' : donorForm.address.$invalid && donorForm.$submitted }"> | ||
<label class="control-label" translate>FORM.LABELS.ADDRESS</label> | ||
<input type="text" class="form-control col-md-9" name="address" ng-model="DonorAddCtrl.donor.address"> | ||
<div class="help-block" ng-messages="donorForm.address.$error" ng-show="donorForm.$submitted"> | ||
<div ng-messages-include="modules/templates/messages.tmpl.html"></div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="modal-footer"> | ||
<button | ||
type="button" | ||
data-method="cancel" | ||
class="btn btn-default" | ||
ng-click="DonorAddCtrl.close()" | ||
translate> | ||
FORM.BUTTONS.CANCEL | ||
</button> | ||
|
||
<bh-loading-button loading-state="donorForm.$loading"> | ||
</bh-loading-button> | ||
</div> | ||
</form> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
angular.module('bhima.controllers') | ||
.controller('DonorAddController', DonorAddController); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems like the controller is not only for creation of donors, so you could rename this controller to something like : |
||
|
||
DonorAddController.$inject = [ | ||
'data', '$state', 'DonorService', 'NotifyService', '$uibModalInstance', | ||
]; | ||
|
||
function DonorAddController(data, $state, DonorService, Notify, $uibModalInstance) { | ||
const vm = this; | ||
vm.close = $uibModalInstance.close; | ||
vm.submit = submit; | ||
|
||
vm.donor = angular.copy(data); | ||
vm.isCreate = !vm.donor.uid; | ||
vm.action = vm.isCreate ? 'FORM.LABELS.CREATE' : 'FORM.LABELS.UPDATE'; | ||
|
||
function submit(form) { | ||
if (form.$invalid) { | ||
Notify.danger('FORM.ERRORS.HAS_ERRORS'); | ||
return false; | ||
} | ||
|
||
const operation = (!data.id) | ||
? DonorService.create(vm.donor) | ||
: DonorService.update(data.id, vm.donor); | ||
|
||
return operation | ||
.then(() => { | ||
Notify.success('FORM.INFO.OPERATION_SUCCESS'); | ||
$state.reload(); | ||
vm.close(); | ||
}) | ||
.catch(Notify.handleError); | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div | ||
class="ui-grid-cell-contents text-right" | ||
data-row="{{row.entity.display_name}}" | ||
uib-dropdown dropdown-append-to-body> | ||
|
||
<a uib-dropdown-toggle href data-action="open-dropdown-menu"> | ||
<span data-method="action" translate>FORM.BUTTONS.ACTIONS</span> | ||
<span class="caret"></span> | ||
</a> | ||
|
||
<ul data-row-menu="{{ row.entity.display_name }}" class="dropdown-menu-right" bh-dropdown-menu-auto-dropup uib-dropdown-menu> | ||
<li class="bh-dropdown-header">{{row.entity.display_name}}</li> | ||
<li> | ||
<a data-method="edit-record" ng-click="grid.appScope.createUpdateDonorModal(row.entity)" href> | ||
<i class="fa fa-edit"></i> <span translate>FORM.BUTTONS.EDIT</span> | ||
</a> | ||
</li> | ||
|
||
<li class="divider"></li> | ||
<li> | ||
<a data-method="delete-record" ng-click="grid.appScope.remove(row.entity.id)" href> | ||
<span class="text-danger"> | ||
<i class="fa fa-trash"></i> <span translate>FORM.BUTTONS.DELETE</span> | ||
</span> | ||
</a> | ||
</li> | ||
</ul> | ||
</div> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This service is for
/donors
or/donations
? If it is for/donations
you could update this line