mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 15:20:13 +01:00
Refactor the fetching of done todos
Move the get_done_today, get_done_this_week, and get_done_this month methods into their own class in lib/tracks and use the new class in the context, project, and todo controllers. This removes the complexity from the application controller, silos it off, and slightly reduces the complexity of the other controllers so that they don't have to duplicate as much code. The tradeoff here is that the code that was moved out into its own class was also duplicated in the todos controller due to a different use case that I didn't see before. This is still an improvement however and so I'm ok with going back and tackling the extra complexity added to TodoController at a later date.
This commit is contained in:
parent
2393d6d371
commit
4d2f25ab20
5 changed files with 50 additions and 36 deletions
|
|
@ -238,26 +238,6 @@ class ApplicationController < ActionController::Base
|
|||
self.class.prefered_auth?
|
||||
end
|
||||
|
||||
# all completed todos [today@00:00, today@now]
|
||||
def get_done_today(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
start_of_this_day = Time.zone.now.beginning_of_day
|
||||
completed_todos.completed_after(start_of_this_day).all(includes)
|
||||
end
|
||||
|
||||
# all completed todos [begin_of_week, start_of_today]
|
||||
def get_done_this_week(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
start_of_this_week = Time.zone.now.beginning_of_week
|
||||
start_of_this_day = Time.zone.now.beginning_of_day
|
||||
completed_todos.completed_before(start_of_this_day).completed_after(start_of_this_week).all(includes)
|
||||
end
|
||||
|
||||
# all completed todos [begin_of_month, begin_of_week]
|
||||
def get_done_this_month(completed_todos, includes = {:include => Todo::DEFAULT_INCLUDES})
|
||||
start_of_this_month = Time.zone.now.beginning_of_month
|
||||
start_of_this_week = Time.zone.now.beginning_of_week
|
||||
completed_todos.completed_before(start_of_this_week).completed_after(start_of_this_month).all(includes)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse_date_per_user_prefs( s )
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue