mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-27 20:38:48 +01:00
Remove more duplication from Todos::Calendar.
This commit is contained in:
parent
fedfb55ff8
commit
b1fb1dd326
2 changed files with 21 additions and 20 deletions
|
|
@ -51,6 +51,16 @@ class Todo < ActiveRecord::Base
|
|||
scope :created_after, lambda { |date| where("todos.created_at > ?", date) }
|
||||
scope :created_before, lambda { |date| where("todos.created_at < ?", date) }
|
||||
|
||||
scope :due_today, lambda { where("todos.due <= ?", Time.zone.now) }
|
||||
|
||||
def self.due_after(date)
|
||||
where('todos.due > ?', date)
|
||||
end
|
||||
|
||||
def self.due_between(start_date, end_date)
|
||||
where('todos.due > ? AND todos.due <= ?', start_date, end_date)
|
||||
end
|
||||
|
||||
STARRED_TAG_NAME = "starred"
|
||||
DEFAULT_INCLUDES = [ :project, :context, :tags, :taggings, :pending_successors, :uncompleted_predecessors, :recurring_todo ]
|
||||
|
||||
|
|
|
|||
|
|
@ -13,38 +13,23 @@ module Todos
|
|||
end
|
||||
|
||||
def due_today
|
||||
user.todos.not_completed.
|
||||
where('todos.due <= ?', today).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
actions.due_today
|
||||
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")
|
||||
actions.due_between(today, end_of_the_week)
|
||||
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")
|
||||
actions.due_between(end_of_the_week, end_of_next_week)
|
||||
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")
|
||||
actions.due_between(end_of_next_week, end_of_the_month)
|
||||
end
|
||||
|
||||
def due_after_this_month
|
||||
user.todos.not_completed.
|
||||
where('todos.due > ?', end_of_the_month).
|
||||
includes(included_tables).
|
||||
reorder("due")
|
||||
actions.due_after(end_of_the_month)
|
||||
end
|
||||
|
||||
def today
|
||||
|
|
@ -63,5 +48,11 @@ module Todos
|
|||
@end_of_the_month ||= today.end_of_month
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def actions
|
||||
user.todos.not_completed.includes(included_tables).reorder("due")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue