Skip to content

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

Use Data object to easier controll that the menu item objects have the expected form

Henriette Darge6e9b89fa0de8
diff --git a/app/components/open_project/common/submenu_component.html.erb b/app/components/open_project/common/submenu_component.html.erb
index 9e19a14c8da..97fa34d2fa2 100644
--- a/app/components/open_project/common/submenu_component.html.erb
+++ b/app/components/open_project/common/submenu_component.html.erb
@@ -1,14 +1,14 @@
<div class="op-sidebar">
<div class="op-sidebar--body">
- <% top_level_sidebar_menu_items = @sidebar_menu_items.filter { |menu_item| menu_item[:header].nil? } %>
+ <% top_level_sidebar_menu_items = @sidebar_menu_items.filter { |menu_item| menu_item.header.nil? } %>
<% if top_level_sidebar_menu_items.any? %>
<div class="op-sidemenu">
<ul class="op-sidemenu--items">
- <% top_level_sidebar_menu_items.first[:children].each do |menu_item| %>
+ <% top_level_sidebar_menu_items.first.children.each do |menu_item| %>
<li class="op-sidemenu--item">
- <% selected = menu_item[:selected] ? 'selected' : '' %>
- <a class="op-sidemenu--item-action <%= selected %>" href="<%= menu_item[:href] %>">
- <span class="op-sidemenu--item-title"><%= menu_item[:title] %></span>
+ <% selected = menu_item.selected ? 'selected' : '' %>
+ <a class="op-sidemenu--item-action <%= selected %>" href="<%= menu_item.href %>">
+ <span class="op-sidemenu--item-title"><%= menu_item.title %></span>
</a>
</li>
<% end %>
@@ -17,7 +17,7 @@
<% end %>
- <% nested_sidebar_menu_items = @sidebar_menu_items.filter { |menu_item| menu_item[:header].present? } %>
+ <% nested_sidebar_menu_items = @sidebar_menu_items.filter { |menu_item| menu_item.header.present? } %>
<% if nested_sidebar_menu_items.any? %>
<% nested_sidebar_menu_items.each do |menu_item| %>
<div class="op-sidemenu"
@@ -27,7 +27,7 @@
<button class="op-sidemenu--title"
type="button"
data-action="click->menus--expandable-sidemenu#toggleContainer">
- <%= menu_item[:header] %>
+ <%= menu_item.header %>
<span class="icon-small icon-arrow-up1"
aria-hidden="true"
data-menus--expandable-sidemenu-target="indicator">
@@ -36,11 +36,11 @@
<ul class="op-sidemenu--items"
data-menus--expandable-sidemenu-target="container">
- <% menu_item[:children].each do |child_item| %>
+ <% menu_item.children.each do |child_item| %>
<li class="op-sidemenu--item">
- <% selected = child_item[:selected] ? 'selected' : '' %>
- <a class="op-sidemenu--item-action <%= selected %>" href="<%= child_item[:href] %>">
- <span class="op-sidemenu--item-title"><%= child_item[:title] %></span>
+ <% selected = child_item.selected ? 'selected' : '' %>
+ <a class="op-sidemenu--item-action <%= selected %>" href="<%= child_item.href %>">
+ <span class="op-sidemenu--item-title"><%= child_item.title %></span>
</a>
</li>
<% end %>
diff --git a/app/constants/menu.rb b/app/constants/menu.rb
new file mode 100644
index 00000000000..d5b801b7544
--- /dev/null
+++ b/app/constants/menu.rb
@@ -0,0 +1,34 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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 Menu
+ MenuGroup = Data.define(:header, :children)
+ MenuItem = Data.define(:title, :href, :selected)
+end
diff --git a/app/controllers/members/menus_controller.rb b/app/controllers/members/menus_controller.rb
index 6ebd8496d81..218cdf6e96e 100644
--- a/app/controllers/members/menus_controller.rb
+++ b/app/controllers/members/menus_controller.rb
@@ -36,37 +36,31 @@ module Members
def first_level_menu_items
[
- {
- header: nil,
- children: user_status_options
- }
+ Menu::MenuGroup.new(header: nil,
+ children: user_status_options)
]
end
def user_status_options
[
- {
- title: I18n.t('members.menu.all'),
- href: project_members_path,
- selected: active_filter_count == 0
- },
- {
- title: I18n.t('members.menu.locked'),
- href: project_members_path(status: :locked),
- selected: selected?(:status, :locked)
- },
- {
- title: I18n.t('members.menu.invited'),
- href: project_members_path(status: :invited),
- selected: selected?(:status, :invited)
- }
+ Menu::MenuItem.new(title: I18n.t('members.menu.all'),
+ href: project_members_path,
+ selected: active_filter_count == 0),
+ Menu::MenuItem.new(title: I18n.t('members.menu.locked'),
+ href: project_members_path(status: :locked),
+ selected: selected?(:status, :locked)),
+ Menu::MenuItem.new(title: I18n.t('members.menu.invited'),
+ href: project_members_path(status: :invited),
+ selected: selected?(:status, :invited))
]
end
def nested_menu_items
- [{ header: I18n.t('members.menu.project_roles'), children: project_roles_entries },
- { header: I18n.t('members.menu.wp_shares'), children: permission_menu_entries },
- { header: I18n.t('members.menu.groups'), children: project_group_entries }]
+ [
+ Menu::MenuGroup.new(header: I18n.t('members.menu.project_roles'), children: project_roles_entries),
+ Menu::MenuGroup.new(header: I18n.t('members.menu.wp_shares'), children: permission_menu_entries),
+ Menu::MenuGroup.new(header: I18n.t('members.menu.groups'), children: project_group_entries)
+ ]
end
private
@@ -95,11 +89,9 @@ module Members
end
def menu_item(filter_key, id, name)
- {
- title: name,
- href: project_members_path(filter_key => id),
- selected: selected?(filter_key, id)
- }
+ Menu::MenuItem.new(title: name,
+ href: project_members_path(filter_key => id),
+ selected: selected?(filter_key, id))
end
def selected?(filter_key, value)