diff --git a/tracks/app/controllers/todo_controller.rb b/tracks/app/controllers/todo_controller.rb index 75df0f9f..b9804e54 100644 --- a/tracks/app/controllers/todo_controller.rb +++ b/tracks/app/controllers/todo_controller.rb @@ -16,15 +16,8 @@ class TodoController < ApplicationController # If you've set no_completed to zero, the completed items box # isn't shown on the home page - max_completed = @user.preference.show_number_completed - 1 - @done = nil - if max_completed > 0 - @done = Todo.find(:all, - :conditions => ['todos.user_id = ? and todos.state = ?', @user.id, 'completed'], - :order => 'todos.completed_at DESC', - :limit => max_completed, - :include => [ :project, :context ]) - end + max_completed = @user.preference.show_number_completed + @done = @user.completed_todos.find(:all, :limit => max_completed) unless max_completed == 0 @contexts_to_show = @contexts.reject {|x| x.hide? } @@ -221,7 +214,7 @@ class TodoController < ApplicationController def completed @page_title = "TRACKS::Completed tasks" - @done = Todo.find_completed(@user.id) + @done = @user.completed_todos @done_today = @done.completed_within 1.day.ago @done_this_week = @done.completed_within 1.week.ago @done_this_month = @done.completed_within 4.week.ago @@ -229,34 +222,27 @@ class TodoController < ApplicationController def completed_archive @page_title = "TRACKS::Archived completed tasks" - @done = Todo.find_completed(@user.id) + @done = @user.completed_todos @done_archive = @done.completed_more_than 28.day.ago end def tickler @source_view = 'deferred' @page_title = "TRACKS::Tickler" - @tickles = @user.todos.find_in_state(:all, :deferred, :order => "show_from ASC") + @tickles = @user.deferred_todos @count = @tickles.size end # Check for any due tickler items, activate them # Called by periodically_call_remote def check_tickler - now = Date.today() - @due_tickles = @user.todos.find_in_state(:all, :deferred, :conditions => ['show_from < ? OR show_from = ?', now, now ], :order => "show_from ASC") - # Change the due tickles to active - @due_tickles.each do |t| - t.activate! - t.save - end - respond_to do |wants| - wants.html { redirect_to :controller => 'todo', :action => 'index' } - wants.js + @due_tickles = @user.deferred_todos.find_and_activate_ready + respond_to do |format| + format.html { redirect_to :controller => 'todo', :action => 'index' } + format.js end end - private def check_user_return_item diff --git a/tracks/app/models/todo.rb b/tracks/app/models/todo.rb index aa0c79f4..d02052f5 100644 --- a/tracks/app/models/todo.rb +++ b/tracks/app/models/todo.rb @@ -57,6 +57,11 @@ class Todo < ActiveRecord::Base complete! end end + + def activate_and_save! + activate! + save! + end def show_from=(date) activate! if deferred? && date.blank? @@ -73,33 +78,11 @@ class Todo < ActiveRecord::Base alias_method :original_set_initial_state, :set_initial_state def set_initial_state - if show_from && (show_from > Date.today()) + if show_from && (show_from > Date.today) write_attribute self.class.state_column, 'deferred' else original_set_initial_state end end - - def self.not_done( id=id ) - self.find(:all, :conditions =>[ "done = ? AND context_id = ?", false, id], :order =>"due IS NULL, due ASC, created_at ASC") - end - - def self.find_completed(user_id) - done = self.find(:all, - :conditions => ['todos.user_id = ? and todos.state = ? and todos.completed_at is not null', user_id, 'completed'], - :order => 'todos.completed_at DESC', - :include => [ :project, :context ]) - - def done.completed_within( date ) - reject { |x| x.completed_at < date } - end - - def done.completed_more_than( date ) - reject { |x| x.completed_at > date } - end - - done - - end - -end + +end \ No newline at end of file diff --git a/tracks/app/models/user.rb b/tracks/app/models/user.rb index 96b524ec..3f0e5894 100644 --- a/tracks/app/models/user.rb +++ b/tracks/app/models/user.rb @@ -1,9 +1,36 @@ require 'digest/sha1' class User < ActiveRecord::Base - has_many :contexts, :order => "position ASC", :dependent => :delete_all - has_many :projects, :order => "position ASC", :dependent => :delete_all - has_many :todos, :order => "completed_at DESC, created_at DESC", :dependent => :delete_all + has_many :contexts, + :order => 'position ASC', + :dependent => :delete_all + has_many :projects, + :order => 'position ASC', + :dependent => :delete_all + has_many :todos, + :order => 'completed_at DESC, created_at DESC', + :dependent => :delete_all + has_many :deferred_todos, + :class_name => 'Todo', + :conditions => [ 'state = ?', 'deferred' ], + :order => 'show_from ASC, created_at DESC' do + def find_and_activate_ready + find(:all, :conditions => ['show_from <= ?', Date.today ]).collect { |t| t.activate_and_save! } + end + end + has_many :completed_todos, + :class_name => 'Todo', + :conditions => ['todos.state = ? and todos.completed_at is not null', 'completed'], + :order => 'todos.completed_at DESC', + :include => [ :project, :context ] do + def completed_within( date ) + reject { |x| x.completed_at < date } + end + + def completed_more_than( date ) + reject { |x| x.completed_at > date } + end + end has_many :notes, :order => "created_at DESC", :dependent => :delete_all has_one :preference diff --git a/tracks/app/views/feed/index.rhtml b/tracks/app/views/feed/index.rhtml deleted file mode 100644 index 4a1b6f0e..00000000 --- a/tracks/app/views/feed/index.rhtml +++ /dev/null @@ -1,82 +0,0 @@ -
-
-
-

Legend:

-
-
<%= image_tag("feed-icon.png", :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.

-
- -
-
- -
- <%= render "sidebar/sidebar" %> -
\ No newline at end of file