07_user_preference_for_issue_history_default_tab_r16963.patch

Marius BALTEANU, 2017-09-10 14:18

Download (6.39 KB)

View differences:

app/helpers/issues_helper.rb
82 82
    s << '<div>'
83 83
    subject = h(issue.subject)
84 84
    if issue.is_private?
85
      subject = subject + ' ' + content_tag('span', l(:field_is_private), :class => 'private') 
85
      subject = subject + ' ' + content_tag('span', l(:field_is_private), :class => 'private')
86 86
    end
87 87
    s << content_tag('h3', subject)
88 88
    s << '</div>' * (ancestors.size + 1)
......
557 557
    tabs
558 558
  end
559 559

  
560
  def issue_history_default_tab
561
    # tab params overrides user default tab preference
562
    return params[:tab] if params[:tab].present?
563
    user_default_tab = User.current.pref.history_default_tab
564

  
565
    case user_default_tab
566
    when 'last_tab_visited'
567
      cookies['history_last_tab'].present? ? cookies['history_last_tab'] : 'notes'
568
    when ''
569
      'notes'
570
    else
571
      user_default_tab
572
    end
573
  end
574

  
560 575
end
app/helpers/users_helper.rb
34 34
    [[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]}
35 35
  end
36 36

  
37
  def history_default_tab_options
38
    [[l('label_issue_history_notes'), 'notes'],
39
     [l('label_history'), 'history'],
40
     [l('label_issue_history_properties'), 'properties'],
41
     [l('label_time_entry_plural'), 'time_entries'],
42
     [l('label_associated_revisions'), 'changesets'],
43
     [l('label_last_tab_visited'), 'last_tab_visited']]
44
  end
45

  
37 46
  def change_status_link(user)
38 47
    url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil}
39 48

  
app/models/user_preference.rb
30 30
    'comments_sorting',
31 31
    'warn_on_leaving_unsaved',
32 32
    'no_self_notified',
33
    'textarea_font'
33
    'textarea_font',
34
    'history_default_tab'
34 35

  
35 36
  TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional']
36 37

  
......
88 89
  def textarea_font; self[:textarea_font] end
89 90
  def textarea_font=(value); self[:textarea_font]=value; end
90 91

  
92
  def history_default_tab; self[:history_default_tab]; end
93
  def history_default_tab=(value); self[:history_default_tab]=value; end
94

  
91 95
  # Returns the names of groups that are displayed on user's page
92 96
  # Example:
93 97
  #   preferences.my_page_groups
app/views/issues/show.html.erb
120 120

  
121 121
<div id="history">
122 122
<h3><%=l(:label_history)%></h3>
123
<%= render_tabs issue_history_tabs, params[:tab] ? params[:tab] : 'notes' %>
123
<%= render_tabs issue_history_tabs, issue_history_default_tab %>
124 124
</div>
125 125

  
126 126
<div style="clear: both;"></div>
app/views/users/_preferences.html.erb
4 4
<p><%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %></p>
5 5
<p><%= pref_fields.check_box :warn_on_leaving_unsaved %></p>
6 6
<p><%= pref_fields.select :textarea_font, textarea_font_options %></p>
7
<p><%= pref_fields.select :history_default_tab, history_default_tab_options %></p>
7 8
<% end %>
config/locales/en.yml
376 376
  field_full_width_layout: Full width layout
377 377
  field_digest: Checksum
378 378
  field_default_assigned_to: Default assignee
379
  field_history_default_tab: Issue's history default tab
379 380

  
380 381
  setting_app_title: Application title
381 382
  setting_app_subtitle: Application subtitle
......
1027 1028
  label_last_notes: Last notes
1028 1029
  label_issue_history_properties: Property changes
1029 1030
  label_issue_history_notes: Notes
1031
  label_last_tab_visited: Last visited tab
1030 1032

  
1031 1033
  button_login: Login
1032 1034
  button_submit: Submit
public/javascripts/application.js
892 892
$(document).ready(function(){
893 893
  $('#content').on('change', 'input[data-disables], input[data-enables], input[data-shows]', toggleDisabledOnChange);
894 894
  toggleDisabledInit();
895

  
896
  $('#history .tabs').on('click', 'a', function(e){
897
    var tab = $(e.target).attr('id').replace('tab-','');
898
    document.cookie = 'history_last_tab=' + tab
899
  });
895 900
});
896 901

  
897 902
function keepAnchorOnSignIn(form){
test/functional/users_controller_test.rb
203 203
          'time_zone' => 'Paris',
204 204
          'comments_sorting' => 'desc',
205 205
          'warn_on_leaving_unsaved' => '0',
206
          'textarea_font' => 'proportional'
206
          'textarea_font' => 'proportional',
207
          'history_default_tab' => 'history'
207 208
        }
208 209
      }
209 210
    end
......
214 215
    assert_equal 'desc', user.pref[:comments_sorting]
215 216
    assert_equal '0', user.pref[:warn_on_leaving_unsaved]
216 217
    assert_equal 'proportional', user.pref[:textarea_font]
218
    assert_equal 'history', user.pref[:history_default_tab]
217 219
  end
218 220

  
219 221
  def test_create_with_generate_password_should_email_the_password
test/helpers/issues_helper_test.rb
329 329
  def test_find_name_by_reflection_should_return_nil_for_missing_record
330 330
    assert_nil find_name_by_reflection('status', 99)
331 331
  end
332

  
332 333
end