diff options
author | Seb Bacon <seb.bacon@gmail.com> | 2011-08-24 11:50:10 +0100 |
---|---|---|
committer | Seb Bacon <seb.bacon@gmail.com> | 2011-08-29 09:44:32 +0100 |
commit | 284808d259b3ba8ba1e6c106d949fffeb110a5a7 (patch) | |
tree | e71adef34ba97cec8c0fa53232f37e6d0eebb30c /app/controllers/application_controller.rb | |
parent | 50cd41b88b4421824e436d9189f8780b84c46a1a (diff) |
First stab at filtering on the "View requests" page
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 55 |
1 files changed, 55 insertions, 0 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. |