Commit 43afd69f3ae5082b23e96df218569b93283a459e
1 parent
fed2d986
Exists in
master
and in
5 other branches
Refactor extended SearchController
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
1 changed file
with
14 additions
and
23 deletions
Show diff stats
lib/ext/search_controller.rb
| @@ -3,20 +3,7 @@ require_dependency 'search_controller' | @@ -3,20 +3,7 @@ require_dependency 'search_controller' | ||
| 3 | class SearchController | 3 | class SearchController |
| 4 | 4 | ||
| 5 | def communities | 5 | def communities |
| 6 | - unfiltered_list = visible_profiles(Community) | ||
| 7 | - unless params[:query].nil? | ||
| 8 | - unfiltered_list = unfiltered_list.select do |com| | ||
| 9 | - com.name.downcase =~ /#{params[:query].downcase}/ | ||
| 10 | - end | ||
| 11 | - end | ||
| 12 | - | ||
| 13 | - list_without_software_and_institution = [] | ||
| 14 | - unfiltered_list.each do |p| | ||
| 15 | - if p.class == Community and !p.software? and !p.institution? | ||
| 16 | - list_without_software_and_institution << p | ||
| 17 | - end | ||
| 18 | - end | ||
| 19 | - results = list_without_software_and_institution | 6 | + results = filter_communities_list{|community| !community.software? and !community.institution?} |
| 20 | results = results.paginate(:per_page => 24, :page => params[:page]) | 7 | results = results.paginate(:per_page => 24, :page => params[:page]) |
| 21 | @searches[@asset] = {:results => results} | 8 | @searches[@asset] = {:results => results} |
| 22 | @search = results | 9 | @search = results |
| @@ -24,22 +11,26 @@ class SearchController | @@ -24,22 +11,26 @@ class SearchController | ||
| 24 | 11 | ||
| 25 | def software_infos | 12 | def software_infos |
| 26 | @titles[:software_infos] = "Software Infos" | 13 | @titles[:software_infos] = "Software Infos" |
| 14 | + | ||
| 15 | + results = filter_communities_list{|community| community.software?} | ||
| 16 | + results = results.paginate(:per_page => 24, :page => params[:page]) | ||
| 17 | + @searches[@asset] = {:results => results} | ||
| 18 | + @search = results | ||
| 19 | + end | ||
| 20 | + | ||
| 21 | + def filter_communities_list | ||
| 27 | unfiltered_list = visible_profiles(Community) | 22 | unfiltered_list = visible_profiles(Community) |
| 28 | unless params[:query].nil? | 23 | unless params[:query].nil? |
| 29 | unfiltered_list = unfiltered_list.select do |com| | 24 | unfiltered_list = unfiltered_list.select do |com| |
| 30 | com.name.downcase =~ /#{params[:query].downcase}/ | 25 | com.name.downcase =~ /#{params[:query].downcase}/ |
| 31 | end | 26 | end |
| 32 | end | 27 | end |
| 33 | - | ||
| 34 | - list_community_of_software = [] | ||
| 35 | - unfiltered_list.each do |p| | ||
| 36 | - if p.class == Community and p.software? | ||
| 37 | - list_community_of_software << p | 28 | + communities_list = [] |
| 29 | + unfiltered_list.each do |profile| | ||
| 30 | + if profile.class == Community and yield(profile) | ||
| 31 | + communities_list << profile | ||
| 38 | end | 32 | end |
| 39 | end | 33 | end |
| 40 | - results = list_community_of_software | ||
| 41 | - results = results.paginate(:per_page => 24, :page => params[:page]) | ||
| 42 | - @searches[@asset] = {:results => results} | ||
| 43 | - @search = results | 34 | + communities_list |
| 44 | end | 35 | end |
| 45 | end | 36 | end |
| 46 | \ No newline at end of file | 37 | \ No newline at end of file |