mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-24 03:00:12 +01:00
Add a Todos::Calendar object
This commit is contained in:
parent
84e49c451c
commit
ba38277df8
1 changed files with 67 additions and 0 deletions
67
app/models/todos/calendar.rb
Normal file
67
app/models/todos/calendar.rb
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
module Todos
|
||||
class Calendar
|
||||
|
||||
attr_reader :user, :included_tables
|
||||
|
||||
def initialize(user)
|
||||
@user = user
|
||||
@included_tables = Todo::DEFAULT_INCLUDES
|
||||
end
|
||||
|
||||
def projects
|
||||
user.projects
|
||||
end
|
||||
|
||||
def due_today
|
||||
user.todos.not_completed.
|
||||
where('todos.due <= ?', today).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
end
|
||||
|
||||
def due_this_week
|
||||
user.todos.not_completed.
|
||||
where('todos.due > ? AND todos.due <= ?', today, Time.zone.now.end_of_week).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
end
|
||||
|
||||
def due_next_week
|
||||
user.todos.not_completed.
|
||||
where('todos.due > ? AND todos.due <= ?', end_of_the_week, end_of_next_week).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
end
|
||||
|
||||
def due_this_month
|
||||
user.todos.not_completed.
|
||||
where('todos.due > ? AND todos.due <= ?', end_of_next_week, end_of_the_month).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
end
|
||||
|
||||
def due_after_this_month
|
||||
user.todos.not_completed.
|
||||
where('todos.due > ?', end_of_the_month).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
end
|
||||
|
||||
def today
|
||||
@today ||= Time.zone.now
|
||||
end
|
||||
|
||||
def end_of_the_week
|
||||
@end_of_the_week ||= today.end_of_week
|
||||
end
|
||||
|
||||
def end_of_next_week
|
||||
@end_of_next_week ||= end_of_the_week + 7.days
|
||||
end
|
||||
|
||||
def end_of_the_month
|
||||
@end_of_the_month ||= today.end_of_month
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue