fix corner case where recurring todo with due in future and show_from in past did not create corresponding todo

you cannot add todos with show_from in the past
This commit is contained in:
Reinier Balt 2008-08-19 14:33:09 +02:00
parent 223cf93597
commit 065f543a83
4 changed files with 151 additions and 146 deletions

View file

@ -9,12 +9,12 @@ require "redcloth"
require 'date'
require 'time'
# Commented the following line because of #744. It prevented rake db:migrate to
# Commented the following line because of #744. It prevented rake db:migrate to
# run because this tag went looking for the taggings table that did not exist
# when you feshly create a new database
# Old comment: We need this in development mode, or you get 'method missing' errors
# when you feshly create a new database Old comment: We need this in development
# mode, or you get 'method missing' errors
#
# Tag
# Tag
class ApplicationController < ActionController::Base
@ -160,7 +160,34 @@ class ApplicationController < ActionController::Base
response.content_type = 'text/html'
end
end
def create_todo_from_recurring_todo(rt, date=nil)
# create todo and initialize with data from recurring_todo rt
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
# set dates
todo.recurring_todo_id = rt.id
todo.due = rt.get_due_date(date)
# make sure that show_from is not in the past
show_from_date = rt.get_show_from_date(date)
todo.show_from = show_from_date < Time.now.utc ? nil : show_from_date
saved = todo.save
if saved
todo.tag_with(rt.tag_list, current_user)
todo.tags.reload
end
# increate number of occurences created from recurring todo
rt.inc_occurences
# mark recurring todo complete if there are no next actions left
checkdate = todo.due.nil? ? todo.show_from : todo.due
rt.toggle_completion! unless rt.has_next_todo(checkdate)
return saved ? todo : nil
end
protected
def admin_login_required
@ -192,7 +219,7 @@ class ApplicationController < ActionController::Base
def openid_enabled?
self.class.openid_enabled?
end
private
def parse_date_per_user_prefs( s )
@ -231,29 +258,5 @@ class ApplicationController < ActionController::Base
def set_time_zone
Time.zone = current_user.prefs.time_zone if logged_in?
end
def create_todo_from_recurring_todo(rt, date=nil)
# create todo and initialize with data from recurring_todo rt
todo = current_user.todos.build( { :description => rt.description, :notes => rt.notes, :project_id => rt.project_id, :context_id => rt.context_id})
# set dates
todo.due = rt.get_due_date(date)
todo.show_from = rt.get_show_from_date(date)
todo.recurring_todo_id = rt.id
saved = todo.save
if saved
todo.tag_with(rt.tag_list, current_user)
todo.tags.reload
end
# increate number of occurences created from recurring todo
rt.inc_occurences
# mark recurring todo complete if there are no next actions left
checkdate = todo.due.nil? ? todo.show_from : todo.due
rt.toggle_completion! unless rt.has_next_todo(checkdate)
return saved ? todo : nil
end
end