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

Implement disabled project select on copy page

Alexander Brandon Coles3344904253a2
diff --git a/app/components/projects/source_project_select_component.html.erb b/app/components/projects/source_project_select_component.html.erb
new file mode 100644
index 00000000000..ae5644df8db
--- /dev/null
+++ b/app/components/projects/source_project_select_component.html.erb
@@ -0,0 +1,66 @@
+<%#-- 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.
+
+++#%>
+
+<%=
+ component_wrapper do
+ settings_primer_form_with(
+ url: copy_project_path(source_project),
+ method: :get
+ ) do |f|
+ render(
+ Primer::Box.new(
+ border: true,
+ border_radius: 2,
+ bg: :inset,
+ my: 3,
+ p: 3
+ )
+ ) do
+ source_project_id_value = source_project_id
+ render_inline_form(f) do |form|
+ form.project_autocompleter(
+ name: :project_id,
+ label: I18n.t("copy_project.source_project_label"),
+ autocomplete_options: {
+ disabled: true,
+ focusDirectly: false,
+ dropdownPosition: "bottom",
+ inputValue: source_project_id_value,
+ placeholder: I18n.t("label_none_parentheses"),
+ filters: [
+ { name: "user_action", operator: "=", values: ["projects/copy"] },
+ { name: "templated", operator: "=", values: ["f"] }
+ ]
+ }
+ )
+ end
+ end
+ end
+ end
+%>
diff --git a/app/components/projects/source_project_select_component.rb b/app/components/projects/source_project_select_component.rb
new file mode 100644
index 00000000000..4e3dda2f63e
--- /dev/null
+++ b/app/components/projects/source_project_select_component.rb
@@ -0,0 +1,43 @@
+# frozen_string_literal: true
+
+# -- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2010-2024 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 SourceProjectSelectComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ options :source_project
+
+ private
+
+ def source_project_id = source_project.id
+ end
+end
diff --git a/app/views/projects/copy_form.html.erb b/app/views/projects/copy_form.html.erb
index 5a6d4b3d265..00d1ca625dc 100644
--- a/app/views/projects/copy_form.html.erb
+++ b/app/views/projects/copy_form.html.erb
@@ -41,6 +41,10 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
+<%=
+ render Projects::SourceProjectSelectComponent.new(source_project: @project)
+%>
+
<%=
render Projects::CopyFormComponent.new(
source_project: @project,
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 1b8ea3f3773..a0a25f3708b 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -2043,6 +2043,7 @@ en:
text:
failed: 'Could not copy project "%{source_project_name}" to project "%{target_project_name}".'
succeeded: 'Copied project "%{source_project_name}" to "%{target_project_name}".'
+ source_project_label: "Project copied"
copy_options:
dependencies_label: 'Copy from project'
diff --git a/spec/components/projects/source_project_select_component_spec.rb b/spec/components/projects/source_project_select_component_spec.rb
new file mode 100644
index 00000000000..cf81600a966
--- /dev/null
+++ b/spec/components/projects/source_project_select_component_spec.rb
@@ -0,0 +1,52 @@
+# 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 "rails_helper"
+
+RSpec.describe Projects::SourceProjectSelectComponent, type: :component do
+ let(:source_project) { build_stubbed(:project) }
+
+ def render_component(**params)
+ render_inline(described_class.new(source_project:, **params))
+ page
+ end
+
+ it "renders form" do
+ expect(render_component).to have_css "form"
+ end
+
+ it "renders disabled project autocompleter" do
+ expect(render_component).to have_element "opce-project-autocompleter",
+ "data-input-name": "\"project_id\"",
+ "data-disabled": "true" do |element|
+ expect(element["data-input-value"]).to eq source_project.id.to_s
+ end
+ end
+end