aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/application.rb39
-rw-r--r--app/controllers/request_controller.rb15
-rw-r--r--app/controllers/track_controller.rb22
-rw-r--r--app/helpers/link_to_helper.rb12
-rw-r--r--app/models/track_mailer.rb13
-rw-r--r--app/models/track_thing.rb6
-rw-r--r--app/views/layouts/default.atom.erb1
-rw-r--r--app/views/request/_request_listing_via_event.rhtml4
-rw-r--r--app/views/request/show.rhtml6
-rw-r--r--app/views/track/atom_feed.atom.builder24
-rw-r--r--app/views/track/track_set.rhtml6
-rw-r--r--app/views/track_mailer/event_digest.rhtml4
-rw-r--r--app/views/user/show.rhtml9
13 files changed, 119 insertions, 42 deletions
diff --git a/app/controllers/application.rb b/app/controllers/application.rb
index 3b2b04d4f..39a676669 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.35 2008-04-03 15:29:50 francis Exp $
+# $Id: application.rb,v 1.36 2008-04-09 01:32:52 francis Exp $
class ApplicationController < ActionController::Base
@@ -124,32 +124,41 @@ class ApplicationController < ActionController::Base
end
end
+ # Convert URL name for sort by order, to Lucene query
+ def order_to_sort_by(sortby)
+ if sortby.nil?
+ return nil
+ elsif sortby == 'newest'
+ return 'created_at desc'
+ elsif sortby == 'described'
+ return 'last_described_at desc' # use this for RSS
+ else
+ raise "Unknown sort order " + @sortby
+ end
+ end
+
# Function for search
- def perform_search(query, sortby, per_page = 25)
+ def perform_search(query, sortby, per_page = 25, this_page = nil, html_highlight = true)
@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
+ order = order_to_sort_by(@sortby)
# Peform the search
@per_page = per_page
- @page = (params[:page] || "1").to_i
+ if this_page.nil?
+ @page = (params[:page] || "1").to_i
+ else
+ @page = this_page
+ end
- # XXX remember to update in models/track_mailer.rb also
+ # XXX remove duplication with models/track_mailer.rb
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>',
+ :prefix => html_highlight ? '<span class="highlight">' : "*",
+ :suffix => html_highlight ? '</span>' : "*",
:fragsize => 250,
:fields => ["solr_text_main", "title", # InfoRequestEvent
"name", "short_name", # PublicBody
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb
index b16fc93cf..e14d3ae27 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.72 2008-04-04 02:29:09 francis Exp $
+# $Id: request_controller.rb,v 1.73 2008-04-09 01:32:52 francis Exp $
class RequestController < ApplicationController
@@ -227,6 +227,19 @@ class RequestController < ApplicationController
end
end
+ # Used for links from polymorphic URLs e.g. in Atom feeds - just redirect to
+ # proper URL for the message the event refers to
+ def show_request_event
+ @info_request_event = InfoRequestEvent.find(params[:info_request_event_id])
+ if not @info_request_event.incoming_message.nil?
+ redirect_to incoming_message_url(@info_request_event.incoming_message)
+ elsif not @info_request_event.outgoing_message.nil?
+ redirect_to outgoing_message_url(@info_request_event.outgoing_message)
+ else
+ # XXX maybe there are better URLs for some events than this
+ redirect_to request_url(@info_request_event.info_request)
+ end
+ end
# Show an individual incoming message, and allow followup
def show_response
diff --git a/app/controllers/track_controller.rb b/app/controllers/track_controller.rb
index 0ea3376f5..f9d02111a 100644
--- a/app/controllers/track_controller.rb
+++ b/app/controllers/track_controller.rb
@@ -5,7 +5,9 @@
# 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.4 2008-04-04 03:02:02 francis Exp $
+# $Id: track_controller.rb,v 1.5 2008-04-09 01:32:52 francis Exp $
+
+require 'feedparser'
class TrackController < ApplicationController
@@ -15,8 +17,12 @@ class TrackController < ApplicationController
@track_thing = TrackThing.create_track_for_request(@info_request)
ret = self.track_set
if ret
- flash[:notice] = "You are " + ret + " tracking this request!"
- redirect_to request_url(@info_request)
+ 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 this request!"
+ redirect_to request_url(@info_request)
+ end
end
end
@@ -31,7 +37,7 @@ class TrackController < ApplicationController
@track_thing.track_medium = 'email_daily'
- @title = @track_thing.params[:title]
+ @title = @track_thing.params[:set_title]
if params[:track_thing]
@track_thing.track_medium = params[:track_thing][:track_medium]
end
@@ -51,6 +57,14 @@ class TrackController < ApplicationController
return "now"
end
+ # Atom feed (like RSS) for the track
+ def atom_feed
+ @track_thing = TrackThing.find(params[:track_id].to_i)
+
+ perform_search(@track_thing.track_query, @track_thing.params[:feed_sortby], 25, 1)
+ respond_to :atom
+ end
+
# Delete a track
def delete
track_thing = TrackThing.find(params[:track_id].to_i)
diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb
index 7e4b26be7..ab8915e5d 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.24 2008-04-03 18:36:57 francis Exp $
+# $Id: link_to_helper.rb,v 1.25 2008-04-09 01:32:53 francis Exp $
module LinkToHelper
@@ -24,7 +24,15 @@ module LinkToHelper
def request_admin_link(info_request)
link_to h(info_request.title), request_admin_url(info_request)
end
-
+
+ # Incoming / outgoing messages
+ def incoming_message_url(incoming_message)
+ return request_url(incoming_message.info_request)+"#incoming-"+incoming_message.id.to_s
+ end
+ def outgoing_message_url(outgoing_message)
+ return request_url(outgoing_message.info_request)+"#outgoing-"+outgoing_message.id.to_s
+ end
+
# Public bodies
def public_body_url(public_body)
return show_public_body_url(:url_name => public_body.url_name, :only_path => true)
diff --git a/app/models/track_mailer.rb b/app/models/track_mailer.rb
index 20ca104a1..119654009 100644
--- a/app/models/track_mailer.rb
+++ b/app/models/track_mailer.rb
@@ -4,7 +4,7 @@
# Copyright (c) 2008 UK Citizens Online Democracy. All rights reserved.
# Email: francis@mysociety.org; WWW: http://www.mysociety.org/
#
-# $Id: track_mailer.rb,v 1.4 2008-04-04 14:50:51 francis Exp $
+# $Id: track_mailer.rb,v 1.5 2008-04-09 01:32:53 francis Exp $
class TrackMailer < ApplicationMailer
def event_digest(user, email_about_things)
@@ -28,7 +28,7 @@ class TrackMailer < ApplicationMailer
#STDERR.puts "user " + user.url_name
email_about_things = []
- track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ?", user.id ])
+ track_things = TrackThing.find(:all, :conditions => [ "tracking_user_id = ? and track_medium = ?", user.id, 'email_daily' ])
for track_thing in track_things
#STDERR.puts " track " + track_thing.track_query
@@ -41,16 +41,17 @@ class TrackMailer < ApplicationMailer
end
# Query for things in this track
- # XXX remember to update in controllers/application.rb also
+ # XXX remove duplication with controllers/application.rb
+ #perform_search(track_thing.track_query, 'newest', 100, 1, false)
solr_object = InfoRequestEvent.multi_solr_search(track_thing.track_query, :models => [ PublicBody, User ],
- :limit => 100, :offset => 0,
+ :limit => 100, :offset => 0,
:highlight => {
- :prefix => '*', :suffix => '*',
+ :prefix => "*", :suffix => "*",
:fragsize => 250,
:fields => ["solr_text_main", "title", # InfoRequestEvent
"name", "short_name", # PublicBody
"name" # User
- ]}, :order => "created_at desc"
+ ]}, :order => 'created_at desc'
)
# Go through looking for unalerted things
diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb
index 778252c53..2ee494b9d 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.7 2008-04-04 02:29:09 francis Exp $
+# $Id: track_thing.rb,v 1.8 2008-04-09 01:32:53 francis Exp $
class TrackThing < ActiveRecord::Base
belongs_to :tracking_user, :class_name => 'User'
@@ -40,6 +40,7 @@ class TrackThing < ActiveRecord::Base
validates_inclusion_of :track_medium, :in => [
'email_daily',
+ 'feed'
]
def TrackThing.create_track_for_request(info_request)
@@ -57,10 +58,11 @@ class TrackThing < ActiveRecord::Base
if self.track_type == 'request_updates'
@params = {
# Website
- :title => "Track the request '" + CGI.escapeHTML(self.info_request.title) + "'",
+ :set_title => "How would you like to track the request '" + CGI.escapeHTML(self.info_request.title) + "'?",
:list_description => "'<a href=\"/request/" + CGI.escapeHTML(self.info_request.url_title) + "\">" + CGI.escapeHTML(self.info_request.title) + "</a>', a request", # XXX yeuch, sometimes I just want to call view helpers from the model, sorry! can't work out how
# Email
:title_in_email => "New updates for the request '" + self.info_request.title + "'",
+ :title_in_rss => "New updates for the request '" + CGI.escapeHTML(self.info_request.title) + "'",
# Authentication
:web => "To follow updates to the request '" + CGI.escapeHTML(self.info_request.title) + "'",
:email => "Then you will be emailed whenever the request '" + CGI.escapeHTML(self.info_request.title) + "' is updated.",
diff --git a/app/views/layouts/default.atom.erb b/app/views/layouts/default.atom.erb
new file mode 100644
index 000000000..37f0bddbd
--- /dev/null
+++ b/app/views/layouts/default.atom.erb
@@ -0,0 +1 @@
+<%= yield %>
diff --git a/app/views/request/_request_listing_via_event.rhtml b/app/views/request/_request_listing_via_event.rhtml
index 8e673a142..79bbe0ef4 100644
--- a/app/views/request/_request_listing_via_event.rhtml
+++ b/app/views/request/_request_listing_via_event.rhtml
@@ -4,9 +4,9 @@
<%= link_to @highlighting['InfoRequestEvent'][event.id]["title"], request_url(info_request) %>
<% @highlighting['InfoRequestEvent'][event.id].delete("title") %>
<% elsif not event.incoming_message.nil? %>
- <%= link_to "Response to '" + h(info_request.title) + "'", request_url(info_request)+"#incoming-"+event.incoming_message.id.to_s %>
+ <%= link_to "Response to '" + h(info_request.title) + "'", incoming_message_url(event.incoming_message) %>
<% elsif not event.outgoing_message.nil? and event.event_type == 'followup_sent' %>
- <%= link_to "Follow up message for '" + h(info_request.title) + "'", request_url(info_request)+"#outgoing-"+event.outgoing_message.id.to_s %>
+ <%= link_to "Follow up message for '" + h(info_request.title) + "'", outgoing_message_url(event.outgoing_message) %>
<% else %>
<%= link_to h(info_request.title), request_url(info_request) %>
<% end %>
diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml
index ff3330362..702a8c2e9 100644
--- a/app/views/request/show.rhtml
+++ b/app/views/request/show.rhtml
@@ -79,12 +79,12 @@
(<%= link_to "alter your subscriptions", user_url(@user) %>).
<% else %>
<%= link_to "Track updates to this request", track_request_url(:url_title => @info_request.url_title) %>
- (by email or RSS)
+ (by email or RSS feed)
<% end %>
</p>
<% else %>
- <%= link_to "Track updates to this request", track_request_url(:url_title => @info_request.url_title) %>
- (by email or RSS; be the first)
+ Be the first to <%= link_to "track updates to this request", track_request_url(:url_title => @info_request.url_title) %>
+ (by email or RSS feed)
<% end %>
<% if @info_requests_same_user_same_body.size > 0 %>
diff --git a/app/views/track/atom_feed.atom.builder b/app/views/track/atom_feed.atom.builder
new file mode 100644
index 000000000..627c53d11
--- /dev/null
+++ b/app/views/track/atom_feed.atom.builder
@@ -0,0 +1,24 @@
+atom_feed do |feed|
+ feed.title(@track_thing.params[:title_in_rss])
+
+ for search_result in @search_results
+ feed.entry(search_result) do |entry|
+ # Get the HTML content from the same partial template as website search does
+ content = ''
+ if search_result.class.to_s == 'InfoRequestEvent'
+ content += render :partial => 'request/request_listing_via_event', :locals => { :event => search_result, :info_request => search_result.info_request }
+ else
+ content = "<p><strong>Unknown search result type " + search_result.class.to_s + "</strong></p>"
+ end
+ # Pull out the heading as separate item, from the partial template
+ content.match(/(<a href="[^>]*">(.*)<\/a>\s+<br>)/)
+ heading = $1
+ heading_text = $2
+ content.sub!(heading, "")
+ # Render the atom
+ entry.title(heading_text, :type => 'html')
+ entry.content(content, :type => 'html')
+ end
+ end
+end
+
diff --git a/app/views/track/track_set.rhtml b/app/views/track/track_set.rhtml
index 47e4f59a1..90b767219 100644
--- a/app/views/track/track_set.rhtml
+++ b/app/views/track/track_set.rhtml
@@ -13,11 +13,9 @@
<br> -->
<%= radio_button "track_thing", "track_medium", "email_daily" %>
<label for="track_thing_track_medium_email_daily">Send me emails at most once a day</label>
- <!--
<br>
- <%= radio_button "track_thing", "track_medium", "rss" %>
- <label for="track__thingtrack_medium_rss">Give me a feed to use in my news reader (RSS)</label>
- -->
+ <%= radio_button "track_thing", "track_medium", "feed" %>
+ <label for="track_thing_track_medium_feed">Give me a feed to use in my news reader (RSS)</label>
</div>
<p class="form_note">
diff --git a/app/views/track_mailer/event_digest.rhtml b/app/views/track_mailer/event_digest.rhtml
index f88a23bdf..9c8a5ad9a 100644
--- a/app/views/track_mailer/event_digest.rhtml
+++ b/app/views/track_mailer/event_digest.rhtml
@@ -20,10 +20,10 @@
extract.gsub!(/\s+/, ' ')
if event.event_type == 'response'
- url = main_url(request_url(event.info_request))+"#incoming-"+event.incoming_message.id.to_s
+ url = incoming_message_url(event.incoming_message)
main_text += event.info_request.public_body.name + " sent a response to " + event.info_request.user.name
elsif event.event_type == 'followup_sent'
- url = main_url(request_url(event.info_request))+"#outgoing-"+event.outgoing_message.id.to_s
+ url = outgoing_message_url(event.outgoing_message)
main_text += event.info_request.user.name + " sent a follow up message to " + event.info_request.public_body.name
elsif event.event_type == 'sent'
# this is unlikely to happen in real life, but happens in the test code
diff --git a/app/views/user/show.rhtml b/app/views/user/show.rhtml
index b80ab35f5..402ccf251 100644
--- a/app/views/user/show.rhtml
+++ b/app/views/user/show.rhtml
@@ -31,7 +31,14 @@
<% for track_thing in @display_user.track_things %>
<li>
<% form_tag :controller => 'track', :action => 'delete', :track_id => track_thing.id do %>
- <%= track_thing.params[:list_description] %>
+ <%= track_thing.params[:list_description] %>,
+ <% if track_thing.track_medium == 'email_daily' %>
+ by email daily
+ <% elsif track_thing.track_medium == 'feed' %>
+ by <%= link_to "RSS feed", :controller => 'track', :action => 'atom_feed', :track_id => track_thing.id %>
+ <% else %>
+ <% raise "unknown track medium '" + track_thing.track_medium + "'" %>
+ <% end %>
<!-- (<%= link_to "view latest updates", :controller => 'general', :action => 'search', :query => track_thing.track_query %>) -->
<%= submit_tag "Delete" %>
<% end %>