diff options
author | francis <francis> | 2008-05-12 08:35:24 +0000 |
---|---|---|
committer | francis <francis> | 2008-05-12 08:35:24 +0000 |
commit | f743dbb49a82ccd38a4c24a682c60a1ae1663258 (patch) | |
tree | 5ac98f9cc347f54008a314d1140cdba49e7da191 | |
parent | 3caa59078b3f0c2673797690df10aab4249c6ef2 (diff) |
Generalise links to tracking.
-rw-r--r-- | app/controllers/request_controller.rb | 10 | ||||
-rw-r--r-- | app/helpers/link_to_helper.rb | 13 | ||||
-rw-r--r-- | app/models/track_thing.rb | 12 | ||||
-rw-r--r-- | app/views/request/list.rhtml | 17 | ||||
-rw-r--r-- | app/views/request/show.rhtml | 32 | ||||
-rw-r--r-- | app/views/track/_tracking_people_and_link.rhtml | 43 |
6 files changed, 74 insertions, 53 deletions
diff --git a/app/controllers/request_controller.rb b/app/controllers/request_controller.rb index 7bf2deba0..a4d8beba6 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.81 2008-05-12 01:53:41 francis Exp $ +# $Id: request_controller.rb,v 1.82 2008-05-12 08:35:24 francis Exp $ class RequestController < ApplicationController @@ -40,9 +40,8 @@ class RequestController < ApplicationController @info_requests_same_user_same_body_more = true end - # Already tracking? + # Track corresponding to this page @track_thing = TrackThing.create_track_for_request(@info_request) - @existing_track = TrackThing.find_by_existing_track(@user, @track_thing.track_query) end def list @@ -52,9 +51,8 @@ class RequestController < ApplicationController @title = "Recently sent Freedom of Information requests" query = "variety:sent"; sortby = "newest" - # Already tracking? - @track_thing = TrackThing.create_track_for_all_new_requests() - @existing_track = TrackThing.find_by_existing_track(@user, @track_thing.track_query) + # Track corresponding to this page + @track_thing = TrackThing.create_track_for_all_new_requests elsif @view == 'successful' @title = "Recent successful responses" query = 'variety:response (status:successful OR status:partially_successful)' diff --git a/app/helpers/link_to_helper.rb b/app/helpers/link_to_helper.rb index bc0bdbafe..75b2a9589 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.26 2008-04-30 00:37:50 francis Exp $ +# $Id: link_to_helper.rb,v 1.27 2008-05-12 08:35:25 francis Exp $ module LinkToHelper @@ -81,6 +81,17 @@ module LinkToHelper link_to h(user.name), user_admin_url(user) end + # Teacks + def do_track_url(track_thing) + if track_thing.track_type == 'request_updates' + track_request_url(:url_title => track_thing.info_request.url_title) + elsif track_thing.track_type == 'all_new_requests' + track_new_requests_url + else + raise "unknown tracking type " + track_thing.track_type + end + end + # General pages def search_url(query, sortby = nil) if sortby.nil? diff --git a/app/models/track_thing.rb b/app/models/track_thing.rb index bf329b5dc..f808856d9 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.13 2008-05-12 01:53:41 francis Exp $ +# $Id: track_thing.rb,v 1.14 2008-05-12 08:35:25 francis Exp $ class TrackThing < ActiveRecord::Base belongs_to :tracking_user, :class_name => 'User' @@ -68,6 +68,8 @@ class TrackThing < ActiveRecord::Base # Website :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 + :verb_on_page => "Track updates to this request", + :verb_on_page_already => "tracking this request", # Email :title_in_email => "New updates for the request '" + self.info_request.title + "'", :title_in_rss => "New updates for the request '" + self.info_request.title + "'", @@ -83,6 +85,8 @@ class TrackThing < ActiveRecord::Base # Website :set_title => "How would you like to be told about any new requests?", :list_description => "any <a href=\"/list\">new requests</a>", + :verb_on_page => "Be told about any new requests", + :verb_on_page_already => "being told about any new requests", # Email :title_in_email => "New Freedom of Information requests", :title_in_rss => "New Freedom of Information requests", @@ -93,7 +97,7 @@ class TrackThing < ActiveRecord::Base # Other :feed_sortby => 'described', # for RSS, as newest would give a date for responses possibly days before description } - else + else raise "unknown tracking type " + self.track_type end end @@ -108,6 +112,10 @@ class TrackThing < ActiveRecord::Base return TrackThing.find(:first, :conditions => [ 'tracking_user_id = ? and track_query = ?', tracking_user.id, track_query ] ) end + # List of people tracking same thing + def TrackThing.find_tracking_people(track_query) + return TrackThing.find(:all, :conditions => [ 'track_query = ?', track_query ]).map { |t| t.tracking_user } + end end diff --git a/app/views/request/list.rhtml b/app/views/request/list.rhtml index 6688dedb1..aac9f57a6 100644 --- a/app/views/request/list.rhtml +++ b/app/views/request/list.rhtml @@ -1,9 +1,5 @@ -<% if @existing_track %> -<p>You are already being told about any new requests (<%= link_to "alter your subscriptions", user_url(@user) %>).</p> -<% elsif @view.nil? %> -<p><%= link_to "Be told about any new requests", track_new_requests_url() %> -(by email or RSS feed <img src="/images/feed-14.png" alt="" class="rss">) -</p> +<% if @track_thing %> + <%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => false, :list_people => false } %> <% end %> <h1><%=@title%></h1> @@ -22,11 +18,6 @@ <%= will_paginate WillPaginate::Collection.new(@page, @per_page, @search_hits) %> -<% if @existing_track %> -<p>You are already being told about any new requests. (<%= link_to "alter your subscriptions", user_url(@user) %>).</p> -<% elsif @view.nil? %> -<p><%= link_to "Be told about any new requests", track_new_requests_url() %> -(by email or RSS feed <img src="/images/feed-14.png" alt="" class="rss">) -</p> +<% if @track_thing %> + <%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => false, :list_people => false } %> <% end %> - diff --git a/app/views/request/show.rhtml b/app/views/request/show.rhtml index a13a129b5..a994df6cd 100644 --- a/app/views/request/show.rhtml +++ b/app/views/request/show.rhtml @@ -8,37 +8,7 @@ <div id="request_sidebar"> <h2>People tracking this request</h2> - <% if @info_request.track_things.size > 0 %> - <ul> - <% for track_thing in @info_request.track_things %> - <li><%=user_link(track_thing.tracking_user)%></li> - <% end %> - </ul> - <p> - <% if @existing_track %> - You are already tracking this request - (<%= link_to "alter your subscriptions", user_url(@user) %>). - <% else %> - <% if @info_request.user == @user %> - <p>You will be emailed when there are updates to your own request.</p> - <p>You may also <%= link_to "get an RSS feed", track_request_url(:url_title => @info_request.url_title) %> - <img src="/images/feed-14.png" alt="" class="rss"></p> - <% else %> - <%= link_to "Track updates to this request", track_request_url(:url_title => @info_request.url_title) %> - (by email or RSS feed <img src="/images/feed-14.png" alt="" class="rss">) - <% end %> - <% end %> - </p> - <% else %> - <% if @info_request.user == @user %> - <p>You will be emailed when there are updates to your own request.</p> - <p>You may also get an <%= link_to 'RSS feed', track_request_url(:url_title => @info_request.url_title) %> - <img src="/images/feed-14.png" alt="" class="rss"></p> - <% else %> - <p>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 <img src="/images/feed-14.png" alt="" class="rss">)</p> - <% end %> - <% end %> + <%= render :partial => 'track/tracking_people_and_link', :locals => { :track_thing => @track_thing, :own_request => @info_request.user == @user, :list_people => true } %> <h2>Act on this request</h2> <p> diff --git a/app/views/track/_tracking_people_and_link.rhtml b/app/views/track/_tracking_people_and_link.rhtml new file mode 100644 index 000000000..fbbda245a --- /dev/null +++ b/app/views/track/_tracking_people_and_link.rhtml @@ -0,0 +1,43 @@ +<% + existing_track = TrackThing.find_by_existing_track(@user, track_thing.track_query) + if list_people + tracking_people = TrackThing.find_tracking_people(track_thing.track_query) + end +%> + +<% if not list_people %> + <p><%= link_to track_thing.params[:verb_on_page], do_track_url(track_thing) %> + (by email or RSS feed <img src="/images/feed-14.png" alt="" class="rss">)</p> +<% elsif tracking_people.size > 0 %> + <ul> + <% for u in tracking_people %> + <li><%=user_link(u)%></li> + <% end %> + </ul> + <p> + <% if existing_track %> + You are already <%= track_thing.params[:verb_on_page_already] %> + (<%= link_to "alter your subscriptions", user_url(@user) %>). + <% else %> + <% if own_request %> + <p>You will be emailed when there are updates to your own request.</p> + <p>You may also <%= link_to "get an RSS feed", do_track_url(track_thing) %> + <img src="/images/feed-14.png" alt="" class="rss"></p> + <% else %> + <%= link_to track_thing.params[:verb_on_page], do_track_url(track_thing) %> + (by email or RSS feed <img src="/images/feed-14.png" alt="" class="rss">) + <% end %> + <% end %> + </p> +<% else %> + <% if own_request %> + <p>You will be emailed when there are updates to your own request.</p> + <p>You may also get an <%= link_to 'RSS feed', do_track_url(track_thing) %> + <img src="/images/feed-14.png" alt="" class="rss"></p> + <% else %> + <p>Be the first to <%= link_to track_thing.params[:verb_on_page].downcase, do_track_url(track_thing) %> + (by email or RSS feed <img src="/images/feed-14.png" alt="" class="rss">)</p> + <% end %> +<% end %> + + |