aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application_controller.rb55
-rw-r--r--app/controllers/request_controller.rb26
-rw-r--r--app/models/info_request.rb3
-rw-r--r--app/models/info_request_event.rb18
-rw-r--r--app/views/request/list.rhtml45
5 files changed, 115 insertions, 32 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
diff --git a/app/models/info_request.rb b/app/models/info_request.rb
index c667e1499..9b0f1047b 100644
--- a/app/models/info_request.rb
+++ b/app/models/info_request.rb
@@ -451,7 +451,7 @@ public
self.log_event("response", params)
self.save!
end
-
+ self.info_request_events.each { |event| event.xapian_mark_needs_index } # for the "waiting_classification" index
RequestMailer.deliver_new_response(self, incoming_message)
end
@@ -564,6 +564,7 @@ public
def calculate_event_states
curr_state = nil
for event in self.info_request_events.reverse
+ event.xapian_mark_needs_index # we need to reindex all events in order to update their latest_* terms
if curr_state.nil?
if !event.described_state.nil?
curr_state = event.described_state
diff --git a/app/models/info_request_event.rb b/app/models/info_request_event.rb
index 1550a4bf5..fbf70332d 100644
--- a/app/models/info_request_event.rb
+++ b/app/models/info_request_event.rb
@@ -94,7 +94,7 @@ class InfoRequestEvent < ActiveRecord::Base
[ :created_at_numeric, 1, "created_at", :number ], # for sorting
[ :described_at_numeric, 2, "described_at", :number ], # XXX using :number for lack of :datetime support in Xapian values
[ :request, 3, "request_collapse", :string ],
- [ :request_title_collapse, 4, "request_title_collapse", :string ]
+ [ :request_title_collapse, 4, "request_title_collapse", :string ],
],
:terms => [ [ :calculated_state, 'S', "status" ],
[ :requested_by, 'B', "requested_by" ],
@@ -102,6 +102,9 @@ class InfoRequestEvent < ActiveRecord::Base
[ :commented_by, 'C', "commented_by" ],
[ :request, 'R', "request" ],
[ :variety, 'V', "variety" ],
+ [ :latest_variety, 'K', "latest_variety" ],
+ [ :latest_status, 'L', "latest_status" ],
+ [ :waiting_classification, 'W', "waiting_classification" ],
[ :filetype, 'T', "filetype" ],
[ :tags, 'U', "tag" ]
],
@@ -129,6 +132,19 @@ class InfoRequestEvent < ActiveRecord::Base
def request
self.info_request.url_title
end
+
+ def latest_variety
+ self.info_request.get_last_event.variety
+ end
+
+ def latest_status
+ self.info_request.get_last_event.calculated_state
+ end
+
+ def waiting_classification
+ self.info_request.awaiting_description == true ? "yes" : "no"
+ end
+
def request_title_collapse
url_title = self.info_request.url_title
# remove numeric section from the end, use this to group lots
diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml
index 04dc0d010..50e98f6e1 100644
--- a/app/views/request/list.rhtml
+++ b/app/views/request/list.rhtml
@@ -1,15 +1,38 @@
-<div id="list_sidebar">
-<h1><%= _('Show only...')%></h1>
-<ul>
-<% for view, description, target in [
- ['successful', _('Successful responses'), request_list_successful_url(:view => 'successful')],
- ['recent', _('Recently sent requests'), request_list_recent_url(:view => 'recent')]
-] %>
-<li>
- <%= link_to_unless (@view == view), description, target %>
-</li>
+<div id="list-filter">
+<% form_tag({}, :method => "get") do %>
+ <%= label_tag(:query, "Search for:") %>
+ <%= text_field_tag(:query, params[:query]) %> <br/>
+ <% [["sent", "messages from users"],
+ ["response", "messages from authorities"],
+ ["comment", "comments"]].each_with_index do |item, index|
+ variety, title = item %>
+
+ <%= check_box_tag "request_variety[]", variety, params[:request_variety].nil? ? true : params[:request_variety].include?(variety), :id => "request_variety_#{index}" %>
+ <%= label_tag("request_variety_#{index}", title) %> <br />
+ <% end %>
+
+ <ul class="request-selector">
+ <% for status in ["all", "successful", "unsuccessful", "awaiting"] %>
+ <li>
+ <% if params[:view] != status %>
+ <%= link_to "#{status} requests", url_for(:controller => "request", :action => "list", :view => status) + "?#{request.query_string}" %>
+ <% else %>
+ <%= status %> requests
+ <% end %>
+ </li>
+ <% end %>
+ </ul>
+
+ <div class="filter-item last">
+ between dates:
+ <input type="text" name="request_date_after" /> from<br>
+ <input type="text" name="request_date_before" /> to<br>
+ </div>
+
+
+
+ <%= submit_tag("Search") %>
<% end %>
-</ul>
</div>
<h1><%=@title%></h1>