fix #1169 and also improve i18n on repeating todos

This commit is contained in:
Reinier Balt 2011-05-08 20:37:07 +02:00
parent 739402fa7d
commit 7fb6fba6f2
7 changed files with 372 additions and 214 deletions

View file

@ -627,25 +627,26 @@ class TodosController < ApplicationController
due_this_week_date = Time.zone.now.end_of_week
due_next_week_date = due_this_week_date + 7.days
due_this_month_date = Time.zone.now.end_of_month
included_tables = [:taggings, :tags, :recurring_todo]
@due_today = current_user.todos.not_completed.find(:all,
:include => [:taggings, :tags],
:include => included_tables,
:conditions => ['todos.due <= ?', due_today_date],
:order => "due")
@due_this_week = current_user.todos.not_completed.find(:all,
:include => [:taggings, :tags],
:include => included_tables,
:conditions => ['todos.due > ? AND todos.due <= ?', due_today_date, due_this_week_date],
:order => "due")
@due_next_week = current_user.todos.not_completed.find(:all,
:include => [:taggings, :tags],
:include => included_tables,
:conditions => ['todos.due > ? AND todos.due <= ?', due_this_week_date, due_next_week_date],
:order => "due")
@due_this_month = current_user.todos.not_completed.find(:all,
:include => [:taggings, :tags],
:include => included_tables,
:conditions => ['todos.due > ? AND todos.due <= ?', due_next_week_date, due_this_month_date],
:order => "due")
@due_after_this_month = current_user.todos.not_completed.find(:all,
:include => [:taggings, :tags],
:include => included_tables,
:conditions => ['todos.due > ?', due_this_month_date],
:order => "due")

View file

@ -161,12 +161,12 @@ module ApplicationHelper
def recurrence_time_span(rt)
case rt.ends_on
when "no_end_date"
return rt.start_from.nil? ? "" : "from " + format_date(rt.start_from)
return rt.start_from.nil? ? "" : I18n.t("todos.recurrence.pattern.from") + " " + format_date(rt.start_from)
when "ends_on_number_of_times"
return "for "+rt.number_of_occurences.to_s + " times"
return I18n.t("todos.recurrence.pattern.times", :number => rt.number_of_occurences)
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)
starts = rt.start_from.nil? ? "" : I18n.t("todos.recurrence.pattern.from") + " " + format_date(rt.start_from)
ends = rt.end_date.nil? ? "" : " " + I18n.t("todos.recurrence.pattern.until") + " " + format_date(rt.end_date)
return starts+ends
else
raise Exception.new, "unknown recurrence time span selection (#{rt.ends_on})"

View file

@ -388,9 +388,9 @@ class RecurringTodo < ActiveRecord::Base
def recurring_target_as_text
case self.target
when 'due_date'
return "due"
return I18n.t("todos.recurrence.pattern.due")
when 'show_from_date'
return "show"
return I18n.t("todos.recurrence.pattern.show")
else
raise Exception.new, "unexpected value of recurrence target '#{self.target}'"
end
@ -403,38 +403,51 @@ class RecurringTodo < ActiveRecord::Base
def recurring_show_always=(value)
self.show_always=value
end
def recurrence_pattern
return "invalid repeat pattern" if every_other1.nil?
case recurring_period
when 'daily'
if only_work_days
return "on work days"
return I18n.t("todos.recurrence.pattern.on_work_days")
else
if every_other1 > 1
return "every #{every_other1} days"
return I18n.t("todos.recurrence.pattern.every_n", :n => every_other1) + " " + I18n.t("common.days")
else
return "every day"
return I18n.t("todos.recurrence.pattern.every_day")
end
end
when 'weekly'
if every_other1 > 1
return "every #{every_other1} weeks"
return I18n.t("todos.recurrence.pattern.every_n", :n => every_other1) + " " + I18n.t("common.weeks")
else
return 'weekly'
return I18n.t('todos.recurrence.pattern.weekly')
end
when 'monthly'
return "invalid repeat pattern" if every_other2.nil?
if self.recurrence_selector == 0
return "every #{self.every_other2} month#{self.every_other2>1?'s':''} on day #{self.every_other1}"
on_day = " " + I18n.t('todos.recurrence.pattern.on_day_n', :n => self.every_other1)
if self.every_other2>1
return I18n.t("todos.recurrence.pattern.every_n", :n => self.every_other2) + " " + I18n.t('common.months') + on_day
else
return I18n.t("todos.recurrence.pattern.every_month") + on_day
end
else
return "every #{self.xth} #{self.day_of_week} of every #{self.every_other2} month#{self.every_other2>1?'s':''}"
if self.every_other2>1
n_months = "#{self.every_other2} " + I18n.t('common.months')
else
n_months = I18n.t('common.month')
end
return I18n.t('todos.recurrence.pattern.every_xth_day_of_every_n_months',
:x => self.xth, :day => self.day_of_week, :n_months => n_months)
end
when 'yearly'
if self.recurrence_selector == 0
return "every year on #{self.month_of_year} #{self.every_other1}"
return I18n.t("todos.recurrence.pattern.every_year_on",
:date => I18n.l(DateTime.new(Time.zone.now.year, self.every_other2, self.every_other1), :format => :month_day))
else
return "every year on the #{self.xth} #{self.day_of_week} of #{self.month_of_year}"
return I18n.t("todos.recurrence.pattern.every_year_on",
:date => I18n.t("todos.recurrence.pattern.the_xth_day_of_month", :x => self.xth, :day => self.day_of_week, :month => self.month_of_year))
end
else
return 'unknown recurrence pattern: period unknown'
@ -442,18 +455,18 @@ class RecurringTodo < ActiveRecord::Base
end
def xth
xth_day = ['first','second','third','fourth','last']
xth_day = [
I18n.t('todos.recurrence.pattern.first'),I18n.t('todos.recurrence.pattern.second'),I18n.t('todos.recurrence.pattern.third'),
I18n.t('todos.recurrence.pattern.fourth'),I18n.t('todos.recurrence.pattern.last')]
return self.every_other3.nil? ? '??' : xth_day[self.every_other3-1]
end
def day_of_week
days_of_week = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday']
return (self.every_count.nil? ? '??' : days_of_week[self.every_count])
return (self.every_count.nil? ? '??' : I18n.t('todos.recurrence.pattern.day_names')[self.every_count])
end
def month_of_year
months_of_year = ['January','Februari','March','April','May','June','July','August','September','October','November','December']
return self.every_other2.nil? ? '??' : months_of_year[self.every_other2-1]
return self.every_other2.nil? ? '??' : I18n.t('todos.recurrence.pattern.month_names')[self.every_other2]
end
def starred?

View file

@ -31,7 +31,7 @@
</div>
<div class="container">
<h2><%= t('todos.calendar.due_this_month', :month => Time.zone.now.strftime("%B")) %></h2>
<h2><%= t('todos.calendar.due_this_month', :month => l(Time.zone.now, :format => "%B")) %></h2>
<div id="empty_due_this_month" <%= "style=\"display:none\"" unless @due_this_month.empty? %>>
<%= t('todos.calendar.no_actions_due_this_month') %>
</div>
@ -41,7 +41,7 @@
</div>
<div class="container">
<h2><%= t('todos.calendar.due_next_month_and_later', :month => (Time.zone.now+1.month).strftime("%B")) %></h2>
<h2><%= t('todos.calendar.due_next_month_and_later', :month => l(Time.zone.now+1.month, :format => "%B")) %></h2>
<div id="empty_due_after_this_month" <%= "style=\"display:none\"" unless @due_after_this_month.empty? %>>
<%= t('todos.calendar.no_actions_due_after_this_month') %>
</div>