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

Replace AdminSettingsFormComponent with a wrapper to be able to use it with inline Forms that do not have an own component around

Henriette Dargebb9e15586971
diff --git a/app/components/_index.sass b/app/components/_index.sass
index b943ce7ea8b..911fab2e6d7 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -1,4 +1,3 @@
-@import "admin_settings_form_component"
@import "work_packages/activities_tab/index_component"
@import "work_packages/activities_tab/journals/new_component"
@import "work_packages/activities_tab/journals/index_component"
@@ -22,6 +21,7 @@
@import "filter/filters_component"
@import "projects/row_component"
@import "op_primer/border_box_table_component"
+@import "op_primer/form_helpers"
@import "work_packages/exports/modal_dialog_component"
@import "work_package_relations_tab/index_component"
@import "work_package_relations_tab/relation_component"
diff --git a/app/components/admin_settings_form_component.rb b/app/components/admin_settings_form_component.rb
deleted file mode 100644
index cd77878032c..00000000000
--- a/app/components/admin_settings_form_component.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# 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 AdminSettingsFormComponent < ApplicationComponent
- def render_in(view_context, &)
- tag.div(class: "op-admin-settings-form-wrapper") do
- super
- end
- end
-end
diff --git a/app/components/custom_fields/details_component.html.erb b/app/components/custom_fields/details_component.html.erb
index 491c3a84e1f..47f257a4bd6 100644
--- a/app/components/custom_fields/details_component.html.erb
+++ b/app/components/custom_fields/details_component.html.erb
@@ -15,7 +15,7 @@
end
content.with_row do
- primer_form_with(
+ admin_settings_primer_form_with(
model:,
scope: :custom_field,
id: "custom_field_form",
diff --git a/app/components/custom_fields/details_component.rb b/app/components/custom_fields/details_component.rb
index 5642117e1d2..dd258b29326 100644
--- a/app/components/custom_fields/details_component.rb
+++ b/app/components/custom_fields/details_component.rb
@@ -30,6 +30,7 @@
#
module CustomFields
class DetailsComponent < ApplicationComponent
+ include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
diff --git a/app/components/op_primer/form_helpers.rb b/app/components/op_primer/form_helpers.rb
index fb742d2a5d4..64f7bfcde55 100644
--- a/app/components/op_primer/form_helpers.rb
+++ b/app/components/op_primer/form_helpers.rb
@@ -93,5 +93,32 @@ module OpPrimer
end
render(form_class.new(form_builder))
end
+
+ # An extension of primers default `primer_form_with`
+ # Renders a primer form with a special wrapper around to limit the width.
+ #
+ # This method dynamically creates a container around the actual form.
+ # All arguments and the content are simply passed through to the `primer_form_with` call
+ #
+ # It is meant for settings pages within the administration to
+ # have a unified look and feel for our users.
+ #
+ # @example
+ # admin_settings_primer_form_with(scope: :settings, action: :update, method: :patch) do |form|
+ # render_inline_settings_form(form) do |f|
+ # f.check_box(name: :allow_tracking_start_and_end_times)
+ # f.check_box(name: :enforce_tracking_start_and_end_times)
+ #
+ # f.submit
+ # end
+ # end
+ #
+ # @param kwargs [Hash] The arguments for the form
+ # @param block [Proc] A block that defines the form structure.
+ def admin_settings_primer_form_with(**, &)
+ render(Primer::BaseComponent.new(tag: :div, classes: "op-admin-settings-form-wrapper")) do
+ primer_form_with(**, &)
+ end
+ end
end
end
diff --git a/app/components/admin_settings_form_component.sass b/app/components/op_primer/form_helpers.sass
similarity index 100%
rename from app/components/admin_settings_form_component.sass
rename to app/components/op_primer/form_helpers.sass
diff --git a/app/components/work_packages/types/settings_component.html.erb b/app/components/work_packages/types/settings_component.html.erb
index f9c74101ee8..623376f9d09 100644
--- a/app/components/work_packages/types/settings_component.html.erb
+++ b/app/components/work_packages/types/settings_component.html.erb
@@ -28,7 +28,7 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<%=
- primer_form_with(**form_options) do |f|
+ admin_settings_primer_form_with(**form_options) do |f|
render(WorkPackages::Types::SettingsForm.new(f))
end
%>
diff --git a/app/components/work_packages/types/settings_component.rb b/app/components/work_packages/types/settings_component.rb
index 039f1fc5be8..926039e5bc8 100644
--- a/app/components/work_packages/types/settings_component.rb
+++ b/app/components/work_packages/types/settings_component.rb
@@ -30,7 +30,8 @@
module WorkPackages
module Types
- class SettingsComponent < AdminSettingsFormComponent
+ class SettingsComponent < ApplicationComponent
+ include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
diff --git a/app/components/work_packages/types/subject_configuration_component.html.erb b/app/components/work_packages/types/subject_configuration_component.html.erb
index 6597b015094..062014b3d7e 100644
--- a/app/components/work_packages/types/subject_configuration_component.html.erb
+++ b/app/components/work_packages/types/subject_configuration_component.html.erb
@@ -32,7 +32,7 @@ See COPYRIGHT and LICENSE files for more details.
%>
<%=
- primer_form_with(**form_options) do |f|
+ admin_settings_primer_form_with(**form_options) do |f|
render(WorkPackages::Types::SubjectConfigurationForm.new(f))
end
%>
diff --git a/app/components/work_packages/types/subject_configuration_component.rb b/app/components/work_packages/types/subject_configuration_component.rb
index 142b8877240..d96df46f714 100644
--- a/app/components/work_packages/types/subject_configuration_component.rb
+++ b/app/components/work_packages/types/subject_configuration_component.rb
@@ -30,7 +30,8 @@
module WorkPackages
module Types
- class SubjectConfigurationComponent < AdminSettingsFormComponent
+ class SubjectConfigurationComponent < ApplicationComponent
+ include ApplicationHelper
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
diff --git a/app/views/admin/settings/progress_tracking/show.html.erb b/app/views/admin/settings/progress_tracking/show.html.erb
index 653120e5aff..383eb7dbf83 100644
--- a/app/views/admin/settings/progress_tracking/show.html.erb
+++ b/app/views/admin/settings/progress_tracking/show.html.erb
@@ -38,42 +38,42 @@ See COPYRIGHT and LICENSE files for more details.
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_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",
- button_options: {
- data: { action: "admin--progress-tracking#updateEnabledOptions" }
- }
- )
- form.html_content do
- render(
- Primer::Alpha::Banner.new(
- scheme: :warning,
- data: { admin__progress_tracking_target: "warningToast" }
- )
- ) do
- render(Primer::Beta::Text.new(data: { admin__progress_tracking_target: "warningText" }))
+ admin_settings_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_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",
+ button_options: {
+ data: { action: "admin--progress-tracking#updateEnabledOptions" }
+ }
+ )
+ form.html_content do
+ render(
+ Primer::Alpha::Banner.new(
+ scheme: :warning,
+ data: { admin__progress_tracking_target: "warningToast" }
+ )
+ ) do
+ render(Primer::Beta::Text.new(data: { admin__progress_tracking_target: "warningText" }))
+ end
end
+ form.radio_button_group(
+ name: "total_percent_complete_mode",
+ values: WorkPackage::TOTAL_PERCENT_COMPLETE_MODE_OPTIONS
+ )
+ form.radio_button_group(
+ name: "percent_complete_on_status_closed",
+ disabled: WorkPackage.status_based_mode?,
+ data: { admin__progress_tracking_target: "statusClosedRadioGroup" }
+ )
+ form.submit
end
- form.radio_button_group(
- name: "total_percent_complete_mode",
- values: WorkPackage::TOTAL_PERCENT_COMPLETE_MODE_OPTIONS
- )
- form.radio_button_group(
- name: "percent_complete_on_status_closed",
- disabled: WorkPackage.status_based_mode?,
- data: { admin__progress_tracking_target: "statusClosedRadioGroup" }
- )
- form.submit
end
-end
%>
diff --git a/app/views/admin/settings/project_life_cycle_step_definitions/form.html.erb b/app/views/admin/settings/project_life_cycle_step_definitions/form.html.erb
index e11d2ad56ba..1542e789e27 100644
--- a/app/views/admin/settings/project_life_cycle_step_definitions/form.html.erb
+++ b/app/views/admin/settings/project_life_cycle_step_definitions/form.html.erb
@@ -36,7 +36,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= render Settings::ProjectLifeCycleStepDefinitions::FormHeaderComponent.new(@definition, heading_scope:) %>
<%=
- primer_form_with(
+ admin_settings_primer_form_with(
model: [:admin, :settings, @definition.becomes(Project::LifeCycleStepDefinition)]
) do |f|
render Projects::LifeCycleStepDefinitions::Form.new(f)
diff --git a/app/views/admin/settings/work_package_priorities/edit.html.erb b/app/views/admin/settings/work_package_priorities/edit.html.erb
index 8d359a45514..c3cc4c7082c 100644
--- a/app/views/admin/settings/work_package_priorities/edit.html.erb
+++ b/app/views/admin/settings/work_package_priorities/edit.html.erb
@@ -43,6 +43,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
+<%= admin_settings_primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
<%= render(Admin::Enumerations::ItemForm.new(f)) %>
<% end %>
diff --git a/app/views/admin/settings/work_package_priorities/new.html.erb b/app/views/admin/settings/work_package_priorities/new.html.erb
index 31a3b54415f..4fc91cb1caa 100644
--- a/app/views/admin/settings/work_package_priorities/new.html.erb
+++ b/app/views/admin/settings/work_package_priorities/new.html.erb
@@ -41,6 +41,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :create)) do |f| %>
+<%= admin_settings_primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :create)) do |f| %>
<%= render(Admin::Enumerations::ItemForm.new(f)) %>
<% end %>
diff --git a/app/views/statuses/edit.html.erb b/app/views/statuses/edit.html.erb
index 03bb2b1574a..c288054bdb6 100644
--- a/app/views/statuses/edit.html.erb
+++ b/app/views/statuses/edit.html.erb
@@ -44,13 +44,13 @@ See COPYRIGHT and LICENSE files for more details.
<%= error_messages_for :status %>
<%=
-primer_form_with(
- model: @status,
- data: {
- application_target: "dynamic",
- controller: "admin--statuses"
- }
-) do |f|
- render Statuses::Form.new(f)
-end
+ admin_settings_primer_form_with(
+ model: @status,
+ data: {
+ application_target: "dynamic",
+ controller: "admin--statuses"
+ }
+ ) do |f|
+ render Statuses::Form.new(f)
+ end
%>
diff --git a/lookbook/docs/patterns/17-settings-pages.md.erb b/lookbook/docs/patterns/17-settings-pages.md.erb
index b816757cbaf..fb76f3956f9 100644
--- a/lookbook/docs/patterns/17-settings-pages.md.erb
+++ b/lookbook/docs/patterns/17-settings-pages.md.erb
@@ -1,30 +1,19 @@
Settings pages usually stretch to the full width of the viewport as they tend not to have addition horizontally-positioned elements.
-## Settings page base component
+## Settings page form helper
As specified in the documentation for [forms](./forms), we prefer limiting the width of a form for legibility. Because the default behaviour of form elements to fill the full width of the container, we wrap forms in a container that limits its available width.
-Any view component rendering a form should inherit from `AdminSettingsFormComponent`. The template stays unchanged. This
+Any view component rendering a form should use the the `admin_settings_primer_form_with` form helper instead of the standard `primer_form_with`. The form itself stays unchanged. This
way, the rendered form is wrapped into a container with `680px` max-width.
-```ruby
-module WorkPackages
- module Types
- class SettingsComponent < AdminSettingsFormComponent
- # component logic goes here
- end
- end
-end
-```
-
```erb
<%%=
- primer_form_with(**form_options) do |f|
+ admin_settings_primer_form_with(**form_options) do |f|
render(WorkPackages::Types::SettingsForm.new(f))
- end
-%>
+ end %>
```
-As a general rule, only _free-floating_ forms should use this wrapper.
+As a general rule, only _free-floating_ forms should use this wrapper.
-Forms that are contained inside box-components (eg. setting up or editing a File store or an OpenID provider) do not need this wrapper; they can stretch to the full width of the box table they are contained in. Individual elements will of course have their own width setting.
\ No newline at end of file
+Forms that are contained inside box-components (eg. setting up or editing a File store or an OpenID provider) do not need this wrapper; they can stretch to the full width of the box table they are contained in. Individual elements will of course have their own width setting.
diff --git a/modules/costs/app/views/admin/costs_settings/show.html.erb b/modules/costs/app/views/admin/costs_settings/show.html.erb
index cc89471cc93..6c133299d25 100644
--- a/modules/costs/app/views/admin/costs_settings/show.html.erb
+++ b/modules/costs/app/views/admin/costs_settings/show.html.erb
@@ -48,7 +48,7 @@ render(Primer::Alpha::TabPanels.new(label: I18n.t(:project_module_costs))) do |c
component.with_tab(selected: true, id: "tab-time") do |tab|
tab.with_text { I18n.t(:label_time) }
tab.with_panel do
- primer_form_with(scope: :settings, action: :update, method: :patch) do |time_form|
+ admin_settings_primer_form_with(scope: :settings, action: :update, method: :patch) do |time_form|
render_inline_settings_form(time_form) do |form|
form.html_content do
render(Primer::Beta::Subhead.new(hide_border: true)) do |subhead|
@@ -70,7 +70,7 @@ render(Primer::Alpha::TabPanels.new(label: I18n.t(:project_module_costs))) do |c
component.with_tab(id: "tab-costs", selected: !OpenProject::FeatureDecisions.track_start_and_end_times_for_time_entries_active?) do |tab|
tab.with_text { I18n.t(:label_costs) }
tab.with_panel do
- primer_form_with(scope: :settings, action: :update, method: :patch) do |time_form|
+ admin_settings_primer_form_with(scope: :settings, action: :update, method: :patch) do |time_form|
render_inline_settings_form(time_form) do |form|
form.html_content do
render(Primer::Beta::Subhead.new(hide_border: true)) do |subhead|
@@ -78,8 +78,8 @@ render(Primer::Alpha::TabPanels.new(label: I18n.t(:project_module_costs))) do |c
subhead.with_description { I18n.t(:description_costs_settings) }
end
end
- form.text_field(name: :costs_currency, input_width: :large)
- form.text_field(name: :costs_currency_format, input_width: :large)
+ form.text_field(name: :costs_currency, input_width: :small)
+ form.text_field(name: :costs_currency_format, input_width: :small)
form.submit
end
diff --git a/modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erb b/modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erb
index f141496879e..5870f2af448 100644
--- a/modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erb
+++ b/modules/costs/app/views/admin/settings/time_entry_activities/edit.html.erb
@@ -43,6 +43,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
+<%= admin_settings_primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
<%= render(Admin::Enumerations::ItemForm.new(f)) %>
<% end %>
diff --git a/modules/documents/app/views/admin/settings/document_categories/edit.html.erb b/modules/documents/app/views/admin/settings/document_categories/edit.html.erb
index c1fb93378a5..dfba6ded0f7 100644
--- a/modules/documents/app/views/admin/settings/document_categories/edit.html.erb
+++ b/modules/documents/app/views/admin/settings/document_categories/edit.html.erb
@@ -42,6 +42,6 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
+<%= admin_settings_primer_form_with(model: @enumeration, scope: :enumeration, url: url_for(action: :update, id: @enumeration)) do |f| %>
<%= render(Admin::Enumerations::ItemForm.new(f)) %>
<% end %>