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

[#67453] added hierarchical lists to project custom fields

Eric Schuberte321db10d43b
diff --git a/app/components/custom_fields/details_component.rb b/app/components/custom_fields/details_component.rb
index 98493124464..f7b75c6b55b 100644
--- a/app/components/custom_fields/details_component.rb
+++ b/app/components/custom_fields/details_component.rb
@@ -38,7 +38,7 @@ module CustomFields
def persisted_cf_has_no_items_or_projects?
custom_field.persisted? &&
- custom_field.field_format_hierarchy? &&
+ custom_field.hierarchical_list? &&
custom_field.hierarchy_root.children.empty? &&
custom_field.projects.empty?
end
diff --git a/app/components/settings/project_custom_fields/edit_form_header_component.rb b/app/components/settings/project_custom_fields/edit_form_header_component.rb
index 5b869942ee3..4bddbab106f 100644
--- a/app/components/settings/project_custom_fields/edit_form_header_component.rb
+++ b/app/components/settings/project_custom_fields/edit_form_header_component.rb
@@ -37,18 +37,30 @@ module Settings
end
def tabs
- [
+ tabs = [
{
name: "project_custom_field_edit",
path: edit_admin_settings_project_custom_field_path(@custom_field),
label: t(:label_details)
},
+ ]
+
+ if @custom_field.hierarchical_list?
+ tabs << {
+ name: "items",
+ path: admin_settings_project_custom_field_items_path(@custom_field),
+ label: t(:label_item_plural)
+ }
+ end
+
+ tabs <<
{
name: "project_custom_field_project_mappings",
path: project_mappings_admin_settings_project_custom_field_path(@custom_field),
label: t(:label_project_mappings)
}
- ]
+
+ tabs
end
def breadcrumbs_items
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb
new file mode 100644
index 00000000000..aed7e2bf356
--- /dev/null
+++ b/app/controllers/admin/custom_fields/hierarchy/items_base_controller.rb
@@ -0,0 +1,231 @@
+# 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 Admin
+ module CustomFields
+ module Hierarchy
+ class ItemsBaseController < ApplicationController
+ include OpTurbo::ComponentStream
+ include Dry::Monads[:result]
+
+ layout :admin_or_frame_layout
+ model_object CustomField
+
+ before_action :require_admin, :find_model_object, :find_active_item
+
+ # See https://github.com/hotwired/turbo-rails?tab=readme-ov-file#a-note-on-custom-layouts
+ def admin_or_frame_layout
+ return "turbo_rails/frame" if turbo_frame_request?
+
+ "admin"
+ end
+
+ def index; end
+
+ def show
+ render action: :index
+ end
+
+ def new
+ @new_item = @active_item.children.build(sort_order: params[:position])
+ end
+
+ def edit; end
+
+ def create
+ item_service
+ .insert_item(contract_class: create_contract, **item_input)
+ .either(
+ lambda { |item| redirect_to action: :new, position: item.sort_order + 1 },
+ lambda do |validation_result|
+ add_errors_to_form(validation_result)
+ render :new
+ end
+ )
+ end
+
+ def update
+ input = item_input
+ item_service
+ .update_item(contract_class: update_contract,
+ item: @active_item,
+ label: input[:label],
+ short: input[:short],
+ score: input[:score])
+ .either(
+ ->(*) { redirect_to action: :show, id: @active_item.parent, status: :see_other },
+ lambda do |validation_result|
+ add_errors_to_edit_form(validation_result)
+ update_via_turbo_stream(component: ItemComponent.new(item: @active_item, show_edit_form: true))
+ respond_with_turbo_streams
+ end
+ )
+ end
+
+ def move
+ item_service
+ .reorder_item(item: @active_item, new_sort_order: params.require(:new_sort_order))
+
+ redirect_to action: :show, id: @active_item.parent, status: :see_other
+ end
+
+ def change_parent # rubocop:disable Metrics/AbcSize
+ input = params.require(:custom_field_hierarchy_forms_new_parent_form_model).require(:new_parent)
+
+ parse_parent_input(input).bind do |new_parent|
+ validate_new_parent(new_parent).bind do
+ item_service.move_item(item: @active_item, new_parent:)
+ end
+ end.either(
+ ->(result) do
+ redirect_to action: :show,
+ id: result.parent,
+ status: :see_other,
+ notice: I18n.t(:notice_successful_update)
+ end,
+ ->(error) do
+ render_error_flash_message_via_turbo_stream(message: error)
+ respond_with_turbo_streams(&:html)
+ end
+ )
+ end
+
+ def destroy
+ item_service
+ .delete_branch(item: @active_item)
+ .either(
+ ->(_) { update_via_turbo_stream(component: ItemsComponent.new(item: @active_item.parent.reload)) },
+ ->(errors) { render_error_flash_message_via_turbo_stream(message: errors.full_messages) }
+ )
+
+ respond_with_turbo_streams(&:html)
+ end
+
+ def deletion_dialog
+ respond_with_dialog DeleteItemDialogComponent.new(custom_field: @custom_field, hierarchy_item: @active_item)
+ end
+
+ def change_parent_dialog
+ respond_with_dialog ChangeItemParentDialogComponent.new(
+ custom_field: @custom_field,
+ hierarchy_item: @active_item
+ )
+ end
+
+ private
+
+ def item_service
+ ::CustomFields::Hierarchy::HierarchicalItemService.new
+ end
+
+ def item_input # rubocop:disable Metrics/AbcSize
+ input = { parent: @active_item, label: params[:label] }
+ input[:short] = params[:short] if params[:short].present?
+ input[:score] = params[:score] if params[:score].present?
+ input[:sort_order] = params[:sort_order].to_i if params[:sort_order].present?
+
+ input
+ end
+
+ def create_contract
+ case @custom_field.field_format
+ when "hierarchy"
+ ::CustomFields::Hierarchy::InsertListItemContract
+ when "scored_list"
+ ::CustomFields::Hierarchy::InsertScoredItemContract
+ else
+ raise ArgumentError, "unsupported custom field format '#{@custom_field.field_format}'"
+ end
+ end
+
+ def update_contract
+ case @custom_field.field_format
+ when "hierarchy"
+ ::CustomFields::Hierarchy::UpdateListItemContract
+ when "scored_list"
+ ::CustomFields::Hierarchy::UpdateScoredItemContract
+ else
+ raise ArgumentError, "unsupported custom field format '#{@custom_field.field_format}'"
+ end
+ end
+
+ def add_errors_to_form(validation_result)
+ @new_item = ::CustomField::Hierarchy::Item.new(**item_input)
+ validation_result.errors(full: true).to_h.each do |attribute, errors|
+ @new_item.errors.add(attribute, errors.join(", "))
+ end
+ end
+
+ def add_errors_to_edit_form(validation_result)
+ @active_item.assign_attributes(**validation_result.to_h.slice(:label, :short, :score))
+
+ validation_result.errors(full: true).to_h.each do |attribute, errors|
+ @active_item.errors.add(attribute, errors.join(", "))
+ end
+ end
+
+ def parse_parent_input(new_parent_input)
+ case new_parent_input
+ in [new_parent]
+ input = MultiJson.load(new_parent, symbolize_keys: true)[:value]
+ new_parent = CustomField::Hierarchy::Item.including_children.find(input)
+ Success(new_parent)
+ else
+ Failure("Invalid input: #{new_parent_input}")
+ end
+ end
+
+ def validate_new_parent(new_parent)
+ return Failure(I18n.t(:notice_change_parent_same_target)) if @active_item.parent.id == new_parent.id
+ return Failure(I18n.t(:notice_change_parent_to_self)) if @active_item.id == new_parent.id
+
+ Success()
+ end
+
+ def find_model_object
+ @object = find_custom_field
+ @custom_field = @object
+ end
+
+ def find_custom_field
+ raise NotImplementedError, "SubclassResponsibility"
+ end
+
+ def find_active_item
+ @active_item = if params[:id].present?
+ CustomField::Hierarchy::Item.including_children.find(params[:id])
+ else
+ @object.hierarchy_root
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
index 0793930f9d1..a4816eac0c5 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
@@ -31,203 +31,13 @@
module Admin
module CustomFields
module Hierarchy
- class ItemsController < ApplicationController
- include OpTurbo::ComponentStream
- include Dry::Monads[:result]
-
- layout :admin_or_frame_layout
- model_object CustomField
-
- before_action :require_admin, :find_model_object, :find_active_item
-
+ class ItemsController < ItemsBaseController
menu_item :custom_fields
- # See https://github.com/hotwired/turbo-rails?tab=readme-ov-file#a-note-on-custom-layouts
- def admin_or_frame_layout
- return "turbo_rails/frame" if turbo_frame_request?
-
- "admin"
- end
-
- def index; end
-
- def show
- render action: :index
- end
-
- def new
- @new_item = @active_item.children.build(sort_order: params[:position])
- end
-
- def edit; end
-
- def create
- item_service
- .insert_item(contract_class: create_contract, **item_input)
- .either(
- lambda do |item|
- redirect_to(
- new_child_custom_field_item_path(@custom_field, @active_item, position: item.sort_order + 1),
- status: :see_other
- )
- end,
- lambda do |validation_result|
- add_errors_to_form(validation_result)
- render :new
- end
- )
- end
-
- def update # rubocop:disable Metrics/AbcSize
- input = item_input
- item_service
- .update_item(contract_class: update_contract,
- item: @active_item,
- label: input[:label],
- short: input[:short],
- score: input[:score])
- .either(
- ->(*) { redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other) },
- lambda do |validation_result|
- add_errors_to_edit_form(validation_result)
- update_via_turbo_stream(component: ItemComponent.new(item: @active_item, show_edit_form: true))
- respond_with_turbo_streams
- end
- )
- end
-
- def move
- item_service
- .reorder_item(item: @active_item, new_sort_order: params.require(:new_sort_order))
-
- redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other)
- end
-
- def change_parent # rubocop:disable Metrics/AbcSize
- input = params.require(:custom_field_hierarchy_forms_new_parent_form_model).require(:new_parent)
-
- parse_parent_input(input).bind do |new_parent|
- validate_new_parent(new_parent).bind do
- item_service.move_item(item: @active_item, new_parent:)
- end
- end.either(
- ->(result) do
- redirect_to(
- custom_field_item_path(@custom_field, result.parent),
- status: :see_other,
- notice: I18n.t(:notice_successful_update)
- )
- end,
- ->(error) do
- render_error_flash_message_via_turbo_stream(message: error)
- respond_with_turbo_streams(&:html)
- end
- )
- end
-
- def destroy
- item_service
- .delete_branch(item: @active_item)
- .either(
- ->(_) { update_via_turbo_stream(component: ItemsComponent.new(item: @active_item.parent.reload)) },
- ->(errors) { render_error_flash_message_via_turbo_stream(message: errors.full_messages) }
- )
-
- respond_with_turbo_streams(&:html)
- end
-
- def deletion_dialog
- respond_with_dialog DeleteItemDialogComponent.new(custom_field: @custom_field, hierarchy_item: @active_item)
- end
-
- def change_parent_dialog
- respond_with_dialog ChangeItemParentDialogComponent.new(
- custom_field: @custom_field,
- hierarchy_item: @active_item
- )
- end
-
private
- def item_service
- ::CustomFields::Hierarchy::HierarchicalItemService.new
- end
-
- def item_input # rubocop:disable Metrics/AbcSize
- input = { parent: @active_item, label: params[:label] }
- input[:short] = params[:short] if params[:short].present?
- input[:score] = params[:score] if params[:score].present?
- input[:sort_order] = params[:sort_order].to_i if params[:sort_order].present?
-
- input
- end
-
- def create_contract
- case @custom_field.field_format
- when "hierarchy"
- ::CustomFields::Hierarchy::InsertListItemContract
- when "scored_list"
- ::CustomFields::Hierarchy::InsertScoredItemContract
- else
- raise ArgumentError, "unsupported custom field format '#{@custom_field.field_format}'"
- end
- end
-
- def update_contract
- case @custom_field.field_format
- when "hierarchy"
- ::CustomFields::Hierarchy::UpdateListItemContract
- when "scored_list"
- ::CustomFields::Hierarchy::UpdateScoredItemContract
- else
- raise ArgumentError, "unsupported custom field format '#{@custom_field.field_format}'"
- end
- end
-
- def add_errors_to_form(validation_result)
- @new_item = ::CustomField::Hierarchy::Item.new(**item_input)
- validation_result.errors(full: true).to_h.each do |attribute, errors|
- @new_item.errors.add(attribute, errors.join(", "))
- end
- end
-
- def add_errors_to_edit_form(validation_result)
- @active_item.assign_attributes(**validation_result.to_h.slice(:label, :short, :score))
-
- validation_result.errors(full: true).to_h.each do |attribute, errors|
- @active_item.errors.add(attribute, errors.join(", "))
- end
- end
-
- def parse_parent_input(new_parent_input)
- case new_parent_input
- in [new_parent]
- input = MultiJson.load(new_parent, symbolize_keys: true)[:value]
- new_parent = CustomField::Hierarchy::Item.including_children.find(input)
- Success(new_parent)
- else
- Failure("Invalid input: #{new_parent_input}")
- end
- end
-
- def validate_new_parent(new_parent)
- return Failure(I18n.t(:notice_change_parent_same_target)) if @active_item.parent.id == new_parent.id
- return Failure(I18n.t(:notice_change_parent_to_self)) if @active_item.id == new_parent.id
-
- Success()
- end
-
- def find_model_object
- @object = CustomField.hierarchy_root_and_children.find(params[:custom_field_id])
- @custom_field = @object
- end
-
- def find_active_item
- @active_item = if params[:id].present?
- CustomField::Hierarchy::Item.including_children.find(params[:id])
- else
- @object.hierarchy_root
- end
+ def find_custom_field
+ CustomField.hierarchy_root_and_children.find(params[:custom_field_id])
end
end
end
diff --git a/app/controllers/admin/settings/project_custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/settings/project_custom_fields/hierarchy/items_controller.rb
new file mode 100644
index 00000000000..f9d74794073
--- /dev/null
+++ b/app/controllers/admin/settings/project_custom_fields/hierarchy/items_controller.rb
@@ -0,0 +1,47 @@
+# 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 Admin
+ module Settings
+ module ProjectCustomFields
+ module Hierarchy
+ class ItemsController < CustomFields::Hierarchy::ItemsBaseController
+ menu_item :project_custom_fields_settings
+
+ private
+
+ def find_custom_field
+ CustomField.hierarchy_root_and_children.find(params[:project_custom_field_id])
+ end
+ end
+ end
+ end
+ end
+end
diff --git a/app/forms/custom_fields/details_form.rb b/app/forms/custom_fields/details_form.rb
index 73e7fb9ea53..30fe8c7e9f0 100644
--- a/app/forms/custom_fields/details_form.rb
+++ b/app/forms/custom_fields/details_form.rb
@@ -23,7 +23,7 @@
#
# 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.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
@@ -48,6 +48,18 @@ module CustomFields
required: true
)
+ if model.is_a?(ProjectCustomField)
+ details_form.select_list(
+ name: :custom_field_section_id,
+ label: I18n.t("activerecord.attributes.project_custom_field.custom_field_section"),
+ required: true
+ ) do |list|
+ ProjectCustomFieldSection.find_each do |cs|
+ list.option(value: cs.id, label: cs.name)
+ end
+ end
+ end
+
if model.multi_value_possible?
details_form.check_box(
name: :multi_value,
diff --git a/app/models/project_custom_field.rb b/app/models/project_custom_field.rb
index f0101bc3e3f..52d362db5ec 100644
--- a/app/models/project_custom_field.rb
+++ b/app/models/project_custom_field.rb
@@ -33,6 +33,7 @@ class ProjectCustomField < CustomField
inverse_of: :custom_fields
has_many :project_custom_field_project_mappings, class_name: "ProjectCustomFieldProjectMapping", foreign_key: :custom_field_id,
dependent: :destroy, inverse_of: :project_custom_field
+ has_many :projects, through: :project_custom_field_project_mappings
acts_as_list column: :position_in_custom_field_section, scope: [:custom_field_section_id]
diff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rb
index 8f5e1425c9f..20d850ec3db 100644
--- a/app/services/custom_fields/create_service.rb
+++ b/app/services/custom_fields/create_service.rb
@@ -58,7 +58,9 @@ module CustomFields
if cf.is_a?(ProjectCustomField)
add_cf_to_visible_columns(cf)
- elsif cf.hierarchical_list?
+ end
+
+ if cf.hierarchical_list?
CustomFields::Hierarchy::HierarchicalItemService.new.generate_root(cf)
end
diff --git a/app/views/admin/settings/project_custom_fields/edit.html.erb b/app/views/admin/settings/project_custom_fields/edit.html.erb
index a2b1c26facf..4e240c22976 100644
--- a/app/views/admin/settings/project_custom_fields/edit.html.erb
+++ b/app/views/admin/settings/project_custom_fields/edit.html.erb
@@ -21,7 +21,7 @@ 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.
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
@@ -40,6 +40,8 @@ See COPYRIGHT and LICENSE files for more details.
<% if @custom_field.field_format_calculated_value? %>
<%= render Admin::CustomFields::CalculatedValues::DetailsComponent.new(@custom_field) %>
+<% elsif @custom_field.hierarchical_list? %>
+ <%= render CustomFields::DetailsComponent.new(@custom_field) %>
<% else %>
<%= error_messages_for "custom_field" %>
diff --git a/app/views/admin/settings/project_custom_fields/hierarchy/items/edit.html.erb b/app/views/admin/settings/project_custom_fields/hierarchy/items/edit.html.erb
new file mode 100644
index 00000000000..0f3085fa91f
--- /dev/null
+++ b/app/views/admin/settings/project_custom_fields/hierarchy/items/edit.html.erb
@@ -0,0 +1,34 @@
+<%#-- 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), t("settings.project_attributes.heading"), @custom_field.name, t(:label_item_plural) %>
+
+<%= render(Settings::ProjectCustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :items)) %>
+
+<%= render(Admin::CustomFields::Hierarchy::ItemComponent.new(item: @active_item, show_edit_form: true)) %>
diff --git a/app/views/admin/settings/project_custom_fields/hierarchy/items/index.html.erb b/app/views/admin/settings/project_custom_fields/hierarchy/items/index.html.erb
new file mode 100644
index 00000000000..787bbbf6bad
--- /dev/null
+++ b/app/views/admin/settings/project_custom_fields/hierarchy/items/index.html.erb
@@ -0,0 +1,34 @@
+<%#-- 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), t("settings.project_attributes.heading"), @custom_field.name, t(:label_item_plural) %>
+
+<%= render(Settings::ProjectCustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :items)) %>
+
+<%= render(Admin::CustomFields::Hierarchy::ItemsComponent.new(item: @active_item)) %>
diff --git a/app/views/admin/settings/project_custom_fields/hierarchy/items/new.html.erb b/app/views/admin/settings/project_custom_fields/hierarchy/items/new.html.erb
new file mode 100644
index 00000000000..7ec3ce304ee
--- /dev/null
+++ b/app/views/admin/settings/project_custom_fields/hierarchy/items/new.html.erb
@@ -0,0 +1,34 @@
+<%#-- 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), t("settings.project_attributes.heading"), @custom_field.name, t(:label_item_plural) %>
+
+<%= render(Settings::ProjectCustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :items)) %>
+
+<%= render(Admin::CustomFields::Hierarchy::ItemsComponent.new(item: @active_item, new_item: @new_item)) %>
diff --git a/app/views/admin/settings/project_custom_fields/new.html.erb b/app/views/admin/settings/project_custom_fields/new.html.erb
index 4be11d8fcd8..33dbea678b7 100644
--- a/app/views/admin/settings/project_custom_fields/new.html.erb
+++ b/app/views/admin/settings/project_custom_fields/new.html.erb
@@ -21,7 +21,7 @@ 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.
+Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
See COPYRIGHT and LICENSE files for more details.
@@ -33,6 +33,8 @@ See COPYRIGHT and LICENSE files for more details.
<% if @custom_field.field_format_calculated_value? %>
<%= render Admin::CustomFields::CalculatedValues::DetailsComponent.new(@custom_field) %>
+<% elsif @custom_field.hierarchical_list? %>
+ <%= render CustomFields::DetailsComponent.new(@custom_field) %>
<% else %>
<%= error_messages_for "custom_field" %>
diff --git a/config/initializers/custom_field_format.rb b/config/initializers/custom_field_format.rb
index 89532ddee1b..a0aa92316be 100644
--- a/config/initializers/custom_field_format.rb
+++ b/config/initializers/custom_field_format.rb
@@ -23,7 +23,7 @@
#
# 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.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
@@ -85,7 +85,7 @@ OpenProject::CustomFieldFormat.map do |fields|
fields.register OpenProject::CustomFieldFormat.new("hierarchy",
label: :label_hierarchy,
- only: %w(WorkPackage),
+ only: %w(Project WorkPackage),
order: 12,
multi_value_possible: true,
enterprise_feature: :custom_field_hierarchies,
@@ -93,7 +93,7 @@ OpenProject::CustomFieldFormat.map do |fields|
fields.register OpenProject::CustomFieldFormat.new("scored_list",
label: :label_scored_list,
- only: %w(WorkPackage),
+ only: %w(Project WorkPackage),
order: 13,
enabled: lambda do
OpenProject::FeatureDecisions.scored_list_custom_fields_active?
diff --git a/config/routes.rb b/config/routes.rb
index 1347fc5b5e5..7a7665d1432 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -634,6 +634,16 @@ Rails.application.routes.draw do
post :link
delete :unlink
end
+ resources :items, controller: "/admin/settings/project_custom_fields/hierarchy/items" do
+ member do
+ get :change_parent, action: :change_parent_dialog
+ post :change_parent, action: :change_parent
+ get :delete, action: :deletion_dialog
+ post :move
+ get :new_child, action: :new
+ post :new_child, action: :create
+ end
+ end
end
resources :project_custom_field_sections, controller: "/admin/settings/project_custom_field_sections",
only: %i[create update destroy] do