Commit 53303e030464bb4c494c76fc1eb20602507356d2
Committed by
Gabriela Navarro
1 parent
afd37db9
Exists in
master
and in
5 other branches
Dynamically update pagination on software search
Signed-off-by: Fabio Teixeira <fabio1079@gmail.com> Signed-off-by: Luciano Prestes <lucianopcbr@gmail.com>
Showing
3 changed files
with
58 additions
and
11 deletions
Show diff stats
public/software-catalog.js
@@ -106,6 +106,8 @@ | @@ -106,6 +106,8 @@ | ||
106 | selected_categories_ids.push(element.value); | 106 | selected_categories_ids.push(element.value); |
107 | }); | 107 | }); |
108 | 108 | ||
109 | + open_loading("Loading"); | ||
110 | + | ||
109 | $.ajax({ | 111 | $.ajax({ |
110 | url: AJAX_URL.software_infos, | 112 | url: AJAX_URL.software_infos, |
111 | type: "GET", | 113 | type: "GET", |
@@ -113,19 +115,27 @@ | @@ -113,19 +115,27 @@ | ||
113 | query: query_text, | 115 | query: query_text, |
114 | selected_categories: selected_categories_ids | 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 | function update_search_page_on_ajax(response) { | 125 | function update_search_page_on_ajax(response) { |
126 | + close_loading(); | ||
127 | + response = $(response); | ||
121 | var search_list = $("#search-results"); | 128 | var search_list = $("#search-results"); |
122 | var selected_categories_field = $("#filter-categories-select-catalog"); | 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 | search_list.html(result_list); | 136 | search_list.html(result_list); |
128 | selected_categories_field.html(result_categories); | 137 | selected_categories_field.html(result_categories); |
138 | + pagination.html(result_pagination); | ||
129 | show_head_message(); | 139 | show_head_message(); |
130 | } | 140 | } |
131 | 141 |
test/functional/search_controller_test.rb
@@ -20,10 +20,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -20,10 +20,7 @@ class SearchControllerTest < ActionController::TestCase | ||
20 | @request.stubs(:ssl?).returns(:false) | 20 | @request.stubs(:ssl?).returns(:false) |
21 | @response = ActionController::TestResponse.new | 21 | @response = ActionController::TestResponse.new |
22 | 22 | ||
23 | - @category_software = Category.create!( | ||
24 | - :name => _("Software"), | ||
25 | - :environment => @environment | ||
26 | - ) | 23 | + create_software_categories |
27 | end | 24 | end |
28 | 25 | ||
29 | should "communities searches don't have software or institution" do | 26 | should "communities searches don't have software or institution" do |
@@ -45,7 +42,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -45,7 +42,7 @@ class SearchControllerTest < ActionController::TestCase | ||
45 | assert_not_includes assigns(:searches)[:communities][:results], institution | 42 | assert_not_includes assigns(:searches)[:communities][:results], institution |
46 | end | 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 | community = create_community("New Community") | 46 | community = create_community("New Community") |
50 | software = create_software_info("New Software") | 47 | software = create_software_info("New Software") |
51 | institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63") | 48 | institution = create_private_institution("New Private Institution", "NPI" , "Brazil", "DF", "Gama", "66.544.314/0001-63") |
@@ -58,7 +55,7 @@ class SearchControllerTest < ActionController::TestCase | @@ -58,7 +55,7 @@ class SearchControllerTest < ActionController::TestCase | ||
58 | assert_includes assigns(:searches)[:software_infos][:results], software.community | 55 | assert_includes assigns(:searches)[:software_infos][:results], software.community |
59 | assert_not_includes assigns(:searches)[:software_infos][:results], community | 56 | assert_not_includes assigns(:searches)[:software_infos][:results], community |
60 | assert_not_includes assigns(:searches)[:software_infos][:results], institution.community | 57 | assert_not_includes assigns(:searches)[:software_infos][:results], institution.community |
61 | - end | 58 | + end |
62 | 59 | ||
63 | 60 | ||
64 | should "Don't found template in communities search" do | 61 | should "Don't found template in communities search" do |
@@ -89,7 +86,6 @@ class SearchControllerTest < ActionController::TestCase | @@ -89,7 +86,6 @@ class SearchControllerTest < ActionController::TestCase | ||
89 | end | 86 | end |
90 | 87 | ||
91 | should "institutions_search don't have community or software" do | 88 | should "institutions_search don't have community or software" do |
92 | - | ||
93 | community = create_community("New Community") | 89 | community = create_community("New Community") |
94 | software = create_software_info("New Software") | 90 | software = create_software_info("New Software") |
95 | institution = create_private_institution( | 91 | institution = create_private_institution( |
@@ -112,6 +108,47 @@ class SearchControllerTest < ActionController::TestCase | @@ -112,6 +108,47 @@ class SearchControllerTest < ActionController::TestCase | ||
112 | assigns(:searches)[:institutions][:results], | 108 | assigns(:searches)[:institutions][:results], |
113 | software.community | 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 | end | 153 | end |
117 | end | 154 | end |
views/search/_mpog_search_form.html.erb
@@ -13,7 +13,7 @@ | @@ -13,7 +13,7 @@ | ||
13 | <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50, :placeholder=>_("Type words about the software_info you're looking for") %> | 13 | <%= text_field_tag 'query', @query, :id => 'search-input', :size => 50, :placeholder=>_("Type words about the software_info you're looking for") %> |
14 | </span> | 14 | </span> |
15 | 15 | ||
16 | - <%= submit_button(:search, _('Search'), :class => "button with-text icon-search submit") %> | 16 | + <%= submit_button(:search, _('Search')) %> |
17 | </div> | 17 | </div> |
18 | 18 | ||
19 | <%= render :partial => 'search_form_extra_fields' %> | 19 | <%= render :partial => 'search_form_extra_fields' %> |