aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/application.rb39
-rw-r--r--app/controllers/request_controller.rb15
-rw-r--r--app/controllers/track_controller.rb22
3 files changed, 56 insertions, 20 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)