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

apply action menu also to project custom field settings

ulfertsbabd74733074
diff --git a/app/components/custom_fields/format_sub_header_component.html.erb b/app/components/custom_fields/format_sub_header_component.html.erb
new file mode 100644
index 00000000000..fabc74856e9
--- /dev/null
+++ b/app/components/custom_fields/format_sub_header_component.html.erb
@@ -0,0 +1,51 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ render(Primer::OpenProject::SubHeader.new) do |subheader|
+ subheader.with_action_menu(
+ scheme: :primary,
+ leading_icon: :plus,
+ trailing_icon: :"triangle-down",
+ label:,
+ button_arguments: {
+ scheme: :primary,
+ aria: { label: }
+ }
+ ) do |menu|
+ available_format_names.map do |format|
+ menu.with_item(
+ label: helpers.label_for_custom_field_format(format),
+ tag: :a,
+ href: new_custom_field_path(type: type, field_format: format)
+ )
+ end
+ end
+ end
+%>
diff --git a/app/components/custom_fields/format_sub_header_component.rb b/app/components/custom_fields/format_sub_header_component.rb
new file mode 100644
index 00000000000..b8f5bd6869f
--- /dev/null
+++ b/app/components/custom_fields/format_sub_header_component.rb
@@ -0,0 +1,53 @@
+# 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 CustomFields
+ class FormatSubHeaderComponent < ApplicationComponent
+ def initialize(customizable_name:)
+ super
+ @customizable_name = customizable_name
+ end
+
+ def label
+ I18n.t(:label_custom_field_new)
+ end
+
+ def type
+ "#{@customizable_name}CustomField"
+ end
+
+ def available_format_names
+ OpenProject::CustomFieldFormat
+ .available_for_class_name(@customizable_name)
+ .map(&:name)
+ .sort
+ end
+ end
+end
diff --git a/app/views/custom_fields/index.html.erb b/app/views/custom_fields/index.html.erb
index 2a8f63abdf1..5138b2c3045 100644
--- a/app/views/custom_fields/index.html.erb
+++ b/app/views/custom_fields/index.html.erb
@@ -31,29 +31,6 @@ See COPYRIGHT and LICENSE files for more details.
<%= render CustomFields::IndexPageHeaderComponent.new(tabs: custom_fields_tabs) %>
-<%=
- render(Primer::OpenProject::SubHeader.new) do |subheader|
- subheader.with_action_menu(
- scheme: :primary,
- leading_icon: :plus,
- trailing_icon: :"triangle-down",
- label: I18n.t(:label_custom_field_new),
- button_arguments: {
- scheme: :primary,
- aria: { label: I18n.t(:label_custom_field_new) }
- }
- ) do |menu|
- OpenProject::CustomFieldFormat.available_for_class_name(@tab.delete_suffix("CustomField"))
- .sort_by(&:name)
- .map do |format|
- menu.with_item(
- label: label_for_custom_field_format(format.name),
- tag: :a,
- href: new_custom_field_path(type: selected_tab(custom_fields_tabs)[:name], field_format: format.name)
- )
- end
- end
- end
-%>
+<%= render(CustomFields::FormatSubHeaderComponent.new(customizable_name: @tab.delete_suffix("CustomField"))) %>
<%= render_tabs custom_fields_tabs %>
diff --git a/app/views/projects/settings/work_packages/custom_fields/show.html.erb b/app/views/projects/settings/work_packages/custom_fields/show.html.erb
index a5dc15346a1..beea40eab77 100644
--- a/app/views/projects/settings/work_packages/custom_fields/show.html.erb
+++ b/app/views/projects/settings/work_packages/custom_fields/show.html.erb
@@ -31,17 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
<%=
if current_user.admin?
- render(Primer::OpenProject::SubHeader.new) do |subheader|
- subheader.with_action_button(
- scheme: :primary,
- leading_icon: :plus,
- label: t(:label_custom_field_new),
- tag: :a,
- href: new_custom_field_path(type: "WorkPackageCustomField")
- ) do
- CustomField.model_name.human
- end
- end
+ render(CustomFields::FormatSubHeaderComponent.new(customizable_name: "WorkPackage"))
end
%>