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
[57530] Add percent_complete_on_status_closed setting
Christophe Bliard4154588d0ae8
diff --git a/app/forms/settings_form_decorator.rb b/app/forms/settings_form_decorator.rbindex 3d79ef6d401..396ae7abf83 100644--- a/app/forms/settings_form_decorator.rb+++ b/app/forms/settings_form_decorator.rb@@ -28,9 +28,17 @@# See COPYRIGHT and LICENSE files for more details.#+++# Decorates a form object to provide a more convenient interface for+# rendering settings.+#+# It automatically sets the label, value, and disabled properties from the+# setting name and its definition attributes.class SettingsFormDecoratorattr_reader :form+ # Initializes a new SettingsFormDecorator+ #+ # @param form [Object] The form object to be decorateddef initialize(form)@form = formend@@ -43,6 +51,15 @@ class SettingsFormDecoratorform.respond_to?(method, include_private)end+ # Creates a text field input for a setting.+ #+ # The text field label is set from translating the key "setting_<name>".+ #+ # Any options passed to this method will override the default options.+ #+ # @param name [Symbol] The name of the setting+ # @param options [Hash] Additional options for the text field+ # @return [Object] The text field inputdef text_field(name:, **options)options.reverse_merge!(label: setting_label(name),@@ -52,6 +69,15 @@ class SettingsFormDecoratorform.text_field(name:, **options)end+ # Creates a check box input for a setting.+ #+ # The check box label is set from translating the key "setting_<name>".+ #+ # Any options passed to this method will override the default options.+ #+ # @param name [Symbol] The name of the setting+ # @param options [Hash] Additional options for the check box+ # @return [Object] The check box inputdef check_box(name:, **options)options.reverse_merge!(label: setting_label(name),@@ -61,13 +87,31 @@ class SettingsFormDecoratorform.check_box(name:, **options)end- def radio_button_group(name:, values:, button_options: {}, **options)+ # Creates a radio button group for a setting.+ #+ # The radio button group label is set from translating the key+ # "setting_<name>". The radio button label are set from translating the+ # key "setting_<name>_<value>". The caption is set from translating the+ # key "setting_<name>_<value>_caption_html", which will be rendered as HTML,+ # or "setting_<name>_<value>_caption", or nothing if none of the above+ # are defined.+ #+ # Any options passed to this method will override the default options.+ #+ # @param name [Symbol] The name of the setting+ # @param values [Array] The values for the radio buttons. Default to the+ # setting's allowed values.+ # @param button_options [Hash] Options for individual radio buttons+ # @param options [Hash] Additional options for the radio button group+ # @return [Object] The radio button group+ def radio_button_group(name:, values: [], button_options: {}, **options)+ values = values.presence || setting_allowed_values(name)radio_group_options = options.reverse_merge(- label: setting_label(name)+ label: setting_label(name),+ disabled: setting_disabled?(name))form.radio_button_group(name:,- disabled: setting_disabled?(name),**radio_group_options) do |radio_group|values.each do |value|@@ -76,13 +120,16 @@ class SettingsFormDecoratorvalue:,checked: setting_value(name) == value,label: setting_label(name, value),- caption: setting_caption_html(name, value)+ caption: setting_caption(name, value)))endendend+ # Creates a save button to submit the form+ #+ # @return [Object] The submit buttondef submitform.submit(name: "submit",label: I18n.t("button_save"),@@ -91,18 +138,59 @@ class SettingsFormDecoratorprotected+ # Returns a translated string for a setting name.+ #+ # The translation key is "setting_<name>". Add additional names to the key+ # to allow for translations with more context:+ # "setting_<name>_<param2>_<param3>_...".+ #+ # @param names [Array<String | Symbol>] The name(s) of the setting+ # @return [String] The translated labeldef setting_label(*names)I18n.t("setting_#{names.join('_')}")end- def setting_caption_html(*names)- I18n.t("setting_#{names.join('_')}_caption_html").html_safe+ # Generates an HTML-safe caption for a setting.+ #+ # The translation key is "setting_<name>_caption". If not present, it will+ # return nil.+ #+ # The translation will be marked as html_safe automatically if it ends with+ # "_html", allowing to have HTML in the caption.+ #+ # Add additional names to the key to allow for translations with more context:+ # "setting_<name>_<context>_caption_html" for instance.+ #+ # @param names [Array<Symbol>] The name(s) of the setting+ # @return [String] The translated HTML-safe caption+ def setting_caption(*names)+ I18n.t("setting_#{names.join('_')}_caption_html", default: nil)&.html_safe \+ || I18n.t("setting_#{names.join('_')}_caption", default: nil)end+ # Retrieves the current value of a setting+ #+ # @param name [Symbol] The name of the setting+ # @return [Object] The value of the settingdef setting_value(name)Setting[name]end+ # Retrieves the allowed values for a setting's definition+ #+ # @param name [Symbol] The name of the setting+ # @return [Array] The allowed values for the setting+ def setting_allowed_values(name)+ Settings::Definition[name].allowed+ end++ # Checks if a setting is disabled.+ #+ # Any non-writable setting set by environment variables will be considered+ # disabled.+ #+ # @param name [Symbol] The name of the setting+ # @return [Boolean] `true` if the setting is disabled, `false` otherwisedef setting_disabled?(name)!Setting.send(:"#{name}_writable?")enddiff --git a/app/views/admin/settings/progress_tracking/show.html.erb b/app/views/admin/settings/progress_tracking/show.html.erbindex 1231e32b00f..43c0f274888 100644--- a/app/views/admin/settings/progress_tracking/show.html.erb+++ b/app/views/admin/settings/progress_tracking/show.html.erb@@ -52,7 +52,6 @@ primer_form_with(render_inline_settings_form(f) do |form|form.radio_button_group(name: "work_package_done_ratio",- values: WorkPackage::DONE_RATIO_OPTIONS,button_options: {data: { action: "admin--progress-tracking#displayWarning" }}@@ -66,6 +65,9 @@ primer_form_with(endendend+ form.radio_button_group(+ name: "percent_complete_on_status_closed"+ )form.submitendenddiff --git a/config/constants/settings/definition.rb b/config/constants/settings/definition.rbindex cfda12e8083..1f403b76cae 100644--- a/config/constants/settings/definition.rb+++ b/config/constants/settings/definition.rb@@ -741,6 +741,11 @@ module Settingsper_page_options: {default: "20, 100"},+ percent_complete_on_status_closed: {+ description: "Describes how % complete should change when setting a work package status to a closed one",+ default: "no_change",+ allowed: %w[no_change set_100p]+ },plain_text_mail: {default: false},diff --git a/config/locales/en.yml b/config/locales/en.ymlindex 2a2d4a9e379..f8953c98345 100644--- a/config/locales/en.yml+++ b/config/locales/en.yml@@ -3328,6 +3328,13 @@ en:setting_password_min_length: "Minimum length"setting_password_min_adhered_rules: "Minimum number of required classes"setting_per_page_options: "Objects per page options"+ setting_percent_complete_on_status_closed: "% Complete when status is closed"+ setting_percent_complete_on_status_closed_no_change: "No change"+ setting_percent_complete_on_status_closed_no_change_caption_html: >-+ The value of <i>% Complete</i> will not change even when a work package is closed.+ setting_percent_complete_on_status_closed_set_100p: "Automatically set to 100%"+ setting_percent_complete_on_status_closed_set_100p_caption: >-+ A closed work package is considered complete.setting_plain_text_mail: "Plain text mail (no HTML)"setting_protocol: "Protocol"setting_project_gantt_query: "Project portfolio Gantt view"