Skip to content

Commit

Permalink
Add logic for saving selected tenants to @edit and to Catalog Item
Browse files Browse the repository at this point in the history
  • Loading branch information
Hilda Stastna committed Apr 25, 2019
1 parent 915799e commit e3f3760
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,10 @@ def atomic_req_submit
end
end

# Save selected Tenants from the tree
tenant_objects = Tenant.where(:id => @edit[:new][:tenant_ids])
st.additional_tenants = tenant_objects

if st.save
set_resource_action(st) unless st.kind_of?(ServiceTemplateContainerTemplate)
flash_key = params[:button] == "save" ? _("Service Catalog Item \"%{name}\" was saved") : _("Service Catalog Item \"%{name}\" was added")
Expand Down Expand Up @@ -1254,6 +1258,7 @@ def set_form_vars
@edit[:new][:catalog_id] = @record.service_template_catalog.try(:id)
@edit[:new][:st_prov_type] ||= @record.prov_type
@edit[:new][:generic_subtype] = @record.generic_subtype || "custom" if @edit[:new][:st_prov_type] == 'generic'
@edit[:new][:tenant_ids] = @record.additional_tenants
@tenants_tree = build_tenants_tree # Build the tree with available tenants
@available_catalogs = available_catalogs.sort # Get available catalogs with tenants and ancestors
available_orchestration_templates if @record.kind_of?(ServiceTemplateOrchestration)
Expand Down Expand Up @@ -1392,13 +1397,23 @@ def get_form_vars
# saving it in @edit as well, to use it later because prov_set_form_vars resets @edit[:new]
@edit[:st_prov_type] = @edit[:new][:st_prov_type] = params[:st_prov_type] if params[:st_prov_type]
@edit[:new][:long_description] = @edit[:new][:long_description].to_s + "..." if params[:transOne]
checked_tenants if params[:check] # Save checked Tenants to @edit

@tenants_tree = build_tenants_tree # Build the tree with available tenants
@available_catalogs = available_catalogs.sort # Get available catalogs with tenants and ancestors
get_form_vars_orchestration if @edit[:new][:st_prov_type] == 'generic_orchestration'
fetch_form_vars_ansible_or_ct if %w[generic_ansible_tower generic_container_template].include?(@edit[:new][:st_prov_type])
end

def checked_tenants
new_id = params[:id].split('-').pop if params[:id].starts_with?('tn')
if params[:check] == '1' # Adding/checking Tenant(s) in the tree for the Catalog Item
@edit[:new][:tenant_ids] = @edit[:new][:tenant_ids] + [new_id]
else # Unchecking selected Tenant(s)
@edit[:new][:tenant_ids].delete(new_id)
end
end

def available_container_managers
@edit[:new][:available_managers] =
ManageIQ::Providers::ContainerManager.all.collect { |t| [t.name, t.id] }.sort
Expand Down

0 comments on commit e3f3760

Please sign in to comment.