aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/user_controller.rb13
-rw-r--r--app/views/user/show.rhtml25
-rw-r--r--spec/controllers/user_controller_spec.rb7
3 files changed, 38 insertions, 7 deletions
diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb
index 6916b4456..47a133135 100644
--- a/app/controllers/user_controller.rb
+++ b/app/controllers/user_controller.rb
@@ -33,9 +33,16 @@ class UserController < ApplicationController
# Use search query for this so can collapse and paginate easily
# XXX really should just use SQL query here rather than Xapian.
begin
- @xapian_requests = perform_search([InfoRequestEvent], 'requested_by:' + @display_user.url_name, 'newest', 'request_collapse')
- @xapian_comments = perform_search([InfoRequestEvent], 'commented_by:' + @display_user.url_name, 'newest', nil)
-
+ requests_query = 'requested_by:' + @display_user.url_name
+ comments_query = 'commented_by:' + @display_user.url_name
+ if !params[:user_query].nil?
+ requests_query += " " + params[:user_query]
+ comments_query += " " + params[:user_query]
+ @match_phrase = _("{{search_results}} matching '{{query}}'", :search_results => "", :query => params[:user_query])
+ end
+ @xapian_requests = perform_search([InfoRequestEvent], requests_query, 'newest', 'request_collapse')
+ @xapian_comments = perform_search([InfoRequestEvent], comments_query, 'newest', nil)
+
if (@page > 1)
@page_desc = " (page " + @page.to_s + ")"
else
diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml
index e3dd74332..63f9fe3a0 100644
--- a/app/views/user/show.rhtml
+++ b/app/views/user/show.rhtml
@@ -116,19 +116,34 @@
</div>
</div>
<div style="clear:both"></div>
+ <% form_tag(show_user_url, :method => "get", :id=>"search_form") do %>
+ <div>
+ <%= text_field_tag(:user_query, params[:user_query]) %>
+ <% if @is_you %>
+ <%= submit_tag(_("Search your contributions")) %>
+ <% else %>
+ <%= submit_tag(_("Search contributions by this person")) %>
+ <% end %>
+ </div>
+ <% end %>
+
<% if !@xapian_requests.nil? %>
<% if @xapian_requests.results.empty? %>
<% if @page == 1 %>
- <h2 class="foi_results" id="foi_requests"><%= @is_you ? 'Freedom of Information requests made by you' : 'Freedom of Information requests made by this person' %> </h2>
+ <h2 class="foi_results" id="foi_requests"><%= @is_you ? 'Freedom of Information requests made by you' : 'Freedom of Information requests made by this person' %> <%= @match_phrase %>
+</h2>
<p><%= @is_you ? _('You have made no Freedom of Information requests using this site.') : _('This person has made no Freedom of Information requests using this site.') %>
+ <%= @page_desc %>
<% end %>
<% else %>
<h2 class="foi_results" id="foi_requests">
- <%= @is_you ? n_('Your %d Freedom of Information request', 'Your %d Freedom of Information requests', @display_user.info_requests.size) % @display_user.info_requests.size : n_('This person\'s %d Freedom of Information request', 'This person\'s %d Freedom of Information requests', @display_user.info_requests.size) % @display_user.info_requests.size %>
+ <%= @is_you ? n_('Your %d Freedom of Information request', 'Your %d Freedom of Information requests', @xapian_requests.results.size) % @xapian_requests.results.size : n_('This person\'s %d Freedom of Information request', 'This person\'s %d Freedom of Information requests', @xapian_requests.results.size) % @xapian_requests.results.size %>
<!-- matches_estimated <%=@xapian_requests.matches_estimated%> -->
- <%= @page_desc %>
+ <%= @match_phrase %>
+ <%= @page_desc %>
</h2>
+
<% for result in @xapian_requests.results %>
<%= render :partial => 'request/request_listing_via_event', :locals => { :event => result[:model], :info_request => result[:model].info_request } %>
@@ -144,7 +159,9 @@
<% if !@xapian_comments.nil? %>
<% if @xapian_comments.results.empty? %>
<% if @page == 1 %>
- <h2><%= @is_you ? _('Your annotations') : _('This person\'s annotations') %></h2>
+ <h2><%= @is_you ? _('Your annotations') : _('This person\'s annotations') %>
+ <%= @match_phrase %>
+ </h2>
<p><%= _('None made.')%></p>
<% end %>
<% else %>
diff --git a/spec/controllers/user_controller_spec.rb b/spec/controllers/user_controller_spec.rb
index 438fb8c0c..e373c8df6 100644
--- a/spec/controllers/user_controller_spec.rb
+++ b/spec/controllers/user_controller_spec.rb
@@ -32,6 +32,13 @@ describe UserController, "when showing a user" do
assigns[:display_user].should == users(:bob_smith_user)
end
+ it "should search the user's contributions" do
+ get :show, :url_name => "bob_smith"
+ assigns[:xapian_requests].results.count.should == 2
+ get :show, :url_name => "bob_smith", :user_query => "money"
+ assigns[:xapian_requests].results.count.should == 1
+ end
+
# Error handling not quite good enough for this yet
# it "should not show unconfirmed users" do
# get :show, :url_name => "silly_emnameem"