Skip to content

Commit

Permalink
Merge 2d32d2c into 5cd807e
Browse files Browse the repository at this point in the history
  • Loading branch information
RocKhalil authored Nov 25, 2021
2 parents 5cd807e + 2d32d2c commit acbea9e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
9 changes: 8 additions & 1 deletion app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,14 @@ def menu_for(parent, abstract_model = nil, object = nil, only_icon = false)
else
'javascript:void(0)'
end
content_tag(:a, label, {href: href}.merge(action.pjax? ? {class: ['pjax']} : {}))

extra_classes = []
extra_classes << 'pjax' if action.pjax? && action.target_window != :_blank

extra_tags = {}
extra_tags[:target] = action.target_window if action.target_window.present?

content_tag(:a, label, {href: href, class: extra_classes}.merge(extra_tags))
else
content_tag(:span, label)
end
Expand Down
5 changes: 5 additions & 0 deletions lib/rails_admin/config/actions/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ class Base
true
end

# Target window [_self, _blank]
register_instance_option :target_window do
nil
end

# This block is evaluated in the context of the controller when action is called
# You can access:
# - @objects if you're on a model scope
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/rails_admin/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,24 @@
expect(helper.menu_for(:root)).not_to match(/Dashboard/)
expect(helper.menu_for(:root)).to match(/Look this/)
end

it 'should render allow an action to have target_window as config' do
RailsAdmin.config do |config|
config.actions do
dashboard
index
show do
target_window :_blank
end
end
end

@action = RailsAdmin::Config::Actions.find :show
@abstract_model = RailsAdmin::AbstractModel.new(Team)
@object = FactoryBot.create(:team, name: 'the avengers')

expect(helper.menu_for(:member, @abstract_model, @object)).to match(/_blank/)
end
end

describe '#main_navigation' do
Expand Down

0 comments on commit acbea9e

Please sign in to comment.