Skip to content

Commit

Permalink
Use API call to populate cloud_types drop down
Browse files Browse the repository at this point in the history
Use credential_types from options returned from API call to populate Cloud Types drop down. Added changes to handle sorting of list of cloud types returned from API call

https://www.pivotaltracker.com/story/show/140931909
  • Loading branch information
h-kataria committed Mar 15, 2017
1 parent fa6c2af commit 4e78b47
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
retirement_value: '',
retirement_variables: {},
retirement_editMode: false,
retirement_cloud_type: '',
cloud_types: ["Amazon", "Azure", "Google", "Openstack", "Vmware"]
retirement_cloud_type: ''
};
getRemoveResourcesTypes();
vm.formId = catalogItemFormId;
Expand Down Expand Up @@ -249,6 +248,29 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
vm._retirement_network_credential = _.find(vm.network_credentials, {id: vm.catalogItemModel.retirement_network_credential_id});
vm._provisioning_network_credential = _.find(vm.network_credentials, {id: vm.catalogItemModel.provisioning_network_credential_id});
})

API.options('/api/authentications').then(function(data) {
var cloud_types = {};
angular.forEach(data.data.credential_types.embedded_ansible_credentials, function(cred_object, cred_type) {
cloud_types[cred_type] = cred_object.label;
});
vm.cloud_types = getSortedHash(cloud_types);
});
};

getSortedHash = function(inputHash) {
var sortedHash = Object.keys(inputHash)
.map(function(key) {
return ({"k": key, "v": inputHash[key]})
})
.sort(function(a, b) {
return a.v.localeCompare(b.v)
})
.reduce(function(o, e) {
o[e.k] = e.v;
return o;
}, {});
return sortedHash;
};

// get playbooks for selected repository
Expand Down Expand Up @@ -280,9 +302,9 @@ ManageIQ.angular.app.controller('catalogItemFormController', ['$scope', 'catalog
});

$scope.cloudTypeChanged = function(prefix) {
typ = vm.catalogItemModel[prefix + "_cloud_type"];
var typ = vm.catalogItemModel[prefix + "_cloud_type"];
// list of cloud credentials based upon selected cloud type
url = "/api/authentications?collection_class=ManageIQ::Providers::EmbeddedAnsible::AutomationManager::" + typ + "Credential&expand=resources&attributes=id,name" + sort_options
var url = '/api/authentications?collection_class=' + typ + '&expand=resources&attributes=id,name' + sort_options;
API.get(url).then(function (data) {
vm[prefix + '_cloud_credentials'] = data.resources;
vm[prefix + '_cloud_credential'] = _.find(vm[prefix + '_cloud_credentials'], {id: vm.catalogItemModel[prefix + '_cloud_credential_id']});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
.col-md-9
%select{"ng-model" => "#{ng_model}.#{prefix}_cloud_type",
"name" => "#{prefix}_cloud_type",
'ng-options' => "cloud_type for cloud_type in #{ng_model}.cloud_types",
'ng-options' => "k as v for (k, v) in vm.cloud_types",
"ng-change" => "cloudTypeChanged('#{prefix}')",
:checkchange => true,
"pf-select" => true}
Expand Down

0 comments on commit 4e78b47

Please sign in to comment.