diff options
-rw-r--r-- | app/controllers/admin_request_controller.rb | 17 | ||||
-rw-r--r-- | app/models/info_request.rb | 5 | ||||
-rw-r--r-- | app/views/admin_request/list_old_unclassified.rhtml | 3 | ||||
-rw-r--r-- | spec/models/info_request_spec.rb | 8 |
4 files changed, 28 insertions, 5 deletions
diff --git a/app/controllers/admin_request_controller.rb b/app/controllers/admin_request_controller.rb index c5abf8769..7cf23e61e 100644 --- a/app/controllers/admin_request_controller.rb +++ b/app/controllers/admin_request_controller.rb @@ -16,12 +16,25 @@ class AdminRequestController < AdminController def list @query = params[:query] - @info_requests = InfoRequest.paginate :order => "created_at desc", :page => params[:page], :per_page => 100, + @info_requests = InfoRequest.paginate :order => "created_at desc", + :page => params[:page], + :per_page => 100, :conditions => @query.nil? ? nil : ["lower(title) like lower('%'||?||'%')", @query] end def list_old_unclassified - @info_requests = InfoRequest.find_old_unclassified(:conditions => ["prominence = 'normal'"]) + @info_requests = WillPaginate::Collection.create((params[:page] or 1), 50) do |pager| + info_requests = InfoRequest.find_old_unclassified(:conditions => ["prominence = 'normal'"], + :limit => pager.per_page, + :offset => pager.offset) + # inject the result array into the paginated collection: + pager.replace(info_requests) + + unless pager.total_entries + # the pager didn't manage to guess the total count, do it manually + pager.total_entries = InfoRequest.count_old_unclassified(:conditions => ["prominence = 'normal'"]) + end + end end def show diff --git a/app/models/info_request.rb b/app/models/info_request.rb index ed54da840..2e16d0f58 100644 --- a/app/models/info_request.rb +++ b/app/models/info_request.rb @@ -977,8 +977,9 @@ public def InfoRequest.find_old_unclassified(extra_params={}) params = old_unclassified_params(extra_params, include_last_response_time=true) - params[:limit] = extra_params[:limit] if extra_params[:limit] - params[:include] = extra_params[:include] if extra_params[:include] + [:limit, :include, :offset].each do |extra| + params[extra] = extra_params[extra] if extra_params[extra] + end if extra_params[:order] params[:order] = extra_params[:order] params.delete(:select) diff --git a/app/views/admin_request/list_old_unclassified.rhtml b/app/views/admin_request/list_old_unclassified.rhtml index f42ed0d43..2e75c2174 100644 --- a/app/views/admin_request/list_old_unclassified.rhtml +++ b/app/views/admin_request/list_old_unclassified.rhtml @@ -6,10 +6,11 @@ <ul> <% for @request in @info_requests %> <li> - <%= request_both_links(@request) %> + <%= request_both_links(@request) %> – <%=simple_date(@request.get_last_response_event.created_at)%> </li> <% end %> </ul> +<%= will_paginate(@info_requests) %> diff --git a/spec/models/info_request_spec.rb b/spec/models/info_request_spec.rb index 76be32e0c..204c600d9 100644 --- a/spec/models/info_request_spec.rb +++ b/spec/models/info_request_spec.rb @@ -341,6 +341,14 @@ describe InfoRequest do InfoRequest.find_old_unclassified(:limit => 5) end + it 'should ask for requests using any offset param supplied' do + InfoRequest.should_receive(:find).with(:all, {:select => anything, + :order => anything, + :conditions=> anything, + :offset => 100}) + InfoRequest.find_old_unclassified(:offset => 100) + end + it 'should not limit the number of requests returned by default' do InfoRequest.should_not_receive(:find).with(:all, {:select => anything, :order => anything, |