aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/controllers/general_controller.rb4
-rw-r--r--app/controllers/track_controller.rb18
-rw-r--r--app/helpers/link_to_helper.rb4
-rw-r--r--app/models/track_thing.rb31
-rw-r--r--app/views/general/search.rhtml7
-rw-r--r--config/routes.rb3
-rw-r--r--todo.txt9
7 files changed, 60 insertions, 16 deletions
diff --git a/app/controllers/general_controller.rb b/app/controllers/general_controller.rb
index 3c94940dd..aafd76ff3 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.23 2008-05-15 17:40:43 francis Exp $
+# $Id: general_controller.rb,v 1.24 2008-05-15 22:47:16 francis Exp $
class GeneralController < ApplicationController
@@ -73,6 +73,8 @@ class GeneralController < ApplicationController
# Spelling and highight words are same for all three queries
@spelling_correction = @xapian_requests.spelling_correction
@highlight_words = @xapian_requests.words_to_highlight
+
+ @track_thing = TrackThing.create_track_for_search_query(query)
end
# For debugging
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index 7f0553a34..b37afc6d5 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_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: track_controller.rb,v 1.17 2008-05-15 17:40:43 francis Exp $
+# $Id: track_controller.rb,v 1.18 2008-05-15 22:47:16 francis Exp $
class TrackController < ApplicationController
@@ -95,6 +95,22 @@ class TrackController < ApplicationController
end
end
+ # Track a search term
+ def track_search_query
+ @query = params[:query]
+ @track_thing = TrackThing.create_track_for_search_query(@query)
+ ret = self.track_set
+ if ret
+ if @track_thing.track_medium == 'feed'
+ redirect_to :controller => 'track', :action => 'atom_feed', :track_id => @track_thing.id
+ else
+ flash[:notice] = "You are " + ret + " tracking the search '" + CGI.escapeHTML(@query) + "' !"
+ redirect_to user_url(@track_user)
+ end
+ end
+ end
+
+
# Generic request tracker - set @track_thing before calling
def track_set
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index c5556bfa2..cb4b7e5b6 100644
--- a/app/helpers/link_to_helper.rb
+++ b/app/helpers/link_to_helper.rb
@@ -5,7 +5,7 @@
# Copyright (c) 2007 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: link_to_helper.rb,v 1.30 2008-05-12 10:57:44 francis Exp $
+# $Id: link_to_helper.rb,v 1.31 2008-05-15 22:47:16 francis Exp $
module LinkToHelper
@@ -93,6 +93,8 @@ module LinkToHelper
track_public_body_url(:url_name => track_thing.public_body.url_name)
elsif track_thing.track_type == 'user_updates'
track_user_url(:url_name => track_thing.tracked_user.url_name)
+ elsif track_thing.track_type == 'search_query'
+ track_search_url(track_thing.track_query)
else
raise "unknown tracking type " + track_thing.track_type
end
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 86349d761..3d7b29578 100644
--- a/app/models/track_thing.rb
+++ b/app/models/track_thing.rb
@@ -21,7 +21,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: track_thing.rb,v 1.18 2008-05-15 22:18:19 francis Exp $
+# $Id: track_thing.rb,v 1.19 2008-05-15 22:47:16 francis Exp $
class TrackThing < ActiveRecord::Base
belongs_to :tracking_user, :class_name => 'User'
@@ -39,7 +39,8 @@ class TrackThing < ActiveRecord::Base
'all_new_requests',
'all_successful_requests',
'public_body_updates',
- 'user_updates'
+ 'user_updates',
+ 'search_query'
]
validates_inclusion_of :track_medium, :in => [
@@ -85,6 +86,13 @@ class TrackThing < ActiveRecord::Base
return track_thing
end
+ def TrackThing.create_track_for_search_query(query)
+ track_thing = TrackThing.new
+ track_thing.track_type = 'search_query'
+ track_thing.track_query = query
+ return track_thing
+ end
+
# Return hash of text parameters describing the request etc.
include LinkToHelper
def params
@@ -174,7 +182,24 @@ class TrackThing < ActiveRecord::Base
# Other
:feed_sortby => 'described', # for RSS, as newest would give a date for responses possibly days before description
}
- else
+ elsif self.track_type == 'search_query'
+ @params = {
+ # Website
+ :set_title => "How would you like to be updated about new requests and responses matching '" + CGI.escapeHTML(self.track_query) + "'?",
+ :list_description => "requests and responses matching '<a href=\"/search/" + CGI.escapeHTML(self.track_query) + "/newest\">" + CGI.escapeHTML(self.track_query) + "</a>'", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
+ :verb_on_page => "Track new requests and responses matching '" + CGI.escapeHTML(self.track_query) + "'",
+ :verb_on_page_already => "tracking '" + CGI.escapeHTML(self.track_query) + "'",
+ # Email
+ :title_in_email => "Requests or responses matching '" + self.track_query + "'",
+ :title_in_rss => "Requests or responses matching '" + self.track_query + "'",
+ # Authentication
+ :web => "To follow requests and responses matching '" + CGI.escapeHTML(self.track_query) + "'",
+ :email => "Then you will be emailed whenever a new request or response matches '" + CGI.escapeHTML(self.track_query) + "'.",
+ :email_subject => "Confirm you want to be told about new requests or responses matching '" + CGI.escapeHTML(self.track_query) + "'",
+ # Other
+ :feed_sortby => 'described', # for RSS, as newest would give a date for responses possibly days before description
+ }
+ else
raise "unknown tracking type " + self.track_type
end
end
diff --git a/app/views/general/search.rhtml b/app/views/general/search.rhtml
index 839fe0155..0526d2026 100644
--- a/app/views/general/search.rhtml
+++ b/app/views/general/search.rhtml
@@ -35,6 +35,10 @@
<p id="did_you_mean">Did you mean: <%= link_to @spelling_correction, search_url(@spelling_correction, @sortby) %></p>
<% end %>
+ <% if @track_thing %>
+ <%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => false, :list_people => false } %>
+ <% end %>
+
<% if @xapian_bodies.results.size > 0 %>
<h1><%= "Public authorities " + ((@page-1)*@per_page+1).to_s + "-" + [@page*@per_page, @xapian_bodies.matches_estimated].min.to_s + " of " + @xapian_bodies.matches_estimated.to_s + " for '" + h(@query) + "'" %></h1>
@@ -63,6 +67,9 @@
<% end %>
<%= will_paginate WillPaginate::Collection.new(@page, @per_page, @xapian_requests.matches_estimated) %>
+ <% if @track_thing %>
+ <%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => false, :list_people => false } %>
+ <% end %>
<% end %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index 9b8b34270..61dae0b31 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.61 2008-05-12 10:57:44 francis Exp $
+# $Id: routes.rb,v 1.62 2008-05-15 22:47:16 francis Exp $
ActionController::Routing::Routes.draw do |map|
@@ -64,6 +64,7 @@ ActionController::Routing::Routes.draw do |map|
track.track_list '/track/list/:view', :action => 'track_list', :view => nil
track.track_public_body "/track/body/:url_name", :action => 'track_public_body'
track.track_user "/track/user/:url_name", :action => 'track_user'
+ track.track_search "/track/search/:query", :action => 'track_search_query'
track.update '/track/update/:track_id', :action => 'update'
track.atom_feed '/track/feed/:track_id', :action => 'atom_feed'
diff --git a/todo.txt b/todo.txt
index 10fee63c6..81f8a3288 100644
--- a/todo.txt
+++ b/todo.txt
@@ -1,9 +1,3 @@
-highlight_words
-
-@search_spelling = xapian_object.spelling_correction
-@highlight_words = xapian_object.words_to_highlight
-
-
FOI requests to use to test it
==============================
@@ -39,9 +33,6 @@ Next
Unusual FOI response subject should have name of request
-Things to track
- - anything requesty with keyword
-
In email alerts, show request heading somewhere
Blog posts / Wikipedia articles about this request