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
[#66410] add common denominator for hierarchical lists
Eric Schubertbe7b7f35facb
diff --git a/app/components/admin/custom_fields/edit_form_header_component.rb b/app/components/admin/custom_fields/edit_form_header_component.rbindex 9a48f72223b..c96877ca656 100644--- a/app/components/admin/custom_fields/edit_form_header_component.rb+++ b/app/components/admin/custom_fields/edit_form_header_component.rb@@ -46,7 +46,7 @@ module Admin}]- if @custom_field.field_format_hierarchy? || @custom_field.field_format_scored_list?+ if @custom_field.hierarchical_list?tabs << {name: "items",path: custom_field_items_path(@custom_field),diff --git a/app/contracts/custom_fields/hierarchy/generate_root_contract.rb b/app/contracts/custom_fields/hierarchy/generate_root_contract.rbindex ebd0609eb06..bb8323c8790 100644--- a/app/contracts/custom_fields/hierarchy/generate_root_contract.rb+++ b/app/contracts/custom_fields/hierarchy/generate_root_contract.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.#++@@ -38,7 +38,8 @@ module CustomFieldsendrule(:custom_field) do- key.failure(:format_not_supported) if %w[hierarchy scored_list].exclude?(value.field_format)+ field_format = value.field_format+ key.failure(:format_not_supported, field_format:) if %w[hierarchy scored_list].exclude?(field_format)key.failure(:defined) if value.hierarchy_root.present?endenddiff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rbindex 1f6d2133318..172f224d1ea 100644--- a/app/helpers/custom_fields_helper.rb+++ b/app/helpers/custom_fields_helper.rb@@ -71,10 +71,6 @@ module CustomFieldsHelperclass: "form--label"end- def show_primer_forms?(custom_field)- custom_field.field_format_hierarchy? || custom_field.field_format_scored_list?- end-def custom_field_tag_for_bulk_edit(name, custom_field, project = nil) # rubocop:disable Metrics/AbcSizefield_name = "#{name}[custom_field_values][#{custom_field.id}]"field_id = "#{name}_custom_field_values_#{custom_field.id}"diff --git a/app/models/custom_field.rb b/app/models/custom_field.rbindex 1f057d3d9c0..2dd7a8ffa81 100644--- a/app/models/custom_field.rb+++ b/app/models/custom_field.rb@@ -321,6 +321,10 @@ class CustomField < ApplicationRecordfield_format == "calculated_value"end+ def hierarchical_list?+ field_format_hierarchy? || field_format_scored_list?+ end+def multi_value_possible?OpenProject::CustomFieldFormat.find_by(name: field_format)&.multi_value_possible?enddiff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rbindex 54b103a16ab..8f5e1425c9f 100644--- a/app/services/custom_fields/create_service.rb+++ b/app/services/custom_fields/create_service.rb@@ -58,7 +58,7 @@ module CustomFieldsif cf.is_a?(ProjectCustomField)add_cf_to_visible_columns(cf)- elsif cf.field_format_hierarchy? || cf.field_format_scored_list?+ elsif cf.hierarchical_list?CustomFields::Hierarchy::HierarchicalItemService.new.generate_root(cf)enddiff --git a/app/views/custom_fields/edit.html.erb b/app/views/custom_fields/edit.html.erbindex b61753405cd..0814385d202 100644--- a/app/views/custom_fields/edit.html.erb+++ b/app/views/custom_fields/edit.html.erb@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.<%= render(Admin::CustomFields::EditFormHeaderComponent.new(custom_field: @custom_field, selected: :edit)) %>-<% if show_primer_forms?(@custom_field) %>+<% if @custom_field.hierarchical_list? %><%= render CustomFields::DetailsComponent.new(@custom_field) %><% else %><%= error_messages_for "custom_field" %>diff --git a/app/views/custom_fields/new.html.erb b/app/views/custom_fields/new.html.erbindex 3737a298ea4..3769b68cc7b 100644--- a/app/views/custom_fields/new.html.erb+++ b/app/views/custom_fields/new.html.erb@@ -42,7 +42,7 @@ See COPYRIGHT and LICENSE files for more details.end%>-<% if show_primer_forms?(@custom_field) %>+<% if @custom_field.hierarchical_list? %><%= render CustomFields::DetailsComponent.new(@custom_field) %><% else %><%= error_messages_for "custom_field" %>diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 75ef6967c3e..dbc20e01f67 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -370,7 +370,7 @@ en:copy_workflow_from:workflow_missing: "has no own workflow."custom_field:- format_not_supported: "format is of unsupported type."+ format_not_supported: "format '%{field_format}' is unsupported."item:root_item: "cannot be a root item."not_persisted: "must be an already existing item."diff --git a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rbindex c034b8cbf81..573a1c55b5b 100644--- a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.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.#++@@ -62,7 +62,7 @@ RSpec.describe CustomFields::Hierarchy::GenerateRootContract,it "is invalid" doresult = subject.call(custom_field:)expect(result).to be_failure- expect(result.errors[:custom_field]).to match_array("format is of unsupported type.")+ expect(result.errors[:custom_field]).to match_array("format 'string' is unsupported.")endenddiff --git a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rbindex 5984ce6d7a6..03b2036460a 100644--- a/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.rb+++ b/spec/services/custom_fields/hierarchy/hierarchical_item_service_spec.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.#++@@ -50,7 +50,7 @@ RSpec.describe CustomFields::Hierarchy::HierarchicalItemService, with_ee: [:custit "requires a custom field of type hierarchy" doresult = service.generate_root(invalid_custom_field).failure- expect(result.errors[:custom_field]).to eq(["format is of unsupported type."])+ expect(result.errors[:custom_field]).to eq(["format 'text' is unsupported."])endcontext "with persistence of hierarchy root fails" do