Skip to content

Commit fa0f69b

Browse files
spadgettf0x11
authored andcommitted
Wait for service classes and plans to load
Wait for all service classes and plans to load on the overview before checking bindability and sorting service instances. origin-web-common 0.0.70 -> 0.0.71
1 parent 9d72823 commit fa0f69b

File tree

4 files changed

+387
-304
lines changed

4 files changed

+387
-304
lines changed

app/scripts/controllers/overview.js

+35-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
angular.module('openshiftConsole').controller('OverviewController', [
44
'$scope',
55
'$filter',
6+
'$q',
67
'$routeParams',
78
'AlertMessageService',
89
'APIService',
@@ -24,6 +25,7 @@ angular.module('openshiftConsole').controller('OverviewController', [
2425
'OwnerReferencesService',
2526
'PodsService',
2627
'ProjectsService',
28+
'PromiseUtils',
2729
'ResourceAlertsService',
2830
'RoutesService',
2931
'ServiceInstancesService',
@@ -32,6 +34,7 @@ angular.module('openshiftConsole').controller('OverviewController', [
3234

3335
function OverviewController($scope,
3436
$filter,
37+
$q,
3538
$routeParams,
3639
AlertMessageService,
3740
APIService,
@@ -53,6 +56,7 @@ function OverviewController($scope,
5356
OwnerReferencesService,
5457
PodsService,
5558
ProjectsService,
59+
PromiseUtils,
5660
ResourceAlertsService,
5761
RoutesService,
5862
ServiceInstancesService) {
@@ -1336,46 +1340,69 @@ function OverviewController($scope,
13361340
// The canI check on watch should be temporary until we have a different solution for handling secret parameters
13371341
if (CatalogService.SERVICE_CATALOG_ENABLED && canI(serviceInstancesVersion, 'watch')) {
13381342

1339-
// Get the service class for this instance.
1343+
// Get the service class for this instance. Returns a promise.
13401344
fetchServiceClass = function(instance) {
13411345
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(instance);
13421346

1347+
var serviceClass = _.get(state, ['serviceClasses', serviceClassName]);
1348+
if (serviceClass) {
1349+
return $q.when(serviceClass);
1350+
}
1351+
13431352
// Check if we already have the service class or if a request is already in flight.
1344-
if (!_.has(state, ['serviceClasses', serviceClassName]) && !serviceClassPromises[serviceClassName]) {
1353+
if (!serviceClassPromises[serviceClassName]) {
13451354
serviceClassPromises[serviceClassName] = DataService.get(serviceClassesVersion, serviceClassName, {}).then(function(serviceClass) {
13461355
state.serviceClasses[serviceClassName] = serviceClass;
1356+
return serviceClass;
13471357
}).finally(function() {
13481358
delete servicePlanPromises[serviceClassName];
13491359
});
13501360
}
1361+
1362+
return serviceClassPromises[serviceClassName];
13511363
};
13521364

1353-
// Get the service plan for this instance.
1365+
// Get the service plan for this instance. Returns a promise.
13541366
fetchServicePlan = function(instance) {
13551367
var servicePlanName = ServiceInstancesService.getServicePlanNameForInstance(instance);
13561368

13571369
// Check if we already have the service plan or if a request is already in flight.
1358-
if (!_.has(state, ['servicePlans', servicePlanName]) && !servicePlanPromises[servicePlanName]) {
1370+
var servicePlan = _.get(state, ['servicePlans', servicePlanName]);
1371+
if (servicePlan) {
1372+
return $q.when(servicePlan);
1373+
}
1374+
1375+
if (!servicePlanPromises[servicePlanName]) {
13591376
servicePlanPromises[servicePlanName] = DataService.get(servicePlansVersion, servicePlanName, {}).then(function(servicePlan) {
13601377
state.servicePlans[servicePlanName] = servicePlan;
1378+
return servicePlan;
13611379
}).finally(function() {
13621380
delete servicePlanPromises[servicePlanName];
13631381
});
13641382
}
1383+
1384+
return servicePlanPromises[servicePlanName];
13651385
};
13661386

13671387
watches.push(DataService.watch(serviceInstancesVersion, context, function(serviceInstances) {
13681388
state.serviceInstances = serviceInstances.by('metadata.name');
1389+
1390+
var promises = [];
13691391
_.each(state.serviceInstances, function(instance) {
13701392
var notifications = ResourceAlertsService.getServiceInstanceAlerts(instance);
13711393
setNotifications(instance, notifications);
13721394

1373-
fetchServiceClass(instance);
1374-
fetchServicePlan(instance);
1395+
promises.push(fetchServiceClass(instance));
1396+
promises.push(fetchServicePlan(instance));
1397+
});
1398+
1399+
// Wait for all promises to complete before trying to sort the
1400+
// instances and check bindability.
1401+
PromiseUtils.waitForAll(promises).finally(function() {
1402+
sortServiceInstances();
1403+
updateFilter();
13751404
});
1376-
sortServiceInstances();
13771405
updateLabelSuggestions(state.serviceInstances);
1378-
updateFilter();
13791406
}, {poll: limitWatches, pollInterval: DEFAULT_POLL_INTERVAL}));
13801407
}
13811408

bower.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
"angular-moment": "1.0.0",
4747
"angular-utf8-base64": "0.0.5",
4848
"file-saver": "1.3.3",
49-
"origin-web-common": "0.0.70",
49+
"origin-web-common": "0.0.71",
5050
"origin-web-catalog": "0.0.60"
5151
},
5252
"devDependencies": {

0 commit comments

Comments
 (0)