Commit 31849db7f8d8b4cb72aa6b6b28bd5d75c35523d6
1 parent
7046d391
Exists in
master
and in
29 other branches
ActionItem252: only categories with more than X entries should show up in the top menu
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1827 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
5 changed files
with
31 additions
and
3 deletions
Show diff stats
app/models/category.rb
| ... | ... | @@ -47,7 +47,13 @@ class Category < ActiveRecord::Base |
| 47 | 47 | end |
| 48 | 48 | |
| 49 | 49 | def total_items |
| 50 | + # FIXME this can be SLOW (??) | |
| 50 | 51 | articles.count + comments.count + enterprises.count + people.count + communities.count + products.count |
| 51 | 52 | end |
| 52 | 53 | |
| 54 | + def display_in_menu? | |
| 55 | + # FIXME don't hardcode like this. Should be a setting of the environment, maybe | |
| 56 | + total_items >= 10 | |
| 57 | + end | |
| 58 | + | |
| 53 | 59 | end | ... | ... |
app/views/profile_editor/index.rhtml
| ... | ... | @@ -14,8 +14,6 @@ |
| 14 | 14 | |
| 15 | 15 | <%= file_manager_button(_('Manage Content'), 'icons-app/cms.png', :controller => 'cms') %> |
| 16 | 16 | |
| 17 | - <%= file_manager_button(_('My Interests'), 'icons-app/categories.png', :controller => 'profile_editor', :action => 'edit_categories') %> | |
| 18 | - | |
| 19 | 17 | <%= file_manager_button(_('Change Password'), 'icons-app/change-password.png', :controller => 'account', :action => 'change_password') if profile.person? %> |
| 20 | 18 | |
| 21 | 19 | <%= file_manager_button(_('Manage friends'), 'icons-app/friends.png', :controller => 'friends', :action => 'index') if profile.person? %> | ... | ... |
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.all_children.each do |child| %> | |
| 7 | + <% item.all_children.select{|i| i.display_in_menu?}.each do |child| %> | |
| 8 | 8 | <% if (@controller.controller_name == 'search') && (@controller.action_name == '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 %> | ... | ... |
test/functional/application_controller_test.rb
| ... | ... | @@ -127,4 +127,16 @@ class ApplicationControllerTest < Test::Unit::TestCase |
| 127 | 127 | assert_no_tag :tag => 'div', :attributes => { :id => 'boxes', :class => 'boxes' } |
| 128 | 128 | end |
| 129 | 129 | |
| 130 | + # FIXME why this not work??? | |
| 131 | + should 'display categories in menu' do | |
| 132 | + c1 = Category.create!(:name => 'category 1', :environment => Environment.default) | |
| 133 | + c2 = Category.create!(:name => 'category 2', :environment => Environment.default, :parent => c1) | |
| 134 | + c3 = Category.create!(:name => 'category 3', :environment => Environment.default, :parent => c1) | |
| 135 | + c2.expects(:display_in_menu?).returns(true) | |
| 136 | + c3.expects(:display_in_menu?).returns(false) | |
| 137 | + get :index | |
| 138 | + assert_tag :tag => 'a', :attributes => { :content => /category 2/ } | |
| 139 | + assert_no_tag :tag => 'a', :attributes => { :content => /category 3/ } | |
| 140 | + end | |
| 141 | + | |
| 130 | 142 | end | ... | ... |
test/unit/category_test.rb
| ... | ... | @@ -385,4 +385,16 @@ class CategoryTest < Test::Unit::TestCase |
| 385 | 385 | end |
| 386 | 386 | end |
| 387 | 387 | |
| 388 | + should 'display in menu' do | |
| 389 | + c = Category.create!(:name => 'test category1', :environment => Environment.default) | |
| 390 | + c.expects(:total_items).returns(10) | |
| 391 | + assert c.display_in_menu? | |
| 392 | + end | |
| 393 | + | |
| 394 | + should 'not display in menu' do | |
| 395 | + c = Category.create!(:name => 'test category1', :environment => Environment.default) | |
| 396 | + c.expects(:total_items).returns(1) | |
| 397 | + assert !c.display_in_menu? | |
| 398 | + end | |
| 399 | + | |
| 388 | 400 | end | ... | ... |