diff --git a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js index e4623f0f1c78..703e33ad74bb 100644 --- a/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js +++ b/app/assets/javascripts/controllers/catalog/catalog_item_form_controller.js @@ -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; @@ -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 @@ -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']}); diff --git a/app/views/layouts/angular/_ansible_form_options_angular.html.haml b/app/views/layouts/angular/_ansible_form_options_angular.html.haml index e0906e97fed2..de72fa1462cc 100644 --- a/app/views/layouts/angular/_ansible_form_options_angular.html.haml +++ b/app/views/layouts/angular/_ansible_form_options_angular.html.haml @@ -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}