From c8fc7884e1e13e7a46ea720fe7fd4d47d095a67f Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 12:47:58 +0000 Subject: RequestController#search_typeahead filter by body Action now supports the `request_from` param as per the Xapian filtering system to filter search typeaheads by public body --- app/controllers/request_controller.rb | 14 ++++++++++---- spec/controllers/request_controller_spec.rb | 6 ++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 9e2c291dc..9f17532b8 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -900,10 +900,16 @@ class RequestController < ApplicationController # Type ahead search def search_typeahead - # Since acts_as_xapian doesn't support the Partial match flag, we work around it - # by making the last work a wildcard, which is quite the same - query = params[:q] - @xapian_requests = perform_search_typeahead(query, InfoRequestEvent) + # Since acts_as_xapian doesn't support the Partial match flag, we work + # around it by making the last word a wildcard, which is quite the same + @query = '' + + if params.key?(:requested_from) + @query << "requested_from:#{ params[:requested_from] } " + end + + @query << params[:q] + @xapian_requests = perform_search_typeahead(@query, InfoRequestEvent) render :partial => "request/search_ahead" end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index 6c0f4573e..ce91f7a83 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2380,6 +2380,12 @@ describe RequestController, "when doing type ahead searches" do get :search_typeahead, :q => "dog -chicken" assigns[:xapian_requests].results.size.should == 1 end + + it 'can filter search results by public body' do + get :search_typeahead, :q => 'boring', :requested_from => 'dfh' + expect(assigns[:query]).to eq('requested_from:dfh boring') + end + end describe RequestController, "when showing similar requests" do -- cgit v1.2.3 From e12ef04af94676ee7c308233c6904da74a4a7ac9 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 12:56:39 +0000 Subject: Filter related requests by body on /new/:body --- app/views/request/new.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index 79b4f8548..5ea64aa30 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -4,7 +4,7 @@ // Avoid triggering too often (on each keystroke) by using the debounce jQuery plugin: // http://benalman.com/projects/jquery-throttle-debounce-plugin/ $("#typeahead_search").keypress($.debounce( 300, function() { - $("#typeahead_response").load("<%=search_ahead_url%>?q="+encodeURI(this.value), function() { + $("#typeahead_response").load("<%= search_ahead_url %>?q="+encodeURI(this.value)+"&requested_from=<%= @info_request.public_body.url_name %>", function() { // When following links in typeahead results, open new tab/window $("#typeahead_response a").attr("target","_blank"); -- cgit v1.2.3 From 29552f13f7340875e519b1e017349cb3c6d705a6 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 13:01:35 +0000 Subject: Refactor request/_search_ahead partial Each instead of for Unless instead of if ! .any? instead of size > 0 Line length --- app/views/request/_search_ahead.html.erb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/app/views/request/_search_ahead.html.erb b/app/views/request/_search_ahead.html.erb index 1e65a5458..7120f3862 100644 --- a/app/views/request/_search_ahead.html.erb +++ b/app/views/request/_search_ahead.html.erb @@ -1,10 +1,14 @@
- <% if !@xapian_requests.nil? %> - <% if @xapian_requests.results.size > 0 %> + <% unless @xapian_requests.nil? %> + + <% if @xapian_requests.results.any? %>

<%= _("Possibly related requests:") %>

<% end %> - <% for result in @xapian_requests.results %> - <%= render :partial => 'request/request_listing_short_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %> + + <% @xapian_requests.results.each do |result| %> + <%= render :partial => 'request/request_listing_short_via_event', + :locals => { :event => result[:model], + :info_request => result[:model].info_request } %> <% end %>

-- cgit v1.2.3 From 16762e7379ecd39d3a1e62ca6c7ddfc95914f7bc Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 13:07:17 +0000 Subject: Only attempt to render results if there are any MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No point trying to render the results if there aren’t any to render --- app/views/request/_search_ahead.html.erb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/views/request/_search_ahead.html.erb b/app/views/request/_search_ahead.html.erb index 7120f3862..f77f5b3ee 100644 --- a/app/views/request/_search_ahead.html.erb +++ b/app/views/request/_search_ahead.html.erb @@ -3,12 +3,12 @@ <% if @xapian_requests.results.any? %>

<%= _("Possibly related requests:") %>

- <% end %> - <% @xapian_requests.results.each do |result| %> - <%= render :partial => 'request/request_listing_short_via_event', - :locals => { :event => result[:model], - :info_request => result[:model].info_request } %> + <% @xapian_requests.results.each do |result| %> + <%= render :partial => 'request/request_listing_short_via_event', + :locals => { :event => result[:model], + :info_request => result[:model].info_request } %> + <% end %> <% end %>

-- cgit v1.2.3 From 5835134a93b99d2c6af869cbcdea6f25bbb956f6 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 13:10:15 +0000 Subject: =?UTF-8?q?Don=E2=80=99t=20render=20=E2=80=9Csearch=20their=20webs?= =?UTF-8?q?ite=E2=80=9D=20if=20no=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/request/_search_ahead.html.erb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app/views/request/_search_ahead.html.erb b/app/views/request/_search_ahead.html.erb index f77f5b3ee..d8d7995bb 100644 --- a/app/views/request/_search_ahead.html.erb +++ b/app/views/request/_search_ahead.html.erb @@ -9,10 +9,13 @@ :locals => { :event => result[:model], :info_request => result[:model].info_request } %> <% end %> + +

+ + <%= _("Search in their website for this information →") %> + +

<% end %> -

- <%= _("Or search in their website for this information.") %> -

<% end %>
-- cgit v1.2.3 From a4b050e3cf8833b5565cfa581235bae092d056ba Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 13:11:39 +0000 Subject: =?UTF-8?q?Don=E2=80=99t=20render=20search=20ahead=20results=20if?= =?UTF-8?q?=20no=20results?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only render the request_search_ahead_results div when a search has been made. --- app/views/request/_search_ahead.html.erb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/app/views/request/_search_ahead.html.erb b/app/views/request/_search_ahead.html.erb index d8d7995bb..62c7c65af 100644 --- a/app/views/request/_search_ahead.html.erb +++ b/app/views/request/_search_ahead.html.erb @@ -1,6 +1,5 @@ -
- <% unless @xapian_requests.nil? %> - +<% unless @xapian_requests.nil? %> +
<% if @xapian_requests.results.any? %>

<%= _("Possibly related requests:") %>

@@ -16,6 +15,5 @@

<% end %> - - <% end %> -
+
+<% end %> -- cgit v1.2.3 From a9853bf1a41623df1b84656ce8dac6f01231f2cd Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 14:58:40 +0000 Subject: RequestController#search_typaahead limit results Use the per_page parameter to limit the results returned --- app/controllers/request_controller.rb | 4 +++- spec/controllers/request_controller_spec.rb | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 9f17532b8..346aaf384 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -908,8 +908,10 @@ class RequestController < ApplicationController @query << "requested_from:#{ params[:requested_from] } " end + @per_page = (params.fetch(:per_page) { 25 }).to_i + @query << params[:q] - @xapian_requests = perform_search_typeahead(@query, InfoRequestEvent) + @xapian_requests = perform_search_typeahead(@query, InfoRequestEvent, @per_page) render :partial => "request/search_ahead" end diff --git a/spec/controllers/request_controller_spec.rb b/spec/controllers/request_controller_spec.rb index ce91f7a83..4d0070470 100644 --- a/spec/controllers/request_controller_spec.rb +++ b/spec/controllers/request_controller_spec.rb @@ -2386,6 +2386,17 @@ describe RequestController, "when doing type ahead searches" do expect(assigns[:query]).to eq('requested_from:dfh boring') end + it 'defaults to 25 results per page' do + get :search_typeahead, :q => 'boring' + expect(assigns[:per_page]).to eq(25) + end + + it 'can limit the number of searches returned' do + get :search_typeahead, :q => 'boring', :per_page => '1' + expect(assigns[:per_page]).to eq(1) + expect(assigns[:xapian_requests].results.size).to eq(1) + end + end describe RequestController, "when showing similar requests" do -- cgit v1.2.3 From c7b4ff24eae6c50cc43799f54df4caed5efa25f0 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 15:06:17 +0000 Subject: Limit typeahead similar requests on /new/:body Only return 3 similar requests to prevent the suggestions swamping the page --- app/views/request/new.html.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index 5ea64aa30..4840b5064 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -4,7 +4,9 @@ // Avoid triggering too often (on each keystroke) by using the debounce jQuery plugin: // http://benalman.com/projects/jquery-throttle-debounce-plugin/ $("#typeahead_search").keypress($.debounce( 300, function() { - $("#typeahead_response").load("<%= search_ahead_url %>?q="+encodeURI(this.value)+"&requested_from=<%= @info_request.public_body.url_name %>", function() { + $("#typeahead_response").load("<%= search_ahead_url %>?q="+encodeURI(this.value)+ + "&requested_from=<%= @info_request.public_body.url_name %>"+ + "&per_page=3", function() { // When following links in typeahead results, open new tab/window $("#typeahead_response a").attr("target","_blank"); -- cgit v1.2.3 From 99933850d587a5d80be7af2ff2bebcc032cf33d8 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Thu, 30 Oct 2014 16:59:38 +0000 Subject: Add close button to similar requests on /new/:body --- app/assets/stylesheets/responsive/_new_request_layout.scss | 4 ++++ app/views/request/_search_ahead.html.erb | 1 + app/views/request/new.html.erb | 9 ++++++--- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/app/assets/stylesheets/responsive/_new_request_layout.scss b/app/assets/stylesheets/responsive/_new_request_layout.scss index a2ab23060..a8b24e1b1 100644 --- a/app/assets/stylesheets/responsive/_new_request_layout.scss +++ b/app/assets/stylesheets/responsive/_new_request_layout.scss @@ -58,6 +58,10 @@ } } +#typeahead_response .close-button { + float: right; +} + /* Advice sits on right hand side */ #request_advice { diff --git a/app/views/request/_search_ahead.html.erb b/app/views/request/_search_ahead.html.erb index 62c7c65af..4fbe06ebc 100644 --- a/app/views/request/_search_ahead.html.erb +++ b/app/views/request/_search_ahead.html.erb @@ -1,6 +1,7 @@ <% unless @xapian_requests.nil? %>
<% if @xapian_requests.results.any? %> + X

<%= _("Possibly related requests:") %>

<% @xapian_requests.results.each do |result| %> diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index 4840b5064..f6194fb41 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -1,21 +1,24 @@ <% unless @batch %> <% end %> -- cgit v1.2.3 From bd3ed955718576a27a7c9194946d9721fde4c4a8 Mon Sep 17 00:00:00 2001 From: Gareth Rees Date: Tue, 11 Nov 2014 15:43:18 +0000 Subject: Add slideUp/slideDown to related requests results --- app/views/request/new.html.erb | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/app/views/request/new.html.erb b/app/views/request/new.html.erb index f6194fb41..178ef7638 100644 --- a/app/views/request/new.html.erb +++ b/app/views/request/new.html.erb @@ -5,18 +5,27 @@ // debounce jQuery plugin: // http://benalman.com/projects/jquery-throttle-debounce-plugin/ $("#typeahead_search").keypress($.debounce( 300, function() { + if ( $('#request_search_ahead_results').text().trim().length > 0) { + $('#typeahead_response').slideUp('fast'); + } + $("#typeahead_response").load("<%= search_ahead_url %>?q="+encodeURI(this.value)+ "&requested_from=<%= @info_request.public_body.url_name %>"+ "&per_page=3", function() { - // When following links in typeahead results, open new - // tab/window - $("#typeahead_response a").attr("target","_blank"); - - // Update the public body site search link - $("#body-site-search-link").attr("href", "http://www.google.com/#q="+encodeURI($("#typeahead_search").val())+ - "+site:<%= @info_request.public_body.calculated_home_page %>"); - $('.close-button').click(function() { $(this).parent().hide() }); + if ( $('#request_search_ahead_results').text().trim().length > 0) { + $('#typeahead_response').hide().slideDown('fast'); + + // When following links in typeahead results, open new + // tab/window + $("#typeahead_response a").attr("target","_blank"); + + // Update the public body site search link + $("#body-site-search-link").attr("href", "http://www.google.com/#q="+encodeURI($("#typeahead_search").val())+ + "+site:<%= @info_request.public_body.calculated_home_page %>"); + + $('.close-button').click(function() { $(this).parent().hide() }); + } }); })); }); -- cgit v1.2.3 From fca9d8de71045006ffee2f08b287e90607151b99 Mon Sep 17 00:00:00 2001 From: Henare Degan Date: Tue, 9 Dec 2014 12:13:04 +1100 Subject: Remove unused "web analytics" section of admin pages - it's confusing! --- app/views/admin_general/stats.html.erb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/app/views/admin_general/stats.html.erb b/app/views/admin_general/stats.html.erb index 27dc25ee0..03268cc14 100644 --- a/app/views/admin_general/stats.html.erb +++ b/app/views/admin_general/stats.html.erb @@ -53,8 +53,3 @@
-
-
-

Web analytics

-
-
-- cgit v1.2.3