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

[#67328] add change parent to item's action menu

Eric Schubert222b41990ded
diff --git a/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.html.erb b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.html.erb
new file mode 100644
index 00000000000..c03a235ccc8
--- /dev/null
+++ b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.html.erb
@@ -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.
+
+++#%>
+
+<%=
+ render Primer::Alpha::Dialog.new(id: dialog_id, title: I18n.t(:label_change_parent)) do |dialog|
+ dialog.with_body do
+ primer_form_with(**form_arguments) do |f|
+ helpers.render_inline_form(f) do |form|
+ form.text_field(name: :new_parent, label: "New Parent")
+ end
+ end
+ end
+
+ dialog.with_footer(show_divider: true) do
+ concat(render(Primer::Beta::Button.new(data: { close_dialog_id: dialog_id })) { I18n.t(:button_cancel) })
+
+ concat(
+ render(
+ Primer::Beta::Button.new(
+ scheme: :primary,
+ form: form_id,
+ type: :submit,
+ data: { turbo: true }
+ )
+ ) do
+ I18n.t(:button_select)
+ end
+ )
+ end
+ end
+%>
diff --git a/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb
new file mode 100644
index 00000000000..d75daaa5b96
--- /dev/null
+++ b/app/components/admin/custom_fields/hierarchy/change_item_parent_dialog_component.rb
@@ -0,0 +1,66 @@
+# 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 ChangeItemParentDialogComponent < ApplicationComponent
+ include OpTurbo::Streamable
+
+ TEST_SELECTOR = "op-custom-fields--change-item-parent-dialog"
+
+ def initialize(custom_field:, hierarchy_item:)
+ super
+ @custom_field = custom_field
+ @hierarchy_item = hierarchy_item
+ end
+
+ def dialog_id = "custom-fields--change-item-parent-dialog"
+
+ def form_id = "custom-fields--change-item-parent-form"
+
+ def form_arguments
+ {
+ form_id:,
+ url: change_parent_custom_field_item_path(custom_field_id: @custom_field.id, id: @hierarchy_item.id),
+ model: form_model,
+ method: :post
+ }
+ end
+
+ private
+
+ def form_model
+ CustomField::Hierarchy::Forms::NewParentFormModel.new(new_parent: nil)
+ end
+ end
+ end
+ end
+end
diff --git a/app/components/admin/custom_fields/hierarchy/item_component.rb b/app/components/admin/custom_fields/hierarchy/item_component.rb
index 88619bdcc41..f759ea50398 100644
--- a/app/components/admin/custom_fields/hierarchy/item_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_component.rb
@@ -71,21 +71,30 @@ module Admin
model.sort_order == model.parent.children.length - 1
end
- def menu_items(menu)
+ def menu_items(menu) # rubocop:disable Metrics/AbcSize
edit_action_item(menu)
menu.with_divider
add_above_action_item(menu)
add_below_action_item(menu)
add_sub_item_action_item(menu)
- menu.with_divider
- if !first_item?
+
+ if OpenProject::FeatureDecisions.change_hierarchy_item_parent_active?
+ menu.with_divider
+ change_parent_item(menu)
+ end
+
+ unless first_item? && last_item?
+ menu.with_divider
+ end
+ unless first_item?
move_to_top_action_item(menu)
move_up_action_item(menu)
end
- if !last_item?
+ unless last_item?
move_down_action_item(menu)
move_to_bottom_action_item(menu)
end
+
menu.with_divider
deletion_action_item(menu)
end
@@ -129,6 +138,15 @@ module Admin
) { it.with_leading_visual_icon(icon: "op-arrow-in") }
end
+ def change_parent_item(menu)
+ menu.with_item(
+ label: I18n.t(:label_change_parent),
+ tag: :a,
+ content_arguments: { data: { controller: "async-dialog" } },
+ href: change_parent_dialog_custom_field_item_path(custom_field_id: @root.custom_field_id, id: model.id)
+ ) { it.with_leading_visual_icon(icon: "arrow-switch") }
+ end
+
def move_to_top_action_item(menu)
form_inputs = [{ name: "new_sort_order", value: 0 }]
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
index daa9e5de3a4..b5fd7ba86b5 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
@@ -77,8 +77,7 @@ module Admin
)
end
- # rubocop:disable Metrics/AbcSize
- def update
+ def update # rubocop:disable Metrics/AbcSize
input = item_input
item_service
.update_item(contract_class: update_contract,
@@ -95,7 +94,6 @@ module Admin
end
)
end
- # rubocop:enable Metrics/AbcSize
def move
item_service
@@ -104,6 +102,14 @@ module Admin
redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other)
end
+ def change_parent
+ permitted = params.expect(custom_field_hierarchy_forms_new_parent_form_model: [:new_parent])
+ new_parent = CustomField::Hierarchy::Item.including_children.find(permitted[:new_parent])
+ item_service.move_item(item: @active_item, new_parent:)
+
+ redirect_to(custom_field_item_path(@custom_field, new_parent), status: :see_other)
+ end
+
def destroy
item_service
.delete_branch(item: @active_item)
@@ -119,6 +125,13 @@ module Admin
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
diff --git a/app/models/custom_field/hierarchy/forms/new_parent_form_model.rb b/app/models/custom_field/hierarchy/forms/new_parent_form_model.rb
new file mode 100644
index 00000000000..eb6d9b4f7e5
--- /dev/null
+++ b/app/models/custom_field/hierarchy/forms/new_parent_form_model.rb
@@ -0,0 +1,39 @@
+# 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 CustomField::Hierarchy::Forms::NewParentFormModel
+ extend ActiveModel::Naming
+
+ attr_reader :new_parent
+
+ def initialize(new_parent:)
+ @new_parent = new_parent
+ end
+end
diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rb
index f6980d0262c..9f21912e616 100644
--- a/config/initializers/feature_decisions.rb
+++ b/config/initializers/feature_decisions.rb
@@ -71,3 +71,7 @@ OpenProject::FeatureDecisions.add :scored_list_custom_fields,
OpenProject::FeatureDecisions.add :portfolio_models,
description: "Enables the creation and management of portfolio and program work spaces."
+
+OpenProject::FeatureDecisions.add :change_hierarchy_item_parent,
+ description: "Enables a functionality to change the parent of a hierarchy item of " \
+ "custom fields of type hierarchy and scored list."
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 841781adfd6..bfb6a03876a 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -1983,6 +1983,7 @@ en:
button_add_watcher: "Add watcher"
button_annotate: "Annotate"
button_apply: "Apply"
+ button_apply_changes: "Apply changes"
button_archive: "Archive"
button_back: "Back"
button_cancel: "Cancel"
@@ -2032,8 +2033,8 @@ en:
button_rollback: "Rollback to this version"
button_save: "Save"
button_save_as: "Save as"
- button_apply_changes: "Apply changes"
button_save_back: "Save and back"
+ button_select: "Select"
button_set_reminder: "Set reminder"
button_show: "Show"
button_sort: "Sort"
@@ -2928,6 +2929,7 @@ en:
label_required_disk_storage: "Required disk storage"
label_send_invitation: Send invitation
label_calculated_value: "Calculated value"
+ label_change_parent: "Change parent"
label_change_plural: "Changes"
label_change_properties: "Change properties"
label_change_status: "Change status"
diff --git a/config/routes.rb b/config/routes.rb
index 1babbc0c5e0..451b9b66165 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -209,9 +209,11 @@ Rails.application.routes.draw do
resources :items, controller: "/admin/custom_fields/hierarchy/items" do
member do
get :deletion_dialog
+ get :change_parent_dialog
get :new_child, action: :new
post :new_child, action: :create
post :move
+ post :change_parent
end
end
end
diff --git a/lookbook/docs/patterns/05-dialogs.md.erb b/lookbook/docs/patterns/05-dialogs.md.erb
index ef3f88bae4c..645af75d938 100644
--- a/lookbook/docs/patterns/05-dialogs.md.erb
+++ b/lookbook/docs/patterns/05-dialogs.md.erb
@@ -118,11 +118,11 @@ you have to make sure that the data-turbo attribute is also set.
d.with_footer do
render(Primer::Beta::Button.new(
+ scheme: :primary,
tag: :button,
type: :submit,
form: "my-dialog-form"
data: { turbo: true }
- variant: :primary,
) do |button|
button.text = t(:button_save)
end)