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
Base values on input so it's easier to pass custom options
Oliver Günther35c73795626c
diff --git a/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb b/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rbindex fa46850be4c..37a2304fe83 100644--- a/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb+++ b/app/forms/custom_fields/inputs/base/autocomplete/multi_value_input.rb@@ -26,15 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#++-class CustomFields::Inputs::Base::Autocomplete::MultiValueInput < ApplicationForm- include CustomFields::Inputs::Base::Utils-- def initialize(custom_field:, custom_values:, object:)- @custom_field = custom_field- @custom_values = custom_values- @object = object- end-+class CustomFields::Inputs::Base::Autocomplete::MultiValueInput < CustomFields::Inputs::Base::Inputdef input_attributesbase_input_attributes.merge(autocomplete_options:,@@ -55,11 +47,15 @@ class CustomFields::Inputs::Base::Autocomplete::MultiValueInput < ApplicationForraise NotImplementedErrorend+ def custom_values+ @custom_values ||= @object.custom_values_for_custom_field(id: @custom_field.id)+ end+def invalid?- @custom_values.any? { |custom_value| custom_value.errors.any? }+ custom_values.any? { |custom_value| custom_value.errors.any? }enddef validation_message- @custom_values.map { |custom_value| custom_value.errors.full_messages }.join(', ') if invalid?+ custom_values.map { |custom_value| custom_value.errors.full_messages }.join(', ') if invalid?endenddiff --git a/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb b/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rbindex 5472cecb9cc..7cc17044668 100644--- a/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb+++ b/app/forms/custom_fields/inputs/base/autocomplete/single_value_input.rb@@ -26,15 +26,7 @@# See COPYRIGHT and LICENSE files for more details.#++-class CustomFields::Inputs::Base::Autocomplete::SingleValueInput < ApplicationForm- include CustomFields::Inputs::Base::Utils-- def initialize(custom_field:, custom_value:, object:)- @custom_field = custom_field- @custom_value = custom_value- @object = object- end-+class CustomFields::Inputs::Base::Autocomplete::SingleValueInput < CustomFields::Inputs::Base::Inputdef input_attributesbase_input_attributes.merge(autocomplete_options:,@@ -54,12 +46,4 @@ class CustomFields::Inputs::Base::Autocomplete::SingleValueInput < ApplicationFodef decorated?raise NotImplementedErrorend-- def invalid?- @custom_value.errors.any?- end-- def validation_message- @custom_value.errors.full_messages.join(', ') if invalid?- endenddiff --git a/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb b/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rbindex 8312f70c59f..75bceebed24 100644--- a/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb+++ b/app/forms/custom_fields/inputs/base/autocomplete/user_query_utils.rb@@ -36,7 +36,7 @@ module CustomFields::Inputs::Base::Autocomplete::UserQueryUtilssearchKey: search_key,inputValue: custom_input_value,focusDirectly: false,- appendTo: 'body'+ appendTo: append_to}end@@ -48,6 +48,10 @@ module CustomFields::Inputs::Base::Autocomplete::UserQueryUtils'any_name_attribute'end+ def append_to+ options.fetch(:wrapper_id, 'body')+ end+def filters[{ name: 'type', operator: '=', values: ['User', 'Group', 'PlaceholderUser'] },diff --git a/app/forms/custom_fields/inputs/base/input.rb b/app/forms/custom_fields/inputs/base/input.rbindex e8b69c87657..a578a692ef9 100644--- a/app/forms/custom_fields/inputs/base/input.rb+++ b/app/forms/custom_fields/inputs/base/input.rb@@ -29,10 +29,12 @@class CustomFields::Inputs::Base::Input < ApplicationForminclude CustomFields::Inputs::Base::Utils- def initialize(custom_field:, custom_value:, object:)+ attr_reader :options++ def initialize(custom_field:, object:, **options)@custom_field = custom_field- @custom_value = custom_value@object = object+ @options = optionsenddef input_attributes@@ -44,11 +46,15 @@ class CustomFields::Inputs::Base::Input < ApplicationForm)end+ def custom_value+ @custom_value ||= @object.custom_value_for(@custom_field.id)+ end+def invalid?- @custom_value.errors.any?+ custom_value.errors.any?enddef validation_message- @custom_value.errors.full_messages.join(', ') if invalid?+ custom_value.errors.full_messages.join(', ') if invalid?endenddiff --git a/app/forms/projects/custom_fields/form.rb b/app/forms/projects/custom_fields/form.rbindex ef19e8bc668..5d4c00542f7 100644--- a/app/forms/projects/custom_fields/form.rb+++ b/app/forms/projects/custom_fields/form.rb@@ -35,11 +35,12 @@ module Projects::CustomFieldsendend- def initialize(project:, custom_field_section: nil, custom_field: nil)+ def initialize(project:, custom_field_section: nil, custom_field: nil, wrapper_id: nil)super()@project = project@custom_field_section = custom_field_section@custom_field = custom_field+ @wrapper_id = wrapper_idif @custom_field_section.present? && @custom_field.present?raise ArgumentError,@@ -76,8 +77,7 @@ module Projects::CustomFields# - rich text editor is not yet supporteddef single_value_custom_field_input(builder, custom_field)- custom_value = @project.custom_value_for(custom_field.id)- form_args = { custom_field:, custom_value:, object: @project }+ form_args = { custom_field:, object: @project, wrapper_id: @wrapper_id }case custom_field.field_formatwhen "string"@@ -102,8 +102,7 @@ module Projects::CustomFieldsenddef multi_value_custom_field_input(builder, custom_field)- custom_values = @project.custom_values_for_custom_field(id: custom_field.id)- form_args = { custom_field:, custom_values:, object: @project }+ form_args = { custom_field:, object: @project, wrapper_id: @wrapper_id }case custom_field.field_formatwhen "list"diff --git a/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erbindex d71ff4e93ba..a73b0457c9f 100644--- a/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sections/edit_dialog_component.html.erb@@ -1,4 +1,3 @@-<%=content_tag("turbo-frame", id: "edit-project-custom-fields-dialog-#{@project_custom_field_section.id}-frame") docomponent_wrapper(data: { qa_selector: 'async-dialog-content' }) do@@ -10,7 +9,12 @@component_collection do |collection|# TODO: remove inline stylecollection.with_component(Primer::Alpha::Dialog::Body.new(my: 3, style: "max-height: 500px;")) do- render(Projects::CustomFields::Form.new(f, project: @project, custom_field_section: @project_custom_field_section))+ render(Projects::CustomFields::Form.new(+ f,+ project: @project,+ custom_field_section: @project_custom_field_section,+ wrapper_id: "#edit-project-custom-fields-dialog-#{@project_custom_field_section.id}"+ ))endcollection.with_component(Primer::Alpha::Dialog::Footer.new) docomponent_collection do |footer_collection|