Commit 845ef63655944b8dee3c892199c8982b6bb59e68

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent 18e4c60b
Exists in master and in 79 other branches add_sisp_to_chef, add_super_archives_plugin, api_for_colab, automates_core_packing, backup_not_prod, changes_in_buttons_on_content_panel, colab_automated_login, colab_spb_plugin_recipe, colab_widgets_settings, design_validation, dev_env_minimal, disable_email_dev, fix_breadcrumbs_position, fix_categories_software_link, fix_edit_institution, fix_edit_software_with_another_license, fix_get_license_info, fix_gitlab_assets_permission, fix_list_style_inside_article, fix_list_style_on_folder_elements, fix_members_pagination, fix_merge_request_url, fix_models_translations, fix_no_license, fix_software_api, fix_software_block_migration, fix_software_communities_translations, fix_software_communities_unit_test, fix_style_create_institution_admin_panel, fix_superarchives_imports, fix_sym_links_noosfero, focus_search_field_theme, gov-user-refactoring, gov-user-refactoring-rails4, header_fix, institution_modal_on_rating, kalibro-conf-refactoring, kalibro-processor-package, lxc_settings, margin_fix, mezuro_cookbook, prezento, refactor_download_block, refactor_software_communities, refactor_software_for_sisp, register_page, release-process, release-process-v2, remove-unused-images, remove_broken_theme, remove_secondary_email_from_user, remove_sisp_buttons, removing_super_archives_email, review_message, scope2method, signals_user_noosfero, sisp_catalog_header, sisp_colab_config, sisp_dev, sisp_dev_master, sisp_simple_version, software_as_organization, software_catalog_style_fix, software_communities_html_refactor, software_infos_api, spb_minimal_env, spb_to_rails4, spec_refactor, stable-4.1, stable-4.2, stable-4.x, temp_soft_comm_refactoring, theme_header, theme_javascript_refactory, thread_dropdown, thread_page, update_search_by_categories, update_software_api, update_softwares_boxes

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
... ...