From e1cb2b0f29f3dd6fcab64d89a744ce2e3016636a Mon Sep 17 00:00:00 2001 From: bsag Date: Fri, 14 Apr 2006 17:07:29 +0000 Subject: [PATCH] Added iCal subscription links. The feeds page now lists iCal links alongside each RSS and TXT feed link. Copying your chosen link and pasting it in to the text box that appears in iCal when you choose Calendar > Subscribe.. Name your calendar as you wish, but make sure that you get it to refresh periodically and that the 'Remove Todo items' checkbox is UNCHECKED (obviously ;-) ). Then your Tracks next actions should appear as todo items in iCal, with proper due dates assigned, and notes in the notes field. The todos should update periodically in iCal as you add, delete or complete items in Tracks, but the subscription is read-only from iCal's end. However, it does allow you read access on the move if you sync iCal with your Palm or mobile phone. I don't have Sunbird or any other iCal compatible calendar, but it should work with any of those too, as it follows the [http://www.ietf.org/rfc/rfc2445.txt iCalendar] standard format. git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@221 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/feed_controller.rb | 14 +++++++++ tracks/app/helpers/todo_helper.rb | 6 ++++ tracks/app/views/feed/ical.rhtml | 35 +++++++++++++++++++++++ tracks/app/views/todo/feeds.rhtml | 7 +++++ tracks/config/routes.rb | 3 +- 5 files changed, 63 insertions(+), 2 deletions(-) create mode 100644 tracks/app/views/feed/ical.rhtml diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index fc0c7f64..c934e144 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -34,6 +34,20 @@ class FeedController < ApplicationController end @headers["Content-Type"] = "text/plain; charset=utf-8" end + + # Builds an iCal compatible export of uncompleted todos + # so that each action forms a VTODO in your iCal calendar. + # Due dates are supported, and notes are included. + # + def ical + prepare_for_feed + if @params.key?('context') + @contexts = [ @user.contexts.find(@params['context']) ] + else + @contexts = @user.contexts.find_all_by_hide(false, "position ASC") + end + @headers["Content-Type"] = "text/plain; charset=utf-8" + end protected diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index 56d7a3c2..25c60f53 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -121,4 +121,10 @@ module TodoHelper link_to('TXT', linkoptions, :title => "Plain text feed" ) end + def ical_feed_link(options = {}) + linkoptions = {:controller => 'feed', :action => 'ical', :name => "#{@user.login}", :token => "#{@user.word}"} + linkoptions.merge!(options) + link_to('iCal', linkoptions, :title => "iCal feed") + end + end diff --git a/tracks/app/views/feed/ical.rhtml b/tracks/app/views/feed/ical.rhtml new file mode 100644 index 00000000..b0775335 --- /dev/null +++ b/tracks/app/views/feed/ical.rhtml @@ -0,0 +1,35 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//rousette.org.uk//Tracks 1.04//EN +CALSCALE:GREGORIAN +METHOD:PUBLISH +BEGIN:VTIMEZONE +TZID:Europe/London +LAST-MODIFIED:<%= Time.now.strftime("%Y%m%dT%H%M%SZ") %> +BEGIN:DAYLIGHT +DTSTART:20060326T020000 +TZOFFSETTO:+0100 +TZOFFSETFROM:+0000 +TZNAME:BST +END:DAYLIGHT +BEGIN:STANDARD +DTSTART:20061029T020000 +TZOFFSETTO:+0000 +TZOFFSETFROM:+0100 +TZNAME:GMT +END:STANDARD +END:VTIMEZONE +<% for @todo in @todos -%> +BEGIN:VTODO +DTSTAMP:<%= @todo.created_at.strftime("%Y%m%dT%H%M%SZ") %> +DTSTART;VALUE=DATE:<%= @todo.created_at.strftime("%Y%m%d") %> +SUMMARY:<%= @todo.description %> +<% if @todo.notes? -%> +DESCRIPTION:<%= @todo.notes %> +<% end -%> +<% if @todo.due -%> +DUE;VALUE=DATE:<%= @todo.due.strftime("%Y%m%d") %> +<% end -%> +END:VTODO +<% end -%> +END:VCALENDAR \ No newline at end of file diff --git a/tracks/app/views/todo/feeds.rhtml b/tracks/app/views/todo/feeds.rhtml index 9ecb0744..6e542e6b 100644 --- a/tracks/app/views/todo/feeds.rhtml +++ b/tracks/app/views/todo/feeds.rhtml @@ -12,6 +12,7 @@
<%= image_tag("feed-icon", :size => "16X16", :border => 0)%>
RSS Feed
TXT
Plain Text Feed
+
iCal
iCal feed

Note: All feeds show only actions that have not been marked as done.

@@ -19,21 +20,25 @@
  • <%= rss_feed_link({ :limit => 15 }) %> <%= text_feed_link({ :limit => 15 }) %> + <%= ical_feed_link({ :limit => 15 }) %> Last 15 actions
  • <%= rss_feed_link %> <%= text_feed_link %> + <%= ical_feed_link %> All actions
  • <%= rss_feed_link({ :due => 0 }) %> <%= text_feed_link({ :due => 0 }) %> + <%= ical_feed_link({ :due => 0 }) %> Actions due today or earlier
  • <%= rss_feed_link({ :due => 6 }) %> <%= text_feed_link({ :due => 6 }) %> + <%= ical_feed_link({ :due => 6 }) %> Actions due in 7 days or earlier
  • Feeds for uncompleted actions in a specific context:

    @@ -42,6 +47,7 @@
  • <%= rss_feed_link({ :context => context }) %> <%= text_feed_link({ :context => context }) %> + <%= ical_feed_link({ :context => context }) %> Next actions in <%=h context.name %>
  • <% end %> @@ -53,6 +59,7 @@
  • <%= rss_feed_link({ :project => project }) %> <%= text_feed_link({ :project => project }) %> + <%= ical_feed_link({ :project => project }) %> Next actions for <%=h project.name %>
  • <% end %> diff --git a/tracks/config/routes.rb b/tracks/config/routes.rb index ceaf1289..534a40e9 100644 --- a/tracks/config/routes.rb +++ b/tracks/config/routes.rb @@ -50,8 +50,7 @@ ActionController::Routing::Routes.draw do |map| map.connect 'notes', :controller => 'note', :action => 'index' # Feed Routes - map.connect 'feed/:action/:name/:token', :controller => 'feed' - + map.connect 'feed/:action/:name/:token', :controller => 'feed' #map.connect 'add_item', :controller => 'todo', :action => 'add_item'