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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
avoid sorting roots
Marcello Rochaa9310113c8fe
diff --git a/app/models/custom_field/hierarchy/item.rb b/app/models/custom_field/hierarchy/item.rbindex acdbaaf9606..dcb12cc2759 100644--- a/app/models/custom_field/hierarchy/item.rb+++ b/app/models/custom_field/hierarchy/item.rb@@ -32,7 +32,7 @@ class CustomField::Hierarchy::Item < ApplicationRecordself.table_name = "hierarchical_items"belongs_to :custom_field- has_closure_tree order: "sort_order", numeric_order: true, dependent: :destroy+ has_closure_tree order: "sort_order", numeric_order: true, dont_order_roots: true, dependent: :destroyscope :including_children, -> { includes(children: :children) }enddiff --git a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb b/app/services/custom_fields/hierarchy/hierarchical_item_service.rbindex c903ef6044b..8c8f7e556eb 100644--- a/app/services/custom_fields/hierarchy/hierarchical_item_service.rb+++ b/app/services/custom_fields/hierarchy/hierarchical_item_service.rb@@ -118,11 +118,14 @@ module CustomFieldsSuccess(item)end- def create_child_item(validation:, sort_order:)- item = validation[:parent].children.create(label: validation[:label], short: validation[:short], sort_order:)+ def create_child_item(validation:, sort_order: nil)+ attributes = validation.to_h+ attributes[:sort_order] = sort_order - 1 if sort_order++ item = validation[:parent].children.create(**attributes)return Failure(item.errors) if item.new_record?- Success(item.reload)+ Success(item)enddef update_item_attributes(item:, attributes:)