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

[#66411] score input for item form component

Eric Schubert72fcd147d735
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb b/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
index 7b60fdf7659..679b69cb11e 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.html.erb
@@ -29,6 +29,6 @@ See COPYRIGHT and LICENSE files for more details.
<%=
primer_form_with(**item_options) do |f|
- render(CustomFields::Hierarchy::ItemForm.new(f, target_item: model))
+ render(CustomFields::Hierarchy::ItemForm.new(f, target_item: model, input_format:))
end
%>
diff --git a/app/components/admin/custom_fields/hierarchy/item_form_component.rb b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
index 09034d3b962..6ce5c721807 100644
--- a/app/components/admin/custom_fields/hierarchy/item_form_component.rb
+++ b/app/components/admin/custom_fields/hierarchy/item_form_component.rb
@@ -57,6 +57,18 @@ module Admin
end
end
+ def input_format
+ field_format = root.custom_field.field_format
+ case field_format
+ when "hierarchy"
+ :short
+ when "scored_list"
+ :score
+ else
+ raise ArgumentError, "Unsupported field format: #{field_format}"
+ end
+ end
+
private
def root
diff --git a/app/forms/custom_fields/hierarchy/item_form.rb b/app/forms/custom_fields/hierarchy/item_form.rb
index 5c564746bf9..21952689df2 100644
--- a/app/forms/custom_fields/hierarchy/item_form.rb
+++ b/app/forms/custom_fields/hierarchy/item_form.rb
@@ -46,16 +46,30 @@ module CustomFields
validation_message: validation_message_for(:label)
)
- input_group.text_field(
- name: :short,
- label: "Short",
- value: @target_item.short,
- visually_hide_label: true,
- full_width: false,
- required: false,
- placeholder: I18n.t("custom_fields.admin.items.placeholder.short"),
- validation_message: validation_message_for(:short)
- )
+ if @input_format == :short
+ input_group.text_field(
+ name: :short,
+ label: "Short",
+ value: @target_item.short,
+ visually_hide_label: true,
+ full_width: false,
+ required: false,
+ placeholder: I18n.t("custom_fields.admin.items.placeholder.short"),
+ validation_message: validation_message_for(:short)
+ )
+ elsif @input_format == :score
+ input_group.text_field(
+ name: :score,
+ label: "Score",
+ type: :number,
+ value: @target_item.score,
+ visually_hide_label: true,
+ full_width: false,
+ required: true,
+ placeholder: I18n.t("custom_fields.admin.items.placeholder.score"),
+ validation_message: validation_message_for(:score)
+ )
+ end
end
item_form.group(layout: :horizontal, align_self: :end) do |button_group|
@@ -70,9 +84,10 @@ module CustomFields
end
# @param target_item [CustomField::Hierarchy::Item] item that will be acted upon
- def initialize(target_item:)
+ def initialize(target_item:, input_format:)
super()
@target_item = target_item
+ @input_format = input_format
end
private
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 46251b2eec9..f238fd96352 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -321,6 +321,7 @@ en:
placeholder:
label: "Item label"
short: "Short name"
+ score: "Score"
notice:
remember_items_and_projects: "Remember to set items and projects in the respective tabs for this custom field."
hierarchy: