Commit afd37db97d6bc68502c1f0607400838987a0a58f
Committed by
Gabriela Navarro
1 parent
18427e7c
Exists in
master
and in
5 other branches
Update search software dynamically by selecting a category
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
5 changed files
with
53 additions
and
65 deletions
Show diff stats
lib/ext/search_controller.rb
| ... | ... | @@ -22,11 +22,12 @@ class SearchController |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | def software_infos |
| 25 | - prepare_search_page | |
| 25 | + prepare_software_search_page | |
| 26 | 26 | results = filter_software_infos_list |
| 27 | 27 | results = results.paginate(:per_page => 24, :page => params[:page]) |
| 28 | 28 | @searches[@asset] = {:results => results} |
| 29 | 29 | @search = results |
| 30 | + render :layout=>false if request.xhr? | |
| 30 | 31 | end |
| 31 | 32 | |
| 32 | 33 | def filter_communities_list |
| ... | ... | @@ -53,7 +54,7 @@ class SearchController |
| 53 | 54 | |
| 54 | 55 | category_ids = [] |
| 55 | 56 | unless params[:selected_categories].blank? |
| 56 | - category_ids = params[:selected_categories].values | |
| 57 | + category_ids = params[:selected_categories] | |
| 57 | 58 | end |
| 58 | 59 | category_ids = category_ids.map(&:to_i) |
| 59 | 60 | |
| ... | ... | @@ -72,47 +73,30 @@ class SearchController |
| 72 | 73 | filtered_community_list |
| 73 | 74 | end |
| 74 | 75 | |
| 75 | - def get_search_result | |
| 76 | - redirect_to "/" unless request.xhr? | |
| 77 | - | |
| 78 | - selected_categories = {} | |
| 79 | - params[:categories_ids].each do |id| | |
| 80 | - selected_categories[Category.find(id).name] = id | |
| 81 | - end | |
| 82 | - params[:selected_categories] = selected_categories | |
| 83 | - | |
| 84 | - prepare_search_page | |
| 85 | - | |
| 86 | - results = filter_software_infos_list | |
| 87 | - results = results.paginate(:per_page => 24, :page => params[:page]) | |
| 88 | - | |
| 89 | - @searches[@asset] = {:results => results} | |
| 90 | - @search = results | |
| 91 | - render "/software_infos", :layout=>false | |
| 92 | - end | |
| 93 | - | |
| 94 | 76 | protected |
| 95 | 77 | |
| 96 | - def prepare_search_page | |
| 78 | + def prepare_software_search_page | |
| 97 | 79 | @titles[:software_infos] = _("Public Software Catalog") |
| 98 | 80 | @category_filters = [] |
| 99 | 81 | @categories = Category.all |
| 100 | 82 | @selected_categories = params[:selected_categories] |
| 83 | + @selected_categories ||= [] | |
| 84 | + @selected_categories = @selected_categories.map(&:to_i) | |
| 101 | 85 | |
| 102 | - @selected_categories_name = [] | |
| 103 | - @message_selected_options = "Most options" | |
| 104 | - unless @selected_categories.nil? | |
| 86 | + @message_selected_options = "" | |
| 87 | + unless @selected_categories.empty? | |
| 105 | 88 | @message_selected_options = _("Selected options: ") |
| 106 | - @selected_categories.each do |k, v| | |
| 107 | - @message_selected_options << "#{k}; " | |
| 108 | - @selected_categories_name << k | |
| 109 | - end | |
| 89 | + | |
| 90 | + categories = Category.find(@selected_categories) | |
| 91 | + @message_selected_options += categories.collect { |category| | |
| 92 | + "#{category.name}; " | |
| 93 | + }.join() | |
| 110 | 94 | end |
| 111 | 95 | |
| 112 | 96 | @categories.sort!{|a, b| a.name <=> b.name} |
| 113 | 97 | @categories_groupe_one = [] |
| 114 | 98 | @categories_groupe_two = [] |
| 115 | - (0..(@categories.count - 1)).each do |i| | |
| 99 | + @categories.count.times do |i| | |
| 116 | 100 | if i % 2 == 0 |
| 117 | 101 | @categories_groupe_one << @categories[i] |
| 118 | 102 | else | ... | ... |
public/software-catalog.js
| ... | ... | @@ -4,8 +4,8 @@ |
| 4 | 4 | var AJAX_URL = { |
| 5 | 5 | get_categories: |
| 6 | 6 | url_with_subdirectory("/plugin/mpog_software/get_categories"), |
| 7 | - get_search_result: | |
| 8 | - url_with_subdirectory("/search/get_search_result") | |
| 7 | + software_infos: | |
| 8 | + url_with_subdirectory("/search/software_infos") | |
| 9 | 9 | }; |
| 10 | 10 | |
| 11 | 11 | function create_catalog_element(first, value, id) { |
| ... | ... | @@ -90,6 +90,14 @@ |
| 90 | 90 | }); |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | + function selectCheckboxCategory() { | |
| 94 | + $("#filter-categories-option").slideUp(); | |
| 95 | + $("#filter-categories-select-catalog").show(); | |
| 96 | + $("#filter-option-catalog-software").hide(); | |
| 97 | + | |
| 98 | + dispatch_search_ajax(update_search_page_on_ajax); | |
| 99 | + } | |
| 100 | + | |
| 93 | 101 | function dispatch_search_ajax(callback) { |
| 94 | 102 | var query_text = $("#search-input").val(); |
| 95 | 103 | var selected_categories_ids = []; |
| ... | ... | @@ -98,31 +106,27 @@ |
| 98 | 106 | selected_categories_ids.push(element.value); |
| 99 | 107 | }); |
| 100 | 108 | |
| 101 | - | |
| 102 | 109 | $.ajax({ |
| 103 | - url: AJAX_URL.get_search_result, | |
| 110 | + url: AJAX_URL.software_infos, | |
| 104 | 111 | type: "GET", |
| 105 | 112 | data: { |
| 106 | 113 | query: query_text, |
| 107 | - categories_ids: selected_categories_ids | |
| 114 | + selected_categories: selected_categories_ids | |
| 108 | 115 | }, |
| 109 | - success: function(response) { | |
| 110 | - console.log(response); | |
| 111 | - callback(response); | |
| 112 | - } | |
| 116 | + success: callback | |
| 113 | 117 | }); |
| 114 | 118 | } |
| 115 | 119 | |
| 116 | - function update_page_list() { | |
| 117 | - | |
| 118 | - } | |
| 120 | + function update_search_page_on_ajax(response) { | |
| 121 | + var search_list = $("#search-results"); | |
| 122 | + var selected_categories_field = $("#filter-categories-select-catalog"); | |
| 119 | 123 | |
| 120 | - function selectCheckboxCategory() { | |
| 121 | - $("#filter-categories-option").slideUp(); | |
| 122 | - $("#filter-categories-select-catalog").show(); | |
| 123 | - $("#filter-option-catalog-software").hide(); | |
| 124 | + var result_list = $(response).find("#search-results").html(); | |
| 125 | + var result_categories = $(response).find("#filter-categories-select-catalog").html(); | |
| 124 | 126 | |
| 125 | - dispatch_search_ajax(update_page_list); | |
| 127 | + search_list.html(result_list); | |
| 128 | + selected_categories_field.html(result_categories); | |
| 129 | + show_head_message(); | |
| 126 | 130 | } |
| 127 | 131 | |
| 128 | 132 | function selectProjectSoftwareCheckbox() { | ... | ... |
views/search/_catalog_filter.html.erb
| ... | ... | @@ -2,7 +2,7 @@ |
| 2 | 2 | |
| 3 | 3 | <div id="filter-catalog-software"> |
| 4 | 4 | |
| 5 | - <div id="filter-option-catalog-software"> Mais opções </div> | |
| 5 | + <div id="filter-option-catalog-software"><%= _("More options") %></div> | |
| 6 | 6 | <!--Quando tiver filtros(categorias)selecionados mostrar esta opção: Opções selecionadas--> |
| 7 | 7 | |
| 8 | 8 | <div id="filter-categories-select-catalog"> <%= @message_selected_options %> </div> |
| ... | ... | @@ -14,7 +14,7 @@ |
| 14 | 14 | <div id="gruop-catalog-01"> |
| 15 | 15 | <% @categories_groupe_one.each do |category| %> |
| 16 | 16 | <label> |
| 17 | - <%= check_box_tag("selected_categories[#{category.name}]", category.id, @selected_categories_name.include?(category.name), :class => "categories-catalog") %> | |
| 17 | + <%= check_box_tag("selected_categories[]", category.id, @selected_categories.include?(category.id), :class => "categories-catalog") %> | |
| 18 | 18 | <span><%= _("#{category.name}") %></span> |
| 19 | 19 | </label> <br> |
| 20 | 20 | <% end %> |
| ... | ... | @@ -22,7 +22,7 @@ |
| 22 | 22 | <div id="group-catalog-02"> |
| 23 | 23 | <% @categories_groupe_two.each do |category| %> |
| 24 | 24 | <label> |
| 25 | - <%= check_box_tag("selected_categories[#{category.name}]", category.id, @selected_categories_name.include?(category.name), :class => "categories-catalog") %> | |
| 25 | + <%= check_box_tag("selected_categories[]", category.id, @selected_categories.include?(category.id), :class => "categories-catalog") %> | |
| 26 | 26 | <%= _("#{category.name}") %> |
| 27 | 27 | </label> <br> |
| 28 | 28 | <% end %> | ... | ... |
views/search/_mpog_search_form.html.erb
| ... | ... | @@ -10,8 +10,7 @@ |
| 10 | 10 | |
| 11 | 11 | <div class="search-field"> |
| 12 | 12 | <span class="formfield"> |
| 13 | - <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50 %> | |
| 14 | - <%= javascript_tag "jQuery('#search-input').attr('title', \"#{hint}\").hint()" if defined?(hint) %> | |
| 13 | + <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50, :placeholder=>_("Type words about the software_info you're looking for") %> | |
| 15 | 14 | </span> |
| 16 | 15 | |
| 17 | 16 | <%= submit_button(:search, _('Search'), :class => "button with-text icon-search submit") %> |
| ... | ... | @@ -30,4 +29,3 @@ |
| 30 | 29 | |
| 31 | 30 | <div style="clear: both"></div> |
| 32 | 31 | </div> |
| 33 | -<div> | ... | ... |
views/search/software_infos.html.erb
| 1 | -<%= search_page_title( @titles[@asset], @category ) %> | |
| 1 | +<div id="software-search-container"> | |
| 2 | + <%= search_page_title( @titles[@asset], @category ) %> | |
| 2 | 3 | |
| 3 | -<%= render :partial => 'mpog_search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> | |
| 4 | + <%= render :partial => 'mpog_search_form', :locals => { :hint => _("Type words about the %s you're looking for") % @asset.to_s.singularize } %> | |
| 4 | 5 | |
| 5 | -<%= render :partial => 'results_header' %> | |
| 6 | + <%= render :partial => 'results_header' %> | |
| 6 | 7 | |
| 7 | -<%= display_results(@searches, @asset) %> | |
| 8 | -<% if params[:display] != 'map' %> | |
| 9 | - <%= pagination_links @searches[@asset][:results] %> | |
| 10 | -<% end %> | |
| 8 | + <%= display_results(@searches, @asset) %> | |
| 9 | + <% if params[:display] != 'map' %> | |
| 10 | + <%= pagination_links @searches[@asset][:results] %> | |
| 11 | + <% end %> | |
| 11 | 12 | |
| 12 | -<div style="clear: both"></div> | |
| 13 | + <div style="clear: both"></div> | |
| 13 | 14 | |
| 14 | -<% if @asset == :product %> | |
| 15 | - <%= javascript_tag do %> | |
| 16 | - jQuery('.search-product-price-details').altBeautify(); | |
| 15 | + <% if @asset == :product %> | |
| 16 | + <%= javascript_tag do %> | |
| 17 | + jQuery('.search-product-price-details').altBeautify(); | |
| 18 | + <% end %> | |
| 17 | 19 | <% end %> |
| 18 | -<% end %> | |
| 20 | +</div> | |
| 19 | 21 | \ No newline at end of file | ... | ... |