Skip to content

Commit

Permalink
Main navigation helper should not draw empty labels
Browse files Browse the repository at this point in the history
  • Loading branch information
gazay committed Jun 9, 2012
1 parent 18dfcc4 commit 1243d22
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/helpers/rails_admin/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,20 @@ def main_navigation
nodes_stack = RailsAdmin::Config.visible_models(:controller => self.controller)
nodes_stack.group_by(&:navigation_label).map do |navigation_label, nodes|

%{<li class='nav-header'>#{navigation_label || t('admin.misc.navigation')}</li>}.html_safe +
nodes.select{|n| n.parent.nil? || !n.parent.to_s.in?(nodes_stack.map{|c| c.abstract_model.model_name }) }.map do |node|
li_stack = nodes.select{|n| n.parent.nil? || !n.parent.to_s.in?(nodes_stack.map{|c| c.abstract_model.model_name }) }.map do |node|
%{
<li data-model="#{node.abstract_model.to_param}">
<a class="pjax" href="#{url_for(:action => :index, :controller => 'rails_admin/main', :model_name => node.abstract_model.to_param)}">#{node.label_plural}</a>
</li>
#{navigation(nodes_stack, nodes_stack.select{|n| n.parent.to_s == node.abstract_model.model_name}, 1)}
}.html_safe
end.join.html_safe

if li_stack.present?
li_stack = %{<li class='nav-header'>#{navigation_label || t('admin.misc.navigation')}</li>}.html_safe + li_stack
end

li_stack
end.join.html_safe
end

Expand Down
3 changes: 3 additions & 0 deletions spec/dummy_app/app/active_record/comment/confirmed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Comment::Confirmed < Comment
default_scope where(:content => 'something')
end
3 changes: 3 additions & 0 deletions spec/dummy_app/app/mongoid/comment/confirmed.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
class Comment::Confirmed < Comment
default_scope where(:content => 'something')
end
14 changes: 14 additions & 0 deletions spec/helpers/application_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,20 @@
helper.main_navigation.should match /(nav\-header).*(Navigation).*(Balls).*(Comments)/m
end

it 'should not draw empty navigation labels' do
RailsAdmin.config do |config|
config.included_models = [Ball, Comment, Comment::Confirmed]
config.model Comment do
navigation_label 'Commentz'
end
config.model Comment::Confirmed do
label_plural 'Confirmed'
end
end
helper.main_navigation.should match /(nav\-header).*(Navigation).*(Balls).*(Commentz).*(Confirmed)/m
helper.main_navigation.should_not match /(nav\-header).*(Navigation).*(Balls).*(Commentz).*(Confirmed).*(Comment)/m
end

it 'should not show unvisible models' do
RailsAdmin.config do |config|
config.included_models = [Ball, Comment]
Expand Down

0 comments on commit 1243d22

Please sign in to comment.