diff --git a/openstack_dashboard/static/app/core/images/images.module.js b/openstack_dashboard/static/app/core/images/images.module.js index 2aea05188..d6df4ade2 100644 --- a/openstack_dashboard/static/app/core/images/images.module.js +++ b/openstack_dashboard/static/app/core/images/images.module.js @@ -44,6 +44,11 @@ 'killed': gettext('Killed'), 'deleted': gettext('Deleted') }) + .constant('horizon.app.core.images.transitional-statuses', [ + "saving", + "queued", + "pending_delete" + ]) .run(run) .config(config); @@ -59,6 +64,7 @@ registry.getResourceType(imageResourceType) .setNames(gettext('Image'), gettext('Images')) .setSummaryTemplateUrl(basePath + 'details/drawer.html') + .setItemInTransitionFunction(imagesService.isInTransition) .setProperty('checksum', { label: gettext('Checksum') }) @@ -149,7 +155,8 @@ }) .append({ id: 'status', - priority: 1 + priority: 1, + itemInTransitionFunction: imagesService.isInTransition }) .append({ id: 'protected', diff --git a/openstack_dashboard/static/app/core/images/images.service.js b/openstack_dashboard/static/app/core/images/images.service.js index 982bdacaf..ef4afe854 100644 --- a/openstack_dashboard/static/app/core/images/images.service.js +++ b/openstack_dashboard/static/app/core/images/images.service.js @@ -20,7 +20,8 @@ .factory('horizon.app.core.images.service', imageService); imageService.$inject = [ - 'horizon.app.core.openstack-service-api.glance' + 'horizon.app.core.openstack-service-api.glance', + 'horizon.app.core.images.transitional-statuses' ]; /* @@ -33,11 +34,12 @@ * but do not need to be restricted to such use. Each exposed function * is documented below. */ - function imageService(glance) { + function imageService(glance, transitionalStatuses) { return { getDetailsPath: getDetailsPath, getImagesPromise: getImagesPromise, - imageType: imageType + imageType: imageType, + isInTransition: isInTransition }; /* @@ -71,6 +73,22 @@ } } + /** + * @ngdoc function + * @name isInTransition + * @param item {object} - The image object + * @description + * Given an Image object, returns a boolean representing whether the image + * is in a transitional state. + * @returns {boolean} + */ + function isInTransition(item) { + if (item && angular.isString(item.status)) { + return transitionalStatuses.indexOf(item.status.toLowerCase()) > -1; + } + return false; + } + /* * @ngdoc function * @name getImagesPromise diff --git a/openstack_dashboard/static/app/core/images/images.service.spec.js b/openstack_dashboard/static/app/core/images/images.service.spec.js index 73381bdab..f8ac6db19 100644 --- a/openstack_dashboard/static/app/core/images/images.service.spec.js +++ b/openstack_dashboard/static/app/core/images/images.service.spec.js @@ -50,6 +50,39 @@ }); }); + describe('isInTransition Function', function() { + it("should return true for known transitional statuses", function() { + var statuses = ["saving", "queued", "pending_delete"]; + statuses.forEach(function(status) { + var myItem = {status: status}; + expect(service.isInTransition(myItem)).toBe(true); + }); + }); + + it("should return false for unknown statuses", function() { + var myItem = {status: "notATransitionalState"}; + expect(service.isInTransition(myItem)).toBe(false); + }); + + it("should return false for an empty status", function() { + var myItem = {status: undefined}; + expect(service.isInTransition(myItem)).toBe(false); + }); + + it("should return false for an undefined status", function() { + var myItem = {status: undefined}; + expect(service.isInTransition(myItem)).toBe(false); + }); + + it("should return false for a non-string status", function() { + var statuses = [3, true, false]; + statuses.forEach(function(status) { + var myItem = {status: status}; + expect(service.isInTransition(myItem)).toBe(false); + }); + }); + }); + describe('getImagesPromise', function() { it("provides a promise that gets translated", inject(function($q, $injector, $timeout) { var glance = $injector.get('horizon.app.core.openstack-service-api.glance');