From 8ddb0902176dcf1abb795b28796aaaf8403198b5 Mon Sep 17 00:00:00 2001 From: Marius BALTEANU Date: Sun, 9 Sep 2018 11:17:11 +0000 Subject: [PATCH 7/7] user preference for issue history default tab --- app/helpers/issues_helper.rb | 15 +++++++++++++++ app/helpers/users_helper.rb | 9 +++++++++ app/models/user_preference.rb | 6 +++++- app/views/issues/show.html.erb | 2 +- app/views/users/_preferences.html.erb | 1 + config/locales/en.yml | 2 ++ public/javascripts/application.js | 5 +++++ test/functional/users_controller_test.rb | 4 +++- test/helpers/issues_helper_test.rb | 1 + 9 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 613be04..3054e34 100755 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -559,4 +559,19 @@ module IssuesHelper tabs end + def issue_history_default_tab + # tab params overrides user default tab preference + return params[:tab] if params[:tab].present? + user_default_tab = User.current.pref.history_default_tab + + case user_default_tab + when 'last_tab_visited' + cookies['history_last_tab'].present? ? cookies['history_last_tab'] : 'notes' + when '' + 'notes' + else + user_default_tab + end + end + end diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index c0d9544..2fbed85 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -33,6 +33,15 @@ module UsersHelper [[l(:label_font_default), '']] + UserPreference::TEXTAREA_FONT_OPTIONS.map {|o| [l("label_font_#{o}"), o]} end + def history_default_tab_options + [[l('label_issue_history_notes'), 'notes'], + [l('label_history'), 'history'], + [l('label_issue_history_properties'), 'properties'], + [l('label_time_entry_plural'), 'time_entries'], + [l('label_associated_revisions'), 'changesets'], + [l('label_last_tab_visited'), 'last_tab_visited']] + end + def change_status_link(user) url = {:controller => 'users', :action => 'update', :id => user, :page => params[:page], :status => params[:status], :tab => nil} diff --git a/app/models/user_preference.rb b/app/models/user_preference.rb index 7373290..23fcc8b 100644 --- a/app/models/user_preference.rb +++ b/app/models/user_preference.rb @@ -30,7 +30,8 @@ class UserPreference < ActiveRecord::Base 'comments_sorting', 'warn_on_leaving_unsaved', 'no_self_notified', - 'textarea_font' + 'textarea_font', + 'history_default_tab' TEXTAREA_FONT_OPTIONS = ['monospace', 'proportional'] @@ -88,6 +89,9 @@ class UserPreference < ActiveRecord::Base def textarea_font; self[:textarea_font] end def textarea_font=(value); self[:textarea_font]=value; end + def history_default_tab; self[:history_default_tab]; end + def history_default_tab=(value); self[:history_default_tab]=value; end + # Returns the names of groups that are displayed on user's page # Example: # preferences.my_page_groups diff --git a/app/views/issues/show.html.erb b/app/views/issues/show.html.erb index 55523f8..bb64fb3 100755 --- a/app/views/issues/show.html.erb +++ b/app/views/issues/show.html.erb @@ -124,7 +124,7 @@ end %>

<%=l(:label_history)%>

-<%= render_tabs issue_history_tabs, params[:tab] ? params[:tab] : 'notes' %> +<%= render_tabs issue_history_tabs, issue_history_default_tab %>
<%= render partial: 'action_menu_edit' unless User.current.wants_comments_in_reverse_order? %> diff --git a/app/views/users/_preferences.html.erb b/app/views/users/_preferences.html.erb index f876912..8cdcd1d 100644 --- a/app/views/users/_preferences.html.erb +++ b/app/views/users/_preferences.html.erb @@ -4,4 +4,5 @@

<%= pref_fields.select :comments_sorting, [[l(:label_chronological_order), 'asc'], [l(:label_reverse_chronological_order), 'desc']] %>

<%= pref_fields.check_box :warn_on_leaving_unsaved %>

<%= pref_fields.select :textarea_font, textarea_font_options %>

+

<%= pref_fields.select :history_default_tab, history_default_tab_options %>

<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 799d180..7c137af 100755 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -380,6 +380,7 @@ en: field_full_width_layout: Full width layout field_digest: Checksum field_default_assigned_to: Default assignee + field_history_default_tab: Issue's history default tab setting_app_title: Application title setting_welcome_text: Welcome text @@ -1037,6 +1038,7 @@ en: label_nothing_to_preview: Nothing to preview label_issue_history_properties: Property changes label_issue_history_notes: Notes + label_last_tab_visited: Last visited tab button_login: Login button_submit: Submit diff --git a/public/javascripts/application.js b/public/javascripts/application.js index cd0b0b9..8552e40 100755 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -918,6 +918,11 @@ function toggleNewObjectDropdown() { $(document).ready(function(){ $('#content').on('change', 'input[data-disables], input[data-enables], input[data-shows]', toggleDisabledOnChange); toggleDisabledInit(); + + $('#history .tabs').on('click', 'a', function(e){ + var tab = $(e.target).attr('id').replace('tab-',''); + document.cookie = 'history_last_tab=' + tab + }); }); $(document).ready(function(){ diff --git a/test/functional/users_controller_test.rb b/test/functional/users_controller_test.rb index 1f2dd4f..a5cb813 100644 --- a/test/functional/users_controller_test.rb +++ b/test/functional/users_controller_test.rb @@ -244,7 +244,8 @@ class UsersControllerTest < Redmine::ControllerTest 'time_zone' => 'Paris', 'comments_sorting' => 'desc', 'warn_on_leaving_unsaved' => '0', - 'textarea_font' => 'proportional' + 'textarea_font' => 'proportional', + 'history_default_tab' => 'history' } } end @@ -255,6 +256,7 @@ class UsersControllerTest < Redmine::ControllerTest assert_equal 'desc', user.pref[:comments_sorting] assert_equal '0', user.pref[:warn_on_leaving_unsaved] assert_equal 'proportional', user.pref[:textarea_font] + assert_equal 'history', user.pref[:history_default_tab] end def test_create_with_generate_password_should_email_the_password diff --git a/test/helpers/issues_helper_test.rb b/test/helpers/issues_helper_test.rb index 6908d51..9e5f8bc 100644 --- a/test/helpers/issues_helper_test.rb +++ b/test/helpers/issues_helper_test.rb @@ -329,4 +329,5 @@ class IssuesHelperTest < Redmine::HelperTest def test_find_name_by_reflection_should_return_nil_for_missing_record assert_nil find_name_by_reflection('status', 99) end + end -- 2.1.4