26537_show_column_project_by_default_time_entries_index.patch

Marius BALTEANU, 2017-08-06 15:04

Download (5.01 KB)

View differences:

app/controllers/timelog_controller.rb
272 272
  end
273 273

  
274 274
  def retrieve_time_entry_query
275
    retrieve_query(TimeEntryQuery, false, :defaults => Setting.time_entry_list_defaults.symbolize_keys)
275
    retrieve_query(TimeEntryQuery, false)
276 276
  end
277 277
end
app/models/time_entry_query.rb
99 99

  
100 100
  def default_columns_names
101 101
    @default_columns_names ||= begin
102
      default_columns = [:spent_on, :user, :activity, :issue, :comments, :hours]
103

  
102
      default_columns = Setting.time_entry_list_default_columns.map(&:to_sym)
104 103
      project.present? ? default_columns : [:project] | default_columns
105 104
    end
106 105
  end
107 106

  
108 107
  def default_totalable_names
109
    [:hours]
108
    Setting.time_entry_list_default_totals.map(&:to_sym)
110 109
  end
111 110

  
112 111
  def default_sort_criteria
app/views/settings/_timelog.html.erb
12 12
<fieldset class="box">
13 13
  <legend><%= l(:setting_time_entry_list_defaults) %></legend>
14 14

  
15
  <% query = TimeEntryQuery.new(Setting.time_entry_list_defaults) %>
16
  <%= render_query_columns_selection(query,
17
        :name => 'settings[time_entry_list_defaults][column_names]') %>
15
  <%= render_query_columns_selection(TimeEntryQuery.new(:column_names => Setting.time_entry_list_default_columns),
16
        :name => 'settings[time_entry_list_default_columns]') %>
18 17

  
19 18
  <p>
20 19
    <label><%= l(:label_total_plural) %></label>
21
    <%= available_totalable_columns_tags(query,
22
          :name => 'settings[time_entry_list_defaults][totalable_names]') %>
20
    <%= available_totalable_columns_tags(TimeEntryQuery.new(:totalable_names => Setting.time_entry_list_default_totals),
21
          :name => 'settings[time_entry_list_default_totals]') %>
23 22
  </p>
24 23
</fieldset>
25 24

  
config/settings.yml
209 209
  default: []
210 210
display_subprojects_issues:
211 211
  default: 1
212
time_entry_list_defaults:
212
time_entry_list_default_columns:
213 213
  serialized: true
214 214
  default:
215
    column_names:
216 215
    - spent_on
217 216
    - user
218 217
    - activity
219 218
    - issue
220 219
    - comments
221 220
    - hours
221
time_entry_list_default_totals:
222
  serialized: true
223
  default:
224
    - hours
222 225
issue_done_ratio:
223 226
  default: 'issue_field'
224 227
default_projects_public:
test/functional/timelog_controller_test.rb
711 711
    assert_select '.total-for-hours', :text => 'Hours: 162.90'
712 712
    assert_select 'form#query_form[action=?]', '/time_entries'
713 713

  
714
    assert_equal ['Date', 'User', 'Activity', 'Issue', 'Comment', 'Hours'], columns_in_list
714
    assert_equal ['Project', 'Date', 'User', 'Activity', 'Issue', 'Comment', 'Hours'], columns_in_list
715 715
    assert_select '.query-totals>span', 1
716 716
  end
717 717

  
718 718
  def test_index_with_default_query_setting
719
    with_settings :time_entry_list_defaults => {'column_names' => %w(spent_on issue user hours)} do
719
    with_settings :time_entry_list_default_columns => %w(spent_on issue user hours) do
720 720
      get :index
721 721
      assert_response :success
722 722
    end
723 723

  
724
    assert_equal ['Project', 'Date', 'Issue', 'User', 'Hours'], columns_in_list
725
  end
726

  
727
  def test_index_on_project_with_default_query_setting_should_not_include_project_column
728
    with_settings :time_entry_list_default_columns => %w(spent_on issue user hours) do
729
      get :index, :params => {:project_id => 'ecookbook'}
730
      assert_response :success
731
    end
732

  
724 733
    assert_equal ['Date', 'Issue', 'User', 'Hours'], columns_in_list
725 734
  end
726 735

  
727 736
  def test_index_with_default_query_setting_using_custom_field
728 737
    field = TimeEntryCustomField.create!(:name => 'Foo', :field_format => 'int')
729 738

  
730
    with_settings :time_entry_list_defaults => {
731
        'column_names' => ["spent_on", "user", "hours", "cf_#{field.id}"],
732
        'totalable_names' => ["hours", "cf_#{field.id}"]
733
      } do
739
    with_settings :time_entry_list_default_columns => ["spent_on", "user", "hours", "cf_#{field.id}"],
740
      :time_entry_list_default_totals => ["hours", "cf_#{field.id}"] do
734 741
      get :index
735 742
      assert_response :success
736 743
    end
737 744

  
738
    assert_equal ['Date', 'User', 'Hours', 'Foo'], columns_in_list
745
    assert_equal ['Project', 'Date', 'User', 'Hours', 'Foo'], columns_in_list
739 746

  
740 747
    assert_select '.total-for-hours'
741 748
    assert_select ".total-for-cf-#{field.id}"