diff --git a/app/assets/stylesheets/application.css b/app/assets/stylesheets/application.css index 2d82fba7d..fb4d04e8e 100644 --- a/app/assets/stylesheets/application.css +++ b/app/assets/stylesheets/application.css @@ -444,6 +444,12 @@ div.table-list.boards .table-list-cell.name {width: 30%;} .query-columns select { min-width:150px; } +.menu-items label { + display:block; +} +.menu-items select { + min-width: 200px; +} .query-totals {text-align:right; margin-top:-2.3em;} .query-totals>span:not(:first-child) {margin-left:0.6em;} diff --git a/app/views/settings/_projects.html.erb b/app/views/settings/_projects.html.erb index 512bd8920..fe29020f3 100644 --- a/app/views/settings/_projects.html.erb +++ b/app/views/settings/_projects.html.erb @@ -39,6 +39,36 @@

+
+ <%= l(:setting_project_menu_order) %> +
+ <% menu_order_tag_id = "project_menu_order" %> + <% project_menu_items = menu_items(:project_menu) %> +
+ +
+ + + + +
+ <%= javascript_tag do %> + $(document).ready(function(){ + $('.menu-items').closest('form').submit(function(){ + $('#<%= menu_order_tag_id %> option:not(:disabled)').prop('selected', true); + }); + }); + <% end %> +
+
+
+ <%= submit_tag l(:button_save) %> <% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 3ae06f745..0670b4d66 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -516,6 +516,8 @@ en: setting_timelog_accept_future_dates: Accept time logs on future dates setting_show_status_changes_in_mail_subject: Show status changes in issue mail notifications subject setting_project_list_defaults: Projects list defaults + setting_project_menu_order: Project menu order + label_menu_order: order setting_twofa: Two-factor authentication permission_add_project: Create project diff --git a/config/locales/ja.yml b/config/locales/ja.yml index 17faf448c..d48a49131 100644 --- a/config/locales/ja.yml +++ b/config/locales/ja.yml @@ -1299,6 +1299,8 @@ ja: label_display_type: 表示形式 label_display_type_list: リスト label_display_type_board: ボード + setting_project_menu_order: プロジェクトメニューの並び順 + label_menu_order: 順序 label_my_bookmarks: My bookmarks label_import_time_entries: 作業時間のインポート field_toolbar_language_options: ツールバーのコードハイライトボタンで使用する言語 diff --git a/config/settings.yml b/config/settings.yml index bd3795756..a5b6e1f46 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -344,3 +344,22 @@ timelog_accept_future_dates: default: 1 show_status_changes_in_mail_subject: default: 1 +project_menu_order: + serialized: true + default: + - new_object + - overview + - activity + - roadmap + - issues + - new_issue + - time_entries + - gantt + - calendar + - news + - documents + - wiki + - boards + - files + - repository + - settings diff --git a/lib/redmine/menu_manager.rb b/lib/redmine/menu_manager.rb index 19169cfb7..de2da9a62 100644 --- a/lib/redmine/menu_manager.rb +++ b/lib/redmine/menu_manager.rb @@ -193,7 +193,7 @@ module Redmine def menu_items_for(menu, project=nil) items = [] - Redmine::MenuManager.items(menu).root.children.each do |node| + menu_items(menu).each do |node| if node.allowed?(User.current, project) if block_given? yield node @@ -205,6 +205,19 @@ module Redmine return block_given? ? nil : items end + def menu_items(menu) + items = Redmine::MenuManager.items(menu).root.children + if menu.to_sym == :project_menu || menu.to_sym == :application_menu + menu_order = Setting.project_menu_order + menu_order.unshift([:projects]) if menu.to_sym == :application_menu # Projects menu should always be first + items.sort_by.with_index do |menu_item, i| + menu_order.index { |menu_name| menu_item.name.to_s == menu_name.to_s } || i + end + else + items + end + end + def extract_node_details(node, project=nil) item = node url = diff --git a/test/unit/lib/redmine/menu_manager/menu_helper_test.rb b/test/unit/lib/redmine/menu_manager/menu_helper_test.rb index 6cdc4b11e..6f57ee212 100644 --- a/test/unit/lib/redmine/menu_manager/menu_helper_test.rb +++ b/test/unit/lib/redmine/menu_manager/menu_helper_test.rb @@ -381,4 +381,49 @@ class Redmine::MenuManager::MenuHelperTest < Redmine::HelperTest items = menu_items_for(menu_name, Project.find(1)) assert_equal 1, items.size end + + def test_menu_items_should_return_orderd_items_for_project_menu + Redmine::MenuManager.items(:project_menu).root.children.clear + Redmine::MenuManager.map :project_menu do |menu| + menu.push(:menu_1, '/', {}) + menu.push(:menu_2, '/', {}) + menu.push(:menu_3, '/', {}) + end + + with_settings :project_menu_order => [:menu_3, :menu_1, :menu_2] do + project_menu_items = menu_items(:project_menu) + assert_equal 3, project_menu_items.size + assert_equal [:menu_3, :menu_1, :menu_2], project_menu_items.map(&:name) + end + end + + def test_menu_items_should_return_orderd_items_for_application_menu + Redmine::MenuManager.items(:application_menu).root.children.clear + Redmine::MenuManager.map :application_menu do |menu| + menu.push(:projects, '/projects', {}) + menu.push(:menu_1, '/', {}) + menu.push(:menu_2, '/', {}) + menu.push(:menu_3, '/', {}) + end + + with_settings :project_menu_order => [:menu_3, :menu_1, :menu_2] do + application_menu_items = menu_items(:application_menu) + assert_equal 4, application_menu_items.size + assert_equal [:projects, :menu_3, :menu_1, :menu_2], application_menu_items.map(&:name) + end + end + + def test_menu_items_should_not_change_order_for_other_menu + Redmine::MenuManager.map :other_menu do |menu| + menu.push(:menu_1, '/', {}) + menu.push(:menu_2, '/', {}) + menu.push(:menu_3, '/', {}) + end + + with_settings :project_menu_order => [:menu_3, :menu_1, :menu_2] do + other_menu_items = menu_items(:other_menu) + assert_equal 3, other_menu_items.size + assert_equal [:menu_1, :menu_2, :menu_3], other_menu_items.map(&:name) + end + end end diff --git a/test/unit/setting_test.rb b/test/unit/setting_test.rb index d64dca66d..d5eec12f1 100644 --- a/test/unit/setting_test.rb +++ b/test/unit/setting_test.rb @@ -149,4 +149,8 @@ class SettingTest < ActiveSupport::TestCase def test_default_text_formatting_for_new_installations_is_common_mark assert_equal 'common_mark', Setting.text_formatting end + + def test_project_menu_order_should_return_project_menu_names + assert_equal %w(new_object overview activity roadmap issues new_issue time_entries gantt calendar news documents wiki boards files repository settings), Setting.project_menu_order + end end