Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add evaluation of enablement expression and displayed text to custom button #1828

Merged
merged 6 commits into from
Aug 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ def group_skipped?(name)
x_edit_view_tb history_main ems_container_dashboard ems_infra_dashboard).include?(name)
end

def create_custom_button(input, model, record, options = {})
options[:enabled] = true unless options.key?(:enabled)
def create_custom_button(input, model, record)
button_id = input[:id]
button_name = input[:name].to_s
record_id = record.present? ? record.id : 'LIST'
Expand All @@ -247,8 +246,8 @@ def create_custom_button(input, model, record, options = {})
:type => :button,
:icon => "#{input[:image]} fa-lg",
:color => input[:color],
:title => input[:description].to_s,
:enabled => options[:enabled],
:title => !input[:enabled] && input[:disabled_text] ? input[:disabled_text] : input[:description].to_s,
:enabled => 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}"
Expand All @@ -267,20 +266,24 @@ def create_raw_custom_button_hash(cb, record)
:image => cb.options[:button_icon],
:color => cb.options[:button_color],
:text_display => cb.options.key?(:display) ? cb.options[:display] : true,
:enabled => cb.evaluate_enablement_expression_for(record),
:disabled_text => cb.disabled_text,
:target_object => record_id
}
end

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) }

props = {
:id => "custom_#{group[:id]}",
:type => :buttonSelect,
:icon => "#{group[:image]} fa-lg",
:color => group[:color],
:title => group[:description],
:enabled => true,
:items => group[:buttons].collect { |b| create_custom_button(b, model, record) }
:enabled => record ? true : buttons.all?{ |button| button[:enabled]},
:items => buttons
}
props[:text] = group[:text] if group[:text_display]

Expand Down Expand Up @@ -309,7 +312,7 @@ def build_custom_toolbar_class(model, record, toolbar_result)
if record.present?
service_buttons = record_to_service_buttons(record)
unless service_buttons.empty?
buttons = service_buttons.collect { |b| create_custom_button(b, model, record, :enabled => nil) }
buttons = service_buttons.collect { |b| create_custom_button(b, model, record) }
toolbar.button_group("custom_buttons_", buttons)
end
end
Expand Down
3 changes: 2 additions & 1 deletion spec/helpers/application_helper/toolbar_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
:image => @button1.options[:button_icon],
:color => nil,
:text_display => @button1.options.key?(:display) ? @button1.options[:display] : true,
:enabled => true,
:disabled_text => nil,
:target_object => subject.id
}
expected_button_set = {
Expand All @@ -58,7 +60,6 @@
:text_display => @button_set.set_data.key?(:display) ? @button_set.set_data[:display] : true,
:buttons => [expected_button1]
}

expect(toolbar_builder.get_custom_buttons(subject.class, subject, Mixins::CustomButtons::Result.new(:single))).to eq([expected_button_set])
end

Expand Down