Commit 845ef63655944b8dee3c892199c8982b6bb59e68
Committed by
Gabriela Navarro
1 parent
18e4c60b
Exists in
master
and in
5 other branches
Refactory software_infos search controller
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
1 changed file
with
52 additions
and
31 deletions
Show diff stats
lib/ext/search_controller.rb
| ... | ... | @@ -13,7 +13,6 @@ class SearchController |
| 13 | 13 | |
| 14 | 14 | def institutions |
| 15 | 15 | @titles[:institutions] = _("Institution Catalog") |
| 16 | - @category_filters = [] | |
| 17 | 16 | results = filter_communities_list{|community| community.institution?} |
| 18 | 17 | results = results.paginate(:per_page => 24, :page => params[:page]) |
| 19 | 18 | @searches[@asset] = {:results => results} |
| ... | ... | @@ -50,13 +49,25 @@ class SearchController |
| 50 | 49 | end |
| 51 | 50 | |
| 52 | 51 | def filter_software_infos_list |
| 53 | - filtered_software_list = SoftwareInfo.like_search(params[:query]) | |
| 52 | + filtered_software_list = get_filtered_software_list | |
| 53 | + filtered_community_list = get_communities_list(filtered_software_list) | |
| 54 | + sort_communities_list filtered_community_list | |
| 55 | + end | |
| 56 | + | |
| 57 | + protected | |
| 54 | 58 | |
| 59 | + def get_filter_category_ids | |
| 55 | 60 | category_ids = [] |
| 56 | 61 | unless params[:selected_categories].blank? |
| 57 | 62 | category_ids = params[:selected_categories] |
| 58 | 63 | end |
| 59 | - category_ids = category_ids.map(&:to_i) | |
| 64 | + category_ids.map(&:to_i) | |
| 65 | + end | |
| 66 | + | |
| 67 | + def get_filtered_software_list | |
| 68 | + filtered_software_list = SoftwareInfo.like_search(params[:query]) | |
| 69 | + | |
| 70 | + category_ids = get_filter_category_ids | |
| 60 | 71 | |
| 61 | 72 | unless category_ids.empty? |
| 62 | 73 | filtered_software_list.select! do |software| |
| ... | ... | @@ -65,32 +76,53 @@ class SearchController |
| 65 | 76 | end |
| 66 | 77 | end |
| 67 | 78 | |
| 79 | + filtered_software_list | |
| 80 | + end | |
| 81 | + | |
| 82 | + def get_communities_list software_list | |
| 68 | 83 | filtered_community_list = [] |
| 69 | - filtered_software_list.each do |software| | |
| 84 | + software_list.each do |software| | |
| 70 | 85 | if @include_non_public || software.public_software? |
| 71 | 86 | filtered_community_list << software.community |
| 72 | 87 | end |
| 73 | - end | |
| 74 | - | |
| 75 | - filtered_community_list.sort!{|a, b| a.name <=> b.name} | |
| 76 | - if params[:sort] && params[:sort] == "desc" | |
| 77 | - filtered_community_list.reverse! | |
| 78 | 88 | end |
| 79 | - | |
| 80 | 89 | filtered_community_list |
| 81 | 90 | end |
| 82 | 91 | |
| 83 | - protected | |
| 92 | + def sort_communities_list communities_list | |
| 93 | + communities_list.sort!{|a, b| a.name <=> b.name} | |
| 94 | + if params[:sort] && params[:sort] == "desc" | |
| 95 | + communities_list.reverse! | |
| 96 | + end | |
| 97 | + communities_list | |
| 98 | + end | |
| 84 | 99 | |
| 85 | 100 | def prepare_software_search_page |
| 101 | + prepare_software_infos_params | |
| 102 | + prepare_software_infos_message | |
| 103 | + prepare_software_infos_category_groups | |
| 104 | + end | |
| 105 | + | |
| 106 | + def prepare_software_infos_params | |
| 86 | 107 | @titles[:software_infos] = _("Public Software Catalog") |
| 87 | - @category_filters = [] | |
| 88 | - @categories = Category.software_categories | |
| 89 | 108 | @selected_categories = params[:selected_categories] |
| 90 | 109 | @selected_categories ||= [] |
| 91 | 110 | @selected_categories = @selected_categories.map(&:to_i) |
| 92 | 111 | @include_non_public = params[:include_non_public] == "true" |
| 112 | + @per_page = prepare_per_page | |
| 113 | + end | |
| 114 | + | |
| 115 | + def prepare_per_page | |
| 116 | + return 15 if params[:software_display].nil? | |
| 93 | 117 | |
| 118 | + if params[:software_display] == "all" | |
| 119 | + SoftwareInfo.count | |
| 120 | + else | |
| 121 | + params[:software_display].to_i | |
| 122 | + end | |
| 123 | + end | |
| 124 | + | |
| 125 | + def prepare_software_infos_message | |
| 94 | 126 | @message_selected_options = "" |
| 95 | 127 | unless @selected_categories.empty? |
| 96 | 128 | @message_selected_options = _("Selected options: ") |
| ... | ... | @@ -100,25 +132,14 @@ class SearchController |
| 100 | 132 | "#{category.name}; " |
| 101 | 133 | }.join() |
| 102 | 134 | end |
| 135 | + end | |
| 103 | 136 | |
| 104 | - @categories.sort!{|a, b| a.name <=> b.name} | |
| 105 | - @categories_groupe_one = [] | |
| 106 | - @categories_groupe_two = [] | |
| 107 | - @categories.count.times do |i| | |
| 108 | - if i % 2 == 0 | |
| 109 | - @categories_groupe_one << @categories[i] | |
| 110 | - else | |
| 111 | - @categories_groupe_two << @categories[i] | |
| 112 | - end | |
| 113 | - end | |
| 137 | + def prepare_software_infos_category_groups | |
| 138 | + @categories = Category.software_categories.sort{|a, b| a.name <=> b.name} | |
| 114 | 139 | |
| 115 | - @per_page = 15 | |
| 116 | - if params[:software_display] | |
| 117 | - if params[:software_display] == "all" | |
| 118 | - @per_page = SoftwareInfo.count | |
| 119 | - else | |
| 120 | - @per_page = params[:software_display].to_i | |
| 121 | - end | |
| 122 | - end | |
| 140 | + categories_sliced = @categories.each_slice(@categories.count/2) | |
| 141 | + | |
| 142 | + @categories_groupe_one = categories_sliced.next | |
| 143 | + @categories_groupe_two = categories_sliced.next | |
| 123 | 144 | end |
| 124 | 145 | end | ... | ... |