aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application_controller.rb55
-rw-r--r--app/controllers/request_controller.rb26
2 files changed, 62 insertions, 19 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0df3e22da..e16f9f5bb 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -349,6 +349,61 @@ class ApplicationController < ActionController::Base
session[:last_body_id] = public_body.id
end
+ def alter_query_from_params(query)
+ # various forms are used to customise queries and hide
+ # xapian's complexity. This parses the form fields and turns
+ # them into a xapian query string
+ query = "" if query.nil?
+ sortby = "newest"
+ if params[:request_variety] && !(query =~ /variety:/)
+ sortby = "described"
+ varieties = []
+ if params[:request_variety].include? "sent"
+ varieties << ['variety:sent', 'variety:followup_sent']
+ end
+ if params[:request_variety].include? "response"
+ varieties << ['variety:response']
+ end
+ if params[:request_variety].include? "comment"
+ varieties << ['variety:comment']
+ end
+ query += " (#{varieties.join(' OR ')})"
+ end
+ case params[:request_status]
+ when "recent", "all"
+ if !(query =~ /variety:/)
+ query += " (variety:sent)"
+ end
+ when "successful"
+ query += ' (latest_status:successful OR latest_status:partially_successful)'
+ sortby = "described"
+ when "unsuccessful"
+ query += ' (latest_status:rejected OR latest_status:not_held)'
+ sortby = "described"
+ when "awaiting"
+ if query.empty?
+ query += 'variety:sent '
+ end
+ query += ' NOT (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held OR latest_status:gone_postal)'
+ sortby = "described"
+ when "internal_review"
+ query += ' (latest_status:internal_review)'
+ sortby = "described"
+ end
+
+ if !params[:request_date_after].nil? && params[:request_date_before].nil?
+ params[:request_date_before] = Date.now.strftime("%d/%m/%Y")
+ query += " #{params[:request_date_after]}..#{params[:request_date_before]}"
+ elsif params[:request_date_after].nil? && !params[:request_date_before].nil?
+ params[:request_date_after] = "01/01/2008"
+ end
+ if params[:request_date_after]
+ query = "#{params[:request_date_after]}..#{params[:request_date_before]} " + query
+ end
+ return query, sortby
+
+ end
+
# URL generating functions are needed by all controllers (for redirects),
# views (for links) and mailers (for use in emails), so include them into
# all of all.
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index c1a13273a..731348fbf 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -129,25 +129,12 @@ class RequestController < ApplicationController
def list
medium_cache
@view = params[:view]
-
- if @view.nil?
- redirect_to request_list_url(:view => 'successful')
- return
- end
-
- if @view == 'recent'
- @title = _("Recently sent Freedom of Information requests")
- query = "variety:sent";
- sortby = "newest"
- @track_thing = TrackThing.create_track_for_all_new_requests
- elsif @view == 'successful'
- @title = _("Recently successful responses")
- query = 'variety:response (status:successful OR status:partially_successful)'
- sortby = "described"
- @track_thing = TrackThing.create_track_for_all_successful_requests
- else
- raise "unknown request list view " + @view.to_s
+ if !@view.nil?
+ params[:request_status] = @view
end
+ params[:request_status] = "recent" if params[:query].nil? && params[:request_status].nil?
+ query, sortby = alter_query_from_params(params[:query])
+ @title = "Some title"
@page = get_search_page_from_params if !@page # used in cache case, as perform_search sets @page as side effect
behavior_cache :tag => [@view, @page] do
@@ -158,7 +145,8 @@ class RequestController < ApplicationController
@title = @title + " (page " + @page.to_s + ")" if (@page > 1)
- @feed_autodetect = [ { :url => do_track_url(@track_thing, 'feed'), :title => @track_thing.params[:title_in_rss], :has_json => true } ]
+ # XXX need to reinstate the following; @track_thing had previously been set to "TrackThing.create_track_for_all_new_requests" and "TrackThing.create_track_for_all_successful_requests"
+ # @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
if @page > 20