diff --git a/app/components/types/edit_page_header_component.html.erb b/app/components/types/edit_page_header_component.html.erb index 70c2494d3950..27e38756b3c1 100644 --- a/app/components/types/edit_page_header_component.html.erb +++ b/app/components/types/edit_page_header_component.html.erb @@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details. header.with_tab_nav(label: nil) do |tab_nav| @tabs.each do |tab| tab_nav.with_tab(selected: selected_tab(@tabs) == tab, href: tab[:path]) do |t| - t.with_text { I18n.t("js.#{tab[:label]}") } + t.with_text { I18n.t(tab[:label]) } end end end if @tabs.present? diff --git a/app/components/work_packages/types/subject_configuration_component.html.erb b/app/components/work_packages/types/subject_configuration_component.html.erb new file mode 100644 index 000000000000..95792457632a --- /dev/null +++ b/app/components/work_packages/types/subject_configuration_component.html.erb @@ -0,0 +1,34 @@ +<%#-- 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. + +++#%> + +<%= + 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 new file mode 100644 index 000000000000..88850e1b7e9d --- /dev/null +++ b/app/components/work_packages/types/subject_configuration_component.rb @@ -0,0 +1,51 @@ +# 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 WorkPackages + module Types + class SubjectConfigurationComponent < ApplicationComponent + include OpPrimer::ComponentHelpers + include OpTurbo::Streamable + + def form_options + { + url: "https://example.com", + method: :put, + model:, + data: { + application_target: "dynamic", + controller: "admin--subject-configuration", + admin__subject_configuration_hide_pattern_input_value: true + } + } + end + end + end +end diff --git a/app/forms/work_packages/types/subject_configuration_form.rb b/app/forms/work_packages/types/subject_configuration_form.rb new file mode 100644 index 000000000000..455b1213e5ad --- /dev/null +++ b/app/forms/work_packages/types/subject_configuration_form.rb @@ -0,0 +1,72 @@ +# 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 WorkPackages + module Types + class SubjectConfigurationForm < ApplicationForm + form do |subject_form| + subject_form.radio_button_group(name: :subject_configuration) do |group| + group.radio_button( + value: "manual", + checked: !has_pattern?, + label: I18n.t("types.edit.subject_configuration.manually_editable_subjects.label"), + caption: I18n.t("types.edit.subject_configuration.manually_editable_subjects.caption"), + data: { action: "admin--subject-configuration#hidePatternInput" } + ) + group.radio_button( + value: "auto", + checked: has_pattern?, + label: I18n.t("types.edit.subject_configuration.automatically_generated_subjects.label"), + caption: I18n.t("types.edit.subject_configuration.automatically_generated_subjects.caption"), + data: { action: "admin--subject-configuration#showPatternInput" } + ) + end + + subject_form.group(data: { "admin--subject-configuration-target": "patternInput" }) do |toggleable_group| + toggleable_group.text_field( + name: :pattern, + label: I18n.t("types.edit.subject_configuration.pattern.label"), + caption: I18n.t("types.edit.subject_configuration.pattern.caption"), + required: true, + input_width: :large + ) + end + + subject_form.submit(name: :submit, label: I18n.t(:button_save), scheme: :primary) + end + + private + + def has_pattern? + false + end + end + end +end diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rb index fcac23fc709a..71f103504d7b 100644 --- a/app/helpers/types_helper.rb +++ b/app/helpers/types_helper.rb @@ -33,19 +33,25 @@ def types_tabs name: "settings", partial: "types/form/settings", path: edit_type_tab_path(id: @type.id, tab: :settings), - label: "types.edit.settings" + label: "types.edit.settings.tab" }, { name: "form_configuration", partial: "types/form/form_configuration", path: edit_type_tab_path(id: @type.id, tab: :form_configuration), - label: "types.edit.form_configuration" + label: "types.edit.form_configuration.tab" + }, + { + name: "subject_configuration", + path: edit_type_tab_path(id: @type.id, tab: :subject_configuration), + label: "types.edit.subject_configuration.tab", + view_component: WorkPackages::Types::SubjectConfigurationComponent }, { name: "projects", partial: "types/form/projects", path: edit_type_tab_path(id: @type.id, tab: :projects), - label: "types.edit.projects" + label: "types.edit.projects.tab" } ] end diff --git a/app/views/types/edit.html.erb b/app/views/types/edit.html.erb index c3b52c8f96a7..cdba71ebc004 100644 --- a/app/views/types/edit.html.erb +++ b/app/views/types/edit.html.erb @@ -33,12 +33,19 @@ See COPYRIGHT and LICENSE files for more details. <%= render ::Types::EditPageHeaderComponent.new(type: @type, tabs: tabs) %> -<%= form_for @type, +<%= + selected_tab = selected_tab(tabs) + + if selected_tab.key?(:view_component) + render selected_tab[:view_component].new(@type) + else + form_for @type, url: update_type_tab_path(id: @type.id, tab: @tab), builder: TabularFormBuilder, - lang: current_language do |f| %> - - <%= render_tabs tabs, f, with_tab_nav: false %> -<% end %> + lang: current_language do |f| + render partial: "common/tabs", locals: { f:, tabs:, selected_tab:, with_tab_nav: false } + end + end +%> <%= error_messages_for 'type' %> diff --git a/app/views/types/form/_projects.html.erb b/app/views/types/form/_projects.html.erb index 081f5cf2d592..68407540cf19 100644 --- a/app/views/types/form/_projects.html.erb +++ b/app/views/types/form/_projects.html.erb @@ -33,7 +33,7 @@ See COPYRIGHT and LICENSE files for more details. <% if @projects.any? %>