Commit 3176600f291b2ba3dc9e0e64f38f4011425b7035
1 parent
c725c421
Exists in
sisp_simple_version
Fix bugs in categories show on catalog
Signed-off-by: Luciano Prestes Cavalcanti <lucianopcbr@gmail.com>
Showing
3 changed files
with
21 additions
and
17 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/ext/category.rb
... | ... | @@ -28,8 +28,7 @@ class Category |
28 | 28 | } |
29 | 29 | |
30 | 30 | def software_infos |
31 | - software_list = self.communities | |
32 | - software_list.collect { |x| software_list.delete(x) unless x.software? } | |
31 | + software_list = self.communities.collect{|community| community.software_info if community.software?} | |
33 | 32 | software_list |
34 | 33 | end |
35 | 34 | end | ... | ... |
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
... | ... | @@ -14,10 +14,12 @@ class SearchController |
14 | 14 | end |
15 | 15 | |
16 | 16 | def software_infos |
17 | - prepare_software_search_page(:software_infos) | |
18 | - results = filter_software_infos_list do |software| | |
17 | + software_public_condition_block = lambda do |software| | |
19 | 18 | (!@public_software_selected || software.public_software?) && (!software.sisp) |
20 | 19 | end |
20 | + | |
21 | + prepare_software_search_page(:software_infos, &software_public_condition_block) | |
22 | + results = filter_software_infos_list(&software_public_condition_block) | |
21 | 23 | @software_count = results.count |
22 | 24 | results = results.paginate(:per_page => @per_page, :page => params[:page]) |
23 | 25 | @searches[@asset] = {:results => results} |
... | ... | @@ -27,8 +29,10 @@ class SearchController |
27 | 29 | end |
28 | 30 | |
29 | 31 | def sisp |
30 | - prepare_software_search_page(:sisp) | |
31 | - results = filter_software_infos_list{|software| software.sisp } | |
32 | + sisp_condition_block = lambda{|software| software.sisp } | |
33 | + | |
34 | + prepare_software_search_page(:sisp, &sisp_condition_block) | |
35 | + results = filter_software_infos_list(&sisp_condition_block) | |
32 | 36 | @software_count = results.count |
33 | 37 | results = results.paginate(:per_page => @per_page, :page => params[:page]) |
34 | 38 | @searches[@asset] = {:results => results} |
... | ... | @@ -58,9 +62,9 @@ class SearchController |
58 | 62 | communities_list |
59 | 63 | end |
60 | 64 | |
61 | - def filter_software_infos_list | |
65 | + def filter_software_infos_list &software_condition_block | |
62 | 66 | filtered_software_list = get_filtered_software_list |
63 | - filtered_community_list = get_communities_list(filtered_software_list){|software| yield(software)} | |
67 | + filtered_community_list = get_communities_list(filtered_software_list, &software_condition_block) | |
64 | 68 | sort_communities_list filtered_community_list |
65 | 69 | end |
66 | 70 | |
... | ... | @@ -101,10 +105,10 @@ class SearchController |
101 | 105 | filtered_software_list |
102 | 106 | end |
103 | 107 | |
104 | - def get_communities_list software_list | |
108 | + def get_communities_list software_list, &software_condition_block | |
105 | 109 | filtered_community_list = [] |
106 | 110 | software_list.each do |software| |
107 | - if yield(software) | |
111 | + if software_condition_block.call(software) | |
108 | 112 | filtered_community_list << software.community unless software.community.nil? |
109 | 113 | end |
110 | 114 | end |
... | ... | @@ -124,10 +128,10 @@ class SearchController |
124 | 128 | communities_list |
125 | 129 | end |
126 | 130 | |
127 | - def prepare_software_search_page title | |
131 | + def prepare_software_search_page title, &software_condition_block | |
128 | 132 | prepare_software_infos_params(title) |
129 | 133 | prepare_software_infos_message |
130 | - prepare_software_infos_category_groups | |
134 | + prepare_software_infos_category_groups(&software_condition_block) | |
131 | 135 | prepare_software_infos_category_enable |
132 | 136 | end |
133 | 137 | |
... | ... | @@ -165,15 +169,16 @@ class SearchController |
165 | 169 | end |
166 | 170 | end |
167 | 171 | |
168 | - def prepare_software_infos_category_groups | |
169 | - @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} | |
172 | + def prepare_software_infos_category_groups &software_condition_block | |
173 | + @categories = Category.software_categories | |
174 | + @categories = @categories.select{|category| category.software_infos.any?{|software| software_condition_block.call(software)}} | |
175 | + @categories.sort!{|a, b| a.name <=> b.name} | |
170 | 176 | end |
171 | 177 | |
172 | 178 | def prepare_software_infos_category_enable |
173 | 179 | @enabled_check_box = Hash.new |
174 | - categories = Category.software_categories | |
175 | 180 | |
176 | - categories.each do |category| | |
181 | + @categories.each do |category| | |
177 | 182 | if category.software_infos.count > 0 |
178 | 183 | @enabled_check_box[category] = :enabled |
179 | 184 | else | ... | ... |
src/noosfero-spb/software_communities/views/search/_catalog_result_list.html.erb
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | <div id="individually-category"> |
40 | 40 | <% @selected_categories.each do |category| %> |
41 | 41 | <br /> |
42 | - <%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => :software_infos, :selected_categories_id => [category.id]} %> | |
42 | + <%= link_to _("#{category.name}") + " (#{category.software_infos.count})", {:controller => :search, :action => params[:action], :selected_categories_id => [category.id]} %> | |
43 | 43 | <% end %> |
44 | 44 | </div> |
45 | 45 | ... | ... |