From c46e5a9e1d45f39f30464c16fb4c1606b1833ce7 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Mon, 8 Dec 2008 16:59:10 +0100 Subject: [PATCH] show recurrence pattern in :title of a recurring todo. Needed slight refactoring to make it happen --- app/helpers/application_helper.rb | 36 ++++++++++++++++--- app/helpers/recurring_todos_helper.rb | 26 -------------- app/models/recurring_todo.rb | 19 ++++++++-- .../recurring_todos/_recurring_todo.html.erb | 11 +----- app/views/todos/_todo.html.erb | 5 ++- 5 files changed, 52 insertions(+), 45 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index a4147313..549f2fbc 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -8,7 +8,7 @@ module ApplicationHelper # Replicates the link_to method but also checks request.request_uri to find # current page. If that matches the url, the link is marked id = "current" - # + # def navigation_link(name, options = {}, html_options = nil, *parameters_for_method_reference) if html_options html_options = html_options.stringify_keys @@ -29,7 +29,7 @@ module ApplicationHelper # Check due date in comparison to today's date Flag up date appropriately with # a 'traffic light' colour code - # + # def due_date(due) if due == nil return "" @@ -62,7 +62,7 @@ module ApplicationHelper # Check due date in comparison to today's date Flag up date appropriately with # a 'traffic light' colour code Modified method for mobile screen - # + # def due_date_mobile(due) if due == nil return "" @@ -92,7 +92,7 @@ module ApplicationHelper # Returns a count of next actions in the given context or project. The result # is count and a string descriptor, correctly pluralised if there are no # actions or multiple actions - # + # def count_undone_todos_phrase(todos_parent, string="actions") @controller.count_undone_todos_phrase(todos_parent, string) end @@ -143,5 +143,31 @@ module ApplicationHelper page.replace 'flash', "

#{message}

" page.visual_effect :fade, 'flash', :duration => fade_duration end - + + def recurrence_time_span(rt) + case rt.ends_on + when "no_end_date" + return rt.start_from.nil? ? "" : "from " + format_date(rt.start_from) + when "ends_on_number_of_times" + return "for "+rt.number_of_occurences.to_s + " times" + when "ends_on_end_date" + starts = rt.start_from.nil? ? "" : "from " + format_date(rt.start_from) + ends = rt.end_date.nil? ? "" : " until " + format_date(rt.end_date) + return starts+ends + else + raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})" + end + end + + def recurrence_pattern_as_text(recurring_todo) + rt = recurring_todo.recurring_target_as_text + rp = recurring_todo.recurrence_pattern + # only add space if recurrence_pattern has content + rp = " " + rp if !rp.nil? + rts = recurrence_time_span(recurring_todo) + # only add space if recurrence_time_span has content + rts = " " + rts if !(rts == "") + return rt+rp+rts + end + end diff --git a/app/helpers/recurring_todos_helper.rb b/app/helpers/recurring_todos_helper.rb index 76fcc95e..4ba1a690 100644 --- a/app/helpers/recurring_todos_helper.rb +++ b/app/helpers/recurring_todos_helper.rb @@ -1,30 +1,4 @@ module RecurringTodosHelper - - def recurrence_time_span(rt) - case rt.ends_on - when "no_end_date" - return rt.start_from.nil? ? "" : "from " + format_date(rt.start_from) - when "ends_on_number_of_times" - return "for "+rt.number_of_occurences.to_s + " times" - when "ends_on_end_date" - starts = rt.start_from.nil? ? "" : "from " + format_date(rt.start_from) - ends = rt.end_date.nil? ? "" : " until " + format_date(rt.end_date) - return starts+ends - else - raise Exception.new, "unknown recurrence time span selection (#{self.ends_on})" - end - end - - def recurrence_target(rt) - case rt.target - when 'due_date' - return "due" - when 'show_from_date' - return "show" - else - return "ERROR" - end - end def recurring_todo_tag_list tags_except_starred = @recurring_todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME} diff --git a/app/models/recurring_todo.rb b/app/models/recurring_todo.rb index be4e2414..7d24b7eb 100644 --- a/app/models/recurring_todo.rb +++ b/app/models/recurring_todo.rb @@ -295,6 +295,17 @@ class RecurringTodo < ActiveRecord::Base def recurring_target=(t) self.target = t end + + def recurring_target_as_text + case self.target + when 'due_date' + return "due" + when 'show_from_date' + return "show" + else + raise Exception.new, "unexpected value of recurrence target '#{self.target}'" + end + end def recurring_show_days_before=(days) self.show_from_delta=days @@ -361,6 +372,8 @@ class RecurringTodo < ActiveRecord::Base when 'show_from' # so leave due date empty return nil + else + raise Exception.new, "unexpected value of recurrence target '#{self.target}'" end end @@ -476,14 +489,14 @@ class RecurringTodo < ActiveRecord::Base when 0 # specific day of the month if start.mday >= day # there is no next day n in this month, search in next month - # + # # start += n.months - # + # # The above seems to not work. Fiddle with timezone. Looks like we hit a # bug in rails here where 2008-12-01 +0100 plus 1.month becomes # 2008-12-31 +0100. For now, just calculate in UTC and convert back to # local timezone. - # + # # TODO: recheck if future rails versions have this problem too start = Time.utc(start.year, start.month, start.day)+n.months start = Time.zone.local(start.year, start.month, start.day) diff --git a/app/views/recurring_todos/_recurring_todo.html.erb b/app/views/recurring_todos/_recurring_todo.html.erb index ccc93cbb..a1d2c737 100644 --- a/app/views/recurring_todos/_recurring_todo.html.erb +++ b/app/views/recurring_todos/_recurring_todo.html.erb @@ -6,16 +6,7 @@
<%= sanitize(recurring_todo.description) %> <%= recurring_todo_tag_list %> - <% - rt = recurrence_target(recurring_todo) - rp = recurring_todo.recurrence_pattern - # only add space if recurrence_pattern has content - rp = " " + rp if !rp.nil? - rts = recurrence_time_span(recurring_todo) - # only add space if recurrence_time_span has content - rts = " " + rts if !(rts == "") - %> - [<%=rt%><%=rp%><%=rts%>] + [<%= recurrence_pattern_as_text(@recurring_todo) %>]
diff --git a/app/views/todos/_todo.html.erb b/app/views/todos/_todo.html.erb index 288325a0..231eaf97 100644 --- a/app/views/todos/_todo.html.erb +++ b/app/views/todos/_todo.html.erb @@ -14,7 +14,10 @@ <% unless @todo.completed? %><%= defer_link(1) %> <%= defer_link(7) %><% end %> <%= date_span -%> <%= h sanitize(todo.description) %> - <%= link_to(image_tag("recurring16x16.png"), {:controller => "recurring_todos", :action => "index"}, :class => "recurring_icon") if @todo.from_recurring_todo? %> + <%= link_to( + image_tag("recurring16x16.png"), + {:controller => "recurring_todos", :action => "index"}, + :class => "recurring_icon", :title => recurrence_pattern_as_text(@todo.recurring_todo)) if @todo.from_recurring_todo? %> <%= tag_list %> <%= deferred_due_date %> <%= project_and_context_links( parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %>