mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-17 07:40:12 +01:00
show recurrence pattern in :title of a recurring todo. Needed slight refactoring to make it happen
This commit is contained in:
parent
930999829b
commit
c46e5a9e1d
5 changed files with 52 additions and 45 deletions
|
|
@ -144,4 +144,30 @@ module ApplicationHelper
|
||||||
page.visual_effect :fade, 'flash', :duration => fade_duration
|
page.visual_effect :fade, 'flash', :duration => fade_duration
|
||||||
end
|
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
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,5 @@
|
||||||
module RecurringTodosHelper
|
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
|
def recurring_todo_tag_list
|
||||||
tags_except_starred = @recurring_todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
|
tags_except_starred = @recurring_todo.tags.reject{|t| t.name == Todo::STARRED_TAG_NAME}
|
||||||
tag_list = tags_except_starred.collect{|t| "<span class=\"tag #{t.name.gsub(' ','-')}\">" +
|
tag_list = tags_except_starred.collect{|t| "<span class=\"tag #{t.name.gsub(' ','-')}\">" +
|
||||||
|
|
|
||||||
|
|
@ -296,6 +296,17 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
self.target = t
|
self.target = t
|
||||||
end
|
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)
|
def recurring_show_days_before=(days)
|
||||||
self.show_from_delta=days
|
self.show_from_delta=days
|
||||||
end
|
end
|
||||||
|
|
@ -361,6 +372,8 @@ class RecurringTodo < ActiveRecord::Base
|
||||||
when 'show_from'
|
when 'show_from'
|
||||||
# so leave due date empty
|
# so leave due date empty
|
||||||
return nil
|
return nil
|
||||||
|
else
|
||||||
|
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,7 @@
|
||||||
<div class="description">
|
<div class="description">
|
||||||
<span class="todo.descr"><%= sanitize(recurring_todo.description) %></span> <%= recurring_todo_tag_list %>
|
<span class="todo.descr"><%= sanitize(recurring_todo.description) %></span> <%= recurring_todo_tag_list %>
|
||||||
<span class='recurrence_pattern'>
|
<span class='recurrence_pattern'>
|
||||||
<%
|
[<%= recurrence_pattern_as_text(@recurring_todo) %>]
|
||||||
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%>]
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,10 @@
|
||||||
<% unless @todo.completed? %><span class="defer-container"><%= defer_link(1) %> <%= defer_link(7) %></span><% end %>
|
<% unless @todo.completed? %><span class="defer-container"><%= defer_link(1) %> <%= defer_link(7) %></span><% end %>
|
||||||
<%= date_span -%>
|
<%= date_span -%>
|
||||||
<span class="todo.descr"><%= h sanitize(todo.description) %></span>
|
<span class="todo.descr"><%= h sanitize(todo.description) %></span>
|
||||||
<%= 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 %>
|
<%= tag_list %>
|
||||||
<%= deferred_due_date %>
|
<%= deferred_due_date %>
|
||||||
<%= project_and_context_links( parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %>
|
<%= project_and_context_links( parent_container_type, :suppress_context => suppress_context, :suppress_project => suppress_project ) %>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue