diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index cb5f4173..353ce0ca 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -311,6 +311,10 @@ class RecurringTodo < ActiveRecord::Base self.show_from_delta=days end + def recurring_show_always=(value) + self.show_always=value + end + def recurrence_pattern case recurring_period when 'daily' @@ -380,9 +384,12 @@ class RecurringTodo < ActiveRecord::Base 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) diff --git a/app/views/recurring_todos/_edit_form.html.erb b/app/views/recurring_todos/_edit_form.html.erb index 9f6cc2f6..4f641fb8 100644 --- a/app/views/recurring_todos/_edit_form.html.erb +++ b/app/views/recurring_todos/_edit_form.html.erb @@ -134,10 +134,12 @@

- <%= 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)
+ <%= 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 +
<%= 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)

diff --git a/app/views/recurring_todos/_recurring_todo_form.erb b/app/views/recurring_todos/_recurring_todo_form.erb index a6870e6f..ad4750bc 100644 --- a/app/views/recurring_todos/_recurring_todo_form.erb +++ b/app/views/recurring_todos/_recurring_todo_form.erb @@ -132,10 +132,12 @@

- <%= 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)
+ <%= 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 +
<%= radio_button_tag('recurring_todo[recurring_target]', 'show_from_date', false)%> the date todo comes from tickler (no due date set)

diff --git a/db/migrate/20090531111711_add_show_always_to_recurring_todo.rb b/db/migrate/20090531111711_add_show_always_to_recurring_todo.rb new file mode 100644 index 00000000..3ae6b8cc --- /dev/null +++ b/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 diff --git a/test/functional/recurring_todos_controller_test.rb b/test/functional/recurring_todos_controller_test.rb index 7b0bd86d..394e72d7 100644 --- a/test/functional/recurring_todos_controller_test.rb +++ b/test/functional/recurring_todos_controller_test.rb @@ -180,4 +180,56 @@ class RecurringTodosControllerTest < ActionController::TestCase 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 diff --git a/test/unit/recurring_todo_test.rb b/test/unit/recurring_todo_test.rb index 9498216b..d025ba01 100644 --- a/test/unit/recurring_todo_test.rb +++ b/test/unit/recurring_todo_test.rb @@ -67,12 +67,22 @@ class RecurringTodoTest < Test::Rails::TestCase 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