Skip to content

Commit

Permalink
fixed TracksApp#781:
Browse files Browse the repository at this point in the history
* added a "show always" radio to the recurring todo forms
* added a show_always flag to recurring todos
* created a migration to convert existing recurring todos where show_from_delta==0
* recurring todos where show_from_delta is 0 are now shown the same day they're due
  • Loading branch information
sigmike committed May 31, 2009
1 parent 8002eef commit 061840b
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 12 deletions.
13 changes: 10 additions & 3 deletions app/models/recurring_todo.rb
Expand Up @@ -311,6 +311,10 @@ def recurring_show_days_before=(days)
self.show_from_delta=days
end

def recurring_show_always=(value)
self.show_always=value
end

def recurrence_pattern
case recurring_period
when 'daily'
Expand Down Expand Up @@ -380,9 +384,12 @@ def get_due_date(previous)
def get_show_from_date(previous)
case self.target
when 'due_date'
# so set show from date relative to due date unless show_from_delta is
# zero / nil
return (self.show_from_delta == 0 || self.show_from_delta.nil?) ? nil : get_due_date(previous) - self.show_from_delta.days
# so set show from date relative to due date unless show_always is true or show_from_delta is nil
if self.show_always? or self.show_from_delta.nil?
nil
else
get_due_date(previous) - self.show_from_delta.days
end
when 'show_from_date'
# Leave due date empty
return get_next_date(previous)
Expand Down
10 changes: 6 additions & 4 deletions app/views/recurring_todos/_edit_form.html.erb
Expand Up @@ -134,10 +134,12 @@
</div>
<div id="recurring_target">
<label>Set recurrence on</label><br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%> the date that the todo is due.
Show the todo <%=
text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {"size" => 3, "tabindex" => 12}) %>
days before the todo is due (0=show always)<br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', @recurring_todo.target == 'due_date')%> the date that the todo is due. Show the todo:
<%= radio_button_tag('recurring_todo[recurring_show_always]', '1', @recurring_todo.show_always?)%> always
<%= radio_button_tag('recurring_todo[recurring_show_always]', '0', !@recurring_todo.show_always?)%>
<%= text_field_tag( 'recurring_todo[recurring_show_days_before]', @recurring_todo.show_from_delta, {"size" => 3, "tabindex" => 12}) %>
days before the todo is due
<br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', @recurring_todo.target == 'show_from_date')%> the date todo comes from tickler (no due date set)<br/>
<br/>
</div>
Expand Down
10 changes: 6 additions & 4 deletions app/views/recurring_todos/_recurring_todo_form.erb
Expand Up @@ -132,10 +132,12 @@
</div>
<div id="recurring_target">
<label>Set recurrence on</label><br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', true)%> the date that the todo is due.
Show the todo <%=
text_field_tag( 'recurring_todo[recurring_show_days_before]', "0", {"size" => 3, "tabindex" => 12}) %>
days before the todo is due (0=show always)<br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'due_date', true)%> the date that the todo is due. Show the todo:
<%= radio_button_tag('recurring_todo[recurring_show_always]', '1', true)%> always
<%= radio_button_tag('recurring_todo[recurring_show_always]', '0', false)%>
<%= text_field_tag( 'recurring_todo[recurring_show_days_before]', "0", {"size" => 3, "tabindex" => 12}) %>
days before the todo is due
<br/>
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', false)%> the date todo comes from tickler (no due date set)<br/>
<br/>
</div>
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/20090531111711_add_show_always_to_recurring_todo.rb
@@ -0,0 +1,16 @@
class AddShowAlwaysToRecurringTodo < ActiveRecord::Migration
def self.up
add_column :recurring_todos, :show_always, :boolean
recurring_todos = RecurringTodo.find(:all)
recurring_todos.each do |recurring_todo|
if recurring_todo.show_from_delta == 0 or recurring_todo.show_from_delta.nil?
recurring_todo.show_always = true
recurring_todo.save!
end
end
end

def self.down
remove_column :recurring_todos, :show_always
end
end
52 changes: 52 additions & 0 deletions test/functional/recurring_todos_controller_test.rb
Expand Up @@ -180,4 +180,56 @@ def test_last_sunday_of_march
assert_equal Time.zone.local(2013,3,31), new_todo.due
end

def test_recurring_todo_with_due_date_and_show_always
login_as(:admin_user)

orig_rt_count = RecurringTodo.count
orig_todo_count = Todo.count

put :create,
"context_name"=>"library",
"project_name"=>"Build a working time machine",
"recurring_todo" =>
{
"daily_every_x_days"=>"1",
"daily_selector"=>"daily_every_x_day",
"description"=>"new recurring pattern",
"end_date" => "",
"ends_on" => "no_end_date",
"monthly_day_of_week" => "1",
"monthly_every_x_day" => "22",
"monthly_every_x_month2" => "1",
"monthly_every_x_month" => "1",
"monthly_every_xth_day"=>"1",
"monthly_selector"=>"monthly_every_x_day",
"notes"=>"with some notes",
"number_of_occurences" => "",
"recurring_period"=>"yearly",
"recurring_show_always"=>"1",
"recurring_show_days_before"=>"0",
"recurring_target"=>"due_date",
"start_from"=>"1/10/2012", # adjust after 2012
"weekly_every_x_week"=>"1",
"weekly_return_monday"=>"w",
"yearly_day_of_week"=>"0",
"yearly_every_x_day"=>"22",
"yearly_every_xth_day"=>"5",
"yearly_month_of_year2"=>"3",
"yearly_month_of_year"=>"10",
"yearly_selector"=>"yearly_every_xth_day"
},
"tag_list"=>"one, two, three, four"

# check new recurring todo added
assert_equal orig_rt_count+1, RecurringTodo.count
# check new todo added
assert_equal orig_todo_count+1, Todo.count

# find the newly created recurring todo
recurring_todo = RecurringTodo.find_by_description("new recurring pattern")
assert !recurring_todo.nil?

assert_equal "due_date", recurring_todo.target
assert_equal true, recurring_todo.show_always?
end
end
12 changes: 11 additions & 1 deletion test/unit/recurring_todo_test.rb
Expand Up @@ -67,12 +67,22 @@ def test_show_from_date
assert_equal @today+1.day, @every_day.get_show_from_date(@today)

@every_day.target='due_date'
# when target on due_date, show_from is relative to due date unless delta=0
# when target on due_date, show_from is relative to due date unless show_always is true
@every_day.show_always = true
assert_equal nil, @every_day.get_show_from_date(@today-1.days)

@every_day.show_always = false
@every_day.show_from_delta=10
assert_equal @today, @every_day.get_show_from_date(@today+9.days) #today+1+9-10

# when show_from is 0, show_from is the same day it's due
@every_day.show_from_delta=0
assert_equal @every_day.get_due_date(@today+9.days), @every_day.get_show_from_date(@today+9.days)

# when show_from is nil, show always (happend in tests)
@every_day.show_from_delta=nil
assert_equal nil, @every_day.get_show_from_date(@today+9.days)

# TODO: show_from has no use case for daily pattern. Need to test on
# weekly/monthly/yearly
end
Expand Down

0 comments on commit 061840b

Please sign in to comment.