Skip to content

Commit

Permalink
Reflect changes made to adapt navigation to accordeon constraints.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbenezech committed May 31, 2011
1 parent 5d0cc68 commit ac4d207
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
16 changes: 9 additions & 7 deletions README.md
Expand Up @@ -243,35 +243,37 @@ evaluated at runtime.
This will desactivate config.navigation.max_visible_tabs.

RailsAdmin.config do |config|
..
config.model Team do
parent League
end
end

RailsAdmin.config do |config|
config.model Division do
parent League
end
..
end

Obtained navigation:

Dashboard
...
League
League # (non-clickable)
League
Division
Team
...

If you want a non-clickable root menu entry, add 'dropdown ENTRY_NAME' to your parent.
Your parent will then be placed INSIDE his dropdown, in FIRST position.
You probably want to change the name of the dropdown.
This can be easily achieved with the 'dropdown' attribute of the parent model.

Added to previous example:

RailsAdmin.config do |config|
...
config.model League do
dropdown 'League related'
end
...
end

Obtained navigation:
Expand All @@ -290,7 +292,7 @@ By default, they are ordered by alphabetical order. If you need to override this
a weight attribute. Default is 0. Lower values will bubble items to the left, higher values
will move them to the right. Items with same weight will still be ordered by alphabetical order.
The mecanism is fully compatible with dropdown menus. Items will be ordered within their own
menu subset.
menu subset. (but parent will always be first inside his submenu).

Example:

Expand Down
24 changes: 11 additions & 13 deletions app/views/rails_admin/main/_navigation.html.erb
Expand Up @@ -9,24 +9,22 @@
</li>
<% root_models[0..max_visible_tabs-1].each do |model| %>
<%
tab_titles = [model.abstract_model.pretty_name.downcase]
children = models.select { |m| m.parent.to_s == model.abstract_model.model.to_s }
children.each { |child| tab_titles << child.abstract_model.pretty_name.downcase }
children = [model] + models.select { |m| m.parent.to_s == model.abstract_model.model.to_s }
tab_titles = children.map { |child| child.abstract_model.pretty_name.downcase }
%>
<li class="<%= "active" if tab_titles.include? @page_type %> <%= "more" unless children.empty? %>">
<% unless model.dropdown %>
<% if children.size == 1 %>
<%= link_to(model.label, rails_admin_list_path(:model_name => model.abstract_model.to_param)) %>
<% else %>
<a href="#"><%= t(model.dropdown.to_s, :default => model.dropdown.to_s) %></a>
<% children = [model] + children %>
<a href="#"><%= model.dropdown ? t(model.dropdown, :default => model.dropdown) : model.label %></a>
<ul>
<% children.each_with_index do |child, index| %>
<li class="<%= "active" if @page_type == tab_titles[index] %>">
<%= link_to(child.label, rails_admin_list_path(:model_name => child.abstract_model.to_param)) %>
</li>
<% end %>
</ul>
<% end %>
<ul>
<% children.each do |child| %>
<li class="<%= "active" if @page_type == child.abstract_model.pretty_name.downcase %>">
<%= link_to(child.label, rails_admin_list_path(:model_name => child.abstract_model.to_param)) %>
</li>
<% end %>
</ul>
</li>
<% end %>
<% if root_models.size > max_visible_tabs %>
Expand Down
Expand Up @@ -62,6 +62,7 @@

it "should nest menu items with parent and not take max_visible_tabs into account" do
RailsAdmin.config do |config|
config.navigation.max_visible_tabs 3
config.model Comment do
parent Cms::BasicPage
end
Expand All @@ -71,11 +72,11 @@
as.map(&:content)[1..-1].should == ["Cms/Basic Page", "Division", "Draft", "Fan", "League", "Player", "Team", "User"]
end
response.should have_tag("#nav>li.more>ul>li>a") do |as|
as.map(&:content).should == ["Comment"]
as.map(&:content).should == ["Cms/Basic Page", "Comment"]
end
end

it "should put parent in dropdown in first position if parent dropdown is set" do
it "should override parent label with dropdown" do
RailsAdmin.config do |config|
config.model Comment do
parent Cms::BasicPage
Expand Down

0 comments on commit ac4d207

Please sign in to comment.