From 8c7079dba567328c4ceba699a49af1ec63e958e0 Mon Sep 17 00:00:00 2001 From: bsag Date: Mon, 17 Jul 2006 18:54:12 +0000 Subject: [PATCH] Added a feed (RSS and TXT) for the actions completed in the past 7 days, as promised on the home page of the Tracks projects site, but hitherto only implemented in my imagination, and not in reality as I'd somehow assumed ;-) Fixes #323 git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@284 a4c988fc-2ded-0310-b66e-134b36920a42 --- tracks/app/controllers/feed_controller.rb | 13 ++++++++++++- tracks/app/helpers/feed_helper.rb | 6 +++++- tracks/app/views/feed/rss.rxml | 3 ++- tracks/app/views/todo/feeds.rhtml | 5 +++++ 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index 24bb9f31..aebf2158 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -76,7 +76,11 @@ protected condition_builder = FindConditionBuilder.new options = Hash.new - condition_builder.add 'todos.done = ?', false + if params.key?('done') + condition_builder.add 'todos.done = ?', true + else + condition_builder.add 'todos.done = ?', false + end if params.key?('limit') options[:limit] = limit = params['limit'] @@ -94,6 +98,13 @@ protected @description << " with a due date #{due_within_date_s} or earlier" end + if params.key?('done') + done_in_last = params['done'].to_i + condition_builder.add('todos.completed >= ?', done_in_last.days.ago) + @title << " actions completed" + @description << " in the last #{done_in_last.to_s} days" + end + if params.key?('context') context = @user.contexts.find(params['context']) condition_builder.add('todos.context_id = ?', context.id) diff --git a/tracks/app/helpers/feed_helper.rb b/tracks/app/helpers/feed_helper.rb index ce07ee6c..b05f056d 100644 --- a/tracks/app/helpers/feed_helper.rb +++ b/tracks/app/helpers/feed_helper.rb @@ -11,8 +11,12 @@ module FeedHelper if item.context_id == context.id result_string << "\n" + context.name.upcase + ":\n" if result_string.empty? + if item.completed + result_string << " [Completed: " + format_date(item.completed) + "] " + end + if item.due - result_string << " [" + format_date(item.due) + "] " + result_string << " [Due: " + format_date(item.due) + "] " result_string << item.description + " " else result_string << " " + item.description + " " diff --git a/tracks/app/views/feed/rss.rxml b/tracks/app/views/feed/rss.rxml index 7f4eee01..84470254 100644 --- a/tracks/app/views/feed/rss.rxml +++ b/tracks/app/views/feed/rss.rxml @@ -9,13 +9,14 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do xml.link(url_for(:only_path => false, :controller => 'context', :action => 'show', :name => urlize(i.context.name))) item_notes = sanitize(markdown( i.notes )) if i.notes? due = "
Due: #{format_date(i.due)}
\n" if i.due? + done = "
Completed: #{format_date(i.completed)}
\n" if i.completed? context_link = link_to( i.context.name, { :only_path => false, :controller => "context", :action => "show", :name => urlize(i.context.name) } ) project_link = if i.project_id? link_to (i.project.name, { :only_path => false, :controller => "project", :action => "show", :name => urlize(i.project.name)} ) else "none" end - xml.description("#{due||''}#{item_notes||''}\n
Project: #{project_link}
\n
Context: #{context_link}
") + xml.description("#{done||''}#{due||''}#{item_notes||''}\n
Project: #{project_link}
\n
Context: #{context_link}
") end } end diff --git a/tracks/app/views/todo/feeds.rhtml b/tracks/app/views/todo/feeds.rhtml index fd446dc6..863d9247 100644 --- a/tracks/app/views/todo/feeds.rhtml +++ b/tracks/app/views/todo/feeds.rhtml @@ -41,6 +41,11 @@ <%= ical_feed_link({ :due => 6 }) %> Actions due in 7 days or earlier +
  • + <%= rss_feed_link({ :done => 7 }) %> + <%= text_feed_link({ :done => 7 }) %> + Actions completed in the last 7 days +
  • <%= rss_feed_link({ :action => 'list_contexts_only', :feedtype => 'rss' }) %> <%= text_feed_link({ :action => 'list_contexts_only', :feedtype => 'text' }) %>