start modifying done view and do some refactoring

This commit is contained in:
Reinier Balt 2011-05-01 12:48:32 +02:00
parent de7b8e329d
commit 01057af684
19 changed files with 160 additions and 202 deletions

View file

@ -19,6 +19,7 @@ class Context < ActiveRecord::Base
validates_does_not_contain :name, :string => ',', :message => "cannot contain the comma (',') character"
def self.feed_options(user)
# TODO: move to view or helper
{
:title => 'Tracks Contexts',
:description => "Lists all the contexts for #{user.display_name}"
@ -36,14 +37,7 @@ class Context < ActiveRecord::Base
def title
name
end
def summary(undone_todo_count)
s = "<p>#{undone_todo_count}. "
s += "Context is #{hidden? ? 'Hidden' : 'Active'}."
s += "</p>"
s
end
def new_record_before_save?
@new_record_before_save
end

View file

@ -1,28 +1,5 @@
class Project < ActiveRecord::Base
has_many :todos, :dependent => :delete_all
# TODO: remove these scopes. Can be replaced by the named scopes on the todo relation
has_many :not_done_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:conditions => ["todos.state = ?", 'active']
has_many :done_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:order => "todos.due IS NULL, todos.due ASC, todos.created_at ASC",
:conditions => ["todos.state = ?", 'completed']
has_many :deferred_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:conditions => ["todos.state = ? ", "deferred"],
:order => "show_from"
has_many :pending_todos,
:include => [:context,:tags,:project],
:class_name => 'Todo',
:conditions => ["todos.state = ? ", "pending"],
:order => "show_from"
has_many :notes, :dependent => :delete_all, :order => "created_at DESC"
has_many :recurring_todos

View file

@ -1,5 +1,8 @@
class Todo < ActiveRecord::Base
after_save :save_predecessors
# relations
belongs_to :context
belongs_to :project
belongs_to :user
@ -13,20 +16,17 @@ class Todo < ActiveRecord::Base
:source => :predecessor, :conditions => ['NOT (todos.state = ?)', 'completed']
has_many :pending_successors, :through => :predecessor_dependencies,
:source => :successor, :conditions => ['todos.state = ?', 'pending']
after_save :save_predecessors
# scopes for states of this todo
named_scope :active, :conditions => { :state => 'active' }
named_scope :active_or_hidden, :conditions => ["todos.state = ? OR todos.state = ?", 'active', 'project_hidden']
named_scope :not_completed, :conditions => ['NOT (todos.state = ? )', 'completed']
named_scope :completed, :conditions => ["NOT(todos.completed_at IS NULL)"]
named_scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
named_scope :deferred, :conditions => ["todos.completed_at IS NULL AND NOT(todos.show_from IS NULL)"]
named_scope :not_completed, :conditions => ['NOT (todos.state = ?)', 'completed']
named_scope :completed, :conditions => ["NOT (todos.completed_at IS NULL)"]
named_scope :deferred, :conditions => ["todos.completed_at IS NULL AND NOT (todos.show_from IS NULL)"]
named_scope :blocked, :conditions => ['todos.state = ?', 'pending']
named_scope :pending, :conditions => ['todos.state = ?', 'pending']
named_scope :deferred_or_blocked, :conditions => ["(todos.completed_at IS NULL AND NOT(todos.show_from IS NULL)) OR (todos.state = ?)", "pending"]
named_scope :not_deferred_or_blocked, :conditions => ["todos.completed_at IS NULL AND todos.show_from IS NULL AND NOT(todos.state = ?)", "pending"]
named_scope :with_tag, lambda { |tag| {:joins => :taggings, :conditions => ["taggings.tag_id = ? ", tag.id] } }
named_scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
named_scope :hidden,
:joins => :context,
:conditions => ["todos.state = ? OR (contexts.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?))",
@ -36,6 +36,13 @@ class Todo < ActiveRecord::Base
:conditions => ['NOT(todos.state = ? OR (contexts.hide = ? AND (todos.state = ? OR todos.state = ? OR todos.state = ?)))',
'project_hidden', true, 'active', 'deferred', 'pending']
# other scopes
named_scope :are_due, :conditions => ['NOT (todos.due IS NULL)']
named_scope :with_tag, lambda { |tag| {:joins => :taggings, :conditions => ["taggings.tag_id = ? ", tag.id] } }
named_scope :of_user, lambda { |user_id| {:conditions => ["todos.user_id = ? ", user_id] } }
named_scope :completed_after, lambda { |date| {:conditions => ["todos.completed_at > ? ", date] } }
named_scope :completed_before, lambda { |date| {:conditions => ["todos.completed_at < ? ", date] } }
STARRED_TAG_NAME = "starred"
# regular expressions for dependencies
@ -302,7 +309,7 @@ class Todo < ActiveRecord::Base
context_id = default_context_id
unless(context.nil?)
found_context = user.active_contexts.find_by_namepart(context)
found_context = user.contexts.active.find_by_namepart(context)
found_context = user.contexts.find_by_namepart(context) if found_context.nil?
context_id = found_context.id unless found_context.nil?
end
@ -318,7 +325,7 @@ class Todo < ActiveRecord::Base
found_project.name = project[4..255+4].strip
found_project.save!
else
found_project = user.active_projects.find_by_namepart(project)
found_project = user.projects.active.find_by_namepart(project)
found_project = user.projects.find_by_namepart(project) if found_project.nil?
end
project_id = found_project.id unless found_project.nil?

View file

@ -79,19 +79,9 @@ class User < ActiveRecord::Base
return find(:all, :conditions => scope_conditions)
end
end
has_many :active_projects,
:class_name => 'Project',
:order => 'projects.position ASC',
:conditions => [ 'state = ?', 'active' ]
has_many :active_contexts,
:class_name => 'Context',
:order => 'position ASC',
:conditions => [ 'hide = ?', false ]
has_many :todos,
:order => 'todos.completed_at DESC, todos.created_at DESC',
:dependent => :delete_all
has_many :project_hidden_todos,
:conditions => ['(state = ? OR state = ?)', 'project_hidden', 'active']
has_many :recurring_todos,
:order => 'recurring_todos.completed_at DESC, recurring_todos.created_at DESC',
:dependent => :delete_all
@ -103,23 +93,6 @@ class User < ActiveRecord::Base
find(:all, :conditions => ['show_from <= ?', Time.zone.now ]).collect { |t| t.activate! }
end
end
has_many :pending_todos,
:class_name => 'Todo',
:conditions => [ 'state = ?', 'pending' ],
:order => 'show_from ASC, todos.created_at DESC'
has_many :completed_todos,
:class_name => 'Todo',
:conditions => ['todos.state = ? AND NOT(todos.completed_at IS 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, :dependent => :destroy