aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/models/track_thing.rb60
-rw-r--r--app/views/general/search.rhtml4
-rw-r--r--public/stylesheets/theme.css13
-rw-r--r--spec/models/track_thing_spec.rb10
4 files changed, 74 insertions, 13 deletions
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 82848341d..06514dd4e 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -22,6 +22,7 @@
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
# $Id: track_thing.rb,v 1.53 2009-09-17 21:10:05 francis Exp $
+require 'set'
class TrackThing < ActiveRecord::Base
belongs_to :tracking_user, :class_name => 'User'
@@ -67,6 +68,63 @@ class TrackThing < ActiveRecord::Base
TrackThing.track_type_description(self.track_type)
end
+ def track_query_description
+ # XXX this is very brittle... we should probably ask users
+ # simply to name their tracks when they make them?
+ self.track_query = self.track_query.gsub(/([()]|OR)/, "")
+ filters = self.track_query.scan /\b\S+:\S+\b/
+ text = self.track_query
+ varieties = Set.new
+ date = ""
+ statuses = Set.new
+ for filter in filters
+ text = text.sub(filter, "")
+ if filter =~ /variety:user/
+ varieties << _("users")
+ end
+ if filter =~ /variety:comment/
+ varieties << _("comments")
+ end
+ if filter =~ /variety:authority/
+ varieties << _("authorities")
+ end
+ if filter =~ /(variety:(sent|followup_sent|response)|latest_status)/
+ varieties << _("requests")
+ end
+ if filter =~ /[0-9\/]+\.\.[0-9\/]+/
+ date = _("between two dates")
+ end
+ if filter =~ /(rejected|not_held)/
+ statuses << _("unsuccessful")
+ end
+ if filter =~ /(:successful|:partially_successful)/
+ statuses << _("successful")
+ end
+ if filter =~ /waiting/
+ statuses << _("awaiting a response")
+ end
+ end
+ if filters.empty?
+ text = self.track_query
+ end
+ descriptions = []
+ if varieties.include? _("requests")
+ descriptions << _("requests which are {{list_of_statuses}}", :list_of_statuses => Array(statuses).join(_(' or ')))
+ varieties -= [_("requests")]
+ end
+ if descriptions.empty? and varieties.empty?
+ varieties << _("anything")
+ end
+ descriptions += Array(varieties)
+ text = text.strip
+ descriptions = descriptions.join(_(" or "))
+ if !text.empty?
+ descriptions += _("{{list_of_things}} matching text '{{search_query}}'", :list_of_things => "", :search_query => text)
+ end
+ return descriptions
+ end
+
+
def TrackThing.create_track_for_request(info_request)
track_thing = TrackThing.new
track_thing.track_type = 'request_updates'
@@ -217,7 +275,7 @@ class TrackThing < ActiveRecord::Base
elsif self.track_type == 'search_query'
@params = {
# Website
- :list_description => "'<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest\">" + CGI.escapeHTML(self.track_query) + "</a>' in new requests/responses", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :list_description => "<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest/advanced\">" + self.track_query_description + "</a>", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
:verb_on_page => _("Track things matching this search by email"),
:verb_on_page_already => _("You are already tracking things matching this search by email"),
# Email
diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml
index 3bea54158..ba060d33c 100644
--- a/app/views/general/search.rhtml
+++ b/app/views/general/search.rhtml
@@ -20,10 +20,11 @@
<% end%>
<% if @advanced %>
+ <div id="advanced-search">
<p><%= _('To use the advanced search, combine phrases and labels as described in the search tips below.') %></p>
<% form_tag(advanced_search_url, :method => "get") do %>
<p>
- <%= text_field_tag :query, params[:query], { :size => 40 } %>
+ <%= text_field_tag :query, @query, { :size => 60 } %>
<%= hidden_field_tag 'sortby', @inputted_sortby %>
<% if @bodies %>
<%= hidden_field_tag 'bodies', 1 %>
@@ -32,6 +33,7 @@
&nbsp;&nbsp;<%= link_to _('Simple search'), search_redirect_path %>
</p>
<% end %>
+ </div>
<% else %>
<% form_tag(request.url, {:method => "get", :id => "search_form"}) do %>
<p>
diff --git a/public/stylesheets/theme.css b/public/stylesheets/theme.css
index 724fa8a82..7fcb823c4 100644
--- a/public/stylesheets/theme.css
+++ b/public/stylesheets/theme.css
@@ -369,17 +369,8 @@ p.subtitle {
margin:0px -6px 20px 0px;
}
-#search_form input[type=text] {
- margin-right:-6px;
- font-size: 17px;
- color: #555;
- border-radius: 3px 0px 0px 3px;
- -moz-border-radius: 3px 0px 0px 3px;
- border-style: solid;
- border-color: #BBB;
- border-width: 1px;
- width: 250px;
- height: 18px;
+#advanced-search input[type=text] {
+ width: auto;
}
#search_form input[type=submit] {
diff --git a/spec/models/track_thing_spec.rb b/spec/models/track_thing_spec.rb
index 6b9cd6d4a..1a0324a78 100644
--- a/spec/models/track_thing_spec.rb
+++ b/spec/models/track_thing_spec.rb
@@ -28,5 +28,15 @@ describe TrackThing, "when tracking changes" do
found_track.should == @track_thing
end
+ it "will make some sane descriptions of search-based tracks" do
+ tests = [['bob variety:user', "users matching text 'bob'"],
+ ['bob (variety:sent OR variety:followup_sent OR variety:response OR variety:comment) (latest_status:successful OR latest_status:partially_successful OR latest_status:rejected OR latest_status:not_held)', "requests which are successful or unsuccessful or comments matching text 'bob'"],
+ ['(latest_status:waiting_response OR latest_status:waiting_clarification OR waiting_classification:true)', 'requests which are awaiting a response']]
+ for query, description in tests
+ track_thing = TrackThing.create_track_for_search_query(query)
+ track_thing.track_query_description.should == description
+ end
+ end
+
end