Skip to content

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

Start primerizing progress tracking admin section

Christophe Bliard390d878f5872
diff --git a/app/components/op_primer/form_helpers.rb b/app/components/op_primer/form_helpers.rb
new file mode 100644
index 00000000000..9c6d465bfd2
--- /dev/null
+++ b/app/components/op_primer/form_helpers.rb
@@ -0,0 +1,97 @@
+# 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 OpPrimer
+ module FormHelpers
+ # Renders an inline form without needing a dedicated form class.
+ #
+ # This method dynamically creates a form class based on the provided block
+ # and renders it. The form is instantiated with the provided form builder
+ # which comes from a `primer_form_with` call.
+ #
+ # It is meant to avoid boilerplate classes for simple forms.
+ #
+ # @example
+ # primer_form_with(action: :update) do |form_builder|
+ # render_inline_form(form_builder) do |form|
+ # form.text_field(
+ # name: :ultimate_answer,
+ # label: "Ultimate answer",
+ # required: true,
+ # caption: "The answer to life, the universe, and everything"
+ # )
+ # form.submit(name: :submit, label: "Submit")
+ # end
+ # end
+ #
+ # @param f [Object] The form object to be used for the form.
+ # @param blk [Proc] A block that defines the form structure.
+ def render_inline_form(form_builder, &blk)
+ form_class = Class.new(ApplicationForm) do
+ form(&blk)
+ end
+ render(form_class.new(form_builder))
+ end
+
+ # Renders an inline settings form without needing a dedicated form class.
+ #
+ # This method dynamically creates a form class based on the provided block
+ # and renders it. The form is instantiated with the provided form builder
+ # which comes from a `primer_form_with` call, and decorated with the
+ # `settings_form` method.
+ #
+ # The settings form is providing helpers to render settings in a standard
+ # way by reading their value, rendering labels from their name, and checking
+ # if they are writable.
+ #
+ # It is meant to avoid boilerplate code.
+ #
+ # @example
+ # primer_form_with(action: :update) do |f|
+ # render_inline_settings_form(f) do |form|
+ # form.text_field(name: :attachment_max_size)
+ # form.radio_button_group(
+ # name: "work_package_done_ratio",
+ # values: WorkPackage::DONE_RATIO_OPTIONS
+ # )
+ # form.submit
+ # end
+ # end
+ #
+ # @param f [Object] The form object to be used for the form.
+ # @param blk [Proc] A block that defines the form structure.
+ def render_inline_settings_form(form_builder, &blk)
+ form_class = Class.new(ApplicationForm) do
+ settings_form(&blk)
+ end
+ render(form_class.new(form_builder))
+ end
+ end
+end
diff --git a/app/forms/admin/settings/progress_tracking/progress_calculation_mode_form.rb b/app/forms/admin/settings/progress_tracking/progress_calculation_mode_form.rb
new file mode 100644
index 00000000000..1c49792873a
--- /dev/null
+++ b/app/forms/admin/settings/progress_tracking/progress_calculation_mode_form.rb
@@ -0,0 +1,44 @@
+# 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 Admin
+ module Settings
+ module ProgressTracking
+ class ProgressCalculationModeForm < ApplicationForm
+ settings_form do |form|
+ form.radio_button_group(
+ name: "work_package_done_ratio",
+ values: WorkPackage::DONE_RATIO_OPTIONS
+ )
+ end
+ end
+ end
+ end
+end
diff --git a/app/forms/application_form.rb b/app/forms/application_form.rb
new file mode 100644
index 00000000000..4438a280917
--- /dev/null
+++ b/app/forms/application_form.rb
@@ -0,0 +1,42 @@
+# 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.
+#++
+
+class ApplicationForm < Primer::Forms::Base
+ def self.settings_form
+ form do |f|
+ f = SettingsFormDecorator.new(f)
+ yield f
+ end
+ end
+
+ def url_helpers
+ Rails.application.routes.url_helpers
+ end
+end
diff --git a/app/forms/settings_form_decorator.rb b/app/forms/settings_form_decorator.rb
new file mode 100644
index 00000000000..610b1c6e305
--- /dev/null
+++ b/app/forms/settings_form_decorator.rb
@@ -0,0 +1,108 @@
+# 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.
+#++
+
+class SettingsFormDecorator
+ attr_reader :form
+
+ def initialize(form)
+ @form = form
+ end
+
+ def method_missing(method, ...)
+ form.send(method, ...)
+ end
+
+ def respond_to_missing?(method, include_private = false)
+ form.respond_to?(method, include_private)
+ end
+
+ def text_field(name:, **options)
+ options.reverse_merge!(
+ label: setting_label(name),
+ value: setting_value(name),
+ disabled: setting_disabled?(name)
+ )
+ form.text_field(name:, **options)
+ end
+
+ def check_box(name:, **options)
+ options.reverse_merge!(
+ label: setting_label(name),
+ checked: setting_value(name),
+ disabled: setting_disabled?(name)
+ )
+ form.check_box(name:, **options)
+ end
+
+ def radio_button_group(name:, values:, **options)
+ radio_group_options = options.reverse_merge(
+ label: setting_label(name)
+ )
+ form.radio_button_group(
+ name:,
+ disabled: setting_disabled?(name),
+ **radio_group_options
+ ) do |radio_group|
+ values.each do |value|
+ button_options = options.merge(
+ value:,
+ checked: setting_value(name) == value,
+ label: setting_label(name, value),
+ caption: setting_caption_html(name, value)
+ )
+ radio_group.radio_button(**button_options)
+ end
+ end
+ end
+
+ def submit
+ form.submit(name: "submit",
+ label: I18n.t("button_save"),
+ scheme: :primary)
+ end
+
+ protected
+
+ def setting_label(*names)
+ I18n.t("setting_#{names.join('_')}")
+ end
+
+ def setting_caption_html(*names)
+ I18n.t("setting_#{names.join('_')}_caption_html").html_safe
+ end
+
+ def setting_value(name)
+ Setting[name]
+ end
+
+ def setting_disabled?(name)
+ !Setting.send(:"#{name}_writable?")
+ end
+end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index f03f5ca75c9..d7cca379cf7 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -33,6 +33,7 @@ module ApplicationHelper
include OpenProject::TextFormatting
include OpenProject::ObjectLinking
include OpenProject::SafeParams
+ include OpPrimer::FormHelpers
include I18n
include ERB::Util
include Redmine::I18n
diff --git a/app/views/admin/settings/progress_tracking/show.html.erb b/app/views/admin/settings/progress_tracking/show.html.erb
index 45e7dcb48f0..bc67d8dd0b7 100644
--- a/app/views/admin/settings/progress_tracking/show.html.erb
+++ b/app/views/admin/settings/progress_tracking/show.html.erb
@@ -38,6 +38,13 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
+<%= primer_form_with(scope: :settings, action: :update, method: :patch) do |f| %>
+ <%= render Admin::Settings::ProgressTracking::ProgressCalculationModeForm.new(f) %>
+ <%=
+ render_inline_settings_form(f, &:submit)
+ %>
+<% end %>
+
<%= styled_form_tag({ action: :update }, method: :patch) do %>
<section class="form--section"
data-application-target="dynamic"
diff --git a/config/locales/en.yml b/config/locales/en.yml
index b37a56f6a95..fd7f24be11e 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -3280,9 +3280,15 @@ en:
This defines what is considered a "day" when displaying duration in days and hours
(for example, if a day is 8 hours, 32 hours would be 4 days).
setting_invitation_expiration_days: "Activation email expires after"
- setting_work_package_done_ratio: "Progress calculation"
+ setting_work_package_done_ratio: "Progress calculation mode"
setting_work_package_done_ratio_field: "Work-based"
+ setting_work_package_done_ratio_field_caption_html: >-
+ <i>% Complete</i> can be freely set to any value.
+ If you optionally enter a value for <i>Work</i>, <i>Remaining work</i> will automatically be derived.
setting_work_package_done_ratio_status: "Status-based"
+ setting_work_package_done_ratio_status_caption_html: >-
+ Each status has a <i>% Complete</i> value associated with it.
+ Changing status will change <i>% Complete</i>.
setting_work_package_done_ratio_explanation_pre_14_4_without_percent_complete_edition_html: >
In <b>work-based</b> mode, % Complete is calculated from how much work is done in relation to total work.
In <b>status-based</b> mode, each status has a % Complete value associated with it. Changing status will change % Complete.