diff --git a/horizon/static/framework/util/filters/filters.js b/horizon/static/framework/util/filters/filters.js index e10abf0625..fb7e873b02 100644 --- a/horizon/static/framework/util/filters/filters.js +++ b/horizon/static/framework/util/filters/filters.js @@ -23,6 +23,7 @@ .filter('mb', mbFilter) .filter('title', titleFilter) .filter('noUnderscore', noUnderscoreFilter) + .filter('noValue', noValueFilter) .filter('decode', decodeFilter) .filter('bytes', bytesFilter) .filter('itemCount', itemCountFilter); @@ -107,6 +108,23 @@ }; } + /** + * @ngdoc filter + * @name noValue + * @description + * Replaces null / undefined / empty string with translated '-'. + */ + function noValueFilter() { + return function (input) { + if (input === null || angular.isUndefined(input) || + (angular.isString(input) && '' == input.trim())) { + return gettext('-'); + } else { + return input; + } + }; + } + /** * @ngdoc filter * @name decode @@ -161,7 +179,7 @@ */ function itemCountFilter() { - function ensureNonNegative (input) { + function ensureNonNegative(input) { var isNumeric = (input !== null && isFinite(input)); var number = isNumeric ? Math.round(input) : 0; return (number > 0) ? number : 0; diff --git a/horizon/static/framework/util/filters/filters.spec.js b/horizon/static/framework/util/filters/filters.spec.js index e6fa1931dc..7d228c68f6 100644 --- a/horizon/static/framework/util/filters/filters.spec.js +++ b/horizon/static/framework/util/filters/filters.spec.js @@ -127,6 +127,31 @@ }); }); + describe('noValue', function () { + var noValueFilter; + beforeEach(inject(function (_noValueFilter_) { + noValueFilter = _noValueFilter_; + })); + + it('returns value if there is a value', function () { + expect(noValueFilter('foo')).toBe('foo'); + expect(noValueFilter(' foo ')).toBe(' foo '); + expect(noValueFilter(true)).toBe(true); + expect(noValueFilter(false)).toBe(false); + var object = {}; + expect(noValueFilter(object)).toBe(object); + var array = []; + expect(noValueFilter(array)).toBe(array); + }); + + it('replaces undefined, null, blank with -', function () { + expect(noValueFilter(null)).toBe('-'); + expect(noValueFilter()).toBe('-'); + expect(noValueFilter('')).toBe('-'); + expect(noValueFilter(' ')).toBe('-'); + }); + }); + describe("decode", function () { var decodeFilter; beforeEach(inject(function (_decodeFilter_) { diff --git a/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html b/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html index cf47743156..fcd465eb9c 100644 --- a/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html +++ b/openstack_dashboard/dashboards/identity/static/dashboard/identity/users/table/table.html @@ -82,13 +82,13 @@