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

Don't try to format value if it is NA #372

Merged
merged 1 commit into from
Apr 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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