-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: inital billing services implementation
This implements the intial structure of the billing services page. As of this commit, billing service creation works with proper form validation. A skeleton UI grid can also be found on the billing services page. The struture of billing services looks like this: - billing_services/ - billing_services.html # the abstract state template with title bar) - billing_services.list.html # the default grid for the page - billing_service.js # the BillingServicesController - create/ - create.html # the creation form - create.js # the BillingServicesCreateController - update/ - update.html # the update form - update.js # the BillingServicesUpdateController The routes should look like this: - `/billing_services` - lists all billing services in a UI grid - `/billing_services/create` - brings up a creation form - `/billing_services/:id` - brings up an update form TODOs - implement the `?detailed=1` query string on the server + integration tests - implement the UPDATE state
- Loading branch information
Showing
13 changed files
with
433 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
angular.module('bhima.services') | ||
.service('BillingServicesService', BillingServicesService); | ||
|
||
BillingServicesService.$inject = [ | ||
'$http', 'util' | ||
]; | ||
|
||
/** | ||
* Billing Services Service | ||
* | ||
* This function wraps the /billing_services API endpoint and exposes CRUD | ||
* methods to controllers. | ||
* | ||
* @constructor | ||
*/ | ||
function BillingServicesService($http, util) { | ||
var service = this; | ||
var url = '/billing_services/'; | ||
|
||
/* service methods */ | ||
service.read = read; | ||
service.create = create; | ||
service.update = update; | ||
service.delete = del; | ||
|
||
/* ------------------------------------------------------------------------ */ | ||
|
||
/** | ||
* The create() method creates a new billing service in the database via a | ||
* POST requests to the HTTP API endpoint. | ||
* | ||
* @param {Object} data - billing service properties to be submitted to the | ||
* service. | ||
* @return {Promise} promise - resolves with the id of the created billing | ||
* service entity or is rejected with an HTTP error. | ||
*/ | ||
function create(data) { | ||
|
||
// copy the data not do disrupt the view | ||
data = angular.copy(data); | ||
|
||
// remove view-specific values | ||
if (data.account) { | ||
data.account_id = data.account.id; | ||
delete data.account; | ||
} | ||
|
||
return $http.post(url, { billingService : data }) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
/** | ||
* The read() method loads data from the api endpoint. If an id is provided, | ||
* the $http promise is resolved with a single JSON object, otherwise an array | ||
* of objects should be expected. | ||
* | ||
* @param {Number} id - the id of the billing service (optional). | ||
* @param {Object} options - options to be passed as query strings (optional). | ||
* @return {Promise} promise - resolves to either a JSON (if id provided) or | ||
* an array of JSONs. | ||
*/ | ||
function read(id, options) { | ||
var target = url.concat(id || ''); | ||
return $http.get(target, { params : options }) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
/** | ||
* The update() method updates a billing service in the database via a PUT | ||
* request to the HTTP API endpoint. | ||
* | ||
* @param {Number} id - the id of the billing service to be modified. | ||
* @param {Object} data - billing service properties to be updated with new | ||
* values. | ||
* @return {Promise} promise - resolves with the id of the created billing | ||
* service entity or is rejected with an HTTP error. | ||
*/ | ||
function update(id, data) { | ||
var target = url.concat(id); | ||
return $http.put(target, data) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
|
||
/** | ||
* The delete() method deletes data from the database using the API endpoint. | ||
* | ||
* @param {Number} id - the id of the billing service. | ||
* @return {Promise} promise - a promise resolving to an empty object. | ||
*/ | ||
function del(id) { | ||
var target = url.concat(id); | ||
return $http.delete(target) | ||
.then(util.unwrapHttpResponse); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
client/src/partials/billing_services/billing_services.html
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,19 @@ | ||
<div class="flex-header"> | ||
<div class="bhima-title"> | ||
<ol class="headercrumb"> | ||
<li class="static">{{ "TREE.ADMIN" | translate }}</li> | ||
<li class="title">{{ "BILLING_SERVICES.TITLE" | translate }}</li> | ||
</ol> | ||
</div> | ||
</div> | ||
|
||
<div class="flex-util"> | ||
<button class="btn btn-default" ui-sref="billingServices.create" data-method="create"> | ||
<span class="glyphicon glyphicon-plus"></span> {{ "BILLING_SERVICES.CREATE" | translate }} | ||
</button> | ||
</div> | ||
|
||
<!-- template in child views --> | ||
<div class="flex-content"> | ||
<div class="container-fluid" ui-view></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,66 @@ | ||
angular.module('bhima.controllers') | ||
.controller('BillingServicesController', BillingServicesController); | ||
|
||
BillingServicesController.$inject = [ | ||
'$state', '$translate', 'BillingServicesService' | ||
]; | ||
|
||
/** | ||
* The Billing Services Controller | ||
* | ||
* This is the default controller for the billing services URL endpoint. | ||
*/ | ||
function BillingServicesController($state, $translate, BillingServices) { | ||
var vm = this; | ||
|
||
// these options are for the ui-grid | ||
vm.options = { | ||
appScopeProvider: vm, | ||
enableSorting : true, | ||
enableHiding : false, | ||
columnDefs : [ | ||
{ field : 'id', name : $translate.instant('COLUMNS.ID') }, | ||
{ field : 'account_id', name : $translate.instant('COLUMNS.ACCOUNT') }, | ||
{ field : 'label', name : $translate.instant('COLUMNS.LABEL') }, | ||
{ field : 'description', name : $translate.instant('COLUMNS.DESCRIPTION') }, | ||
{ field : 'value', name : $translate.instant('COLUMNS.VALUE') }, | ||
{ field : 'date', name : $translate.instant('COLUMNS.DATE'), cellFilter:'date' }, | ||
] | ||
}; | ||
|
||
// default loading state - false; | ||
vm.loading = false; | ||
|
||
vm.update = update; | ||
|
||
// fired on state init | ||
function startup() { | ||
|
||
// turn the loading indicator on | ||
toggleLoadingIndicator(); | ||
|
||
// retrieve a detailed list of the billing services in the application | ||
BillingServices.read(null, { detailed : 1 }) | ||
.then(function (billingServices) { | ||
console.log('loaded:', billingServices); | ||
vm.options.data = billingServices; | ||
}) | ||
.finally(function () { | ||
|
||
// turn loading indicator off after HTTP request is finished | ||
toggleLoadingIndicator(); | ||
}); | ||
} | ||
|
||
function toggleLoadingIndicator() { | ||
vm.loading = !vm.loading; | ||
} | ||
|
||
// update the clicked billing service | ||
function update(id) { | ||
console.log('clicked:', id); | ||
//$state.go('billingServices.update'); | ||
} | ||
|
||
startup(); | ||
} |
2 changes: 2 additions & 0 deletions
2
client/src/partials/billing_services/billing_services.list.html
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,2 @@ | ||
<div class="grid" id="BillingServicesGrid" ui-grid="BillingServicesCtrl.options"> | ||
</div> |
Oops, something went wrong.