@@ -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 | } |
@@ -296,8 +292,8 private | |||
|
296 | 292 | end |
|
297 | 293 | |
|
298 | 294 | # Returns the TimeEntry scope for index and report actions |
|
299 | def time_entry_scope | |
|
300 | scope = TimeEntry.visible.where(@query.statement) | |
|
295 | def time_entry_scope(options={}) | |
|
296 | scope = @query.results_scope(options) | |
|
301 | 297 | if @issue |
|
302 | 298 | scope = scope.on_issue(@issue) |
|
303 | 299 | 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 |
@@ -559,6 +559,24 class TimelogControllerTest < ActionController::TestCase | |||
|
559 | 559 | assert_select "td.#{field_name}", :text => 'CF Value' |
|
560 | 560 | end |
|
561 | 561 | |
|
562 | def test_index_with_time_entry_custom_field_sorting | |
|
563 | field = TimeEntryCustomField.generate!(:field_format => 'string', :name => 'String Field') | |
|
564 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 1'}) | |
|
565 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 3'}) | |
|
566 | TimeEntry.generate!(:hours => 2.5, :custom_field_values => {field.id => 'CF Value 2'}) | |
|
567 | field_name = "cf_#{field.id}" | |
|
568 | ||
|
569 | get :index, :c => ["hours", field_name], :sort => field_name | |
|
570 | assert_response :success | |
|
571 | assert_include field_name.to_sym, assigns(:query).column_names | |
|
572 | assert_select "th a.sort", :text => 'String Field' | |
|
573 | ||
|
574 | # Make sure that values are properly sorted | |
|
575 | values = assigns(:entries).map {|e| e.custom_field_value(field)}.compact | |
|
576 | assert_equal 3, values.size | |
|
577 | assert_equal values.sort, values | |
|
578 | end | |
|
579 | ||
|
562 | 580 | def test_index_atom_feed |
|
563 | 581 | get :index, :project_id => 1, :format => 'atom' |
|
564 | 582 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now