mirror of
https://github.com/TracksApp/tracks.git
synced 2026-03-16 09:16:32 +01:00
get tag view working for updating todos. Refactored update a lot
This commit is contained in:
parent
1cea27ccc9
commit
f923a40a40
15 changed files with 314 additions and 215 deletions
|
|
@ -1,5 +1,7 @@
|
|||
class Project < ActiveRecord::Base
|
||||
has_many :todos, :dependent => :delete_all, :include => [:context,:tags]
|
||||
|
||||
# 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',
|
||||
|
|
@ -35,6 +37,7 @@ class Project < ActiveRecord::Base
|
|||
named_scope :active, :conditions => { :state => 'active' }
|
||||
named_scope :hidden, :conditions => { :state => 'hidden' }
|
||||
named_scope :completed, :conditions => { :state => 'completed'}
|
||||
named_scope :uncompleted, :conditions => ["NOT state = ?", 'completed']
|
||||
|
||||
validates_presence_of :name
|
||||
validates_length_of :name, :maximum => 255
|
||||
|
|
|
|||
|
|
@ -23,6 +23,16 @@ class Todo < ActiveRecord::Base
|
|||
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 :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 = ?))",
|
||||
'project_hidden', true, 'active', 'deferred']
|
||||
named_scope :not_hidden,
|
||||
:joins => [:context, :project],
|
||||
:conditions => ['contexts.hide = ? AND (projects.state = ? OR todos.project_id IS NULL)', false, 'active']
|
||||
|
||||
STARRED_TAG_NAME = "starred"
|
||||
|
||||
|
|
@ -92,7 +102,6 @@ class Todo < ActiveRecord::Base
|
|||
def no_uncompleted_predecessors?
|
||||
return uncompleted_predecessors.empty?
|
||||
end
|
||||
|
||||
|
||||
# Returns a string with description <context, project>
|
||||
def specification
|
||||
|
|
@ -196,14 +205,24 @@ class Todo < ActiveRecord::Base
|
|||
return false
|
||||
end
|
||||
|
||||
def has_tag?(tag)
|
||||
return self.tags.select{|t| t.name==tag }.size > 0
|
||||
end
|
||||
|
||||
def hidden?
|
||||
puts "hidden => state = #{self.state} context(#{self.context.name}).hidden=#{self.context.hidden?}"
|
||||
return self.state == 'project_hidden' || ( self.context.hidden? && (self.state == 'active' || self.state == 'deferred'))
|
||||
end
|
||||
|
||||
def update_state_from_project
|
||||
if state == 'project_hidden' and !project.hidden?
|
||||
puts "state was #{self.state}; project.hidden?=#{self.project.hidden?}"
|
||||
if state == 'project_hidden' and !self.project.hidden?
|
||||
if self.uncompleted_predecessors.empty?
|
||||
self.state = 'active'
|
||||
else
|
||||
self.state = 'pending'
|
||||
end
|
||||
elsif state == 'active' and project.hidden?
|
||||
elsif self.state == 'active' and self.project.hidden?
|
||||
self.state = 'project_hidden'
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue