Commit 11142e99f55d9b6fd23dee8f553bd0a7d9018d68
1 parent
09f41a83
Exists in
master
and in
28 other branches
ActionItem323: better layout for category index
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@1725 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
8 changed files
with
56 additions
and
108 deletions
Show diff stats
app/controllers/public/search_controller.rb
| ... | ... | @@ -29,19 +29,6 @@ class SearchController < ApplicationController |
| 29 | 29 | end |
| 30 | 30 | end |
| 31 | 31 | |
| 32 | - def action_product_category | |
| 33 | - @products = category.products | |
| 34 | - @enterprises = category.products.map{|p| p.enterprise}.flatten.uniq | |
| 35 | - @users = category.consumers | |
| 36 | - end | |
| 37 | - | |
| 38 | - def action_category | |
| 39 | - @recent_articles = @finder.recent('articles') | |
| 40 | - @recent_comments = @finder.recent('comments') | |
| 41 | - @most_commented_articles = @finder.most_commented_articles | |
| 42 | - end | |
| 43 | - alias :action_region :action_category | |
| 44 | - | |
| 45 | 32 | public |
| 46 | 33 | |
| 47 | 34 | include SearchHelper |
| ... | ... | @@ -58,7 +45,7 @@ class SearchController < ApplicationController |
| 58 | 45 | ] |
| 59 | 46 | |
| 60 | 47 | # TODO don't hardcode like this >:-( |
| 61 | - LIST_LIMIT = 10 | |
| 48 | + LIST_LIMIT = 20 | |
| 62 | 49 | |
| 63 | 50 | def index |
| 64 | 51 | @query = params[:query] || '' |
| ... | ... | @@ -76,7 +63,18 @@ class SearchController < ApplicationController |
| 76 | 63 | |
| 77 | 64 | # view the summary of one category |
| 78 | 65 | def category_index |
| 79 | - send('action_' + category.class.name.underscore) | |
| 66 | + @results = {} | |
| 67 | + @names = {} | |
| 68 | + [ | |
| 69 | + [ :recent_people, _('Recently registered people'), @finder.recent('people') ], | |
| 70 | + [ :recent_communities, _('Recently created communities'), @finder.recent('communities') ], | |
| 71 | + [ :recent_articles, _('Recent articles'), @finder.recent('articles') ], | |
| 72 | + [ :recent_comments, _('Recent comments'), @finder.recent('comments') ], | |
| 73 | + [ :most_commented_articles, _('Most commented articles'), @finder.most_commented_articles ] | |
| 74 | + ].each do |key, name, list| | |
| 75 | + @results[key] = list | |
| 76 | + @names[key] = name | |
| 77 | + end | |
| 80 | 78 | end |
| 81 | 79 | attr_reader :category |
| 82 | 80 | ... | ... |
app/views/search/_category.rhtml
| ... | ... | @@ -1,34 +0,0 @@ |
| 1 | - | |
| 2 | -<div id="category-recent-articles"> | |
| 3 | - <h2><%= _('Recent articles') %></h2> | |
| 4 | - <div class="category-innerbox"> | |
| 5 | - <ul class="recent_on_cat recent_articles"> | |
| 6 | - <%= render :partial => 'article', :collection => @recent_articles %> | |
| 7 | - </ul> | |
| 8 | - </div><!-- end class="category-innerbox" --> | |
| 9 | -</div><!-- end id="category-recent-articles" --> | |
| 10 | - | |
| 11 | -<div id="category-comments"> | |
| 12 | - | |
| 13 | -<div id="category-recent-comments"> | |
| 14 | - <h2><%= _('Recent Comments') %></h2> | |
| 15 | - <div class="category-innerbox"> | |
| 16 | - <ul class="recent_on_cat recent_comments"> | |
| 17 | - <% @recent_comments.each do |comment| %> | |
| 18 | - <%= render :partial => 'comment', :object => comment %> | |
| 19 | - <% end %> | |
| 20 | - </ul> | |
| 21 | - </div><!-- end class="category-innerbox" --> | |
| 22 | -</div><!-- end id="category-recent-articles" --> | |
| 23 | - | |
| 24 | -<div id="most-commented"> | |
| 25 | - <h2><%= _('Most commented articles') %></h2> | |
| 26 | - <div class="category-innerbox"> | |
| 27 | - <ul class="most_commented"> | |
| 28 | - <%= render :partial => 'article', :collection => @most_commented_articles %> | |
| 29 | - </ul> | |
| 30 | - </div><!-- end class="category-innerbox" --> | |
| 31 | -</div><!-- end id="most-commented" --> | |
| 32 | - | |
| 33 | -</div><!-- end id="category-comments" --> | |
| 34 | - |
app/views/search/_display_results.rhtml
| 1 | 1 | <div id="search-results" class="<%= 'only-one-result-box' if @results.size == 1 %>"> |
| 2 | 2 | |
| 3 | -<% if @category %> | |
| 3 | +<% if @category && !@query.blank? %> | |
| 4 | 4 | <div id="search-whole-site"> |
| 5 | 5 | <%= link_to _('Search for "%s" in the whole site') % @query, |
| 6 | 6 | :controller => 'search', :action => 'index', :category_path => [], :query => @query %> | ... | ... |
app/views/search/_product_category.rhtml
| ... | ... | @@ -1,29 +0,0 @@ |
| 1 | -<%= link_to(_('I consume this'), {:profile => current_user.login, :controller => 'consumed_products', :action => 'new', 'consumption[product_category_id]' => @category.id }, :method => :post) if logged_in? %> | |
| 2 | -<ul> | |
| 3 | - <li><%= n_("One product in this category.", "%{num} products in this category.", @products.size) % { :num => @products.size } %></li> | |
| 4 | - <li><%= n_("One enterprise sells products in this category.", "%{num} enterprises sells products in this category.", @enterprises.size) % { :num => @enterprises.size} %></li> | |
| 5 | - <li><%= n_("One user consumes this product.", "%{num} users consumes this product", @users.size) % {:num => @users.size} %></li> | |
| 6 | -</ul> | |
| 7 | - | |
| 8 | -<h3> <%= _('Products under this category:') %> </h3> | |
| 9 | -<ul> | |
| 10 | - <% @products.each do |p| %> | |
| 11 | - <li> | |
| 12 | - <%= image_tag p.image.public_filename(:thumb) if p.image%> | |
| 13 | - <%= link_to_product(p) %> <br/> | |
| 14 | - <% if p.price %> | |
| 15 | - <%= _('Price: %d') % p.price %> <br/> | |
| 16 | - <% end %> | |
| 17 | - <%= _('Enterprise:') %> <%= link_to_homepage p.enterprise.name, p.enterprise.identifier %> <br/><br/> | |
| 18 | - </li> | |
| 19 | - <% end %> | |
| 20 | -</ul> | |
| 21 | - | |
| 22 | -<h3><%= _('Users that consumes products in this category:') %></h3> | |
| 23 | - | |
| 24 | -<% @users.each do |u| %> | |
| 25 | - <p> | |
| 26 | - <%= image_tag u.image.public_filename(:thumb) if u.image %> <br> | |
| 27 | - <%= link_to_homepage(u.name, u.identifier) %> | |
| 28 | - </p> | |
| 29 | -<% end %> |
app/views/search/_region.rhtml
app/views/search/assets.rhtml
| 1 | -<h2><%= @category ? (_('%{asset_name} in %{category}') % { :asset_name => @asset_name, :category => @category.full_name}) : @asset_name %></h2> | |
| 1 | +<h1><%= @category ? (_('%{asset_name} in %{category}') % { :asset_name => @asset_name, :category => @category.name}) : @asset_name %></h1> | |
| 2 | 2 | |
| 3 | 3 | <%= render :partial => 'display_results' %> | ... | ... |
app/views/search/category_index.rhtml
| ... | ... | @@ -6,10 +6,8 @@ |
| 6 | 6 | |
| 7 | 7 | <h1 id="category-name"><%= _('Category: %s') % @category.name %></h1> |
| 8 | 8 | |
| 9 | - <div class="category_itens"> | |
| 10 | - <%= render :partial => @category.class.name.underscore %> | |
| 11 | - </div><!-- end class="category_itens" --> | |
| 12 | - | |
| 9 | + <%= render :partial => 'display_results' %> | |
| 10 | + | |
| 13 | 11 | <div id="category-childs"> |
| 14 | 12 | <h2> <%= _('Sub-categories') %> </h2> |
| 15 | 13 | <% if @category.children.empty? %> | ... | ... |
test/functional/search_controller_test.rb
| ... | ... | @@ -433,46 +433,62 @@ class SearchControllerTest < Test::Unit::TestCase |
| 433 | 433 | end |
| 434 | 434 | |
| 435 | 435 | should 'list recent articles in the category' do |
| 436 | - @controller.expects(:category).returns(@category).at_least_once | |
| 437 | 436 | recent = [] |
| 438 | - finder = CategoryFinder.new(@category) | |
| 439 | - finder.expects(:recent).with('comments').returns(recent) | |
| 440 | - finder.expects(:recent).with('articles').returns(recent) | |
| 441 | - CategoryFinder.expects(:new).with(@category).returns(finder) | |
| 437 | + finger = CategoryFinder.new(@category) | |
| 438 | + finger.expects(:recent).with(anything).at_least_once | |
| 439 | + finger.expects(:recent).with('articles').returns(recent) | |
| 440 | + CategoryFinder.expects(:new).with(@category).returns(finger) | |
| 442 | 441 | |
| 443 | 442 | get :category_index, :category_path => [ 'my-category' ] |
| 444 | - assert_same recent, assigns(:recent_articles) | |
| 443 | + assert_same recent, assigns(:results)[:recent_articles] | |
| 445 | 444 | end |
| 446 | 445 | |
| 447 | 446 | should 'list recent comments in the category' do |
| 448 | - @controller.expects(:category).returns(@category).at_least_once | |
| 449 | 447 | recent = [] |
| 450 | - finder = CategoryFinder.new(@category) | |
| 451 | - finder.expects(:recent).with('comments').returns(recent) | |
| 452 | - finder.expects(:recent).with('articles').returns(recent) | |
| 453 | - CategoryFinder.expects(:new).with(@category).returns(finder) | |
| 448 | + finger = CategoryFinder.new(@category) | |
| 449 | + finger.expects(:recent).with(anything).at_least_once | |
| 450 | + finger.expects(:recent).with('comments').returns(recent) | |
| 451 | + CategoryFinder.expects(:new).with(@category).returns(finger) | |
| 454 | 452 | |
| 455 | 453 | get :category_index, :category_path => [ 'my-category' ] |
| 456 | - assert_same recent, assigns(:recent_comments) | |
| 454 | + assert_same recent, assigns(:results)[:recent_comments] | |
| 457 | 455 | end |
| 458 | 456 | |
| 459 | 457 | should 'list most commented articles in the category' do |
| 460 | - @controller.expects(:category).returns(@category).at_least_once | |
| 461 | 458 | most_commented = [] |
| 462 | - finder = CategoryFinder.new(@category) | |
| 463 | - finder.expects(:most_commented_articles).returns(most_commented) | |
| 464 | - CategoryFinder.expects(:new).with(@category).returns(finder) | |
| 459 | + finger = CategoryFinder.new(@category) | |
| 460 | + finger.expects(:most_commented_articles).returns(most_commented) | |
| 461 | + CategoryFinder.expects(:new).with(@category).returns(finger) | |
| 465 | 462 | |
| 466 | 463 | get :category_index, :category_path => [ 'my-category' ] |
| 467 | - assert_same most_commented, assigns(:most_commented_articles) | |
| 464 | + assert_same most_commented, assigns(:results)[:most_commented_articles] | |
| 468 | 465 | end |
| 469 | 466 | |
| 470 | - should 'display category of products' do | |
| 471 | - cat = ProductCategory.create!(:name => 'Food', :environment => Environment.default) | |
| 472 | - ent = Enterprise.create!(:name => 'Enterprise test', :identifier => 'enterprise_test') | |
| 473 | - p = cat.products.create!(:name => 'product test', :enterprise => ent) | |
| 474 | - get :category_index, :category_path => cat.path.split('/') | |
| 475 | - assert_includes assigns(:products), p | |
| 467 | + should 'list recently registered people in the category' do | |
| 468 | + recent_people = [] | |
| 469 | + finger = CategoryFinder.new(@category) | |
| 470 | + finger.expects(:recent).with(anything).at_least_once | |
| 471 | + finger.expects(:recent).with('people').returns(recent_people) | |
| 472 | + CategoryFinder.expects(:new).with(@category).returns(finger) | |
| 473 | + | |
| 474 | + get :category_index, :category_path => [ 'my-category' ] | |
| 475 | + assert_same recent_people, assigns(:results)[:recent_people] | |
| 476 | + end | |
| 477 | + | |
| 478 | + should 'list recently registered communities in the category' do | |
| 479 | + recent_communities = [] | |
| 480 | + finger = CategoryFinder.new(@category) | |
| 481 | + finger.expects(:recent).with(anything).at_least_once | |
| 482 | + finger.expects(:recent).with('communities').returns(recent_communities) | |
| 483 | + CategoryFinder.expects(:new).with(@category).returns(finger) | |
| 484 | + | |
| 485 | + get :category_index, :category_path => [ 'my-category' ] | |
| 486 | + assert_same recent_communities, assigns(:results)[:recent_communities] | |
| 487 | + end | |
| 488 | + | |
| 489 | + should 'not list "Search for ..." in category_index' do | |
| 490 | + get :category_index, :category_path => [ 'my-category' ] | |
| 491 | + assert_no_tag :content => /Search for ".*" in the whole site/ | |
| 476 | 492 | end |
| 477 | 493 | |
| 478 | 494 | # SECURITY | ... | ... |