mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-22 23:24:07 +01:00
Minor refactor of todo state guard conditions
This commit is contained in:
parent
1f95d7277a
commit
1d97d3cd46
1 changed files with 7 additions and 3 deletions
|
|
@ -78,7 +78,7 @@ class Todo < ActiveRecord::Base
|
||||||
transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors?
|
transitions :to => :active, :from => [:completed], :guard => :no_uncompleted_predecessors?
|
||||||
transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral?
|
transitions :to => :active, :from => [:pending], :guard => :no_uncompleted_predecessors_or_deferral?
|
||||||
transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors?
|
transitions :to => :pending, :from => [:completed], :guard => :uncompleted_predecessors?
|
||||||
transitions :to => :deferred, :from => [:pending], :guard => :guard_for_transition_from_deferred_to_pending
|
transitions :to => :deferred, :from => [:pending], :guard => :guard_for_transition_from_pending_to_deferred
|
||||||
end
|
end
|
||||||
|
|
||||||
aasm.event :hide do
|
aasm.event :hide do
|
||||||
|
|
@ -142,12 +142,16 @@ class Todo < ActiveRecord::Base
|
||||||
return !uncompleted_predecessors.all.empty?
|
return !uncompleted_predecessors.all.empty?
|
||||||
end
|
end
|
||||||
|
|
||||||
def guard_for_transition_from_deferred_to_pending
|
def guard_for_transition_from_pending_to_deferred
|
||||||
no_uncompleted_predecessors? && not_part_of_hidden_container?
|
no_uncompleted_predecessors? && not_part_of_hidden_container?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def part_of_hidden_container?
|
||||||
|
(self.project && self.project.hidden?) || self.context.hidden?
|
||||||
|
end
|
||||||
|
|
||||||
def not_part_of_hidden_container?
|
def not_part_of_hidden_container?
|
||||||
!( (self.project && self.project.hidden?) || self.context.hidden? )
|
!part_of_hidden_container?
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns a string with description <context, project>
|
# Returns a string with description <context, project>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue