mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-03 06:21:49 +01:00
refactor done todos view and tests
This commit is contained in:
parent
aac744e411
commit
85fc82d494
16 changed files with 141 additions and 116 deletions
|
|
@ -1,7 +1,7 @@
|
|||
class DoneTodos
|
||||
def self.done_todos_for_container(container)
|
||||
completed_todos = container.todos.completed
|
||||
return done_today(completed_todos), done_this_week(completed_todos), done_this_month(completed_todos)
|
||||
def self.done_todos_for_container(user)
|
||||
completed_todos = user.todos.completed
|
||||
return done_today(completed_todos), done_rest_of_week(completed_todos), done_rest_of_month(completed_todos)
|
||||
end
|
||||
|
||||
def self.done_today(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
|
|
@ -9,14 +9,31 @@ class DoneTodos
|
|||
todos.completed_after(start_of_this_day).all(includes)
|
||||
end
|
||||
|
||||
def self.done_this_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
def self.done_rest_of_week(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
done_between(todos, includes, Time.zone.now.beginning_of_day, Time.zone.now.beginning_of_week)
|
||||
end
|
||||
|
||||
def self.done_this_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
def self.done_rest_of_month(todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
done_between(todos, includes, Time.zone.now.beginning_of_week, Time.zone.now.beginning_of_month)
|
||||
end
|
||||
|
||||
def self.completed_period(date)
|
||||
return nil if date.nil?
|
||||
|
||||
period = nil
|
||||
period = "rest_of_month" if date > Time.zone.now.beginning_of_month
|
||||
period = "rest_of_week" if date > Time.zone.now.beginning_of_week
|
||||
period = "today" if date > Time.zone.now.beginning_of_day
|
||||
|
||||
return period
|
||||
end
|
||||
|
||||
def self.remaining_in_container(user, period)
|
||||
count = self.send("done_#{period}", user.todos.completed, {}).count
|
||||
return nil if period.nil?
|
||||
return count
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def self.done_between(todos, includes, start_date, end_date)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue