summaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2013-07-28 09:59:34 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2013-07-28 09:59:34 +0000
commit21fc903c0424c45c86430588b0ecb8f0cc589efa (patch)
treed9654cffe1586acae13bf7cdcfca21292f8a6429 /app
parentdc5e5eca6b7cb124da1e47036f8a688bb4a7688c (diff)
downloadredmine-21fc903c0424c45c86430588b0ecb8f0cc589efa.tar.gz
redmine-21fc903c0424c45c86430588b0ecb8f0cc589efa.zip
Fixed that sorting time entries by custom field raises a SQL error (#14366).
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@12042 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app')
-rw-r--r--app/controllers/timelog_controller.rb14
-rw-r--r--app/models/time_entry_query.rb9
2 files changed, 14 insertions, 9 deletions
diff --git a/app/controllers/timelog_controller.rb b/app/controllers/timelog_controller.rb
index 64946a3ad..58f607031 100644
--- a/app/controllers/timelog_controller.rb
+++ b/app/controllers/timelog_controller.rb
@@ -43,10 +43,10 @@ class TimelogController < ApplicationController
def index
@query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_')
- scope = time_entry_scope
sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria)
sort_update(@query.sortable_columns)
+ scope = time_entry_scope(:order => sort_clause)
respond_to do |format|
format.html {
@@ -55,7 +55,6 @@ class TimelogController < ApplicationController
@entry_pages = Paginator.new @entry_count, per_page_option, params['page']
@entries = scope.all(
:include => [:project, :activity, :user, {:issue => :tracker}],
- :order => sort_clause,
:limit => @entry_pages.per_page,
:offset => @entry_pages.offset
)
@@ -68,15 +67,13 @@ class TimelogController < ApplicationController
@offset, @limit = api_offset_and_limit
@entries = scope.all(
:include => [:project, :activity, :user, {:issue => :tracker}],
- :order => sort_clause,
:limit => @limit,
:offset => @offset
)
}
format.atom {
- entries = scope.all(
+ entries = scope.reorder("#{TimeEntry.table_name}.created_on DESC").all(
:include => [:project, :activity, :user, {:issue => :tracker}],
- :order => "#{TimeEntry.table_name}.created_on DESC",
:limit => Setting.feeds_limit.to_i
)
render_feed(entries, :title => l(:label_spent_time))
@@ -84,8 +81,7 @@ class TimelogController < ApplicationController
format.csv {
# Export all entries
@entries = scope.all(
- :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
- :order => sort_clause
+ :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}]
)
send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
}
@@ -296,8 +292,8 @@ private
end
# Returns the TimeEntry scope for index and report actions
- def time_entry_scope
- scope = TimeEntry.visible.where(@query.statement)
+ def time_entry_scope(options={})
+ scope = @query.results_scope(options)
if @issue
scope = scope.on_issue(@issue)
elsif @project
diff --git a/app/models/time_entry_query.rb b/app/models/time_entry_query.rb
index 3a6ab64ef..3325b55a8 100644
--- a/app/models/time_entry_query.rb
+++ b/app/models/time_entry_query.rb
@@ -100,6 +100,15 @@ class TimeEntryQuery < Query
@default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours]
end
+ def results_scope(options={})
+ order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
+
+ TimeEntry.visible.
+ where(statement).
+ order(order_option).
+ joins(joins_for_order_statement(order_option.join(',')))
+ end
+
# Accepts :from/:to params as shortcut filters
def build_from_params(params)
super