aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/application.rb45
-rw-r--r--app/controllers/general_controller.rb44
-rw-r--r--app/controllers/request_controller.rb17
-rw-r--r--app/views/general/frontpage.rhtml2
-rw-r--r--app/views/request/list.rhtml21
-rw-r--r--config/routes.rb5
6 files changed, 84 insertions, 50 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index daa8a955b..c92e084a7 100644
--- a/app/controllers/application.rb
+++ b/app/controllers/application.rb
@@ -6,7 +6,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: application.rb,v 1.32 2008-03-21 14:45:38 francis Exp $
+# $Id: application.rb,v 1.33 2008-04-01 00:36:56 francis Exp $
class ApplicationController < ActionController::Base
@@ -124,6 +124,49 @@ class ApplicationController < ActionController::Base
end
end
+ # Function for search
+ def perform_search(query, sortby)
+ @query = query
+ @sortby = sortby
+
+ # Work out sorting method
+ if @sortby.nil?
+ order = nil
+ elsif @sortby == 'newest'
+ order = 'created_at desc'
+ elsif @sortby == 'described'
+ order = 'last_described_at desc' # use this for RSS
+ else
+ raise "Unknown sort order " + @sortby
+ end
+
+ # Peform the search
+ @per_page = 20
+ @page = (params[:page] || "1").to_i
+
+ solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ],
+ :limit => @per_page, :offset => (@page - 1) * @per_page,
+ :highlight => {
+ :prefix => '<span class="highlight">',
+ :suffix => '</span>',
+ :fragsize => 250,
+ :fields => ["solr_text_main", "title", # InfoRequestEvent
+ "name", "short_name", # PublicBody
+ "name" # User
+ ]}, :order => order
+ )
+ @search_results = solr_object.results
+ @search_hits = solr_object.total_hits
+
+ # Calculate simple word highlighting view code for users and public bodies
+ query_nopunc = @query.gsub(/[^a-z0-9]/i, " ")
+ query_nopunc = query_nopunc.gsub(/\s+/, " ")
+ @highlight_words = query_nopunc.split(" ")
+
+ # Extract better Solr highlighting for info request related results
+ @highlighting = solr_object.highlights
+ end
+
# URL generating functions are needed by all controllers (for redirects)
# and views (for links), so include them into all of both.
include LinkToHelper
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 16f34f1b8..6930b1ddd 100644
--- a/app/controllers/general_controller.rb
+++ b/app/controllers/general_controller.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: general_controller.rb,v 1.14 2008-03-31 23:19:16 francis Exp $
+# $Id: general_controller.rb,v 1.15 2008-04-01 00:36:56 francis Exp $
class GeneralController < ApplicationController
@@ -51,46 +51,12 @@ class GeneralController < ApplicationController
# Actual search
def search
- @per_page = 20
- @query = params[:query]
- @sortby = params[:sortby]
- @page = (params[:page] || "1").to_i
-
- # Work out sorting method
- if @sortby.nil?
- order = nil
- elsif @sortby == 'newest'
- order = 'created_at desc'
- elsif @sortby == 'described'
- order = 'last_described_at desc' # use this for RSS
- else
- raise "Unknown sort order " + @sortby
- end
-
- # Peform the search
- solr_object = InfoRequestEvent.multi_solr_search(@query, :models => [ PublicBody, User ],
- :limit => @per_page, :offset => (@page - 1) * @per_page,
- :highlight => {
- :prefix => '<span class="highlight">',
- :suffix => '</span>',
- :fragsize => 250,
- :fields => ["solr_text_main", "title", # InfoRequestEvent
- "name", "short_name", # PublicBody
- "name" # User
- ]}, :order => order
- )
- @search_results = solr_object.results
- @search_hits = solr_object.total_hits
-
- # Calculate simple word highlighting view code for users and public bodies
- query_nopunc = @query.gsub(/[^a-z0-9]/i, " ")
- query_nopunc = query_nopunc.gsub(/\s+/, " ")
- @highlight_words = query_nopunc.split(" ")
-
- # Extract better Solr highlighting for info request related results
- @highlighting = solr_object.highlights
+ query = params[:query]
+ sortby = params[:sortby]
+ perform_search(query, sortby)
end
+ # For debugging
def fai_test
sleep 10
render :text => "awake\n"
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index 7fe9feda5..4275c944d 100644
--- a/app/controllers/request_controller.rb
+++ b/app/controllers/request_controller.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: request_controller.rb,v 1.68 2008-03-17 10:36:41 francis Exp $
+# $Id: request_controller.rb,v 1.69 2008-04-01 00:36:56 francis Exp $
class RequestController < ApplicationController
@@ -37,7 +37,20 @@ class RequestController < ApplicationController
end
def list
- @info_requests = InfoRequest.paginate :order => "created_at desc", :page => params[:page], :per_page => 25, :conditions => "prominence = 'normal'"
+ view = params[:view]
+
+ if view.nil?
+ @title = "Recent Freedom of Information requests"
+ query = "variety:sent";
+ sortby = "newest"
+ elsif view == 'successful'
+ @title = "Recent successful responses"
+ query = 'variety:response (status:successful OR status:partially_successful)'
+ sortby = "newest"
+ else
+ raise "unknown request list view " + view.to_s
+ end
+ perform_search(query, sortby)
end
# Page new form posts to
diff --git a/app/views/general/frontpage.rhtml b/app/views/general/frontpage.rhtml
index 81822da64..563a2609a 100644
--- a/app/views/general/frontpage.rhtml
+++ b/app/views/general/frontpage.rhtml
@@ -59,7 +59,7 @@
<div id="find_information">
<h1>Explore information that others requested</h1>
<%= render :partial => 'request/request_listing', :locals => { :info_requests => @info_requests } %>
- <p><%=link_to "View more successful requests", search_url(:query => 'variety:response (status:successful OR status:partially_successful)', :sortby => 'newest') %></p>
+ <p><%=link_to "View more successful requests", request_list_url(:view => 'successful') %></p>
<% form_tag({:action => "search_redirect"}, {:id => "search_form"}) do %>
<p>
<%= text_field_tag 'query', params[:query], { :size => 20 } %>
diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml
index 469c79283..b4a101b2d 100644
--- a/app/views/request/list.rhtml
+++ b/app/views/request/list.rhtml
@@ -1,7 +1,20 @@
-<% @title = "Recent Freedom of Information requests" %>
-
<h1><%=@title%></h1>
-<%= render :partial => 'request_listing', :locals => { :info_requests => @info_requests } %>
+<% if @search_results.empty? %>
+ <p>No requests made yet.</p>
+<% else %>
+ <% for search_result in @search_results %>
+ <% if search_result.class.to_s == 'PublicBody' %>
+ <%= render :partial => 'body/body_listing_single', :locals => { :public_body => search_result } %>
+ <% elsif search_result.class.to_s == 'User' %>
+ <%= render :partial => 'user/user_listing_single', :locals => { :display_user => search_result } %>
+ <% elsif search_result.class.to_s == 'InfoRequestEvent' %>
+ <%= render :partial => 'request/request_listing_via_event', :locals => { :event => search_result, :info_request => search_result.info_request } %>
+ <% else %>
+ <p><strong>Unknown search result type <%=search_result.class.to_s%></strong></p>
+ <% end %>
+ <% end %>
+<% end %>
+
+<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @search_hits) %>
-<%= will_paginate(@info_requests) %>
diff --git a/config/routes.rb b/config/routes.rb
index 4945a8e49..2a4a10daa 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: routes.rb,v 1.47 2008-03-19 05:26:31 francis Exp $
+# $Id: routes.rb,v 1.48 2008-04-01 00:36:56 francis Exp $
ActionController::Routing::Routes.draw do |map|
@@ -25,8 +25,7 @@ ActionController::Routing::Routes.draw do |map|
end
map.with_options :controller => 'request' do |request|
-
- request.request_list '/list', :action => 'list'
+ request.request_list '/list/:view', :action => 'list', :view => nil
request.new_request '/new', :action => 'new'
request.new_request_to_body '/new/:public_body_id', :action => 'new'