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
Use version groups for the version html autocompleters.
Dombi Attila453d55e08994
diff --git a/app/components/filter/filter_component.rb b/app/components/filter/filter_component.rbindex 28d1699cd3a..755fb17fd5a 100644--- a/app/components/filter/filter_component.rb+++ b/app/components/filter/filter_component.rb@@ -81,7 +81,7 @@ module Filterenddef custom_field_list_autocomplete_options(filter)- items = if filter.custom_field.field_format == "version"+ items = if filter.custom_field.version?filter.allowed_values.map { |name, id, project_name| { name:, id:, project_name: } }elsefilter.allowed_values.map { |name, id| { name:, id: } }diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rbindex fa29aeb7d05..2bde1027da1 100644--- a/app/helpers/custom_fields_helper.rb+++ b/app/helpers/custom_fields_helper.rb@@ -64,76 +64,6 @@ module CustomFieldsHelper]end- # Return custom field html tag corresponding to its format- def custom_field_tag(name, custom_value) # rubocop:disable Metrics/AbcSize,Metrics/PerceivedComplexity- custom_field = custom_value.custom_field- field_name = "#{name}[custom_field_values][#{custom_field.id}]"- field_id = "#{name}_custom_field_values_#{custom_field.id}"-- field_format = OpenProject::CustomFieldFormat.find_by(name: custom_field.field_format)-- tag = case field_format.try(:edit_as)- when "date"- angular_component_tag "opce-basic-single-date-picker",- inputs: {- required: custom_field.is_required,- value: custom_value.value,- id: field_id,- name: field_name- }- when "text"- styled_text_area_tag(field_name, custom_value.value, id: field_id, rows: 3, container_class: "-middle",- required: custom_field.is_required)- when "bool"- hidden_tag = hidden_field_tag(field_name, "0")- checkbox_tag = styled_check_box_tag(field_name, "1", custom_value.typed_value, id: field_id,- required: custom_field.is_required)- hidden_tag + checkbox_tag- when "list"- include_blank = !custom_field.is_required? ||- (custom_field.default_value.blank? ? I18n.t(:actionview_instancetag_blank_option) : false)-- options = [custom_field.possible_values_options(custom_value.customized), custom_value.value]-- styled_select_tag(- field_name,- options_for_select(*options),- id: field_id,- container_class: "-middle",- required: custom_field.is_required,- include_blank:- )- else- styled_text_field_tag(field_name, custom_value.value, id: field_id, container_class: "-middle",- required: custom_field.is_required)- end-- tag = content_tag :span, tag, lang: custom_field.name_locale, class: "form--field-container"-- if custom_value.errors.empty?- tag- else- ActionView::Base.wrap_with_error_span(tag, custom_value, "value")- end- end-- # Return custom field label tag- def custom_field_label_tag(name, custom_value)- content_tag "label", h(custom_value.custom_field.name) +- (custom_value.custom_field.is_required? ? content_tag("span", " *", class: "required") : ""),- for: "#{name}_custom_field_values_#{custom_value.custom_field.id}",- class: "form--label #{custom_value.errors.empty? ? nil : 'error'}",- lang: custom_value.custom_field.name_locale- end-- def hidden_custom_field_label_tag(name, custom_value)- content_tag "label", h(custom_value.custom_field.name) +- (custom_value.custom_field.is_required? ? content_tag("span", " *", class: "required") : ""),- for: "#{name}_custom_field_values_#{custom_value.custom_field.id}",- class: "hidden-for-sighted",- lang: custom_value.custom_field.name_locale- end-def blank_custom_field_label_tag(name, custom_field)content_tag "label", h(custom_field.name) +(custom_field.is_required? ? content_tag("span", " *", class: "required") : ""),@@ -141,11 +71,6 @@ module CustomFieldsHelperclass: "form--label"end- # Return custom field tag with its label tag- def custom_field_tag_with_label(name, custom_value)- custom_field_label_tag(name, custom_value) + custom_field_tag(name, custom_value)- 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}"@@ -173,8 +98,16 @@ module CustomFieldsHelperunset_label = custom_field.field_format == "user" ? :label_nobody : :label_nonebase_options << [I18n.t(unset_label), "none"]end++ possible_values = custom_field.possible_values_options(project)+ options = if custom_field.version?+ grouped_options_for_select(possible_values.group_by(&:last).to_a)+ else+ options_for_select(possible_values)+ end+styled_select_tag(field_name,- options_for_select(base_options + custom_field.possible_values_options(project)),+ options_for_select(base_options) + options,id: field_id,multiple: custom_field.multi_value?,include_blank: I18n.t(:label_no_change_option))diff --git a/app/models/custom_field.rb b/app/models/custom_field.rbindex eddd0997e48..cf84be290fb 100644--- a/app/models/custom_field.rb+++ b/app/models/custom_field.rb@@ -165,8 +165,10 @@ class CustomField < ApplicationRecord# You MUST NOT pass a customizable if this CF has any other formatdef possible_values(obj = nil)case field_format- when "user", "version"- possible_values_options(obj).map(&:last)+ when "user"+ possible_users(obj).pluck(:id).map(&:to_s)+ when "version"+ possible_versions(obj).pluck(:id).map(&:to_s)when "list"custom_optionselse@@ -316,22 +318,26 @@ class CustomField < ApplicationRecordprivate- def possible_version_values_options(obj)+ def possible_versions(obj)project = deduce_project(obj)- versions = deduce_versions(project)+ deduce_versions(project)+ end- versions.includes(:project)- .sort- .map { |u| [u.name, u.id.to_s, u.project.name] }+ def possible_version_values_options(obj)+ possible_versions(obj).references(:project)+ .sort+ .map { |u| [u.name, u.id.to_s, u.project.name] }end- def possible_user_values_options(obj)+ def possible_users(obj)project = deduce_project(obj)- users = deduce_principals(project)+ deduce_principals(project)+ end- users.select(*user_format_columns, "id", "type")- .sort- .map { |u| [u.name, u.id.to_s] }+ def possible_user_values_options(obj)+ possible_users(obj).select(*user_format_columns, "id", "type")+ .sort+ .map { |u| [u.name, u.id.to_s] }enddef possible_list_values_optionsdiff --git a/app/models/projects/versions.rb b/app/models/projects/versions.rbindex b271f8d6852..d26e0661da3 100644--- a/app/models/projects/versions.rb+++ b/app/models/projects/versions.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -51,7 +53,7 @@ module Projects::VersionsVersion.shared_with(self)end- # Returns all versions a work package can be assigned to. Opposed to+ # Returns all versions a work package can be assigned to. Opposed to# #shared_versions this returns an array of Versions, not a scope.## The main benefit is in scenarios where work packages' projects are eagerdiff --git a/lib/custom_field_form_builder.rb b/lib/custom_field_form_builder.rbindex 84e04e28839..43e84daa00b 100644--- a/lib/custom_field_form_builder.rb+++ b/lib/custom_field_form_builder.rb@@ -83,17 +83,23 @@ class CustomFieldFormBuilder < TabularFormBuilderendend- # rubocop:enable Metrics/AbcSize-def custom_field_input_list(field, input_options)customized = Array(custom_value).first&.customized- possible_options = custom_field.possible_values_options(customized)- select_options = custom_field_select_options_for_object- selected_options = Array(custom_value).map(&:value)- selectable_options = template.options_for_select(possible_options, selected_options)+ selectable_options = custom_field_input_list_options(customized, custom_value)input_options[:multiple] = custom_field.multi_value?- select(field, selectable_options, select_options, input_options).html_safe+ select(field, selectable_options, custom_field_select_options_for_object, input_options)+ end++ def custom_field_input_list_options(customized, selected)+ options = custom_field.possible_values_options(customized)+ selected_options = Array(selected).map(&:value)++ if custom_field.version?+ template.grouped_options_for_select(options.group_by(&:last).to_a, selected_options)+ else+ template.options_for_select(options, selected_options)+ endenddef custom_field_select_options_for_object