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

[OP#57514]: Add the projects tab in custom field edit view wrapped by a feature flag (#16543)

Kabiru Mwenja50780d834e2f
diff --git a/app/components/admin/custom_fields/edit_form_header_component.html.erb b/app/components/admin/custom_fields/edit_form_header_component.html.erb
new file mode 100644
index 00000000000..140535ca0d4
--- /dev/null
+++ b/app/components/admin/custom_fields/edit_form_header_component.html.erb
@@ -0,0 +1,52 @@
+<%#-- 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::PageHeader.new(test_selector: "custom-fields--page-header")) do |header|
+ header.with_title { @custom_field.name }
+
+ header.with_breadcrumbs(breadcrumbs_items)
+
+ header.with_tab_nav(label: nil, test_selector: :custom_field_detail_header) do |tab_nav|
+ tab_nav.with_tab(
+ selected: tab_selected?(:edit),
+ href: edit_custom_field_path(@custom_field)
+ ) do |tab|
+ tab.with_text { t(:label_details) }
+ end
+
+ tab_nav.with_tab(
+ selected: tab_selected?(:custom_field_projects),
+ href: custom_field_projects_path(@custom_field)
+ ) do |tab|
+ tab.with_text { t(:label_project_plural) }
+ end
+ end
+ end
+%>
diff --git a/app/components/admin/custom_fields/edit_form_header_component.rb b/app/components/admin/custom_fields/edit_form_header_component.rb
new file mode 100644
index 00000000000..c64d79dc8c5
--- /dev/null
+++ b/app/components/admin/custom_fields/edit_form_header_component.rb
@@ -0,0 +1,57 @@
+#-- 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 Admin
+ module CustomFields
+ class EditFormHeaderComponent < ApplicationComponent
+ TAB_NAVS = %i[
+ edit
+ custom_field_projects
+ ].freeze
+
+ def initialize(custom_field:, selected:, **)
+ @custom_field = custom_field
+ @selected = selected
+ super(custom_field, **)
+ end
+
+ def tab_selected?(tab_name)
+ TAB_NAVS.include?(tab_name) && tab_name == @selected
+ end
+
+ private
+
+ def breadcrumbs_items
+ [{ href: admin_index_path, text: t(:label_administration) },
+ { href: custom_fields_path, text: t(:label_custom_field_plural) },
+ { href: custom_fields_path(tab: @custom_field.type), text: I18n.t(@custom_field.type_name) },
+ @custom_field.name]
+ end
+ end
+ end
+end
diff --git a/app/controllers/admin/custom_fields/custom_field_projects_controller.rb b/app/controllers/admin/custom_fields/custom_field_projects_controller.rb
new file mode 100644
index 00000000000..1e067876492
--- /dev/null
+++ b/app/controllers/admin/custom_fields/custom_field_projects_controller.rb
@@ -0,0 +1,49 @@
+# 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.
+#++
+
+class Admin::CustomFields::CustomFieldProjectsController < ApplicationController
+ layout "admin"
+
+ model_object CustomField
+
+ before_action :require_admin
+ before_action :find_model_object
+
+ menu_item :custom_fields
+
+ def index; end
+
+ private
+
+ def find_model_object(object_id = :custom_field_id)
+ super
+ @custom_field = @object
+ end
+end
diff --git a/app/views/admin/custom_fields/custom_field_projects/index.html.erb b/app/views/admin/custom_fields/custom_field_projects/index.html.erb
new file mode 100644
index 00000000000..d5f9e0d0ff7
--- /dev/null
+++ b/app/views/admin/custom_fields/custom_field_projects/index.html.erb
@@ -0,0 +1,35 @@
+<%#-- 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.
+
+++#%>
+
+<% html_title t(:label_administration), "#{CustomField.model_name.human} #{h @custom_field.name}", t(:label_project_plural) %>
+
+<%=
+ render(Admin::CustomFields::EditFormHeaderComponent.new(custom_field: @custom_field,
+ selected: :custom_field_projects))
+%>
diff --git a/app/views/custom_fields/edit.html.erb b/app/views/custom_fields/edit.html.erb
index ccebc45111d..ef9cb71b6f1 100644
--- a/app/views/custom_fields/edit.html.erb
+++ b/app/views/custom_fields/edit.html.erb
@@ -28,15 +28,20 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<% html_title t(:label_administration), "#{t(:label_edit)} #{CustomField.model_name.human} #{h @custom_field.name}" %>
-<%=
- render(Primer::OpenProject::PageHeader.new(test_selector: "custom-fields--page-header")) do |header|
- header.with_title { @custom_field.name }
- header.with_breadcrumbs([{ href: admin_index_path, text: t(:label_administration) },
- { href: custom_fields_path, text: t(:label_custom_field_plural) },
- { href: custom_fields_path(tab: @custom_field.type), text: I18n.t(@custom_field.type_name) },
- @custom_field.name])
- end
-%>
+
+<% if OpenProject::FeatureDecisions.enable_custom_field_for_multiple_projects_active? %>
+ <%= render(Admin::CustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :edit)) %>
+<% else %>
+ <%=
+ render(Primer::OpenProject::PageHeader.new(test_selector: "custom-fields--page-header")) do |header|
+ header.with_title { @custom_field.name }
+ header.with_breadcrumbs([{ href: admin_index_path, text: t(:label_administration) },
+ { href: custom_fields_path, text: t(:label_custom_field_plural) },
+ { href: custom_fields_path(tab: @custom_field.type), text: I18n.t(@custom_field.type_name) },
+ @custom_field.name])
+ end
+ %>
+<% end %>
<%= error_messages_for 'custom_field' %>
diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rb
index 373a37fbb91..dea98a89d88 100644
--- a/config/initializers/feature_decisions.rb
+++ b/config/initializers/feature_decisions.rb
@@ -46,3 +46,7 @@ OpenProject::FeatureDecisions.add :percent_complete_edition,
OpenProject::FeatureDecisions.add :meeting_updated_notification,
description: "Allow flash messages to notify users about concurrent meeting edits. " \
"See work package #54744 for more details."
+
+OpenProject::FeatureDecisions.add :enable_custom_field_for_multiple_projects,
+ description: "Allow a custom field to be enabled for multiple projects at once. " \
+ "See work package #56909 for more details."
diff --git a/config/routes.rb b/config/routes.rb
index b5c8414b26f..599deee6f16 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -169,6 +169,14 @@ Rails.application.routes.draw do
post :reorder_alphabetical
end
+
+ scope module: :admin do
+ scope module: :custom_fields do
+ resources :projects,
+ controller: "/admin/custom_fields/custom_field_projects",
+ only: %i[index]
+ end
+ end
end
get "(projects/:project_id)/search" => "search#index", as: "search"
diff --git a/modules/storages/app/components/storages/admin/edit_form_header_component.rb b/modules/storages/app/components/storages/admin/edit_form_header_component.rb
index 1d988e0e07d..9552b42e43b 100644
--- a/modules/storages/app/components/storages/admin/edit_form_header_component.rb
+++ b/modules/storages/app/components/storages/admin/edit_form_header_component.rb
@@ -28,7 +28,7 @@
module Storages
module Admin
- class EditFormHeaderComponent < ApplicationComponent # rubocop:disable OpenProject/AddPreviewForViewComponent
+ class EditFormHeaderComponent < ApplicationComponent
TAB_NAVS = %i[
edit
project_storages