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 @@
Project ID
-
{$ user.tenantId || user.default_project_id || '-'$}
+
{$ user.tenantId || user.default_project_id | noValue $}
Email
-
{$ user.email || '-' $}
+
{$ user.email | noValue $}
Enabled
diff --git a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html index c76f11b2d1..bcab283b61 100644 --- a/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html +++ b/openstack_dashboard/dashboards/project/static/dashboard/project/workflow/launch-instance/security-groups/security-group-details.html @@ -10,11 +10,11 @@ - {$ d.direction || '-' $} - {$ d.ethertype || '-' $} - {$ d.protocol || '-' $} - {$ d.port_range_min || '-' $} - {$ d.port_range_max || '-' $} - {$ d.remote_ip_prefix || '-' $} + {$ d.direction | noValue $} + {$ d.ethertype | noValue $} + {$ d.protocol | noValue $} + {$ d.port_range_min | noValue $} + {$ d.port_range_max | noValue $} + {$ d.remote_ip_prefix | noValue $} diff --git a/openstack_dashboard/static/app/core/images/table/images-table.html b/openstack_dashboard/static/app/core/images/table/images-table.html index 61c9db8766..4684d38457 100644 --- a/openstack_dashboard/static/app/core/images/table/images-table.html +++ b/openstack_dashboard/static/app/core/images/table/images-table.html @@ -70,7 +70,7 @@ {$ image.status | imageStatus $} {$ image.is_public | yesno $} {$ image.protected | yesno $} - {$ image.disk_format || '-' $} + {$ image.disk_format | noValue | uppercase $} {$ image.size | bytes $} @@ -99,7 +99,7 @@
Format
-
{$ image.disk_format || '-' $}
+
{$ image.disk_format | noValue $}
Size
@@ -111,11 +111,11 @@
Min Disk (GB)
-
{$ image.min_disk || '-' $}
+
{$ image.min_disk | noValue $}
Min RAM (MB)
-
{$ image.min_ram || '-' $}
+
{$ image.min_ram | noValue $}