Skip to content

Commit

Permalink
[wip] Do not use '@ record' to indicate custom button screen
Browse files Browse the repository at this point in the history
'@ record' is set while rendering the page, but after button click, the '@ record' is nil.

The id in params[:id] is providers id
  • Loading branch information
romanblanco committed Oct 17, 2018
1 parent 8a4671c commit c139d48
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
15 changes: 13 additions & 2 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,19 @@ def custom_buttons(ids = nil, display_options = {})
button = CustomButton.find(params[:button_id])
cls = custom_button_class_model(button.applies_to_class)
@explorer = true if BASE_MODEL_EXPLORER_CLASSES.include?(cls)
ids ||= params[:id]
if ids.to_s == 'LIST'
ids ||= params[:id] unless relationship_table_screen? && @record.nil?
ids ||= find_checked_items # FIXME: for some reason, this doesn't work


binding.pry

# FIXME: copypasted from below
if ids.empty?
render_flash(_("Error executing custom button: No item was selected."), :error)
return
end

if ids.to_s == 'LIST' || !ids.empty?
objs = Rbac.filtered(cls.where(:id => find_checked_items))
obj = objs.first
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,21 @@ def custom_button_class_model(applies_to_class)
end

# Indicates, whether the user has came from providers relationship screen
# or not
# or not, before the page is rendered
#
# Used to indicate if the custom buttons should be rendered
def relationship_table_screen?
return false if @display.nil? || @record.nil?
return false if @display.nil?
display_class = @display.camelize.singularize
return false unless custom_button_appliable_class?(display_class)

display_model = @display.camelize.singularize
providers = (EmsCloud.descendants +
EmsInfra.descendants +
EmsPhysicalInfra.descendants +
ManageIQ::Providers::ContainerManager.descendants)

custom_button_model = custom_button_appliable_class?(display_model)
provider_screen = providers.any? { |provider| @record.instance_of?(provider) }
show_action = @lastaction == "show"
display_model = display_class.constantize
# method is accessed twice from a different location - from toolbar builder
# and custom button mixin - and so controller class changes
ctrl = self.class == ApplicationHelper::ToolbarBuilder ? controller : self
controller_model = ctrl.class.model

custom_button_model && provider_screen && show_action
display_model != controller_model && show_action
end
end

0 comments on commit c139d48

Please sign in to comment.