Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #372 from LinuxBozo/fix-370
Browse files Browse the repository at this point in the history
Don't try to format value if it is NA
  • Loading branch information
doelleri committed Apr 28, 2015
2 parents 13c316e + d4e77d1 commit a2d6182
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
36 changes: 19 additions & 17 deletions app/scripts/modules/hmdaFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,23 +75,25 @@ angular.module('hmdaFilters', [])
};

return function(value, scope, property) {
var section = getFileSpecSection(scope, value.lineNumber);
var fileSpec = HMDAEngine.getFileSpec(HMDAEngine.getRuleYear());
var propSpec = fileSpec[section][property];

if (propSpec !== undefined && propSpec.hasOwnProperty('validation')) {
var propVal = propSpec.validation;
var result;

if (propVal.type === 'percent') {
return value + '%';
} else if (propVal.type === 'date' && propVal.match === 'yyyyMMdd') {
return $filter('date')(value.toDate(), 'M/d/yyyy');
} else if (propVal.type === 'date' && propVal.match === 'yyyyMMddHHmm') {
return $filter('date')(value.toDate(), 'M/d/yyyy H:mm');
} else if (propVal.type === 'currency') {
result = parseInt(value) * parseInt(propVal.multiplier);
return $filter('currency')(result, '$', 0);
if (value !== 'NA') {
var section = getFileSpecSection(scope, value.lineNumber);
var fileSpec = HMDAEngine.getFileSpec(HMDAEngine.getRuleYear());
var propSpec = fileSpec[section][property];

if (propSpec !== undefined && propSpec.hasOwnProperty('validation')) {
var propVal = propSpec.validation;
var result;

if (propVal.type === 'percent') {
return value + '%';
} else if (propVal.type === 'date' && propVal.match === 'yyyyMMdd') {
return $filter('date')(value.toDate(), 'M/d/yyyy');
} else if (propVal.type === 'date' && propVal.match === 'yyyyMMddHHmm') {
return $filter('date')(value.toDate(), 'M/d/yyyy H:mm');
} else if (propVal.type === 'currency') {
result = parseInt(value) * parseInt(propVal.multiplier);
return $filter('currency')(result, '$', 0);
}
}
}
return value;
Expand Down
4 changes: 4 additions & 0 deletions test/spec/modules/hmdaFilters.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ describe('Filters: hmdaFilters', function() {
expect(hmdaValueFilter('100', 'lar', 'number')).toBe('100');
}));

it('should not format a value of NA', angular.mock.inject(function(hmdaValueFilter) {
expect(hmdaValueFilter('NA', 'lar', 'percent')).toBe('NA');
}));

it('should format a file-spec property of type percent', angular.mock.inject(function(hmdaValueFilter) {
expect(hmdaValueFilter('12.34', 'lar', 'percent')).toBe('12.34%');
}));
Expand Down

0 comments on commit a2d6182

Please sign in to comment.