Commit 53303e030464bb4c494c76fc1eb20602507356d2

Authored by Luciano Prestes
Committed by Gabriela Navarro
1 parent afd37db9

Dynamically update pagination on software search

Signed-off-by: Fabio Teixeira <fabio1079@gmail.com>
Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
public/software-catalog.js
... ... @@ -106,6 +106,8 @@
106 106 selected_categories_ids.push(element.value);
107 107 });
108 108  
  109 + open_loading("Loading");
  110 +
109 111 $.ajax({
110 112 url: AJAX_URL.software_infos,
111 113 type: "GET",
... ... @@ -113,19 +115,27 @@
113 115 query: query_text,
114 116 selected_categories: selected_categories_ids
115 117 },
116   - success: callback
  118 + success: callback,
  119 + error: function(){
  120 + close_loading();
  121 + }
117 122 });
118 123 }
119 124  
120 125 function update_search_page_on_ajax(response) {
  126 + close_loading();
  127 + response = $(response);
121 128 var search_list = $("#search-results");
122 129 var selected_categories_field = $("#filter-categories-select-catalog");
  130 + var pagination = $(".pagination");
123 131  
124   - var result_list = $(response).find("#search-results").html();
125   - var result_categories = $(response).find("#filter-categories-select-catalog").html();
  132 + var result_list = response.find("#search-results").html();
  133 + var result_categories = response.find("#filter-categories-select-catalog").html();
  134 + var result_pagination = response.find(".pagination").html();
126 135  
127 136 search_list.html(result_list);
128 137 selected_categories_field.html(result_categories);
  138 + pagination.html(result_pagination);
129 139 show_head_message();
130 140 }
131 141  
... ...
test/functional/search_controller_test.rb
... ... @@ -20,10 +20,7 @@ class SearchControllerTest &lt; ActionController::TestCase
20 20 @request.stubs(:ssl?).returns(:false)
21 21 @response = ActionController::TestResponse.new
22 22  
23   - @category_software = Category.create!(
24   - :name => _("Software"),
25   - :environment => @environment
26   - )
  23 + create_software_categories
27 24 end
28 25  
29 26 should "communities searches don't have software or institution" do
... ... @@ -45,7 +42,7 @@ class SearchControllerTest &lt; ActionController::TestCase
45 42 assert_not_includes assigns(:searches)[:communities][:results], institution
46 43 end
47 44  
48   - should "software_infos search don't have community or institution" do
  45 + should "software_infos search don't have community or institution" do
49 46 community = create_community("New Community")
50 47 software = create_software_info("New Software")
51 48 institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63")
... ... @@ -58,7 +55,7 @@ class SearchControllerTest &lt; ActionController::TestCase
58 55 assert_includes assigns(:searches)[:software_infos][:results], software.community
59 56 assert_not_includes assigns(:searches)[:software_infos][:results], community
60 57 assert_not_includes assigns(:searches)[:software_infos][:results], institution.community
61   - end
  58 + end
62 59  
63 60  
64 61 should "Don't found template in communities search" do
... ... @@ -89,7 +86,6 @@ class SearchControllerTest &lt; ActionController::TestCase
89 86 end
90 87  
91 88 should "institutions_search don't have community or software" do
92   -
93 89 community = create_community("New Community")
94 90 software = create_software_info("New Software")
95 91 institution = create_private_institution(
... ... @@ -112,6 +108,47 @@ class SearchControllerTest &lt; ActionController::TestCase
112 108 assigns(:searches)[:institutions][:results],
113 109 software.community
114 110 )
  111 + end
  112 +
  113 + should "software_infos search by category" do
  114 + software_one = create_software_info("Software One")
  115 + software_two = create_software_info("Software Two")
  116 +
  117 + software_one.community.categories << Category.first
  118 + software_two.community.categories << Category.last
  119 +
  120 + software_one.license_info = LicenseInfo.create :version=>"GPL - 1.0"
  121 + software_two.license_info = LicenseInfo.create :version=>"GPL - 1.0"
  122 +
  123 + software_one.save!
  124 + software_two.save!
  125 +
  126 + get(
  127 + :software_infos,
  128 + :query => "",
  129 + :selected_categories => [Category.first.id]
  130 + )
  131 +
  132 + assert_includes assigns(:searches)[:software_infos][:results], software_one.community
  133 + assert_not_includes assigns(:searches)[:software_infos][:results], software_two.community
  134 + end
  135 +
  136 + private
115 137  
  138 + def create_software_categories
  139 + category_software = Category.create!(
  140 + :name => "Software",
  141 + :environment => @environment
  142 + )
  143 + Category.create(
  144 + :name => "Category One",
  145 + :environment => @environment,
  146 + :parent => category_software
  147 + )
  148 + Category.create(
  149 + :name => "Category Two",
  150 + :environment => @environment,
  151 + :parent => category_software
  152 + )
116 153 end
117 154 end
... ...
views/search/_mpog_search_form.html.erb
... ... @@ -13,7 +13,7 @@
13 13 <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50, :placeholder=>_("Type words about the software_info you're looking for") %>
14 14 </span>
15 15  
16   - <%= submit_button(:search, _('Search'), :class => "button with-text icon-search submit") %>
  16 + <%= submit_button(:search, _('Search')) %>
17 17 </div>
18 18  
19 19 <%= render :partial => 'search_form_extra_fields' %>
... ...