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
move FormatDependent outside of helpers
Ivan Kuchin9c60b96690b2
diff --git a/app/helpers/custom_fields_helper.rb b/app/helpers/custom_fields_helper.rbindex 3cf850fbe07..6d93fdb5427 100644--- a/app/helpers/custom_fields_helper.rb+++ b/app/helpers/custom_fields_helper.rb@@ -27,44 +27,6 @@#++module CustomFieldsHelper- class FormatDependent- CONFIG = {- allowNonOpenVersions: [:only, %w[version]],- defaultBool: [:only, %w[bool]],- defaultLongText: [:only, %w[text]],- defaultText: [:except, %w[list bool date text user version]],- length: [:except, %w[list bool date user version link]],- multiSelect: [:only, %w[list user version]],- possibleValues: [:only, %w[list]],- regexp: [:except, %w[list bool date user version]],- searchable: [:except, %w[bool date float int user version]],- textOrientation: [:only, %w[text]]- }.freeze-- def self.stimulus_config- CONFIG.map { |target_name, (operator, formats)| [target_name, operator, formats] }.to_json- end-- attr_reader :format-- def initialize(format)- @format = format # rubocop:disable Rails/HelperInstanceVariable- end-- def attributes(target_name)- operator, formats = CONFIG[target_name.to_sym]-- fail ArgumentError, "Unknown target name #{target_name}" unless formats-- visible = operator == :only ? format.in?(formats) : !format.in?(formats)-- ApplicationController.helpers.tag.attributes(- "data-admin--custom-fields-target": target_name,- hidden: !visible- )- end- end-def custom_fields_tabs[{diff --git a/app/views/custom_fields/_form.html.erb b/app/views/custom_fields/_form.html.erbindex ad2634f25ec..f41742ec2cb 100644--- a/app/views/custom_fields/_form.html.erb+++ b/app/views/custom_fields/_form.html.erb@@ -27,14 +27,14 @@ See COPYRIGHT and LICENSE files for more details.++#%>-<% format_dependent = CustomFieldsHelper::FormatDependent.new(@custom_field.field_format) %>+<% format_dependent = OpenProject::CustomFieldFormatDependent.new(@custom_field.field_format) %><sectionclass="form--section"id="custom_field_form"data-controller="admin--custom-fields"data-application-target="dynamic"- data-admin--custom-fields-format-config-value="<%= CustomFieldsHelper::FormatDependent.stimulus_config %>"+ data-admin--custom-fields-format-config-value="<%= OpenProject::CustomFieldFormatDependent.stimulus_config %>"><div class="form--field -required" id="custom_field_name_attributes"><%= f.text_field :name, required: true, container_class: '-middle' %>diff --git a/lib/open_project/custom_field_format_dependent.rb b/lib/open_project/custom_field_format_dependent.rbnew file mode 100644index 00000000000..dcdb8505fd1--- /dev/null+++ b/lib/open_project/custom_field_format_dependent.rb@@ -0,0 +1,67 @@+#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2024 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 OpenProject+ class CustomFieldFormatDependent+ CONFIG = {+ allowNonOpenVersions: [:only, %w[version]],+ defaultBool: [:only, %w[bool]],+ defaultLongText: [:only, %w[text]],+ defaultText: [:except, %w[list bool date text user version]],+ length: [:except, %w[list bool date user version link]],+ multiSelect: [:only, %w[list user version]],+ possibleValues: [:only, %w[list]],+ regexp: [:except, %w[list bool date user version]],+ searchable: [:except, %w[bool date float int user version]],+ textOrientation: [:only, %w[text]]+ }.freeze++ def self.stimulus_config+ CONFIG.map { |target_name, (operator, formats)| [target_name, operator, formats] }.to_json+ end++ attr_reader :format++ def initialize(format)+ @format = format+ end++ def attributes(target_name)+ operator, formats = CONFIG[target_name.to_sym]++ fail ArgumentError, "Unknown target name #{target_name}" unless formats++ visible = operator == :only ? format.in?(formats) : !format.in?(formats)++ ApplicationController.helpers.tag.attributes(+ "data-admin--custom-fields-target": target_name,+ hidden: !visible+ )+ end+ end+end