From 9ca0cc8d34a2c4909fb011f5ca5bb9dd148cb33a Mon Sep 17 00:00:00 2001 From: woodm1979 Date: Fri, 22 Jul 2016 13:02:08 -0600 Subject: [PATCH] hz-images have transitional states defined Using the transitional-states framework defined in https://review.openstack.org/#/c/346174 The images generic panel now defines a call-back method for determining if an image is in a transitional state. Thid call-back is registered in the registry for later use by the table. Change-Id: Ibdb51157a540a2c23d5f5bb324d37a918c2e51ab Co-Authored-By: Tyr Johanson tyr@hpe.com Partially-Implements: blueprint angularize-images-table --- .../static/app/core/images/images.module.js | 9 ++++- .../static/app/core/images/images.service.js | 24 ++++++++++++-- .../app/core/images/images.service.spec.js | 33 +++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) diff --git a/openstack_dashboard/static/app/core/images/images.module.js b/openstack_dashboard/static/app/core/images/images.module.js index 113809d8b..4d420a4ab 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');