Skip to content

Commit

Permalink
Merge pull request #860 from AparnaKarve/q_all_promises
Browse files Browse the repository at this point in the history
$q all promises and resolve them in the end
  • Loading branch information
himdel authored Apr 12, 2017
2 parents 079f752 + 56da8bc commit 73f263d
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global miqFlashLater */

ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window', 'credentialId', 'miqService', 'API', function($window, credentialId, miqService, API) {
ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window', '$q', 'credentialId', 'miqService', 'API', function($window, $q, credentialId, miqService, API) {
var vm = this;

var init = function() {
Expand All @@ -22,12 +22,12 @@ ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window',
miqService.sparkleOn();

// get credential specific options for all supported credential types
API.options('/api/authentications')
var optionsPromise = API.options('/api/authentications')
.then(getCredentialOptions)
.catch(miqService.handleFailure);

if (credentialId !== 'new') {
API.get('/api/authentications/' + credentialId)
var dataPromise = API.get('/api/authentications/' + credentialId)
.then(getCredentialFormData)
.catch(miqService.handleFailure);
} else {
Expand All @@ -40,6 +40,9 @@ ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window',
vm.modelCopy = angular.copy( vm.credentialModel );
miqService.sparkleOff();
}

$q.all([optionsPromise, dataPromise])
.then(retrievedCredentialDetails);
};

vm.cancelClicked = function(angularForm) {
Expand Down Expand Up @@ -68,13 +71,17 @@ ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window',
.catch(miqService.handleFailure);
};

function retrievedCredentialDetails() {
vm.afterGet = true;
miqService.sparkleOff();
}

function getCredentialOptions(response) {
Object.assign(vm.credential_options, response.data.credential_types.embedded_ansible_credential_types);

for (var opt in vm.credential_options) {
vm.select_options.push({'value': opt, 'label': vm.credential_options[opt].label});
}
vm.afterGet = true;
}

function getCredentialFormData(response) {
Expand All @@ -95,8 +102,6 @@ ManageIQ.angular.app.controller('ansibleCredentialsFormController', ['$window',
}

vm.modelCopy = angular.copy( vm.credentialModel );
vm.afterGet = true;
miqService.sparkleOff();
}

function getBack(message, warning, error) {
Expand Down

0 comments on commit 73f263d

Please sign in to comment.