Feature #23778

default sort email reminders by due date (and list due date in email)

Added by John Simmons about 3 years ago. Updated 4 months ago.

Status:ClosedStart date:
Priority:NormalDue date:
Assignee:-% Done:


Category:Email notifications
Target version:-


I think this should be default behavior. I've already written the code to do this, but I'm not sure how to get the code to you since the [contribute](http://www.redmine.org/projects/redmine/wiki/Contribute) page says not to use pull requests. What is the preferred method of getting the code to you on github? I see the link to creating patches on git, but I didn't really follow it. Can someone give me a more detailed explanation?

I uploaded a file of what our email reminders look like now after the changes.

redmineReminderEdited.png (71 KB) John Simmons, 2016-09-07 17:09

emailSortByDate.patch Magnifier (1.67 KB) John Simmons, 2016-09-07 23:20

Related issues

Related to Redmine - Patch #6357: Show and sort by due_date in reminders Closed 2010-09-10
Related to Redmine - Feature #31225: Show the number of days left until the due date in reminders Closed


#1 Updated by Moritz Koehler about 3 years ago

would you mind to share the code here for now. Looks very good.

#2 Updated by John Simmons about 3 years ago

In app/helpers/application_helper.rb, in the link_to_issue function

  def link_to_issue(issue, options={})
    title = nil
    subject = nil
    text = options[:tracker] == false ? "##{issue.id}" : "#{issue.tracker} ##{issue.id}" 
    if options[:subject] == false
      title = issue.subject.truncate(60)
      subject = issue.subject
      if truncate_length = options[:truncate]
        subject = subject.truncate(truncate_length)
    only_path = options[:only_path].nil? ? true : options[:only_path]
    s = link_to(text, issue_url(issue, :only_path => only_path),
                :class => issue.css_classes, :title => title)
    s << h(": #{subject}") if subject
    #This is the only line that changes here
    s = h("Due date #{issue.due_date} : #{issue.project} - ") + s if options[:project]

The other change is in app/models/mailer.rb, in the reminders function

  def self.reminders(options={})
    days = options[:days] || 7
    project = options[:project] ? Project.find(options[:project]) : nil
    tracker = options[:tracker] ? Tracker.find(options[:tracker]) : nil
    target_version_id = options[:version] ? Version.named(options[:version]).pluck(:id) : nil
    if options[:version] && target_version_id.blank?
      raise ActiveRecord::RecordNotFound.new("Couldn't find Version with named #{options[:version]}")
    user_ids = options[:users]
    scope = Issue.open.where("#{Issue.table_name}.assigned_to_id IS NOT NULL" +
      " AND #{Project.table_name}.status = #{Project::STATUS_ACTIVE}" +
      " AND #{Issue.table_name}.due_date <= ?", days.day.from_now.to_date
    scope = scope.where(:assigned_to_id => user_ids) if user_ids.present?
    scope = scope.where(:project_id => project.id) if project
    scope = scope.where(:fixed_version_id => target_version_id) if target_version_id.present?
    scope = scope.where(:tracker_id => tracker.id) if tracker
    issues_by_assignee = scope.includes(:status, :assigned_to, :project, :tracker).
    issues_by_assignee.keys.each do |assignee|
      if assignee.is_a?(Group)
        assignee.users.each do |user|
          issues_by_assignee[user] ||= []
          issues_by_assignee[user] += issues_by_assignee[assignee]
    issues_by_assignee.each do |assignee, issues|
      #My changes start here
      issues = issues.sort_by do |item|
      #End of changes
      reminder(assignee, issues, days).deliver if assignee.is_a?(User) && assignee.active?

I commented where the changes are.

#3 Updated by John Simmons about 3 years ago

It's barely anything, which is why I was a little shocked that it wasn't already sorted. But if accepted it will be my first contribution to redmine....so yay!

Also, this hasn't been fully tested. I've run it against everything I have right now, but I haven't run it through any official testing...so take it for what it's worth right now.

#4 Updated by Marius BALTEANU about 3 years ago

It'll be better to provide a patch. Check How_to_create_patch_series_on_Mercurial_and_Git or use the command git diff > path_to_patch

#5 Updated by John Simmons about 3 years ago

Here's the patch. If I'm supposed to put it somewhere else please let me know. Also, I won't have a chance to really test it for a few days probably, so if you see any errors please let me know.

#6 Updated by Toshi MARUYAMA about 3 years ago

"link_to_issue" is used at many places.

    s = h("Due date #{issue.due_date} : #{issue.project} - ") + s if options[:project]

breaks many places.

#7 Updated by Go MAEDA 11 months ago

  • Related to Patch #6357: Show and sort by due_date in reminders added

#8 Updated by Go MAEDA 11 months ago

Issues in reminders are now sorted by due date (#29771).

#9 Updated by Go MAEDA 5 months ago

  • Related to Feature #31225: Show the number of days left until the due date in reminders added

#10 Updated by Go MAEDA 4 months ago

  • Status changed from New to Closed
  • Resolution set to Duplicate

The upcoming Redmine 4.1.0 shows the number of days left until the due date ("due in X days" / "X days late"). Please see #31225 for details.

Also available in: Atom PDF