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

introduce project custom field mapping UI

Jonas Jabari396f9e2fd7cf
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb
new file mode 100644
index 00000000000..dbe6078f60d
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.html.erb
@@ -0,0 +1,32 @@
+<%=
+ component_wrapper do
+ flex_layout(align_items: :center) do |custom_field_container|
+ custom_field_container.with_column(mr: 2) do
+ if active_in_project?
+ render(Primer::Beta::IconButton.new(
+ tag: :a,
+ href: project_settings_project_custom_fields_path(project_id: @project.id, project_custom_field_id: @project_custom_field.id),
+ scheme: :invisible,
+ icon: 'check-circle',
+ 'aria-label': 'Active in this project, click to disable',
+ data: { 'turbo-method': :put, 'turbo-stream': true }
+ ))
+ else
+ render(Primer::Beta::IconButton.new(
+ tag: :a,
+ href: project_settings_project_custom_fields_path(project_id: @project.id, project_custom_field_id: @project_custom_field.id),
+ scheme: :invisible,
+ icon: 'circle',
+ 'aria-label': 'Inactive in this project, click to enable',
+ data: { 'turbo-method': :put, 'turbo-stream': true }
+ ))
+ end
+ end
+ custom_field_container.with_column do
+ render(Primer::Beta::Text.new(font_weight: :bold)) do
+ @project_custom_field.name
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
new file mode 100644
index 00000000000..e2ac8ff65d4
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/custom_field_row_component.rb
@@ -0,0 +1,55 @@
+#-- 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 Projects
+ module Settings
+ module ProjectCustomFieldSections
+ class CustomFieldRowComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(project:, project_custom_field:, project_custom_field_project_mappings:)
+ super
+
+ @project = project
+ @project_custom_field = project_custom_field
+ @project_custom_field_project_mappings = project_custom_field_project_mappings
+ end
+
+ private
+
+ def active_in_project?
+ @project_custom_field_project_mappings.any? do |mapping|
+ mapping.custom_field_id == @project_custom_field.id
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/projects/settings/project_custom_field_sections/index_component.html.erb b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
new file mode 100644
index 00000000000..0cf52308aad
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/index_component.html.erb
@@ -0,0 +1,16 @@
+<%=
+ component_wrapper do
+ flex_layout do |flex|
+ @project_custom_fields_grouped_by_section.each do |section_id, project_custom_fields|
+ flex.with_row do
+ render(Projects::Settings::ProjectCustomFieldSections::ShowComponent.new(
+ project: @project,
+ project_custom_field_section: get_eager_loaded_project_custom_field_section(section_id),
+ project_custom_fields:,
+ project_custom_field_project_mappings: @project_custom_field_project_mappings
+ ))
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/settings/project_custom_field_sections/index_component.rb b/app/components/projects/settings/project_custom_field_sections/index_component.rb
new file mode 100644
index 00000000000..bba76f062bd
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/index_component.rb
@@ -0,0 +1,59 @@
+#-- 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 Projects
+ module Settings
+ module ProjectCustomFieldSections
+ class IndexComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(
+ project:,
+ project_custom_field_sections:,
+ project_custom_fields_grouped_by_section:,
+ project_custom_field_project_mappings:
+ )
+ super
+
+ @project = project
+ @project_custom_field_sections = project_custom_field_sections
+ @project_custom_fields_grouped_by_section = project_custom_fields_grouped_by_section
+ @project_custom_field_project_mappings = project_custom_field_project_mappings
+ end
+
+ private
+
+ def get_eager_loaded_project_custom_field_section(section_id)
+ @project_custom_field_sections.find { |section| section.id == section_id }
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb
new file mode 100644
index 00000000000..75485fdaf7f
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb
@@ -0,0 +1,46 @@
+<%=
+ component_wrapper do
+ render(Primer::Beta::BorderBox.new(mt: 3)) do |component|
+ component.with_header(font_weight: :bold) do
+ flex_layout(justify_content: :space_between, align_items: :center) do |section_header_container|
+ section_header_container.with_column(flex_layout: true, align_items: :center) do |content_container|
+ content_container.with_column do
+ render(Primer::Beta::Text.new(font_weight: :bold)) do
+ @project_custom_field_section.name
+ end
+ end
+ end
+ section_header_container.with_column(flex_layout: true, justify_content: :flex_end) do |actions_container|
+ actions_container.with_column do
+ # render(Primer::Alpha::ActionMenu.new) do |menu|
+ # menu.with_show_button(icon: "kebab-horizontal", 'aria-label': t("settings.project_attributes.label_section_actions"), scheme: :invisible)
+ # edit_action_item(menu)
+ # move_actions(menu)
+ # if @project_custom_fields.empty?
+ # delete_action_item(menu)
+ # else
+ # disabled_delete_action_item(menu)
+ # end
+ # end
+ end
+ end
+ end
+ end
+ if @project_custom_fields.empty?
+ component.with_row do
+ render(Primer::Beta::Text.new(color: :subtle)) { t("settings.project_attributes.label_no_project_custom_fields") }
+ end
+ else
+ sorted_project_custom_fields.each do |project_custom_field|
+ component.with_row do
+ render(Projects::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(
+ project: @project,
+ project_custom_field:,
+ project_custom_field_project_mappings: @project_custom_field_project_mappings,
+ ))
+ end
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.rb b/app/components/projects/settings/project_custom_field_sections/show_component.rb
new file mode 100644
index 00000000000..beb8c9dee73
--- /dev/null
+++ b/app/components/projects/settings/project_custom_field_sections/show_component.rb
@@ -0,0 +1,63 @@
+#-- 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 Projects
+ module Settings
+ module ProjectCustomFieldSections
+ class ShowComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(
+ project:,
+ project_custom_field_section:,
+ project_custom_fields:,
+ project_custom_field_project_mappings:
+ )
+ super
+
+ @project = project
+ @project_custom_field_section = project_custom_field_section
+ @project_custom_fields = project_custom_fields
+ @project_custom_field_project_mappings = project_custom_field_project_mappings
+ end
+
+ private
+
+ def wrapper_uniq_by
+ @project_custom_field_section.id
+ end
+
+ def sorted_project_custom_fields
+ @project_custom_fields.sort_by { |pcf| pcf.position_in_custom_field_section }
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/projects/settings/project_custom_fields/header_component.html.erb b/app/components/projects/settings/project_custom_fields/header_component.html.erb
new file mode 100644
index 00000000000..d7e5a689eac
--- /dev/null
+++ b/app/components/projects/settings/project_custom_fields/header_component.html.erb
@@ -0,0 +1,15 @@
+<%=
+ flex_layout do |header_container|
+ header_container.with_row do
+ render(Primer::Beta::Heading.new(tag: :h1)) { t('projects.settings.project_custom_fields.header.title') }
+ end
+ header_container.with_row(mt: 1, pb: 3, mb: 2, border: :bottom) do
+ render(Primer::Beta::Text.new(color: :muted)) do
+ t('projects.settings.project_custom_fields.header.description',
+ overview_url: project_path(@project),
+ admin_settings_url: admin_settings_project_custom_fields_path
+ ).html_safe
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/settings/project_custom_fields/header_component.rb b/app/components/projects/settings/project_custom_fields/header_component.rb
new file mode 100644
index 00000000000..c3881b428e8
--- /dev/null
+++ b/app/components/projects/settings/project_custom_fields/header_component.rb
@@ -0,0 +1,44 @@
+#-- 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 Projects
+ module Settings
+ module ProjectCustomFields
+ class HeaderComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+
+ def initialize(project:)
+ super
+
+ @project = project
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb
new file mode 100644
index 00000000000..1e1f1cd5f2d
--- /dev/null
+++ b/app/controllers/concerns/projects/settings/project_custom_fields/component_streams.rb
@@ -0,0 +1,55 @@
+#-- 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 Projects
+ module Settings
+ module ProjectCustomFields
+ module ComponentStreams
+ extend ActiveSupport::Concern
+
+ included do
+ def update_sections_via_turbo_stream(
+ project: @project,
+ project_custom_field_sections: @project_custom_field_sections,
+ project_custom_fields_grouped_by_section: @project_custom_fields_grouped_by_section,
+ project_custom_field_project_mappings: @project_custom_field_project_mappings
+ )
+ update_via_turbo_stream(
+ component: ::Projects::Settings::ProjectCustomFieldSections::IndexComponent.new(
+ project:,
+ project_custom_field_sections:,
+ project_custom_fields_grouped_by_section:,
+ project_custom_field_project_mappings:
+ )
+ )
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rb
new file mode 100644
index 00000000000..77fe7cdfe1a
--- /dev/null
+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb
@@ -0,0 +1,78 @@
+#-- 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.
+#++
+
+class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsController
+ include OpTurbo::ComponentStream
+ include Projects::Settings::ProjectCustomFields::ComponentStreams
+
+ menu_item :settings_project_custom_fields
+
+ before_action :eager_load_project_custom_field_sections, only: %i[show update]
+ before_action :eager_load_project_custom_fields, only: %i[show update]
+ before_action :eager_load_project_custom_field_project_mappings, only: %i[show update]
+
+ def show; end
+
+ def update
+ mapping = ProjectCustomFieldProjectMapping.find_or_initialize_by(
+ project_id: @project.id,
+ custom_field_id: params[:project_custom_field_id]
+ )
+
+ if mapping.persisted?
+ mapping.destroy!
+ else
+ mapping.save!
+ end
+
+ eager_load_project_custom_field_project_mappings # reload mappings
+
+ update_sections_via_turbo_stream
+
+ respond_with_turbo_streams
+ end
+
+ private
+
+ def eager_load_project_custom_field_sections
+ @project_custom_field_sections = ProjectCustomFieldSection.all.to_a
+ end
+
+ def eager_load_project_custom_fields
+ @project_custom_fields_grouped_by_section = ProjectCustomField
+ .includes(:project_custom_field_section)
+ .sort_by { |pcf| pcf.project_custom_field_section.position }
+ .group_by(&:custom_field_section_id)
+ end
+
+ def eager_load_project_custom_field_project_mappings
+ @project_custom_field_project_mappings = ProjectCustomFieldProjectMapping
+ .where(project_id: @project.id)
+ .to_a
+ end
+end
diff --git a/app/views/projects/settings/project_custom_fields/show.html.erb b/app/views/projects/settings/project_custom_fields/show.html.erb
new file mode 100644
index 00000000000..9b62dc8d9f5
--- /dev/null
+++ b/app/views/projects/settings/project_custom_fields/show.html.erb
@@ -0,0 +1,38 @@
+<%#-- 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.
+
+++#%>
+<div data-turbo="true">
+ <%= render(Projects::Settings::ProjectCustomFields::HeaderComponent.new(project: @project)) %>
+ <%= render(Projects::Settings::ProjectCustomFieldSections::IndexComponent.new(
+ project: @project,
+ project_custom_field_sections: @project_custom_field_sections,
+ project_custom_fields_grouped_by_section: @project_custom_fields_grouped_by_section,
+ project_custom_field_project_mappings: @project_custom_field_project_mappings,
+ )) %>
+</div>
+
diff --git a/config/initializers/menus.rb b/config/initializers/menus.rb
index 4cb63a19881..7e38a9eb562 100644
--- a/config/initializers/menus.rb
+++ b/config/initializers/menus.rb
@@ -613,6 +613,7 @@ Redmine::MenuManager.map :project_menu do |menu|
{
general: :label_information_plural,
+ project_custom_fields: :label_project_attributes_plural,
modules: :label_module_plural,
types: :label_work_package_types,
custom_fields: :label_custom_field_plural,
diff --git a/config/initializers/permissions.rb b/config/initializers/permissions.rb
index 51da2b030c7..680efcaf09f 100644
--- a/config/initializers/permissions.rb
+++ b/config/initializers/permissions.rb
@@ -109,6 +109,13 @@ Rails.application.reloader.to_prepare do
permissible_on: :project,
require: :member
+ map.permission :select_project_custom_fields,
+ {
+ 'projects/settings/project_custom_fields': %i[show update]
+ },
+ permissible_on: :project,
+ require: :member
+
map.permission :manage_members,
{ members: %i[index new create update destroy autocomplete_for_member] },
permissible_on: :project,
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 15b593c5579..5a80eb9ce43 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -288,6 +288,11 @@ en:
no_results_content_text: Create a new work package category
custom_fields:
no_results_title_text: There are currently no custom fields available.
+ project_custom_fields:
+ header:
+ title: "Project attributes"
+ description: "These project attributes will be displayed in your <a href=%{overview_url} target=\"_blank\">project overview page</a> under their respective sections. You can enable or disable individual attributes.
+Project attributes and sections are defined in the <a href=%{admin_settings_url} target=\"_blank\">administration settings</a> by the administrator of the instance. "
types:
no_results_title_text: There are currently no types available.
form:
diff --git a/config/routes.rb b/config/routes.rb
index 1f57c092e58..8731ab72c90 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -185,6 +185,7 @@ OpenProject::Application.routes.draw do
resource :general, only: %i[show], controller: 'general'
resource :modules, only: %i[show update]
resource :types, only: %i[show update]
+ resource :project_custom_fields, only: %i[show update]
resource :custom_fields, only: %i[show update]
resource :repository, only: %i[show], controller: 'repository'
resource :versions, only: %i[show]