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] added new custom field type scored list
Eric Schubert97f14394b9fa
diff --git a/app/components/admin/custom_fields/edit_form_header_component.rb b/app/components/admin/custom_fields/edit_form_header_component.rbindex b1b3afce987..9a48f72223b 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?+ if @custom_field.field_format_hierarchy? || @custom_field.field_format_scored_list?tabs << {name: "items",path: custom_field_items_path(@custom_field),@@ -55,7 +55,7 @@ module Adminendif @custom_field.is_a?(WorkPackageCustomField) ||- @custom_field.is_a?(ProjectCustomField)+ @custom_field.is_a?(ProjectCustomField)tabs <<{name: "custom_field_projects",diff --git a/app/contracts/custom_fields/hierarchy/generate_root_contract.rb b/app/contracts/custom_fields/hierarchy/generate_root_contract.rbindex 137d13ab0c2..ebd0609eb06 100644--- a/app/contracts/custom_fields/hierarchy/generate_root_contract.rb+++ b/app/contracts/custom_fields/hierarchy/generate_root_contract.rb@@ -31,13 +31,15 @@module CustomFieldsmodule Hierarchyclass GenerateRootContract < Dry::Validation::Contract+ config.messages.backend = :i18n+params dorequired(:custom_field).filled(type?: CustomField)endrule(:custom_field) do- key.failure("must have field format 'hierarchy'") if value.field_format != "hierarchy"- key.failure("cannot be defined") if value.hierarchy_root.present?+ key.failure(:format_not_supported) if %w[hierarchy scored_list].exclude?(value.field_format)+ key.failure(:defined) if value.hierarchy_root.present?endendenddiff --git a/app/forms/custom_fields/details_form.rb b/app/forms/custom_fields/details_form.rbindex 889fba281e9..73e7fb9ea53 100644--- a/app/forms/custom_fields/details_form.rb+++ b/app/forms/custom_fields/details_form.rb@@ -48,11 +48,13 @@ module CustomFieldsrequired: true)- details_form.check_box(- name: :multi_value,- label: I18n.t("activerecord.attributes.custom_field.multi_value"),- caption: I18n.t("custom_fields.instructions.multi_select")- )+ if model.multi_value_possible?+ details_form.check_box(+ name: :multi_value,+ label: I18n.t("activerecord.attributes.custom_field.multi_value"),+ caption: I18n.t("custom_fields.instructions.multi_select")+ )+ enddetails_form.check_box(name: :is_required,diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rbindex 172f224d1ea..1f6d2133318 100644--- a/app/helpers/custom_fields_helper.rb+++ b/app/helpers/custom_fields_helper.rb@@ -71,6 +71,10 @@ 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 8bbfadc8d86..1f057d3d9c0 100644--- a/app/models/custom_field.rb+++ b/app/models/custom_field.rb@@ -313,6 +313,10 @@ class CustomField < ApplicationRecordfield_format == "hierarchy"end+ def field_format_scored_list?+ field_format == "scored_list"+ end+def field_format_calculated_value?field_format == "calculated_value"enddiff --git a/app/services/custom_fields/create_service.rb b/app/services/custom_fields/create_service.rbindex 40832d27992..54b103a16ab 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?+ elsif cf.field_format_hierarchy? || cf.field_format_scored_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 78a61bde421..b61753405cd 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 @custom_field.field_format_hierarchy? %>+<% if show_primer_forms?(@custom_field) %><%= 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 706a94d2b77..3737a298ea4 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 @custom_field.field_format_hierarchy? %>+<% if show_primer_forms?(@custom_field) %><%= 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.rbindex 57e1ebc3b5d..89532ddee1b 100644--- a/config/initializers/custom_field_format.rb+++ b/config/initializers/custom_field_format.rb@@ -91,10 +91,19 @@ OpenProject::CustomFieldFormat.map do |fields|enterprise_feature: :custom_field_hierarchies,formatter: "CustomValue::HierarchyStrategy")+ fields.register OpenProject::CustomFieldFormat.new("scored_list",+ label: :label_scored_list,+ only: %w(WorkPackage),+ order: 13,+ enabled: lambda do+ OpenProject::FeatureDecisions.scored_list_custom_fields_active?+ end,+ formatter: "CustomValue::HierarchyStrategy")+fields.register OpenProject::CustomFieldFormat.new("calculated_value",label: :label_calculated_value,only: %w(Project),- order: 13,+ order: 14,enabled: lambda doOpenProject::FeatureDecisions.calculated_value_project_attribute_active?end,diff --git a/config/initializers/feature_decisions.rb b/config/initializers/feature_decisions.rbindex 9a095fe9d1c..7998fcd34ba 100644--- a/config/initializers/feature_decisions.rb+++ b/config/initializers/feature_decisions.rb@@ -60,3 +60,7 @@ OpenProject::FeatureDecisions.add :block_note_editor,OpenProject::FeatureDecisions.add :minutes_styling_meeting_pdf,description: "Allow exporting a meeting with FITKO styling. " \"See #65124 for details."++OpenProject::FeatureDecisions.add :scored_list_custom_fields,+ description: "Enables the use of the custom field type 'Scored List', which lets " \+ "the admin add scores to list items."diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 9b24e30aa6e..75ef6967c3e 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -361,6 +361,7 @@ en:dry_validation:errors:+ defined: "must not be defined."int?: "must be an integer."filled?: "must be filled."greater_or_equal_zero: "must be greater or equal to 0."@@ -368,6 +369,8 @@ en:rules:copy_workflow_from:workflow_missing: "has no own workflow."+ custom_field:+ format_not_supported: "format is of unsupported type."item:root_item: "cannot be a root item."not_persisted: "must be an already existing item."@@ -3043,6 +3046,7 @@ en:label_invite_user: "Invite user"label_item: "Item"label_item_plural: "Items"+ label_scored_list: "Scored list"label_share: "Share"label_share_project_list: "Share project list"label_share_work_package: "Share work package"diff --git a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rbindex 733575a5006..c034b8cbf81 100644--- a/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb+++ b/spec/contracts/custom_fields/hierarchy/generate_root_contract_spec.rb@@ -30,7 +30,9 @@require "rails_helper"-RSpec.describe CustomFields::Hierarchy::GenerateRootContract, with_ee: [:custom_field_hierarchies] do+RSpec.describe CustomFields::Hierarchy::GenerateRootContract,+ with_ee: [:custom_field_hierarchies],+ with_flag: { scored_list_custom_fields: true } dosubject { described_class.new }describe "#call" do@@ -50,12 +52,22 @@ RSpec.describe CustomFields::Hierarchy::GenerateRootContract, with_ee: [:custom_it "is invalid" doresult = subject.call(custom_field:)expect(result).to be_failure- expect(result.errors[:custom_field]).to match_array("cannot be defined")+ expect(result.errors[:custom_field]).to match_array("must not be defined.")+ end+ end++ context "when custom field format is not supported" do+ let(:custom_field) { create(:string_wp_custom_field) }++ it "is invalid" do+ result = subject.call(custom_field:)+ expect(result).to be_failure+ expect(result.errors[:custom_field]).to match_array("format is of unsupported type.")endendcontext "when inputs are valid" do- let(:custom_field) { create(:hierarchy_wp_custom_field, hierarchy_root: nil) }+ let(:custom_field) { create(:scored_list_wp_custom_field, hierarchy_root: nil) }it "creates a success result" doexpect(subject.call(custom_field:)).to be_successdiff --git a/spec/factories/custom_field_factory.rb b/spec/factories/custom_field_factory.rbindex e7a8123bb99..04db3c1287f 100644--- a/spec/factories/custom_field_factory.rb+++ b/spec/factories/custom_field_factory.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.#++@@ -31,7 +31,7 @@FactoryBot.define dofactory :custom_field dotransient do- # These values are used internally to customize the custom field name+ # These values are used internally to customize the custom field name# when using traits. They are not meant to be set externally._format_name do[@@ -189,6 +189,14 @@ FactoryBot.define domulti_valueend+ trait :scored_list do+ field_format { "scored_list" }+ hierarchy_root do+ service = CustomFields::Hierarchy::HierarchicalItemService.new+ service.generate_root(instance).value!+ end+ end+factory :project_custom_field, class: "ProjectCustomField" doproject_custom_field_section@@ -253,6 +261,7 @@ FactoryBot.define dofactory :multi_user_wp_custom_field, traits: [:multi_user]factory :link_wp_custom_field, traits: [:link]factory :hierarchy_wp_custom_field, traits: [:hierarchy]+ factory :scored_list_wp_custom_field, traits: [:scored_list]endfactory :issue_custom_field, class: "WorkPackageCustomField" do