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,66 +2,11 @@ require_dependency 'search_controller' | ||
2 | 2 | ||
3 | class SearchController | 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 | protected | 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 | # def sort_communities_list communities_list | 7 | # def sort_communities_list communities_list |
63 | # communities_list.sort! {|a, b| a.name.downcase <=> b.name.downcase} | 8 | # communities_list.sort! {|a, b| a.name.downcase <=> b.name.downcase} |
64 | - | 9 | + # |
65 | # if params[:sort] && params[:sort] == "desc" | 10 | # if params[:sort] && params[:sort] == "desc" |
66 | # communities_list.reverse! | 11 | # communities_list.reverse! |
67 | # elsif params[:sort] && params[:sort] == "relevance" | 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,14 +141,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
141 | @scope = visible_profiles(Community) | 141 | @scope = visible_profiles(Community) |
142 | @asset = class_name_underscored | 142 | @asset = class_name_underscored |
143 | @assets = [@asset] | 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 | params[:limit] = 24 | 144 | params[:limit] = 24 |
153 | end | 145 | end |
154 | 146 | ||
@@ -161,7 +153,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -161,7 +153,6 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
161 | scope = Community.where(:id => community_ids) | 153 | scope = Community.where(:id => community_ids) |
162 | end | 154 | end |
163 | 155 | ||
164 | - scope.order(:name) | ||
165 | # scope = scope.like_search(query, options) unless query.blank? | 156 | # scope = scope.like_search(query, options) unless query.blank? |
166 | # scope = scope.send(options[:filter]) unless options[:filter].blank? | 157 | # scope = scope.send(options[:filter]) unless options[:filter].blank? |
167 | {:results => scope.paginate(paginate_options)} | 158 | {:results => scope.paginate(paginate_options)} |
@@ -169,19 +160,44 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -169,19 +160,44 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
169 | 160 | ||
170 | protected | 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 | if context.params[:only_softwares] | 181 | if context.params[:only_softwares] |
176 | context.params[:only_softwares].collect!{ |software_name| software_name.to_slug } | 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 | end | 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 | unless category_ids.empty? | 199 | unless category_ids.empty? |
184 | - filtered_software_list.select! do |software| | 200 | + software_list.select! do |software| |
185 | if software.nil? || software.community.nil? | 201 | if software.nil? || software.community.nil? |
186 | false | 202 | false |
187 | else | 203 | else |
@@ -191,13 +207,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | @@ -191,13 +207,7 @@ class SoftwareCommunitiesPlugin < Noosfero::Plugin | ||
191 | end | 207 | end |
192 | end | 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 | end | 211 | end |
202 | 212 | ||
203 | def sort_communities_list communities_list | 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,7 +35,7 @@ class SoftwareCommunitiesPlugin::SoftwaresBlock < CommunitiesBlock | ||
35 | when Environment | 35 | when Environment |
36 | lambda do |context| | 36 | lambda do |context| |
37 | link_to s_('softwares|View all'), :controller => 'search', | 37 | link_to s_('softwares|View all'), :controller => 'search', |
38 | - :action => 'software_infos' | 38 | + :action => 'softwares' |
39 | end | 39 | end |
40 | else | 40 | else |
41 | '' | 41 | '' |