OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Extract modules menu code into a separate file
Henriette Darge9cd66f5e7977
diff --git a/lib/redmine/menu_manager/top_menu/help_menu.rb b/lib/redmine/menu_manager/top_menu/help_menu.rbindex c1704eade92..0ab3e2a98dc 100644--- a/lib/redmine/menu_manager/top_menu/help_menu.rb+++ b/lib/redmine/menu_manager/top_menu/help_menu.rb@@ -51,6 +51,10 @@ module Redmine::MenuManager::TopMenu::HelpMenuendend+ def help_menu_item+ split_top_menu_into_main_or_more_menus[:help]+ end+def render_help_dropdownrender Primer::Alpha::ActionMenu.new(classes: "op-app-menu--item",menu_id: "op-app-header--help-menu",diff --git a/lib/redmine/menu_manager/top_menu/module_menu.rb b/lib/redmine/menu_manager/top_menu/module_menu.rbnew file mode 100644index 00000000000..7b268494412--- /dev/null+++ b/lib/redmine/menu_manager/top_menu/module_menu.rb@@ -0,0 +1,116 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# You should have received a copy of the GNU General Public License+# along with this program; if not, write to the Free Software+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module Redmine::MenuManager::TopMenu::ModuleMenu+ def render_module_top_menu_node(item_groups = module_top_menu_item_groups)+ unless item_groups.empty?+ render Primer::Alpha::Dialog.new(classes: "op-app-menu--item",+ title: I18n.t("label_modules"),+ visually_hide_title: true,+ size: :small,+ position: :left) do |dialog|+ dialog.with_show_button(icon: "op-grid-menu",+ scheme: :invisible,+ classes: "op-app-header--primer-button",+ title: I18n.t("label_modules"),+ test_selector: "op-app-header--modules-menu-button",+ "aria-controls": "op-app-header--modules-menu-list",+ "aria-label": I18n.t("label_modules"))+ dialog.with_header(classes: "op-app-header--modules-menu-header") do+ render_logo_icon+ end++ item_groups.each do |item_group|+ render_dialog_item_group(dialog, item_group)+ end+ end+ end+ end++ private++ def render_dialog_item_group(dialog, item_group)+ dialog.with_body do+ render Primer::Alpha::ActionList.new(+ classes: "op-app-menu--items",+ id: "op-app-header--modules-menu-list"+ ) do |list|+ list.with_heading(title: item_group[:title], align_items: :flex_start) if item_group[:title]++ my_items, remaining_items = item_group[:items].partition { |item| item.context == :my }++ render_action_list_items(list, my_items)++ list.with_divider if my_items.any? && remaining_items.any?++ render_action_list_items(list, remaining_items)+ end+ end+ end++ def render_action_list_items(list, items)+ items.each do |item|+ list.with_item(+ href: url_for(item.url),+ label: item.caption,+ test_selector: "op-menu--item-action"+ ) do |menu_item|+ menu_item.with_leading_visual_icon(icon: item.icon) if item.icon+ end+ end+ end++ def module_top_menu_item_groups+ items = more_top_menu_items+ item_groups = []++ # add untitled group, if no heading is present+ unless items.first.heading?+ item_groups = [{ title: nil, items: [] }]+ end++ # create item groups+ items.reduce(item_groups) do |groups, item|+ if item.heading?+ groups << { title: item.caption, items: [] }+ else+ groups.last[:items] << item+ end++ groups+ end+ end++ # Menu items for the modules top menu+ def more_top_menu_items+ split = split_top_menu_into_main_or_more_menus+ split[:modules] + split[:my]+ end+enddiff --git a/lib/redmine/menu_manager/top_menu/user_menu.rb b/lib/redmine/menu_manager/top_menu/user_menu.rbindex 255a3ef2a2a..0ceb21dca48 100644--- a/lib/redmine/menu_manager/top_menu/user_menu.rb+++ b/lib/redmine/menu_manager/top_menu/user_menu.rb@@ -57,7 +57,6 @@ module Redmine::MenuManager::TopMenu::UserMenuposition: :right) do |dialog|lateral_user_menu_button(dialog, avatar)-dialog.with_header(classes: "op-app-header--modules-menu-header") dolateral_user_menu_header(avatar)enddiff --git a/lib/redmine/menu_manager/top_menu_helper.rb b/lib/redmine/menu_manager/top_menu_helper.rbindex 1898aa8670a..0d654e1c4f5 100644--- a/lib/redmine/menu_manager/top_menu_helper.rb+++ b/lib/redmine/menu_manager/top_menu_helper.rb@@ -33,6 +33,7 @@ module Redmine::MenuManager::TopMenuHelperinclude Redmine::MenuManager::TopMenu::ProjectsMenuinclude Redmine::MenuManager::TopMenu::QuickAddMenuinclude Redmine::MenuManager::TopMenu::UserMenu+ include Redmine::MenuManager::TopMenu::ModuleMenudef render_top_menu_leftcontent_tag :ul, class: "op-app-menu op-app-menu_drop-left" do@@ -113,93 +114,6 @@ module Redmine::MenuManager::TopMenuHelperendend- def render_module_top_menu_node(item_groups = module_top_menu_item_groups)- unless item_groups.empty?- render Primer::Alpha::Dialog.new(classes: "op-app-menu--item",- title: I18n.t("label_modules"),- visually_hide_title: true,- size: :small,- position: :left) do |dialog|- dialog.with_show_button(icon: "op-grid-menu",- scheme: :invisible,- classes: "op-app-header--primer-button",- title: I18n.t("label_modules"),- test_selector: "op-app-header--modules-menu-button",- "aria-controls": "op-app-header--modules-menu-list",- "aria-label": I18n.t("label_modules"))- dialog.with_header(classes: "op-app-header--modules-menu-header") do- render_logo_icon- end-- item_groups.each do |item_group|- render_dialog_item_group(dialog, item_group)- end- end- end- end-- def render_dialog_item_group(dialog, item_group)- dialog.with_body do- render Primer::Alpha::ActionList.new(- classes: "op-app-menu--items",- id: "op-app-header--modules-menu-list"- ) do |list|- list.with_heading(title: item_group[:title], align_items: :flex_start) if item_group[:title]-- my_items, remaining_items = item_group[:items].partition { |item| item.context == :my }-- render_action_list_items(list, my_items)-- list.with_divider if my_items.any? && remaining_items.any?-- render_action_list_items(list, remaining_items)- end- end- end-- def render_action_list_items(list, items)- items.each do |item|- list.with_item(- href: url_for(item.url),- label: item.caption,- test_selector: "op-menu--item-action"- ) do |menu_item|- menu_item.with_leading_visual_icon(icon: item.icon) if item.icon- end- end- end-- # Menu items for the modules top menu- def more_top_menu_items- split = split_top_menu_into_main_or_more_menus- split[:modules] + split[:my]- end-- def module_top_menu_item_groups- items = more_top_menu_items- item_groups = []-- # add untitled group, if no heading is present- unless items.first.heading?- item_groups = [{ title: nil, items: [] }]- end-- # create item groups- items.reduce(item_groups) do |groups, item|- if item.heading?- groups << { title: item.caption, items: [] }- else- groups.last[:items] << item- end-- groups- end- end-- def help_menu_item- split_top_menu_into_main_or_more_menus[:help]- end-# Split the :top_menu into separate :main and :modules itemsdef split_top_menu_into_main_or_more_menus@split_top_menu_into_main_or_more_menus ||= begin