##// END OF EJS Templates
Merged r12042 from trunk (#14366)....
Jean-Philippe Lang -
r11813:493119e795f0
parent child
Show More
@@ -43,10 +43,10 class TimelogController < ApplicationController
43 43
44 44 def index
45 45 @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_')
46 scope = time_entry_scope
47 46
48 47 sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria)
49 48 sort_update(@query.sortable_columns)
49 scope = time_entry_scope(:order => sort_clause)
50 50
51 51 respond_to do |format|
52 52 format.html {
@@ -55,7 +55,6 class TimelogController < ApplicationController
55 55 @entry_pages = Paginator.new @entry_count, per_page_option, params['page']
56 56 @entries = scope.all(
57 57 :include => [:project, :activity, :user, {:issue => :tracker}],
58 :order => sort_clause,
59 58 :limit => @entry_pages.per_page,
60 59 :offset => @entry_pages.offset
61 60 )
@@ -68,15 +67,13 class TimelogController < ApplicationController
68 67 @offset, @limit = api_offset_and_limit
69 68 @entries = scope.all(
70 69 :include => [:project, :activity, :user, {:issue => :tracker}],
71 :order => sort_clause,
72 70 :limit => @limit,
73 71 :offset => @offset
74 72 )
75 73 }
76 74 format.atom {
77 entries = scope.all(
75 entries = scope.reorder("#{TimeEntry.table_name}.created_on DESC").all(
78 76 :include => [:project, :activity, :user, {:issue => :tracker}],
79 :order => "#{TimeEntry.table_name}.created_on DESC",
80 77 :limit => Setting.feeds_limit.to_i
81 78 )
82 79 render_feed(entries, :title => l(:label_spent_time))
@@ -84,8 +81,7 class TimelogController < ApplicationController
84 81 format.csv {
85 82 # Export all entries
86 83 @entries = scope.all(
87 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}],
88 :order => sort_clause
84 :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}]
89 85 )
90 86 send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv')
91 87 }
@@ -295,8 +291,8 private
295 291 end
296 292
297 293 # Returns the TimeEntry scope for index and report actions
298 def time_entry_scope
299 scope = TimeEntry.visible.where(@query.statement)
294 def time_entry_scope(options={})
295 scope = @query.results_scope(options)
300 296 if @issue
301 297 scope = scope.on_issue(@issue)
302 298 elsif @project
@@ -100,6 +100,15 class TimeEntryQuery < Query
100 100 @default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours]
101 101 end
102 102
103 def results_scope(options={})
104 order_option = [group_by_sort_order, options[:order]].flatten.reject(&:blank?)
105
106 TimeEntry.visible.
107 where(statement).
108 order(order_option).
109 joins(joins_for_order_statement(order_option.join(',')))
110 end
111
103 112 # Accepts :from/:to params as shortcut filters
104 113 def build_from_params(params)
105 114 super
@@ -540,6 +540,24 class TimelogControllerTest < ActionController::TestCase
540 540 assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field'
541 541 end
542 542
543 def test_index_with_time_entry_custom_field_sorting
544 field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field')
545 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'})
546 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'})
547 TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'})
548 field_name = "cf_#{field.id}"
549
550 get :index, :c => ["hours", field_name], :sort => field_name
551 assert_response :success
552 assert_include field_name.to_sym, assigns(:query).column_names
553 assert_select "th a.sort", :text => 'String Field'
554
555 # Make sure that values are properly sorted
556 values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact
557 assert_equal 3, values.size
558 assert_equal values.sort, values
559 end
560
543 561 def test_index_atom_feed
544 562 get :index, :project_id => 1, :format => 'atom'
545 563 assert_response :success
General Comments 0
You need to be logged in to leave comments. Login now