Commit f6d72f7e2c3285a10a72095f8ec0cd350e83341d

Authored by Fabio Teixeira
Committed by Gabriela Navarro
1 parent b2ff44d1

Add sort and display in software's filter ajax

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
lib/ext/search_controller.rb
@@ -24,7 +24,7 @@ class SearchController @@ -24,7 +24,7 @@ class SearchController
24 def software_infos 24 def software_infos
25 prepare_software_search_page 25 prepare_software_search_page
26 results = filter_software_infos_list 26 results = filter_software_infos_list
27 - results = results.paginate(:per_page => 24, :page => params[:page]) 27 + results = results.paginate(:per_page => @per_page, :page => params[:page])
28 @searches[@asset] = {:results => results} 28 @searches[@asset] = {:results => results}
29 @search = results 29 @search = results
30 render :layout=>false if request.xhr? 30 render :layout=>false if request.xhr?
@@ -70,6 +70,11 @@ class SearchController @@ -70,6 +70,11 @@ class SearchController
70 filtered_community_list << software.community 70 filtered_community_list << software.community
71 end 71 end
72 72
  73 + filtered_community_list.sort!{|a, b| a.name <=> b.name}
  74 + if params[:sort] && params[:sort] == "desc"
  75 + filtered_community_list.reverse!
  76 + end
  77 +
73 filtered_community_list 78 filtered_community_list
74 end 79 end
75 80
@@ -103,5 +108,14 @@ class SearchController @@ -103,5 +108,14 @@ class SearchController
103 @categories_groupe_two << @categories[i] 108 @categories_groupe_two << @categories[i]
104 end 109 end
105 end 110 end
  111 +
  112 + @per_page = 15
  113 + if params[:software_display]
  114 + if params[:software_display] == "all"
  115 + @per_page = SoftwareInfo.count
  116 + else
  117 + @per_page = params[:software_display].to_i
  118 + end
  119 + end
106 end 120 end
107 end 121 end
public/software-catalog.js
@@ -57,22 +57,16 @@ @@ -57,22 +57,16 @@
57 57
58 58
59 function dispatch_search_ajax(callback) { 59 function dispatch_search_ajax(callback) {
60 - var query_text = $("#search-input").val();  
61 - var selected_categories_ids = []; 60 + var search_params = get_search_params();
62 61
63 - $(".categories-catalog:checked").each(function(index, element) {  
64 - selected_categories_ids.push(element.value);  
65 - }); 62 + console.log(search_params);
66 63
67 open_loading("Loading"); 64 open_loading("Loading");
68 65
69 $.ajax({ 66 $.ajax({
70 url: AJAX_URL.software_infos, 67 url: AJAX_URL.software_infos,
71 type: "GET", 68 type: "GET",
72 - data: {  
73 - query: query_text,  
74 - selected_categories: selected_categories_ids  
75 - }, 69 + data: search_params,
76 success: callback, 70 success: callback,
77 error: function(){ 71 error: function(){
78 close_loading(); 72 close_loading();
@@ -81,16 +75,33 @@ @@ -81,16 +75,33 @@
81 } 75 }
82 76
83 77
  78 + function get_search_params() {
  79 + var params = {};
  80 +
  81 + params.query = $("#search-input").val();
  82 + params.selected_categories = [];
  83 +
  84 + $(".categories-catalog:checked").each(function(index, element) {
  85 + params.selected_categories.push(element.value);
  86 + });
  87 +
  88 + params.software_display = $("#software_display").val();
  89 + params.sort = $("#sort").val();
  90 +
  91 + return params;
  92 + }
  93 +
  94 +
84 function update_search_page_on_ajax(response) { 95 function update_search_page_on_ajax(response) {
85 close_loading(); 96 close_loading();
86 response = $(response); 97 response = $(response);
87 var search_list = $("#search-results"); 98 var search_list = $("#search-results");
88 var selected_categories_field = $("#filter-categories-select-catalog"); 99 var selected_categories_field = $("#filter-categories-select-catalog");
89 - var pagination = $(".pagination"); 100 + var pagination = $("#software-pagination");
90 101
91 var result_list = response.find("#search-results").html(); 102 var result_list = response.find("#search-results").html();
92 var result_categories = response.find("#filter-categories-select-catalog").html(); 103 var result_categories = response.find("#filter-categories-select-catalog").html();
93 - var result_pagination = response.find(".pagination").html(); 104 + var result_pagination = response.find("#software-pagination").html();
94 105
95 search_list.html(result_list); 106 search_list.html(result_list);
96 selected_categories_field.html(result_categories); 107 selected_categories_field.html(result_categories);
@@ -103,8 +114,14 @@ @@ -103,8 +114,14 @@
103 $("#filter-categories-option").slideUp(); 114 $("#filter-categories-option").slideUp();
104 $("#filter-categories-select-catalog").show(); 115 $("#filter-categories-select-catalog").show();
105 $("#filter-option-catalog-software").hide(); 116 $("#filter-option-catalog-software").hide();
  117 +
  118 + dispatch_search_ajax(update_search_page_on_ajax);
  119 + show_head_message();
106 } 120 }
107 121
  122 + function update_page_by_ajax_on_select_change() {
  123 + dispatch_search_ajax(update_search_page_on_ajax);
  124 + }
108 125
109 function set_events() { 126 function set_events() {
110 $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog); 127 $("#filter-option-catalog-software").click(slideDowsCategoriesOptionAndHideOptionCatalog);
@@ -113,6 +130,8 @@ @@ -113,6 +130,8 @@
113 $("#cleanup-filter-catalg").click(clearCatalogCheckbox); 130 $("#cleanup-filter-catalg").click(clearCatalogCheckbox);
114 $(".categories-catalog").click(selectCheckboxCategory); 131 $(".categories-catalog").click(selectCheckboxCategory);
115 $(".project-software").click(selectProjectSoftwareCheckbox); 132 $(".project-software").click(selectProjectSoftwareCheckbox);
  133 + $("#software_display").change(update_page_by_ajax_on_select_change);
  134 + $("#sort").change(update_page_by_ajax_on_select_change);
116 } 135 }
117 136
118 137
views/search/_catalog_filter.html.erb
@@ -32,10 +32,9 @@ @@ -32,10 +32,9 @@
32 32
33 <div class="project-software"> <%= _("Software Projects:") %> 33 <div class="project-software"> <%= _("Software Projects:") %>
34 <label><input type="checkbox" name="filter" value="Incluir nos resultados"> <%= _("Include in results") %> </label> 34 <label><input type="checkbox" name="filter" value="Incluir nos resultados"> <%= _("Include in results") %> </label>
35 - <span class"doubts-catalog-software" title="Incluir projetos de software em desenvolvimento que ainda não são oficialmente Software Público Brasileiro.">(?)</span>  
36 - <!--<p><acronym title="Incluir projetos de software em desenvolvimento que ainda não são oficialmente Software Público Brasileiro.">(?)  
37 - </acronym></p>-->  
38 - </div><br> 35 + <span class"doubts-catalog-software" title="<%= _('Include software development projects that are not yet officially Brazilian Public Software.') %>">(?)</span>
  36 + </div>
  37 + <br />
39 <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %> 38 <%= button_tag _("Clean up"), :id => "cleanup-filter-catalg", :type => "button" %>
40 <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %> 39 <%= button_tag _("Close"), :id => "close-filter-catalog", :type => "button" %>
41 </div> 40 </div>
views/search/_mpog_search_form.html.erb
1 <div class='search-form'> 1 <div class='search-form'>
2 -  
3 <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) }, 2 <%= form_tag( { :controller => 'search', :action => @asset ? @asset : 'index', :asset => nil, :category_path => ( @category ? @category.path : nil ) },
4 :method => 'get', :class => 'search_form' ) do %> 3 :method => 'get', :class => 'search_form' ) do %>
5 4
@@ -13,11 +12,37 @@ @@ -13,11 +12,37 @@
13 <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50, :placeholder=>_("Type words about the software_info you're looking for") %> 12 <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50, :placeholder=>_("Type words about the software_info you're looking for") %>
14 </span> 13 </span>
15 14
16 - <%= submit_button(:search, _('Search')) %> 15 + <%= submit_button(:search, _('Filter')) %>
17 </div> 16 </div>
18 -  
19 <%= render :partial => 'search_form_extra_fields' %> 17 <%= render :partial => 'search_form_extra_fields' %>
20 <%= render :partial => 'catalog_filter' %> 18 <%= render :partial => 'catalog_filter' %>
  19 +
  20 + <!-- #display-options sera substituido pelo html passado pela equipe de design -->
  21 + <div id="display-options" class="">
  22 + <div>
  23 + <strong><%= SoftwareInfo.count %> Softwares</strong>
  24 + </div>
  25 +
  26 + <div>
  27 + <div>
  28 + Show:
  29 + <%= select_tag("software_display",
  30 + options_for_select(['15', '30', '90', 'All'], :selected=>params[:display])
  31 + ) %>
  32 + </div>
  33 +
  34 + <div>
  35 + Sort by:
  36 + <%= select_tag("sort",
  37 + options_for_select(
  38 + [
  39 + [_("Name A-Z"), 'asc'],
  40 + [_("Name Z-A"), 'desc']
  41 + ], :selected=>params[:sort])
  42 + ) %>
  43 + </div>
  44 + </div>
  45 + </div>
21 <% end %> 46 <% end %>
22 47
23 <% if @empty_query %> 48 <% if @empty_query %>
views/search/software_infos.html.erb
@@ -6,9 +6,12 @@ @@ -6,9 +6,12 @@
6 <%= render :partial => 'results_header' %> 6 <%= render :partial => 'results_header' %>
7 7
8 <%= display_results(@searches, @asset) %> 8 <%= display_results(@searches, @asset) %>
9 - <% if params[:display] != 'map' %>  
10 - <%= pagination_links @searches[@asset][:results] %>  
11 - <% end %> 9 +
  10 + <div id="software-pagination">
  11 + <% if params[:display] != 'map' %>
  12 + <%= pagination_links @searches[@asset][:results] %>
  13 + <% end %>
  14 + </div>
12 15
13 <div style="clear: both"></div> 16 <div style="clear: both"></div>
14 17