Skip to content

Commit

Permalink
feat(filters): percentage filter implementation
Browse files Browse the repository at this point in the history
This commit adds in a simply percentage filter for adding percent (%)
signs to numbers.  If the input is not a number, the percent filter does
not do anything
  • Loading branch information
jniles committed Mar 31, 2016
1 parent 052be5e commit 6524162
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 24 additions & 0 deletions client/src/js/filters/percentage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
angular.module('bhima.filters')
.filter('percentage', PercentageFilter);

/**
* Percentage Filter
*
* The percentage filter accepts a number and returns it as a percentage.
*/
function PercentageFilter() {
return function percentage(number) {

// escape if no input was passed in
if (angular.isUndefined(number)) { return ''; }

// cast value as number (or NaN)
var value = Number(number);

// angular's isNumber() method reports NaNs as numbers
if (!angular.isNumber(value) || isNaN(value)) { return number; }

// return the value + a percentage sign
return value + '%';
};
}
4 changes: 2 additions & 2 deletions client/src/partials/billing_services/list/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function BillingServicesListController($translate, BillingServices, Accounts) {
{ field : 'account', displayName : $translate.instant('COLUMNS.ACCOUNT'), width: '*' },
{ field : 'label', displayName : $translate.instant('COLUMNS.LABEL') },
{ field : 'description', displayName: $translate.instant('COLUMNS.DESCRIPTION') },
{ field : 'value', displayName : $translate.instant('COLUMNS.VALUE') },
{ field : 'created_at', displayName : $translate.instant('COLUMNS.DATE'), cellFilter:'date' },
{ field : 'value', displayName : $translate.instant('COLUMNS.VALUE'), cellFilter:'percentage', cellClass: 'text-right' },
{ field : 'created_at', displayName : $translate.instant('COLUMNS.DATE'), cellFilter:'date', cellClass: 'text-center' },
{ field : 'edit', displayName: '', cellTemplate : editTemplate, width: 45 },
{ field : 'delete', displayName : '', cellTemplate: deleteTemplate, width: 45 }
]
Expand Down

0 comments on commit 6524162

Please sign in to comment.