Skip to content

Commit

Permalink
Merge pull request #16570 from opf/bug/57508-custom-fields-with-forma…
Browse files Browse the repository at this point in the history
…t-string-text-bool-link-and-date-dont-forbid-multi-select-internally-and-have-handling-in-ordering

Bug/57508 custom fields with format string text bool link and date dont forbid multi select internally and have handling in ordering
  • Loading branch information
toy authored Sep 12, 2024
2 parents c3f2c37 + 0b859db commit 0eaadba
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
21 changes: 9 additions & 12 deletions app/models/custom_field.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ def uniqueness_of_name_with_scope
validates :min_length, numericality: { less_than_or_equal_to: :max_length, message: :smaller_than_or_equal_to_max_length },
unless: Proc.new { |cf| cf.max_length.blank? }

validates :multi_value, absence: true, unless: :multi_value_possible?
validates :allow_non_open_versions, absence: true, unless: :allow_non_open_versions_possible?

before_validation :check_searchability
after_destroy :destroy_help_text

Expand Down Expand Up @@ -265,6 +268,10 @@ def list?
field_format == "list"
end

def user?
field_format == "user"
end

def version?
field_format == "version"
end
Expand All @@ -277,22 +284,12 @@ def boolean?
field_format == "bool"
end

def multi_value?
multi_value
end

def multi_value_possible?
%w[version user list].include?(field_format) &&
[ProjectCustomField, WorkPackageCustomField, TimeEntryCustomField, VersionCustomField].include?(self.class)
end

def allow_non_open_versions?
allow_non_open_versions
version? || user? || list?
end

def allow_non_open_versions_possible?
version? &&
[ProjectCustomField, WorkPackageCustomField, TimeEntryCustomField, VersionCustomField].include?(self.class)
version?
end

##
Expand Down
8 changes: 2 additions & 6 deletions app/models/custom_field/order_statements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,8 @@ def order_statements
else
[select_custom_option_position]
end
when "string", "text", "date", "bool", "link"
if multi_value?
[select_custom_values_as_group]
else
[coalesce_select_custom_value_as_string]
end
when "string", "date", "bool", "link"
[coalesce_select_custom_value_as_string]
when "int", "float"
# Make the database cast values into numeric
# Postgresql will raise an error if a value can not be casted!
Expand Down
4 changes: 2 additions & 2 deletions app/views/custom_fields/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ See COPYRIGHT and LICENSE files for more details.
</span>
</div>

<% if @custom_field.new_record? || @custom_field.list? || @custom_field.multi_value_possible? %>
<% if @custom_field.new_record? || @custom_field.multi_value_possible? %>
<div class="form--field" <%= format_dependent.attributes(:multiSelect) %>>
<%= f.check_box :multi_value,
data: { action: 'admin--custom-fields#checkOnlyOne' } %>
Expand Down Expand Up @@ -118,7 +118,7 @@ See COPYRIGHT and LICENSE files for more details.
</fieldset>
<% end %>
<% if @custom_field.new_record? || @custom_field.version? || @custom_field.allow_non_open_versions_possible? %>
<% if @custom_field.new_record? || @custom_field.allow_non_open_versions_possible? %>
<div class="form--field" <%= format_dependent.attributes(:allowNonOpenVersions) %>>
<%= f.check_box :allow_non_open_versions %>
</div>
Expand Down

0 comments on commit 0eaadba

Please sign in to comment.