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,8 +28,7 @@ class Category | ||
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | def software_infos | 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 | software_list | 32 | software_list |
| 34 | end | 33 | end |
| 35 | end | 34 | end |
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
| @@ -14,10 +14,12 @@ class SearchController | @@ -14,10 +14,12 @@ class SearchController | ||
| 14 | end | 14 | end |
| 15 | 15 | ||
| 16 | def software_infos | 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 | (!@public_software_selected || software.public_software?) && (!software.sisp) | 18 | (!@public_software_selected || software.public_software?) && (!software.sisp) |
| 20 | end | 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 | @software_count = results.count | 23 | @software_count = results.count |
| 22 | results = results.paginate(:per_page => @per_page, :page => params[:page]) | 24 | results = results.paginate(:per_page => @per_page, :page => params[:page]) |
| 23 | @searches[@asset] = {:results => results} | 25 | @searches[@asset] = {:results => results} |
| @@ -27,8 +29,10 @@ class SearchController | @@ -27,8 +29,10 @@ class SearchController | ||
| 27 | end | 29 | end |
| 28 | 30 | ||
| 29 | def sisp | 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 | @software_count = results.count | 36 | @software_count = results.count |
| 33 | results = results.paginate(:per_page => @per_page, :page => params[:page]) | 37 | results = results.paginate(:per_page => @per_page, :page => params[:page]) |
| 34 | @searches[@asset] = {:results => results} | 38 | @searches[@asset] = {:results => results} |
| @@ -58,9 +62,9 @@ class SearchController | @@ -58,9 +62,9 @@ class SearchController | ||
| 58 | communities_list | 62 | communities_list |
| 59 | end | 63 | end |
| 60 | 64 | ||
| 61 | - def filter_software_infos_list | 65 | + def filter_software_infos_list &software_condition_block |
| 62 | filtered_software_list = get_filtered_software_list | 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 | sort_communities_list filtered_community_list | 68 | sort_communities_list filtered_community_list |
| 65 | end | 69 | end |
| 66 | 70 | ||
| @@ -101,10 +105,10 @@ class SearchController | @@ -101,10 +105,10 @@ class SearchController | ||
| 101 | filtered_software_list | 105 | filtered_software_list |
| 102 | end | 106 | end |
| 103 | 107 | ||
| 104 | - def get_communities_list software_list | 108 | + def get_communities_list software_list, &software_condition_block |
| 105 | filtered_community_list = [] | 109 | filtered_community_list = [] |
| 106 | software_list.each do |software| | 110 | software_list.each do |software| |
| 107 | - if yield(software) | 111 | + if software_condition_block.call(software) |
| 108 | filtered_community_list << software.community unless software.community.nil? | 112 | filtered_community_list << software.community unless software.community.nil? |
| 109 | end | 113 | end |
| 110 | end | 114 | end |
| @@ -124,10 +128,10 @@ class SearchController | @@ -124,10 +128,10 @@ class SearchController | ||
| 124 | communities_list | 128 | communities_list |
| 125 | end | 129 | end |
| 126 | 130 | ||
| 127 | - def prepare_software_search_page title | 131 | + def prepare_software_search_page title, &software_condition_block |
| 128 | prepare_software_infos_params(title) | 132 | prepare_software_infos_params(title) |
| 129 | prepare_software_infos_message | 133 | prepare_software_infos_message |
| 130 | - prepare_software_infos_category_groups | 134 | + prepare_software_infos_category_groups(&software_condition_block) |
| 131 | prepare_software_infos_category_enable | 135 | prepare_software_infos_category_enable |
| 132 | end | 136 | end |
| 133 | 137 | ||
| @@ -165,15 +169,16 @@ class SearchController | @@ -165,15 +169,16 @@ class SearchController | ||
| 165 | end | 169 | end |
| 166 | end | 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 | end | 176 | end |
| 171 | 177 | ||
| 172 | def prepare_software_infos_category_enable | 178 | def prepare_software_infos_category_enable |
| 173 | @enabled_check_box = Hash.new | 179 | @enabled_check_box = Hash.new |
| 174 | - categories = Category.software_categories | ||
| 175 | 180 | ||
| 176 | - categories.each do |category| | 181 | + @categories.each do |category| |
| 177 | if category.software_infos.count > 0 | 182 | if category.software_infos.count > 0 |
| 178 | @enabled_check_box[category] = :enabled | 183 | @enabled_check_box[category] = :enabled |
| 179 | else | 184 | else |
src/noosfero-spb/software_communities/views/search/_catalog_result_list.html.erb
| @@ -39,7 +39,7 @@ | @@ -39,7 +39,7 @@ | ||
| 39 | <div id="individually-category"> | 39 | <div id="individually-category"> |
| 40 | <% @selected_categories.each do |category| %> | 40 | <% @selected_categories.each do |category| %> |
| 41 | <br /> | 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 | <% end %> | 43 | <% end %> |
| 44 | </div> | 44 | </div> |
| 45 | 45 |