@@ -43,10 +43,10 class TimelogController < ApplicationController | |||||
43 |
|
43 | |||
44 | def index |
|
44 | def index | |
45 | @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') |
|
45 | @query = TimeEntryQuery.build_from_params(params, :project => @project, :name => '_') | |
46 | scope = time_entry_scope |
|
|||
47 |
|
46 | |||
48 | sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) |
|
47 | sort_init(@query.sort_criteria.empty? ? [['spent_on', 'desc']] : @query.sort_criteria) | |
49 | sort_update(@query.sortable_columns) |
|
48 | sort_update(@query.sortable_columns) | |
|
49 | scope = time_entry_scope(:order => sort_clause) | |||
50 |
|
50 | |||
51 | respond_to do |format| |
|
51 | respond_to do |format| | |
52 | format.html { |
|
52 | format.html { | |
@@ -55,7 +55,6 class TimelogController < ApplicationController | |||||
55 | @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] |
|
55 | @entry_pages = Paginator.new @entry_count, per_page_option, params['page'] | |
56 | @entries = scope.all( |
|
56 | @entries = scope.all( | |
57 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
57 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
58 | :order => sort_clause, |
|
|||
59 | :limit => @entry_pages.per_page, |
|
58 | :limit => @entry_pages.per_page, | |
60 | :offset => @entry_pages.offset |
|
59 | :offset => @entry_pages.offset | |
61 | ) |
|
60 | ) | |
@@ -68,15 +67,13 class TimelogController < ApplicationController | |||||
68 | @offset, @limit = api_offset_and_limit |
|
67 | @offset, @limit = api_offset_and_limit | |
69 | @entries = scope.all( |
|
68 | @entries = scope.all( | |
70 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
69 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
71 | :order => sort_clause, |
|
|||
72 | :limit => @limit, |
|
70 | :limit => @limit, | |
73 | :offset => @offset |
|
71 | :offset => @offset | |
74 | ) |
|
72 | ) | |
75 | } |
|
73 | } | |
76 | format.atom { |
|
74 | format.atom { | |
77 | entries = scope.all( |
|
75 | entries = scope.reorder("#{TimeEntry.table_name}.created_on DESC").all( | |
78 | :include => [:project, :activity, :user, {:issue => :tracker}], |
|
76 | :include => [:project, :activity, :user, {:issue => :tracker}], | |
79 | :order => "#{TimeEntry.table_name}.created_on DESC", |
|
|||
80 | :limit => Setting.feeds_limit.to_i |
|
77 | :limit => Setting.feeds_limit.to_i | |
81 | ) |
|
78 | ) | |
82 | render_feed(entries, :title => l(:label_spent_time)) |
|
79 | render_feed(entries, :title => l(:label_spent_time)) | |
@@ -84,8 +81,7 class TimelogController < ApplicationController | |||||
84 | format.csv { |
|
81 | format.csv { | |
85 | # Export all entries |
|
82 | # Export all entries | |
86 | @entries = scope.all( |
|
83 | @entries = scope.all( | |
87 |
:include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}] |
|
84 | :include => [:project, :activity, :user, {:issue => [:tracker, :assigned_to, :priority]}] | |
88 | :order => sort_clause |
|
|||
89 | ) |
|
85 | ) | |
90 | send_data(query_to_csv(@entries, @query, params), :type => 'text/csv; header=present', :filename => 'timelog.csv') |
|
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 | end |
|
291 | end | |
296 |
|
292 | |||
297 | # Returns the TimeEntry scope for index and report actions |
|
293 | # Returns the TimeEntry scope for index and report actions | |
298 | def time_entry_scope |
|
294 | def time_entry_scope(options={}) | |
299 | scope = TimeEntry.visible.where(@query.statement) |
|
295 | scope = @query.results_scope(options) | |
300 | if @issue |
|
296 | if @issue | |
301 | scope = scope.on_issue(@issue) |
|
297 | scope = scope.on_issue(@issue) | |
302 | elsif @project |
|
298 | elsif @project |
@@ -100,6 +100,15 class TimeEntryQuery < Query | |||||
100 | @default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours] |
|
100 | @default_columns_names ||= [:project, :spent_on, :user, :activity, :issue, :comments, :hours] | |
101 | end |
|
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 | # Accepts :from/:to params as shortcut filters |
|
112 | # Accepts :from/:to params as shortcut filters | |
104 | def build_from_params(params) |
|
113 | def build_from_params(params) | |
105 | super |
|
114 | super |
@@ -540,6 +540,24 class TimelogControllerTest < ActionController::TestCase | |||||
540 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' |
|
540 | assert_select 'td.issue_cf_2', :text => 'filter_on_issue_custom_field' | |
541 | end |
|
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 | def test_index_atom_feed |
|
561 | def test_index_atom_feed | |
544 | get :index, :project_id => 1, :format => 'atom' |
|
562 | get :index, :project_id => 1, :format => 'atom' | |
545 | assert_response :success |
|
563 | assert_response :success |
General Comments 0
You need to be logged in to leave comments.
Login now