-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat(Setting) donor management module
closes #4826
- Loading branch information
1 parent
6015853
commit f396289
Showing
16 changed files
with
383 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
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 = {}) => { | ||
$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; | ||
}) | ||
.catch(Notify.handleError) | ||
.finally(() => { | ||
vm.loading = false; | ||
}); | ||
} | ||
|
||
const columns = [{ | ||
field : 'display_name', | ||
displayName : 'FORM.LABELS.NAME', | ||
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); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="roles-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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}); | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<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"> | ||
<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> | ||
</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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
angular.module('bhima.controllers') | ||
.controller('DonorAddController', DonorAddController); | ||
|
||
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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
const db = require('../../lib/db'); | ||
|
||
module.exports = { | ||
create, | ||
update, | ||
read, | ||
remove, | ||
detail, | ||
}; | ||
|
||
function create(req, res, next) { | ||
const data = req.body; | ||
db.exec(`INSERT INTO donor SET ?`, data).then(() => { | ||
res.sendStatus(201); | ||
}).catch(next); | ||
} | ||
|
||
function update(req, res, next) { | ||
const data = req.body; | ||
const { id } = req.params; | ||
db.exec(`UPDATE donor SET ? WHERE id=?`, [data, id]).then(() => { | ||
res.sendStatus(200); | ||
}).catch(next); | ||
} | ||
|
||
function read(req, res, next) { | ||
db.exec(`SELECT id, display_name FROM donor`).then(donors => { | ||
res.status(200).json(donors); | ||
}).catch(next); | ||
} | ||
|
||
function detail(req, res, next) { | ||
const { id } = req.params; | ||
db.one(`SELECT id, display_name FROM donor WHERE id=?`, id).then(donor => { | ||
res.status(200).json(donor); | ||
}).catch(next); | ||
} | ||
|
||
function remove(req, res, next) { | ||
const { id } = req.params; | ||
db.exec(`DELETE FROM donor WHERE id=?`, id).then(() => { | ||
res.sendStatus(200); | ||
}).catch(next); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.