diff --git a/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js b/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js index 03add74b..49c14122 100644 --- a/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js +++ b/src/javascripts/ng-admin/Crud/misc/EntryFormatter.js @@ -9,6 +9,11 @@ define(function () { return $filter('date')(date, format); }; }; + this.formatNumber = function (format) { + return function (number) { + return $filter('numeraljs')(number, format); + }; + }; } EntryFormatter.prototype.formatField = function formatField(field) { @@ -19,8 +24,6 @@ define(function () { case 'boolean': case 'choice': case 'choices': - case 'number': - case 'float': case 'string': case 'text': case 'wysiwyg': @@ -34,6 +37,16 @@ define(function () { value: entry.values[field.name()] }; }; + case 'number': + case 'float': + var format = field.format(); + var formatNumber = this.formatNumber(format); + return function (entry) { + return { + name: label, + value: formatNumber(entry.values[field.name()]) + }; + }; case 'date': case 'datetime': var format = field.format(); diff --git a/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js b/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js index eb278a40..c9867501 100644 --- a/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js +++ b/src/javascripts/test/unit/Crud/misc/EntryFormatterSpec.js @@ -1,9 +1,10 @@ /*global jasmine,angular,describe,it,expect,beforeEach,spyOn*/ var EntryFormatter = require('../../../../ng-admin/Crud/misc/EntryFormatter'); -var $filter = function () { - return function (date, format) { +var $filter = function (filter) { + return function (value, format) { return { - date: date, + filter: filter, + value: value, format: format }; }; @@ -31,10 +32,12 @@ describe("Service: EntryFormatter.getFormatter formatter", function () { var formatter = entryFormatter.getFormatter([getField({ type: 'number', name: 'number', - label: 'Number' + label: 'Number', + format: '0.000%' })]); + var number = 56; - expect(formatter({values: {number: 5}})).toEqual({Number: 5}); + expect(formatter({ values: { number: number } })).toEqual({ Number: { filter: 'numeraljs', value: 56, format: '0.000%' } }); }); it('formatter should format field of type text', function () { @@ -77,7 +80,8 @@ describe("Service: EntryFormatter.getFormatter formatter", function () { var date = new Date(); expect(formatter({values: {date: date}})).toEqual({Date: { - date: date, + filter: 'date', + value: date, format: 'yyyy/mm/dd' }}); });