Feature #2848

Sort time entries by name, not ID

Added by Brad Beattie over 12 years ago. Updated 21 days ago.

Status:NewStart date:2009-02-26
Priority:NormalDue date:
Assignee:-% Done:

90%

Category:Time tracking
Target version:-
Resolution:

Description

Go to /time_entries/report and filter by project or member. Both result in a list sorted by the row's respective ID, not by it's name.

timelog_controller.rb.patch Magnifier (3.86 KB) Brad Beattie, 2009-02-26 19:34

_report_criteria.rhtml.patch Magnifier (1.06 KB) Brad Beattie, 2009-02-27 01:31

2848.patch Magnifier (4.87 KB) Yuichi HARADA, 2021-09-15 10:18

2848-with-test.patch Magnifier (11.3 KB) Yuichi HARADA, 2021-09-28 07:00

History

#1 Updated by Brad Beattie over 12 years ago

I tried adding an order clause to the query, but found that sql_group_by talks about IDs, not names. Hrm...

Index: timelog_controller.rb
===================================================================
--- timelog_controller.rb    (revision 2521)
+++ timelog_controller.rb    (working copy)
@@ -90,6 +90,7 @@
       sql << " (%s) AND" % Project.allowed_to_condition(User.current, :view_time_entries)
       sql << " (spent_on BETWEEN '%s' AND '%s')" % [ActiveRecord::Base.connection.quoted_date(@from.to_time), ActiveRecord::Base.connection.quoted_date(@to.to_time)]
       sql << " GROUP BY #{sql_group_by}, tyear, tmonth, tweek, spent_on" 
+      sql << " ORDER BY #{sql_group_by}" 

       @hours = ActiveRecord::Base.connection.select_all(sql)

#2 Updated by Brad Beattie over 12 years ago

The attached patch should work. Wouldn't mind another eye on it though.

#3 Updated by Jean-Philippe Lang over 12 years ago

Your patch seems to work for projects and users but not for the other criteria.
Another option would be to the sort the query results in the app. That would save extra joins.

#4 Updated by Brad Beattie over 12 years ago

  • % Done changed from 80 to 30

Mm. Agreed on refactoring the sorting into the controller. I'll take a look at that today.

#5 Updated by Brad Beattie over 12 years ago

Jean-Philippe Lang wrote:

Your patch seems to work for projects and users but not for the other criteria.
Another option would be to the sort the query results in the app. That would save extra joins.

This attached patch should address both concerns.

#6 Updated by Kevin Fischer about 1 year ago

Last week we were looking at this long existing issue with a few people to create an up-to-date patch that covers all necessary cases.

We came to the conclusion that it is first necessary to clarify the right way to implement this issue.

As we can see from the current implementation ( https://github.com/redmine/redmine/blob/master/lib/redmine/helpers/time_report.rb#L49-L59 ), no order is specified for the data shown in the Report Tab, which results in data being returned in order of insertion/primary key. This order can neither be changed via settings/UI nor is it based on anything you can see anywhere in Redmine (like the name/title or a specified order).

The following category columns are available in the Time Report. With each column I write a suggested sorting order to be implemented for this patch.

  • Project: by name
  • Status: by position (Set in Administration > Issue Statuses)
  • Version: by name
  • Issue Category: by name
  • User: by last name and then by first name
  • Tracker: by position (Set in Administration > Trackers)
  • Activities: by position (Set in Administration > Enumerations)
  • Issue: by ID
  • List format custom fields: Alphabetically
  • Bool format custom fields: true first, then false

Above choices were made with a solution in mind, that would only add a fitting ORDER SQL condition to the existing code (similar to/extending Brad Beattie's patch).

I can, however, see at least two possible reasons why such a solution might not be good enough:

  1. User name display depends on Redmine settings. If the sort order should be based on the user name display settings, an SQL only solution becomes impossible
  2. A similar problem exists for list format custom fields. The best solution would probably be to sort the rows in the order of possible values, but since possible values are saved as a serialized JSON array, using their order with SQL is not possible.

Therefore, it might be necessary to implement a custom sorting solution in Ruby.

These are our thoughts so far, what do you think?

#8 Updated by Kevin Fischer about 1 year ago

Ah that's good to know. Then only problem number 2 (the sorting order of the list format custom fields) remains.

#9 Updated by Yuichi HARADA about 1 month ago

Kevin Fischer wrote:

The following category columns are available in the Time Report. With each column I write a suggested sorting order to be implemented for this patch.

  • Project: by name
  • Status: by position (Set in Administration > Issue Statuses)
  • Version: by name
  • Issue Category: by name
  • User: by last name and then by first name
  • Tracker: by position (Set in Administration > Trackers)
  • Activities: by position (Set in Administration > Enumerations)
  • Issue: by ID
  • List format custom fields: Alphabetically
  • Bool format custom fields: true first, then false

I created a patch that displays each column in the above order.
However, List format & Bool format custom fields columns are displayed in the order of the options in the custom field select box.
Any feedback is welcome.

#10 Updated by Yuichi HARADA 21 days ago

Yuichi HARADA wrote:

Kevin Fischer wrote:

The following category columns are available in the Time Report. With each column I write a suggested sorting order to be implemented for this patch.

  • Project: by name
  • Status: by position (Set in Administration > Issue Statuses)
  • Version: by name
  • Issue Category: by name
  • User: by last name and then by first name
  • Tracker: by position (Set in Administration > Trackers)
  • Activities: by position (Set in Administration > Enumerations)
  • Issue: by ID
  • List format custom fields: Alphabetically
  • Bool format custom fields: true first, then false

I created a patch that displays each column in the above order.
However, List format & Bool format custom fields columns are displayed in the order of the options in the custom field select box.

I created tests. I attach a patch with tests.

Also available in: Atom PDF