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

updates the item service to user the form value rather than the param

Marcello Rocha0fa62a154eaf
diff --git a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
index b40a44c5706..b5b5a70d30f 100644
--- a/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
+++ b/app/controllers/admin/custom_fields/hierarchy/items_controller.rb
@@ -56,7 +56,7 @@ module Admin
end
def new
- @new_item = ::CustomField::Hierarchy::Item.new(parent: @active_item)
+ @new_item = ::CustomField::Hierarchy::Item.new(parent: @active_item, sort_order: params[:position])
end
def edit; end
@@ -65,8 +65,12 @@ module Admin
item_service
.insert_item(**item_input)
.either(
- ->(_) { redirect_to(new_child_custom_field_item_path(@custom_field, @active_item), status: :see_other) },
- ->(validation_result) do
+ lambda do |item|
+ redirect_to(
+ new_child_custom_field_item_path(@custom_field, @active_item, position: item.sort_order + 1)
+ )
+ end,
+ lambda do |validation_result|
add_errors_to_form(validation_result)
render action: :new
end
@@ -77,10 +81,10 @@ module Admin
item_service
.update_item(item: @active_item, label: item_input[:label], short: item_input[:short])
.either(
- ->(_) do
- redirect_to(custom_field_item_path(@custom_field, @active_item.parent), status: :see_other)
+ lambda do |_|
+ redirect_to(custom_field_item_path(@custom_field, @active_item.parent))
end,
- ->(validation_result) do
+ lambda do |validation_result|
add_errors_to_edit_form(validation_result)
render action: :edit
end
@@ -111,6 +115,7 @@ module Admin
def item_input
input = { parent: @active_item, label: params[:label] }
input[:short] = params[:short] if params[:short].present?
+ input[:sort_order] = params[:sort_order].to_i if params[:sort_order].present?
input
end