mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-16 23:30:12 +01:00
fixed #781:
* 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 Signed-off-by: Reinier Balt <lrbalt@gmail.com>
This commit is contained in:
parent
8002eef8ab
commit
4e1e18da0f
6 changed files with 101 additions and 12 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue