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
fix custom version fields in time entries
Klaus Zandersbc2e6df7ab2c
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 db2fa302c4d..e1b677dc42b 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@@ -40,6 +40,7 @@ class CustomFields::Inputs::Base::Autocomplete::MultiValueInput < CustomFields::{multiple: true,decorated: decorated?,+ focusDirectly: false,append_to:}enddiff --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 3a9bf73dd15..5f678025d26 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@@ -40,6 +40,7 @@ class CustomFields::Inputs::Base::Autocomplete::SingleValueInput < CustomFields:{multiple: false,decorated: decorated?,+ focusDirectly: false,append_to:}enddiff --git a/app/forms/custom_fields/inputs/multi_version_select_list.rb b/app/forms/custom_fields/inputs/multi_version_select_list.rbindex 8294c1a257f..9d6c65f3f91 100644--- a/app/forms/custom_fields/inputs/multi_version_select_list.rb+++ b/app/forms/custom_fields/inputs/multi_version_select_list.rb@@ -30,8 +30,7 @@class CustomFields::Inputs::MultiVersionSelectList < CustomFields::Inputs::Base::Autocomplete::MultiValueInputinclude AssignableCustomFieldValues-- delegate :assignable_versions, to: :@object+ include CustomFields::Inputs::VersionSelectform do |custom_value_form|# autocompleter does not set key with blank value if nothing is selected or input is cleared@@ -44,7 +43,7 @@ class CustomFields::Inputs::MultiVersionSelectList < CustomFields::Inputs::Base:value:)- custom_value_form.autocompleter(**input_attributes) do |list|+ custom_value_form.autocompleter(**version_input_attributes) do |list|assignable_custom_field_values(@custom_field).each do |version|list.option(label: version.name,diff --git a/app/forms/custom_fields/inputs/single_version_select_list.rb b/app/forms/custom_fields/inputs/single_version_select_list.rbindex 870929858e7..d2649566f83 100644--- a/app/forms/custom_fields/inputs/single_version_select_list.rb+++ b/app/forms/custom_fields/inputs/single_version_select_list.rb@@ -1,3 +1,5 @@+# frozen_string_literal: true+#-- copyright# OpenProject is an open source project management software.# Copyright (C) the OpenProject GmbH@@ -28,16 +30,15 @@class CustomFields::Inputs::SingleVersionSelectList < CustomFields::Inputs::Base::Autocomplete::SingleValueInputinclude AssignableCustomFieldValues-- delegate :assignable_versions, to: :@object+ include CustomFields::Inputs::VersionSelectform do |custom_value_form|# autocompleter does not set key with blank value if nothing is selected or input is cleared# in order to let acts_as_customizable handle the clearing of the value, we need to set the value to blank via a hidden field# which sends blank if autocompleter is cleared- custom_value_form.hidden(**input_attributes.merge(value: ""))+ custom_value_form.hidden(**input_attributes, value: "")- custom_value_form.autocompleter(**input_attributes) do |list|+ custom_value_form.autocompleter(**version_input_attributes) do |list|assignable_custom_field_values(@custom_field).each do |version|list.option(label: version.name, value: version.id,diff --git a/app/forms/custom_fields/inputs/version_select.rb b/app/forms/custom_fields/inputs/version_select.rbnew file mode 100644index 00000000000..8ae754b7b1f--- /dev/null+++ b/app/forms/custom_fields/inputs/version_select.rb@@ -0,0 +1,64 @@+# frozen_string_literal: true++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) the OpenProject GmbH+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License version 3.+#+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:+# Copyright (C) 2006-2013 Jean-Philippe Lang+# Copyright (C) 2010-2013 the ChiliProject Team+#+# This program is free software; you can redistribute it and/or+# modify it under the terms of the GNU General Public License+# as published by the Free Software Foundation; either version 2+# of the License, or (at your option) any later version.+#+# This program is distributed in the hope that it will be useful,+# but WITHOUT ANY WARRANTY; without even the implied warranty of+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+# GNU General Public License for more details.+#+# 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.+#+# See COPYRIGHT and LICENSE files for more details.+#++++module CustomFields+ module Inputs+ module VersionSelect+ protected++ def version_input_attributes+ input_attributes.deep_merge(additional_attributes)+ end++ def additional_attributes+ if @object.blank? || (@object.respond_to?(:project) && @object.project.blank?)+ {+ autocomplete_options: {+ disabled: true,+ placeholder: I18n.t("custom_fields.placeholder_version_select")+ }+ }+ else+ {}+ end+ end++ def assignable_versions(only_open:)+ if @object.is_a?(Project)+ @object.assignable_versions(only_open: only_open)+ elsif @object.respond_to?(:project) && @object.project.present?+ @object.project.assignable_versions(only_open: only_open)+ else+ Version.none+ end+ end+ end+ end+enddiff --git a/config/locales/en.yml b/config/locales/en.ymlindex 4af8b15b390..1dbbe593497 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -49,7 +49,6 @@ en:created: "created"commented: "commented"-admin:plugins:no_results_title_text: There are currently no plugins installed.@@ -275,6 +274,7 @@ en:confirm_destroy_option: "Deleting an option will delete all of its occurrences (e.g. in work packages). Are you sure you want to delete it?"reorder_alphabetical: "Reorder values alphabetically"reorder_confirmation: "Warning: The current order of available values will be lost. Continue?"+ placeholder_version_select: "Work package or project selection is required first"instructions:is_required: "Mark the custom field as required. This will make it mandatory to fill in the field when creating new or updating existing resources."is_required_for_project: "Check to enable this attribute and make it required in all projects. It cannot be deactived for individual projects."