Commit 31719255f669d69bd6d7cf82e84e0a513ebe9544
1 parent
1bbebba9
Exists in
master
and in
29 other branches
ActionItem501: fixed the tracking of the number of item per page
git-svn-id: https://svn.colivre.coop.br/svn/noosfero/trunk@2167 3f533792-8f58-4932-b0fe-aaf55b0a4547
Showing
3 changed files
with
12 additions
and
33 deletions
Show diff stats
app/controllers/public/search_controller.rb
@@ -88,14 +88,16 @@ class SearchController < ApplicationController | @@ -88,14 +88,16 @@ class SearchController < ApplicationController | ||
88 | 88 | ||
89 | def load_product_categories_menu(asset) | 89 | def load_product_categories_menu(asset) |
90 | @results[asset].uniq! | 90 | @results[asset].uniq! |
91 | + # REFACTOR DUPLICATED CODE inner loop doing the same thing that outter loop | ||
91 | @categories_menu = ProductCategory.menu_categories(@product_category, environment).map do |cat| | 92 | @categories_menu = ProductCategory.menu_categories(@product_category, environment).map do |cat| |
92 | hits = @finder.count(asset, @filtered_query, calculate_find_options(asset, nil, nil, cat, @region, params[:radius], nil, nil)) | 93 | hits = @finder.count(asset, @filtered_query, calculate_find_options(asset, nil, nil, cat, @region, params[:radius], nil, nil)) |
93 | childs = [] | 94 | childs = [] |
94 | - # REFACTOR DUPLICATED CODE inner loop doing the same thing that outter loop | ||
95 | - childs = cat.children.map do |child| | ||
96 | - child_hits = @finder.count(asset, @filtered_query, calculate_find_options(asset, nil, nil, child, @region, params[:radius], nil, nil)) | ||
97 | - [child, child_hits] | ||
98 | - end.select{|child, child_hits| child_hits > 0 } | 95 | + if hits > 0 |
96 | + childs = cat.children.map do |child| | ||
97 | + child_hits = @finder.count(asset, @filtered_query, calculate_find_options(asset, nil, nil, child, @region, params[:radius])) | ||
98 | + [child, child_hits] | ||
99 | + end.select{|child, child_hits| child_hits > 0 } | ||
100 | + end | ||
99 | [cat, hits, childs] | 101 | [cat, hits, childs] |
100 | end.select{|cat, hits| hits > 0 } | 102 | end.select{|cat, hits| hits > 0 } |
101 | end | 103 | end |
@@ -117,7 +119,8 @@ class SearchController < ApplicationController | @@ -117,7 +119,8 @@ class SearchController < ApplicationController | ||
117 | # limit the number of results per page | 119 | # limit the number of results per page |
118 | # TODO: dont hardcore like this | 120 | # TODO: dont hardcore like this |
119 | def limit | 121 | def limit |
120 | - (@searching.size == 1) ? 10 : 6 | 122 | + searching = @searching.values.select{|v|v} |
123 | + (searching.size == 1) ? 10 : 6 | ||
121 | end | 124 | end |
122 | 125 | ||
123 | public | 126 | public |
@@ -173,6 +176,7 @@ class SearchController < ApplicationController | @@ -173,6 +176,7 @@ class SearchController < ApplicationController | ||
173 | end | 176 | end |
174 | 177 | ||
175 | render :action => 'index' | 178 | render :action => 'index' |
179 | + render :text => 'bla' | ||
176 | end | 180 | end |
177 | 181 | ||
178 | alias :assets :index | 182 | alias :assets :index |
app/models/product_category.rb
@@ -3,15 +3,11 @@ class ProductCategory < Category | @@ -3,15 +3,11 @@ class ProductCategory < Category | ||
3 | has_many :consumptions | 3 | has_many :consumptions |
4 | has_many :consumers, :through => :consumptions, :source => :profile | 4 | has_many :consumers, :through => :consumptions, :source => :profile |
5 | 5 | ||
6 | - def tree | ||
7 | - children.inject([]){|all,c| all + c.tree } << self | ||
8 | - end | ||
9 | - | ||
10 | def all_products | 6 | def all_products |
11 | - Product.find(:all, :conditions => { :product_category_id => tree.map(&:id) }) | 7 | + Product.find(:all, :conditions => { :product_category_id => (all_children << self).map(&:id) }) |
12 | end | 8 | end |
13 | 9 | ||
14 | def self.menu_categories(top_category, env) | 10 | def self.menu_categories(top_category, env) |
15 | - top_category ? top_category.children : top_level_for(env) | 11 | + top_category ? top_category.children : top_level_for(env).select{|c|c.kind_of?(ProductCategory)} |
16 | end | 12 | end |
17 | end | 13 | end |
test/unit/product_category_test.rb
@@ -18,27 +18,6 @@ class ProductCategoryTest < Test::Unit::TestCase | @@ -18,27 +18,6 @@ class ProductCategoryTest < Test::Unit::TestCase | ||
18 | assert !c3.errors.invalid?(:type) | 18 | assert !c3.errors.invalid?(:type) |
19 | end | 19 | end |
20 | 20 | ||
21 | - def test_tree | ||
22 | - c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default) | ||
23 | - assert ! c0.new_record? | ||
24 | - assert_equivalent [c0], c0.tree | ||
25 | - | ||
26 | - c1 = ProductCategory.create!(:name => 'cat_1', :parent => c0, :environment => Environment.default) | ||
27 | - c0.reload | ||
28 | - assert_equivalent [c1], c1.tree | ||
29 | - assert_equivalent [c0, c1], c0.tree | ||
30 | - | ||
31 | - c2 = ProductCategory.create!(:name => 'cat_2', :parent => c0, :environment => Environment.default) | ||
32 | - c0.reload; c1.reload; | ||
33 | - assert_equivalent [c0,c1,c2] , c0.tree | ||
34 | - | ||
35 | - c3 = ProductCategory.create!(:name => 'cat_3', :parent => c2, :environment => Environment.default) | ||
36 | - c0.reload; c1.reload; c2.reload | ||
37 | - assert_equivalent [c0,c1,c2,c3], c0.tree | ||
38 | - assert_equivalent [c2,c3], c2.tree | ||
39 | - | ||
40 | - end | ||
41 | - | ||
42 | def test_all_products | 21 | def test_all_products |
43 | c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default) | 22 | c0 = ProductCategory.create!(:name => 'base_cat', :environment => Environment.default) |
44 | assert_equivalent [], c0.all_products | 23 | assert_equivalent [], c0.all_products |