Commit a93fffc36a9fe889545802b64c1bcd3ab558f9ca
1 parent
19ebc11f
Exists in
master
and in
22 other branches
ActionItem255: changing the categories menu to list all children of the top level items
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1632 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
22 additions
and
2 deletions
Show diff stats
app/views/shared/categories_menu.rhtml
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | <li id="category<%= item.display_color %>"<%= ' class="active"' if (@category && (@category.top_ancestor == item)) %>> |
| 5 | 5 | <%= item.name %> |
| 6 | 6 | <ul> |
| 7 | - <% item.children.each do |child| %> | |
| 7 | + <% item.all_children.each do |child| %> | |
| 8 | 8 | <% if (params[:controller] == 'search') && (params[:action] == 'assets') %> |
| 9 | 9 | <li><%= link_to(content_tag('span', child.name), :controller => 'search', :action => 'assets', :asset => params[:asset], :category_path => child.explode_path) %></li> |
| 10 | 10 | <% else %> | ... | ... |
lib/acts_as_filesystem.rb
| ... | ... | @@ -164,7 +164,7 @@ module ActsAsFileSystem |
| 164 | 164 | while !stack.empty? |
| 165 | 165 | element = stack.pop |
| 166 | 166 | result.push(element) |
| 167 | - element.children.each do |item| | |
| 167 | + element.children.reverse.each do |item| | |
| 168 | 168 | stack.push(item) |
| 169 | 169 | end |
| 170 | 170 | end |
| ... | ... | @@ -172,6 +172,12 @@ module ActsAsFileSystem |
| 172 | 172 | result.map(&block) |
| 173 | 173 | end |
| 174 | 174 | |
| 175 | + def all_children | |
| 176 | + res = map_traversal | |
| 177 | + res.shift | |
| 178 | + res | |
| 179 | + end | |
| 180 | + | |
| 175 | 181 | end |
| 176 | 182 | end |
| 177 | 183 | ... | ... |
test/unit/acts_as_filesystem_test.rb
| ... | ... | @@ -35,6 +35,20 @@ class ActsAsFilesystemTest < Test::Unit::TestCase |
| 35 | 35 | assert_equivalent [a1, a1_1, a1_2, a1_1_1, a1_1_2], a1.map_traversal |
| 36 | 36 | end |
| 37 | 37 | |
| 38 | + should 'list the full tree without the root' do | |
| 39 | + profile = create_user('testinguser').person | |
| 40 | + | |
| 41 | + a1 = profile.articles.build(:name => 'a1'); a1.save! | |
| 42 | + | |
| 43 | + a1_1 = profile.articles.build(:name => 'a1.1'); a1_1.parent = a1; a1_1.save! | |
| 44 | + a1_2 = profile.articles.build(:name => 'a1.2'); a1_2.parent = a1; a1_2.save! | |
| 45 | + | |
| 46 | + a1_1_1 = profile.articles.build(:name => 'a1.1.1'); a1_1_1.parent = a1_1; a1_1_1.save! | |
| 47 | + a1_1_2 = profile.articles.build(:name => 'a1.1.2'); a1_1_2.parent = a1_1; a1_1_2.save! | |
| 48 | + | |
| 49 | + assert_equivalent [a1_1, a1_2, a1_1_1, a1_1_2].map(&:id), a1.all_children.map(&:id) | |
| 50 | + end | |
| 51 | + | |
| 38 | 52 | should 'be able to traverse with a block' do |
| 39 | 53 | profile = create_user('testinguser').person |
| 40 | 54 | ... | ... |