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

Inline Projects::TemplateAutocompleter form

Alexander Brandon Coles9c3dbbb6f019
diff --git a/app/components/projects/template_select_component.html.erb b/app/components/projects/template_select_component.html.erb
index 5e2736ee5cd..b7b3d033e9f 100644
--- a/app/components/projects/template_select_component.html.erb
+++ b/app/components/projects/template_select_component.html.erb
@@ -47,7 +47,30 @@ See COPYRIGHT and LICENSE files for more details.
p: 3
)
) do
- render Projects::TemplateAutocompleter.new(f, template_id:, parent_id:)
+ template_id_value = template_id
+ parent_id_value = parent_id
+ render_inline_form(f) do |form|
+ form.project_autocompleter(
+ name: :template_id,
+ label: I18n.t("js.project.use_template"),
+ autocomplete_options: {
+ focusDirectly: false,
+ dropdownPosition: "bottom",
+ inputValue: template_id_value,
+ placeholder: I18n.t("js.project.no_template_selected"),
+ filters: [
+ { name: "user_action", operator: "=", values: ["projects/copy"] },
+ { name: "templated", operator: "=", values: ["t"] }
+ ],
+ data: {
+ action: "change->auto-submit#submit",
+ "qa-field-name": "use_template"
+ }
+ }
+ )
+
+ form.hidden name: :parent_id, value: parent_id_value
+ end
end
end
end
diff --git a/app/forms/projects/template_autocompleter.rb b/app/forms/projects/template_autocompleter.rb
deleted file mode 100644
index 62f365542ae..00000000000
--- a/app/forms/projects/template_autocompleter.rb
+++ /dev/null
@@ -1,61 +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.
-#++
-
-module Projects
- class TemplateAutocompleter < ApplicationForm
- extend Dry::Initializer
-
- option :template_id, optional: true
- option :parent_id, optional: true
-
- form do |f|
- f.project_autocompleter(
- name: :template_id,
- label: I18n.t("js.project.use_template"),
- autocomplete_options: {
- focusDirectly: false,
- dropdownPosition: "bottom",
- inputValue: template_id,
- placeholder: I18n.t("js.project.no_template_selected"),
- filters: [
- { name: "user_action", operator: "=", values: ["projects/copy"] },
- { name: "templated", operator: "=", values: ["t"] }
- ],
- data: {
- action: "change->auto-submit#submit",
- "qa-field-name": "use_template"
- }
- }
- )
-
- f.hidden name: :parent_id, value: parent_id
- end
- end
-end
diff --git a/spec/components/projects/template_select_component_spec.rb b/spec/components/projects/template_select_component_spec.rb
index 9a27ef76b39..2344f7051a6 100644
--- a/spec/components/projects/template_select_component_spec.rb
+++ b/spec/components/projects/template_select_component_spec.rb
@@ -38,7 +38,19 @@ RSpec.describe Projects::TemplateSelectComponent, type: :component do
page
end
- it "renders a form" do
+ it "renders form" do
expect(render_component).to have_css "form"
end
+
+ it "renders project autocompleter" do
+ expect(render_component).to have_element "opce-project-autocompleter", "data-input-name": "\"template_id\"" do |element|
+ expect(element["data-input-value"]).to eq template.id.to_s
+ end
+ end
+
+ it "connects Stimulus controller actions" do
+ expect(render_component).to have_element "opce-project-autocompleter", "data-input-name": "\"template_id\"" do |element|
+ expect(element["data-action"]).to include "change->auto-submit#submit"
+ end
+ end
end
diff --git a/spec/forms/projects/template_autocompleter_spec.rb b/spec/forms/projects/template_autocompleter_spec.rb
deleted file mode 100644
index 04c6a596fb5..00000000000
--- a/spec/forms/projects/template_autocompleter_spec.rb
+++ /dev/null
@@ -1,61 +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.
-#++
-#
-require "spec_helper"
-
-RSpec.describe Projects::TemplateAutocompleter, type: :forms do
- include ViewComponent::TestHelpers
-
- def render_form
- render_in_view_context(template_id, described_class) do |template_id, described_class|
- primer_form_with(url: "/foo") do |f|
- render(described_class.new(f, template_id:))
- end
- end
- end
-
- before do
- render_form
- end
-
- let(:template_id) { 1001 }
-
- it "renders field" do
- expect(page).to have_element "opce-project-autocompleter", "data-input-name": "\"template_id\"" do |element|
- expect(element["data-input-value"]).to eq "1001"
- end
- end
-
- it "connects Stimulus controller actions" do
- expect(page).to have_element "opce-project-autocompleter", "data-input-name": "\"template_id\"" do |element|
- expect(element["data-action"]).to include "change->auto-submit#submit"
- end
- end
-end