Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename 'Work package settings' page as 'General' #16550

Merged
merged 10 commits into from
Sep 13, 2024
97 changes: 97 additions & 0 deletions app/components/op_primer/form_helpers.rb
Original file line number Diff line number Diff line change
@@ -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 form_builder [Object] The form builder 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 form_builder [Object] The form builder 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
2 changes: 1 addition & 1 deletion app/components/types/edit_page_header_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def initialize(type:, tabs: nil)

def breadcrumb_items
[{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_work_package_tracking_path, text: t(:label_work_package_plural) },
{ href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },
{ href: types_path, text: t(:label_type_plural) },
@type.name]
end
Expand Down
2 changes: 1 addition & 1 deletion app/components/workflows/page_header_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def initialize(state:)

def breadcrumb_items
base_items = [{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_work_package_tracking_path, text: t(:label_work_package_plural) },
{ href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },
title]

if @state == :edit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
#++

module Admin::Settings
class WorkPackagesSettingsController < ::Admin::SettingsController
class ProgressTrackingController < ::Admin::SettingsController
current_menu_item :show do
:work_packages_setting
:progress_tracking
end
end
end
35 changes: 35 additions & 0 deletions app/controllers/admin/settings/work_packages_general_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#-- 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::Settings
class WorkPackagesGeneralController < ::Admin::SettingsController
current_menu_item :show do
:work_packages_general
end
end
end
42 changes: 42 additions & 0 deletions app/forms/application_form.rb
Original file line number Diff line number Diff line change
@@ -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
109 changes: 109 additions & 0 deletions app/forms/settings_form_decorator.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
# 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:, button_options: {}, **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|
radio_group.radio_button(
**button_options.reverse_merge(
value:,
checked: setting_value(name) == value,
label: setting_label(name, value),
caption: setting_caption_html(name, value)
)
)
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
1 change: 1 addition & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
72 changes: 72 additions & 0 deletions app/views/admin/settings/progress_tracking/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<%#-- 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.

++#%>

<% html_title t(:label_administration), t(:label_work_package_plural), t(:label_progress_tracking) -%>

<%=
render Primer::OpenProject::PageHeader.new do |header|
header.with_title { t(:label_progress_tracking) }
header.with_breadcrumbs([{ href: admin_index_path, text: t("label_administration") },
{ href: admin_settings_work_packages_general_path, text: t(:label_work_package_plural) },
t(:label_progress_tracking)])
end
%>

<%=
primer_form_with(
scope: :settings, action: :update, method: :patch,
data: {
application_target: "dynamic",
controller: "admin--progress-tracking",
admin__progress_tracking_target: "progressCalculationModeRadioGroup",
admin__progress_tracking_percent_complete_edition_active_value: OpenProject::FeatureDecisions.percent_complete_edition_active?,
admin__progress_tracking_initial_mode_value: Setting.work_package_done_ratio
}
) do |f|
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" }
}
)
form.html_content do
tag.div(class: "op-toast -warning -with-bottom-spacing",
hidden: true,
data: { admin__progress_tracking_target: "warningToast" }) do
tag.div(class: "op-toast--content") do
tag.p(data: { admin__progress_tracking_target: "warningText" })
end
end
end
form.submit
end
end
%>
Loading