diff options
author | Shaoquan Chen <sean.chen2@hp.com> | 2015-03-22 23:34:59 -0700 |
---|---|---|
committer | Travis Tripp <travis.tripp@hp.com> | 2015-04-03 16:30:48 -0600 |
commit | 43f2917cbe725eda17f4a5e979711db2a3083207 (patch) | |
tree | 906e51894b5d76cb02daf51b8b7df0abc4a0b3f8 /horizon/static | |
parent | 5bec804f2a40299a9de4694b4b79e65f678a3aa7 (diff) | |
download | horizon-43f2917cbe725eda17f4a5e979711db2a3083207.tar.gz |
[Launch Instance Fix] Conditionally enable UI
In Launch Instance work flow Configuration step, `DiskConfig`
and `ConfigDrive` should be handle only when certain extension
on navaExtension are enbled respectively.
Created a generic way to make this happen.
Co-Authored-By: Travis Tripp <travis.tripp@hp.com>
Change-Id: I98a91ff9e1ae78310fb7e568cce909e76e610cf8
Closes-Bug: #1435155
Diffstat (limited to 'horizon/static')
-rw-r--r-- | horizon/static/horizon/js/angular/services/hz.api.nova.js | 73 |
1 files changed, 44 insertions, 29 deletions
diff --git a/horizon/static/horizon/js/angular/services/hz.api.nova.js b/horizon/static/horizon/js/angular/services/hz.api.nova.js index 3e5ba0247..66ef95803 100644 --- a/horizon/static/horizon/js/angular/services/hz.api.nova.js +++ b/horizon/static/horizon/js/angular/services/hz.api.nova.js @@ -270,41 +270,56 @@ limitations under the License. angular.module('hz.api') .service('novaAPI', ['apiService', NovaAPI]); - /** - * @ngdoc service - * @name hz.api.novaExtensions - * @description - * Provides cached access to Nova Extensions with utilities to help - * with asynchronous data loading. The cache may be reset at any time - * by accessing the cache and calling removeAll. The next call to any - * function will retrieve fresh results. - * - * The enabled extensions do not change often, so using cached data will - * speed up results. Even on a local devstack in informal testing, - * this saved between 30 - 100 ms per request. - */ + /** + * @ngdoc service + * @name hz.api.novaExtensions + * @description + * Provides cached access to Nova Extensions with utilities to help + * with asynchronous data loading. The cache may be reset at any time + * by accessing the cache and calling removeAll. The next call to any + * function will retrieve fresh results. + * + * The enabled extensions do not change often, so using cached data will + * speed up results. Even on a local devstack in informal testing, + * this saved between 30 - 100 ms per request. + */ function NovaExtensions($cacheFactory, $q, novaAPI) { + var service = {}; + service.cache = $cacheFactory('hz.api.novaExtensions', {capacity: 1}); - var service = {}; - service.cache = $cacheFactory('hz.api.novaExtensions', {capacity: 1}); + service.get = function () { + return novaAPI.getExtensions({cache: service.cache}) + .then(function (data) { + return data.data.items; + }); + }; - service.get = function() { - return novaAPI.getExtensions({cache: service.cache}) - .then(function(data){ - return data.data.items; - } - ); - }; + service.ifNameEnabled = function(desired) { + var deferred = $q.defer(); - service.ifNameEnabled = function(desired, doThis) { - return service.get().then(function(extensions){ - if (enabled(extensions, 'name', desired)){ - return $q.when(doThis()); - } + service.get().then(onDataLoaded, onDataFailure); + + function onDataLoaded(extensions) { + if (enabled(extensions, 'name', desired)) { + deferred.resolve(); + } else { + deferred.reject(interpolate( + gettext('Extension is not enabled: %(extension)s'), + {extension: desired}, + true)); } - ); + } + + function onDataFailure() { + deferred.reject(gettext('Cannot get nova extension list.')); + } + + return deferred.promise; }; + // This is an alias to support the extension directive default interface + service.ifEnabled = service.ifNameEnabled; + function enabled(resources, key, desired) { if(resources) { return resources.some(function (resource) { @@ -315,7 +330,7 @@ limitations under the License. } } - return service; + return service; } angular.module('hz.api') |