diff --git a/tracks/app/controllers/feed_controller.rb b/tracks/app/controllers/feed_controller.rb index 1f6bec1d..f4d511d4 100644 --- a/tracks/app/controllers/feed_controller.rb +++ b/tracks/app/controllers/feed_controller.rb @@ -11,25 +11,84 @@ class FeedController < ApplicationController def index end - # Builds an RSS feed for the latest 15 items - # This is fairly basic: it lists the action description as the title - # and the item context as the description - # - def na_feed - @not_done = @user.todos.collect { |x| x.done? ? nil:x }.compact.sort! {|x,y| y.created_at <=> x.created_at } + # Build an RSS feed + def rss + conditions = '(done = 0)' + options = {:conditions => conditions} + + limit = @params['limit'] + options[:limit] = limit if limit + @description = limit ? "Lists the last #{limit} uncompleted next actions" : "Lists uncompleted next actions" + @title = "Tracks - Next Actions" + + if @params['due'] + due_within = @params['due'].to_i + due_within_date_s = due_within.days.from_now.strftime("%Y-%m-%d") + conditions << " AND (due <= '#{due_within_date_s}')" + @title << " due today" if (due_within == 0) + @title << " due within a week" if (due_within == 6) + @description << " with a due date #{due_within_date_s} or earlier" + end + + context_id = @params['context'] + if context_id + conditions << " AND (context_id = #{context_id})" + context = @user.contexts.find(context_id) + @title << " in #{context.name}" + @description << " in context '#{context.name}'" + end + + project_id = @params['project'] + if project_id + conditions << " AND (project_id = #{project_id})" + project = @user.projects.find(project_id) + @title << " for #{project.name}" + @description << " for project '#{project.name}'" + end + + @todos = @user.todos.find_all_by_done(false, options ) @headers["Content-Type"] = "text/xml; charset=utf-8" end - # Builds a plain text page listing all the next actions, - # sorted by context (contexts are sorted by position, as on the home page). + # Builds a plain text page listing uncompleted next actions, + # grouped by context (contexts are sorted by position, as on the home page). # Showing notes doesn't make much sense here so they are omitted. # Hidden contexts are also hidden in the text view # You can use this with GeekTool to get your next actions # on the desktop: # curl [url from "TXT" link on todo/list] # - def na_text - @contexts = @user.contexts.collect { |x| x.hide? ? nil:x }.compact.sort! { |x,y| x.position <=> y.position } + def text + conditions = '(done = 0)' + options = {:conditions => conditions} + + limit = @params['limit'] + options[:limit] = limit if limit + + if @params['due'] + due_within = @params['due'].to_i + due_within_date_s = due_within.days.from_now.strftime("%Y-%m-%d") + conditions << " AND (due <= '#{due_within_date_s}')" + end + + context_id = @params['context'] + if context_id + conditions << " AND (context_id = #{context_id})" + context = @user.contexts.find(context_id) + @contexts = [context] + end + + project_id = @params['project'] + if project_id + conditions << " AND (project_id = #{project_id})" + project = @user.projects.find(project_id) + end + + @todos = @user.todos.find_all_by_done(false, options ) + + if (!@contexts) + @contexts = @user.contexts.find_all_by_hide(false) + end @headers["Content-Type"] = "text/plain; charset=utf-8" end diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 8e7269c0..fea42763 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -189,6 +189,11 @@ class TodoController < ApplicationController archive_date = Time.now - 32 * (60 * 60 * 24) @done_archive = @done.collect { |x| archive_date >= x.completed ? x:nil }.compact end + + def feeds + self.init + @page_title = "TRACKS::Feeds" + end protected diff --git a/tracks/app/helpers/feed_helper.rb b/tracks/app/helpers/feed_helper.rb index 28de48e1..263ff2f5 100644 --- a/tracks/app/helpers/feed_helper.rb +++ b/tracks/app/helpers/feed_helper.rb @@ -7,11 +7,10 @@ module FeedHelper # def build_text_page(list,context) result_string = "" - result_string << "\n" + context.name.upcase + ":\n" - - list.each do |item| + list.each do |item| if item.context_id == context.id - + result_string << "\n" + context.name.upcase + ":\n" if result_string.empty? + if item.due result_string << " [" + format_date(item.due) + "] " result_string << item.description + " " @@ -22,10 +21,9 @@ module FeedHelper if item.project_id result_string << "(" + item.project.name + ")" end - result_string << "\n" - end - + result_string << "\n" end + end return result_string end diff --git a/tracks/app/helpers/todo_helper.rb b/tracks/app/helpers/todo_helper.rb index 4dc72976..2ab9c19f 100644 --- a/tracks/app/helpers/todo_helper.rb +++ b/tracks/app/helpers/todo_helper.rb @@ -110,4 +110,17 @@ module TodoHelper javascript_tag str end + def rss_feed_link(options = {}) + image_tag = image_tag("feed-icon", :size => "16X16", :border => 0, :class => "rss-icon") + linkoptions = {:controller => 'feed', :action => 'rss', :name => "#{@session['user']['login']}", :token => "#{@session['user']['word']}"} + linkoptions.merge!(options) + link_to(image_tag, linkoptions, :title => "RSS feed") + end + + def text_feed_link(options = {}) + linkoptions = {:controller => 'feed', :action => 'text', :name => "#{@session['user']['login']}", :token => "#{@session['user']['word']}"} + linkoptions.merge!(options) + link_to('TXT', linkoptions, :title => "Plain text feed" ) + end + end diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb index aa3b059c..7db65399 100644 --- a/tracks/app/models/user.rb +++ b/tracks/app/models/user.rb @@ -4,7 +4,7 @@ require 'digest/sha1' class User < ActiveRecord::Base has_many :contexts, :order => "position ASC" has_many :projects, :order => "position ASC" - has_many :todos, :order => "completed DESC" + has_many :todos, :order => "completed DESC, created_at DESC" has_many :notes, :order => "created_at DESC" serialize :preferences diff --git a/tracks/app/views/feed/na_text.rhtml b/tracks/app/views/feed/na_text.rhtml deleted file mode 100644 index d02dd48e..00000000 --- a/tracks/app/views/feed/na_text.rhtml +++ /dev/null @@ -1,6 +0,0 @@ -<% -for @context in @contexts - @not_done = @context.find_not_done_todos --%> - <%= build_text_page( @not_done, @context ) %> -<% end -%> diff --git a/tracks/app/views/feed/na_feed.rxml b/tracks/app/views/feed/rss.rxml similarity index 74% rename from tracks/app/views/feed/na_feed.rxml rename to tracks/app/views/feed/rss.rxml index 4772b5f0..edf21681 100644 --- a/tracks/app/views/feed/na_feed.rxml +++ b/tracks/app/views/feed/rss.rxml @@ -1,20 +1,21 @@ xml.rss("version" => "2.0", "xmlns:dc" => "http://purl.org/dc/elements/1.1/") do xml.channel do - xml.title("Tracks - Next Actions") + xml.title(@title) xml.link("http://#{@request.host}:#{@request.port}/todo/list") - xml.description("Lists the last 15 uncompleted next actions") - @not_done.each { |i| + xml.description(@description) + @todos.each { |i| xml.item do xml.title(i.description) 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 = "
Note: All feeds show only actions that have not been marked as done.
+