Project

General

Profile

Actions

Feature #2848

open

Sort time entries by name, not ID

Added by Brad Beattie over 15 years ago. Updated almost 3 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
Time tracking
Start date:
2009-02-26
Due date:
% Done:

90%

Estimated time:
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.


Files

timelog_controller.rb.patch (3.86 KB) timelog_controller.rb.patch Brad Beattie, 2009-02-26 19:34
_report_criteria.rhtml.patch (1.06 KB) _report_criteria.rhtml.patch Brad Beattie, 2009-02-27 01:31
2848.patch (4.87 KB) 2848.patch Yuichi HARADA, 2021-09-15 10:18
2848-with-test.patch (11.3 KB) 2848-with-test.patch Yuichi HARADA, 2021-09-28 07:00
2848-with-test-v2.patch (11.3 KB) 2848-with-test-v2.patch Yuichi HARADA, 2022-01-20 02:23
Actions #1

Updated by Brad Beattie over 15 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)
Actions #2

Updated by Brad Beattie over 15 years ago

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

Actions #3

Updated by Jean-Philippe Lang over 15 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.

Actions #4

Updated by Brad Beattie over 15 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.

Actions #5

Updated by Brad Beattie over 15 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.

Actions #6

Updated by Kevin Fischer over 4 years 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?

Actions #7

Updated by Pavel Rosický over 4 years ago

Actions #8

Updated by Kevin Fischer over 4 years ago

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

Actions #9

Updated by Yuichi HARADA about 3 years 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.

Actions #10

Updated by Yuichi HARADA about 3 years 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.

Actions #11

Updated by Yuichi HARADA almost 3 years ago

Fixed the sort order of activities that work on the trunk(r21371).

Actions #12

Updated by Go MAEDA almost 3 years ago

  • Target version set to Candidate for next major release
Actions

Also available in: Atom PDF