Commit f4094fd29aef5df95492efd861a233411bc9515a
1 parent
12a26bee
Exists in
temp_soft_comm_refactoring
Remove wrong methods from search_controller extansion
Showing
3 changed files
with
34 additions
and
79 deletions
Show diff stats
src/noosfero-spb/software_communities/lib/ext/search_controller.rb
| ... | ... | @@ -2,66 +2,11 @@ require_dependency 'search_controller' |
| 2 | 2 | |
| 3 | 3 | class SearchController |
| 4 | 4 | |
| 5 | - # def communities | |
| 6 | - # delete_communities = [] | |
| 7 | - # valid_communities_string = Community.get_valid_communities_string | |
| 8 | - # Community.all.each{|community| delete_communities << community.id unless eval(valid_communities_string)} | |
| 9 | - | |
| 10 | - # @scope = visible_profiles(Community) | |
| 11 | - # @scope = @scope.where(["id NOT IN (?)", delete_communities]) unless delete_communities.empty? | |
| 12 | - | |
| 13 | - # full_text_search | |
| 14 | - # end | |
| 15 | - | |
| 16 | - # def software_infos | |
| 17 | - # prepare_software_search_page | |
| 18 | - # results = filter_software_infos_list | |
| 19 | - # @software_count = results.count | |
| 20 | - # results = results.paginate(:per_page => @per_page, :page => params[:page]) | |
| 21 | - # @searches[@asset] = {:results => results} | |
| 22 | - # @search = results | |
| 23 | - | |
| 24 | - # render :layout=>false if request.xhr? | |
| 25 | - # end | |
| 26 | - | |
| 27 | 5 | protected |
| 28 | 6 | |
| 29 | - def filter_communities_list | |
| 30 | - unfiltered_list = visible_profiles(Community) | |
| 31 | - | |
| 32 | - unless params[:query].nil? | |
| 33 | - unfiltered_list = unfiltered_list.select do |com| | |
| 34 | - com.name.downcase =~ /#{params[:query].downcase}/ | |
| 35 | - end | |
| 36 | - end | |
| 37 | - | |
| 38 | - communities_list = [] | |
| 39 | - unfiltered_list.each do |profile| | |
| 40 | - if profile.class == Community && !profile.is_template? && yield(profile) | |
| 41 | - communities_list << profile | |
| 42 | - end | |
| 43 | - end | |
| 44 | - | |
| 45 | - communities_list | |
| 46 | - end | |
| 47 | - | |
| 48 | - # def filter_software_infos_list | |
| 49 | - # filtered_software_list = get_community_ids_from_filtered_software | |
| 50 | - # filtered_community_list = get_communities_list(filtered_software_list) | |
| 51 | - # sort_communities_list filtered_community_list | |
| 52 | - # end | |
| 53 | - | |
| 54 | - def get_filter_category_ids | |
| 55 | - category_ids = [] | |
| 56 | - unless params[:selected_categories_id].blank? | |
| 57 | - category_ids = params[:selected_categories_id] | |
| 58 | - end | |
| 59 | - category_ids.map(&:to_i) | |
| 60 | - end | |
| 61 | - | |
| 62 | 7 | # def sort_communities_list communities_list |
| 63 | 8 | # communities_list.sort! {|a, b| a.name.downcase <=> b.name.downcase} |
| 64 | - | |
| 9 | + # | |
| 65 | 10 | # if params[:sort] && params[:sort] == "desc" |
| 66 | 11 | # communities_list.reverse! |
| 67 | 12 | # elsif params[:sort] && params[:sort] == "relevance" | ... | ... |
src/noosfero-spb/software_communities/lib/software_communities_plugin.rb
| ... | ... | @@ -141,14 +141,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
| 141 | 141 | @scope = visible_profiles(Community) |
| 142 | 142 | @asset = class_name_underscored |
| 143 | 143 | @assets = [@asset] |
| 144 | - @titles[class_name_underscored] = _("Result Search") | |
| 145 | - @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} | |
| 146 | - @selected_categories_id = params[:selected_categories_id] | |
| 147 | - @selected_categories_id ||= [] | |
| 148 | - @selected_categories_id = @selected_categories_id.map(&:to_i) | |
| 149 | - @all_selected = params[:software_type] == "all" | |
| 150 | - @public_software_selected = !@all_selected | |
| 151 | - @per_page = prepare_per_page | |
| 152 | 144 | params[:limit] = 24 |
| 153 | 145 | end |
| 154 | 146 | |
| ... | ... | @@ -161,7 +153,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
| 161 | 153 | scope = Community.where(:id => community_ids) |
| 162 | 154 | end |
| 163 | 155 | |
| 164 | - scope.order(:name) | |
| 165 | 156 | # scope = scope.like_search(query, options) unless query.blank? |
| 166 | 157 | # scope = scope.send(options[:filter]) unless options[:filter].blank? |
| 167 | 158 | {:results => scope.paginate(paginate_options)} |
| ... | ... | @@ -169,19 +160,44 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
| 169 | 160 | |
| 170 | 161 | protected |
| 171 | 162 | |
| 172 | - def get_community_ids_from_filtered_software(query) | |
| 173 | - filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.search_by_query(query) | |
| 163 | + def get_community_ids_from_filtered_software query | |
| 164 | + software_list = SoftwareCommunitiesPlugin::SoftwareInfo.search_by_query(query) | |
| 174 | 165 | |
| 166 | + software_list = filter_only_specific_softwares(software_list) | |
| 167 | + | |
| 168 | + software_list = filter_softwares_by_categories(software_list) | |
| 169 | + | |
| 170 | + community_ids = [] | |
| 171 | + | |
| 172 | + software_list.each do |software| | |
| 173 | + community_ids << software.community_id | |
| 174 | + end | |
| 175 | + | |
| 176 | + community_ids | |
| 177 | + end | |
| 178 | + | |
| 179 | + def filter_only_specific_softwares software_list | |
| 180 | + # TODO: refatorar isso para um scope | |
| 175 | 181 | if context.params[:only_softwares] |
| 176 | 182 | context.params[:only_softwares].collect!{ |software_name| software_name.to_slug } |
| 177 | - filtered_software_list = SoftwareCommunitiesPlugin::SoftwareInfo.all.select{ |s| context.params[:only_softwares].include?(s.identifier) } | |
| 178 | - @public_software_selected = false | |
| 183 | + software_list = SoftwareCommunitiesPlugin::SoftwareInfo.all.select{ |s| context.params[:only_softwares].include?(s.identifier) } | |
| 184 | + context.public_software_selected = false | |
| 179 | 185 | end |
| 180 | 186 | |
| 181 | - category_ids = get_filter_category_ids | |
| 187 | + software_list | |
| 188 | + end | |
| 189 | + | |
| 190 | + def filter_softwares_by_categories software_list | |
| 191 | + # TODO: refatorar isso para um scope | |
| 192 | + category_ids = [] | |
| 193 | + unless context.params[:selected_categories_id].blank? | |
| 194 | + category_ids = context.params[:selected_categories_id] | |
| 195 | + end | |
| 196 | + | |
| 197 | + category_ids = category_ids.map(&:to_i) | |
| 182 | 198 | |
| 183 | 199 | unless category_ids.empty? |
| 184 | - filtered_software_list.select! do |software| | |
| 200 | + software_list.select! do |software| | |
| 185 | 201 | if software.nil? || software.community.nil? |
| 186 | 202 | false |
| 187 | 203 | else |
| ... | ... | @@ -191,13 +207,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin |
| 191 | 207 | end |
| 192 | 208 | end |
| 193 | 209 | |
| 194 | - community_ids = [] | |
| 195 | - | |
| 196 | - filtered_software_list.each do |software| | |
| 197 | - community_ids << software.community_id | |
| 198 | - end | |
| 199 | - | |
| 200 | - community_ids | |
| 210 | + software_list | |
| 201 | 211 | end |
| 202 | 212 | |
| 203 | 213 | def sort_communities_list communities_list | ... | ... |
src/noosfero-spb/software_communities/models/software_communities_plugin/softwares_block.rb
| ... | ... | @@ -35,7 +35,7 @@ class SoftwareCommunitiesPlugin::SoftwaresBlock < CommunitiesBlock |
| 35 | 35 | when Environment |
| 36 | 36 | lambda do |context| |
| 37 | 37 | link_to s_('softwares|View all'), :controller => 'search', |
| 38 | - :action => 'software_infos' | |
| 38 | + :action => 'softwares' | |
| 39 | 39 | end |
| 40 | 40 | else |
| 41 | 41 | '' | ... | ... |