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

chore[Op#50737]: Break up `StorageProviderForm` for easier composition

Kabiru Mwenjaad89ddfc9177
diff --git a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb
index 0b5db97d24e..36935e62bf8 100644
--- a/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb
+++ b/modules/storages/app/components/storages/admin/forms/general_info_form_component.html.erb
@@ -7,7 +7,15 @@
) do |form|
flex_layout do |general_info_row|
general_info_row.with_row(mb: 3) do
- render(Storages::Admin::StorageProviderForm.new(form, storage:))
+ render(Storages::Admin::ProviderTypeSelectForm.new(form, storage:))
+ end
+
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ProviderNameInputForm.new(form))
+ end
+
+ general_info_row.with_row(mb: 3) do
+ render(Storages::Admin::ProviderHostInputForm.new(form))
end
general_info_row.with_row do
diff --git a/modules/storages/app/forms/storages/admin/provider_host_input_form.rb b/modules/storages/app/forms/storages/admin/provider_host_input_form.rb
new file mode 100644
index 00000000000..fb49ed372a7
--- /dev/null
+++ b/modules/storages/app/forms/storages/admin/provider_host_input_form.rb
@@ -0,0 +1,44 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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 Storages::Admin
+ class ProviderHostInputForm < ApplicationForm
+ form do |storage_form|
+ storage_form.text_field(
+ name: :host,
+ label: I18n.t('activerecord.attributes.storages/storage.host'),
+ visually_hide_label: false,
+ required: true,
+ type: :url,
+ pattern: ".{1,255}",
+ placeholder: "https://my-file-storage.com",
+ caption: I18n.t('storages.instructions.host')
+ )
+ end
+ end
+end
diff --git a/modules/storages/app/forms/storages/admin/provider_name_input_form.rb b/modules/storages/app/forms/storages/admin/provider_name_input_form.rb
new file mode 100644
index 00000000000..f8ba9f36887
--- /dev/null
+++ b/modules/storages/app/forms/storages/admin/provider_name_input_form.rb
@@ -0,0 +1,40 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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 Storages::Admin
+ class ProviderNameInputForm < ApplicationForm
+ form do |storage_form|
+ storage_form.text_field(
+ name: :name,
+ label: I18n.t('activerecord.attributes.storages/storage.name'),
+ required: true,
+ caption: I18n.t('storages.instructions.name')
+ )
+ end
+ end
+end
diff --git a/modules/storages/app/forms/storages/admin/storage_provider_form.rb b/modules/storages/app/forms/storages/admin/provider_type_select_form.rb
similarity index 78%
rename from modules/storages/app/forms/storages/admin/storage_provider_form.rb
rename to modules/storages/app/forms/storages/admin/provider_type_select_form.rb
index 068004abeb4..c58be9f1b83 100644
--- a/modules/storages/app/forms/storages/admin/storage_provider_form.rb
+++ b/modules/storages/app/forms/storages/admin/provider_type_select_form.rb
@@ -27,14 +27,14 @@
#++
module Storages::Admin
- class StorageProviderForm < ApplicationForm
- form do |storage_provider_form|
- storage_provider_form.select_list(
+ class ProviderTypeSelectForm < ApplicationForm
+ form do |storage_form|
+ storage_form.select_list(
name: :provider_type,
label: I18n.t('activerecord.attributes.storages/storage.provider_type'),
caption: I18n.t('storages.instructions.provider_type',
type_link_text: I18n.t('storages.instructions.type_link_text')),
- include_blank: false,
+ include_blank: @storage.new_record?,
required: true,
disabled: @storage.persisted?
) do |storage_provider_list|
@@ -52,21 +52,6 @@ module Storages::Admin
end
end
end
-
- storage_provider_form.text_field(
- name: :name,
- label: I18n.t('activerecord.attributes.storages/storage.name'),
- required: true,
- caption: I18n.t('storages.instructions.name')
- )
-
- storage_provider_form.text_field(
- name: :host,
- label: I18n.t('activerecord.attributes.storages/storage.host'),
- visually_hide_label: false,
- required: true,
- caption: I18n.t('storages.instructions.host')
- )
end
def initialize(storage:)