diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index cb23b6ce70..5115c5a8c2 100644 --- a/app/controllers/request_controller.rb +++ b/app/controllers/request_controller.rb @@ -14,6 +14,7 @@ class RequestController < ApplicationController before_action :set_info_request, only: [:show] before_action :redirect_new_form_to_pro_version, only: [:select_authority, :new] before_action :set_in_pro_area, only: [:select_authority, :show] + before_action :setup_results_pagination, only: [:list, :similar] helper_method :state_transitions_empty? @@ -110,13 +111,6 @@ def details # Requests similar to this one def similar short_cache - @per_page = 25 - @page = (params[:page] || "1").to_i - - # Later pages are very expensive to load - if @page > MAX_RESULTS / PER_PAGE - raise ActiveRecord::RecordNotFound, "Sorry. No pages after #{MAX_RESULTS / PER_PAGE}." - end @info_request = InfoRequest.find_by_url_title!(params[:url_title]) @@ -133,24 +127,29 @@ def similar def list medium_cache - @view = params[:view] - unless @page # used in cache case, as perform_search sets @page as side effect - @page = get_search_page_from_params - end - @per_page = PER_PAGE - @max_results = MAX_RESULTS - if @view == "recent" - return redirect_to request_list_all_url(action: "list", view: "all", page: @page), status: :moved_permanently - end - # Later pages are very expensive to load - if @page > MAX_RESULTS / PER_PAGE - raise ActiveRecord::RecordNotFound, "Sorry. No pages after #{MAX_RESULTS / PER_PAGE}." - end + @filters = params.slice(:query, :request_date_after, :request_date_before) + @filters[:latest_status] = params[:view] + @tag = @filters[:tag] = params[:tag] - @filters = params.merge(latest_status: @view) + @results = InfoRequest.request_list( + @filters, @page, @per_page, @max_results + ) - if @page > 1 + @category = InfoRequest.category_list.find_by(category_tag: @tag) if @tag + if @category + @title = n_('Found {{count}} request in the category ‘{{category}}’', + 'Found {{count}} requests in the category ‘{{category}}’', + @results[:matches_estimated], + count: @results[:matches_estimated], + category: @category.title) + elsif @tag + @title = n_('Found {{count}} request tagged ‘{{tag_name}}’', + 'Found {{count}} requests tagged ‘{{tag_name}}’', + @results[:matches_estimated], + count: @results[:matches_estimated], + tag_name: @tag) + elsif @page > 1 @title = _("Browse and search requests (page {{count}})", count: @page) else @title = _('Browse and search requests') @@ -158,9 +157,6 @@ def list @track_thing = TrackThing.create_track_for_search_query(InfoRequestEvent.make_query_from_params(@filters)) @feed_autodetect = [ { url: do_track_url(@track_thing, 'feed'), title: @track_thing.params[:title_in_rss], has_json: true } ] - - # Don't let robots go more than 20 pages in - @no_crawl = true if @page > 20 end # Page new form posts to @@ -474,6 +470,21 @@ def outgoing_message_params params.require(:outgoing_message).permit(:body, :what_doing) end + def setup_results_pagination + @page ||= get_search_page_from_params + @per_page = PER_PAGE + @max_results = MAX_RESULTS + + # Don't let robots go more than 20 pages in + @no_crawl = true if @page > 20 + + # Later pages are very expensive to load + return if @page <= MAX_RESULTS / PER_PAGE + + raise ActiveRecord::RecordNotFound, + "Sorry. No pages after #{MAX_RESULTS / PER_PAGE}." + end + def can_update_status(info_request) # Don't allow status update on external requests, otherwise accept param info_request.is_external? ? false : params[:update_status] == "1" diff --git a/app/views/general/_frontpage_requests_list.html.erb b/app/views/general/_frontpage_requests_list.html.erb index 6b8e8a0dd8..3fb6d82f87 100644 --- a/app/views/general/_frontpage_requests_list.html.erb +++ b/app/views/general/_frontpage_requests_list.html.erb @@ -41,5 +41,5 @@ <% end %> - <%= link_to _("Browse all requests →"), request_list_all_path, :class => 'button-secondary' %> + <%= link_to _("Browse all requests →"), request_list_path, :class => 'button-secondary' %> diff --git a/app/views/request/_category.html.erb b/app/views/request/_category.html.erb new file mode 100644 index 0000000000..2f96b70660 --- /dev/null +++ b/app/views/request/_category.html.erb @@ -0,0 +1,2 @@ +<%= render_notes(@category.all_notes) %> +<%= @category.body %> diff --git a/app/views/request/_list_results.html.erb b/app/views/request/_list_results.html.erb index 8824ff0245..382fa9b2fe 100644 --- a/app/views/request/_list_results.html.erb +++ b/app/views/request/_list_results.html.erb @@ -1,4 +1,3 @@ -<% @results = InfoRequest.request_list(@filters, @page, @per_page, @max_results) %> <% if @results[:results].empty? %>

<%= _('No requests of this sort yet.')%>

<% else %> diff --git a/app/views/request/_request_filter_form.html.erb b/app/views/request/_request_filter_form.html.erb index f0770b210d..6155d0a174 100644 --- a/app/views/request/_request_filter_form.html.erb +++ b/app/views/request/_request_filter_form.html.erb @@ -11,7 +11,7 @@ <% if controller?("public_body") %> <%= link_to label, url_for(:controller => "public_body", :action => "show", :view => status, :url_name => @public_body.url_name) + "?" + request.query_string + '#results' %> <% else %> - <%= link_to label, url_for(:controller => "request", :action => "list", :view => status) + "?" + request.query_string + '#results' %> + <%= link_to label, url_for(:controller => "request", :action => "list", :view => status, :tag => @tag) + "?" + request.query_string + '#results' %> <% end %> <% else %> <%= label %> diff --git a/app/views/request/list.html.erb b/app/views/request/list.html.erb index 498c45e7ee..5a89b11565 100644 --- a/app/views/request/list.html.erb +++ b/app/views/request/list.html.erb @@ -2,6 +2,8 @@

<%= @title %>

<%= render :partial => 'request/request_search_form', :locals => { :after_form_fields => render(:partial => 'request/request_filter_form') } %> + + <%= render partial: 'category' if @category %>