Skip to content

Commit

Permalink
Enable the Custom Buttons for GenericObjects only when at least one G…
Browse files Browse the repository at this point in the history
…O is checked in the list
  • Loading branch information
lgalis committed Nov 3, 2017
1 parent 7c32add commit 8d45aa8
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
3 changes: 2 additions & 1 deletion app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,8 @@ def ab_group_delete
BASE_MODEL_EXPLORER_CLASSES = [Vm, MiqTemplate, Service].freeze
APPLIES_TO_CLASS_BASE_MODELS = %w(AvailabilityZone CloudNetwork CloudObjectStoreContainer CloudSubnet CloudTenant
CloudVolume ContainerGroup ContainerImage ContainerNode ContainerProject
ContainerTemplate ContainerVolume EmsCluster ExtManagementSystem Host LoadBalancer
ContainerTemplate ContainerVolume EmsCluster ExtManagementSystem
GenericObjectDefinition Host LoadBalancer
MiqGroup MiqTemp NetworkRouter OrchestrationStack SecurityGroup Service
ServiceTemplate Storage Switch Tenant User Vm).freeze
def applies_to_class_model(applies_to_class)
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/mixins/custom_buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def custom_toolbar_simple
Mixins::CustomButtons::Result.new(:single)
elsif @lastaction == "show_list"
Mixins::CustomButtons::Result.new(:list)
elsif @display == 'generic_objects'
Mixins::CustomButtons::Result.new(:list)
end
end

Expand Down
6 changes: 4 additions & 2 deletions app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class ServiceController < ApplicationController

def button
if @lastaction == 'generic_objects'
params[:id] = @sb[:rec_id]
params[:id] = 'LIST'
#params[:id] = @sb[:rec_id]
end
custom_buttons if params[:pressed] == "custom_button"
return if ["custom_button"].include?(params[:pressed]) # custom button screen, so return, let custom_buttons method handle everything
Expand Down Expand Up @@ -185,6 +186,7 @@ def generic_objects
@item = @record.generic_objects.find(from_cid(id)).first
item_breadcrumbs(_("Generic Objects"), 'generic_objects')
@view = get_db_view(GenericObject, :association => "generic_objects")
@lastaction = "generic_objects_#{@item_id}"
@sb[:rec_id] = @item.id
show_item
else
Expand Down Expand Up @@ -459,7 +461,7 @@ def replace_right_cell(options = {})
if partial == 'layouts/x_gtl'
cb_tb = build_toolbar(Mixins::CustomButtons::Result.new(:list))
partial_locals[:action_url] = @lastaction
presenter[:parent_id] = @record.id # Set parent rec id for JS function miqGridSort to build URL
presenter[:parent_id] = @record.id # Set parent rec id for JS function miqGridSort to build URL
presenter[:parent_class] = params[:controller] # Set parent class for URL also
else
partial_locals[:item_id] = @item.id
Expand Down
38 changes: 19 additions & 19 deletions app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -240,19 +240,24 @@ def group_skipped?(name)
def create_custom_button(input, model, record)
button_id = input[:id]
button_name = input[:name].to_s
record_id = record.present? ? record.id : 'LIST'
if @lastaction.starts_with?('generic_objects')
record_id = 'LIST'
else
record_id = record.present? ? record.id : 'LIST'
end
button = {
:id => "custom__custom_#{button_id}",
:type => :button,
:icon => "#{input[:image]} fa-lg",
:color => input[:color],
:title => !input[:enabled] && input[:disabled_text] ? input[:disabled_text] : input[:description].to_s,
:enabled => input[:enabled],
:enabled => record_id == 'LIST' ? false : input[:enabled],
:klass => ApplicationHelper::Button::ButtonWithoutRbacCheck,
:url => "button",
:url_parms => "?id=#{record_id}&button_id=#{button_id}&cls=#{model}&pressed=custom_button&desc=#{button_name}"
}
button[:text] = button_name if input[:text_display]
button[:onwhen] = '1+' if record_id == 'LIST'
button
end

Expand All @@ -276,23 +281,33 @@ def custom_button_selects(model, record, toolbar_result)
get_custom_buttons(model, record, toolbar_result).collect do |group|
buttons = group[:buttons].collect { |b| create_custom_button(b, model, record) }

enabled = if @lastaction == 'generic_objects'
false
else
record ? true : buttons.all?{ |button| button[:enabled]}
end
props = {
:id => "custom_#{group[:id]}",
:type => :buttonSelect,
:icon => "#{group[:image]} fa-lg",
:color => group[:color],
:title => group[:description],
:enabled => record ? true : buttons.all?{ |button| button[:enabled]},
:enabled => enabled,
:items => buttons
}
props[:text] = group[:text] if group[:text_display]
props[:onwhen] = '1+' if @lastaction == 'generic_objects'

{:name => "custom_buttons_#{group[:text]}", :items => [props]}
end
end

def custom_toolbar_class(toolbar_result)
model = @record ? @record.class : model_for_custom_toolbar
if @lastaction.starts_with?('generic_objects')
model = GenericObjectDefinition
else
model = @record ? @record.class : model_for_custom_toolbar
end
build_custom_toolbar_class(model, @record, toolbar_result)
end

Expand All @@ -315,13 +330,6 @@ def build_custom_toolbar_class(model, record, toolbar_result)
buttons = service_buttons.collect { |b| create_custom_button(b, model, record) }
toolbar.button_group("custom_buttons_", buttons)
end
if @lastaction == 'generic_objects'
generic_object_buttons = record_to_generic_object_buttons(record)
unless generic_object_buttons.nil? || generic_object_buttons.empty?
buttons = generic_object_buttons.collect { |b| create_custom_button(b, model, record) }
toolbar.button_group("custom_buttons_", buttons)
end
end
end

toolbar
Expand All @@ -345,14 +353,6 @@ def record_to_service_buttons(record)
record.service_template.custom_buttons.collect { |cb| create_raw_custom_button_hash(cb, record) }
end

def record_to_generic_object_buttons(record)
return [] unless record.kind_of?(Service)
return [] if record.generic_objects.nil?

cbs = CustomButton.where(:applies_to_class => "GenericObjectDefinition", :applies_to_id => record.generic_objects.collect {|g| g.generic_object_definition.id})
cbs.collect { |cb| create_raw_custom_button_hash(cb, record) } if cbs.count > 0
end

def get_custom_buttons(model, record, toolbar_result)
cbses = CustomButtonSet.find_all_by_class_name(button_class_name(model), service_template_id(record))
cbses = CustomButtonSet.filter_with_visibility_expression(cbses, record)
Expand Down

0 comments on commit 8d45aa8

Please sign in to comment.