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

[#60144] retain and submit copy workflow value

Eric Schubertaf0a31dc50b4
diff --git a/app/components/work_packages/types/settings_component.rb b/app/components/work_packages/types/settings_component.rb
index fa08b10fbbb..8cceabe49ea 100644
--- a/app/components/work_packages/types/settings_component.rb
+++ b/app/components/work_packages/types/settings_component.rb
@@ -34,11 +34,17 @@ module WorkPackages
include OpPrimer::ComponentHelpers
include OpTurbo::Streamable
+ def initialize(model, **options)
+ @copy_workflow_from = options[:copy_workflow_from].to_i
+ super
+ end
+
def form_options
{
url: model.new_record? ? types_path : type_path(id: model.id),
method: model.new_record? ? :post : :patch,
- model:
+ model:,
+ copy_workflow_from: @copy_workflow_from
}
end
end
diff --git a/app/controllers/types_controller.rb b/app/controllers/types_controller.rb
index 939264122d9..c3cc2a5dcbf 100644
--- a/app/controllers/types_controller.rb
+++ b/app/controllers/types_controller.rb
@@ -65,7 +65,7 @@ class TypesController < ApplicationController
def create
CreateTypeService
.new(current_user)
- .call(permitted_type_params, copy_workflow_from: params[:copy_workflow_from]) do |call|
+ .call(permitted_type_params, copy_workflow_from: params.dig(:type, :copy_workflow_from)) do |call|
@type = call.result
call.on_success do
diff --git a/app/forms/work_packages/types/settings_form.rb b/app/forms/work_packages/types/settings_form.rb
index e9bcdcbcab1..9b50d854f69 100644
--- a/app/forms/work_packages/types/settings_form.rb
+++ b/app/forms/work_packages/types/settings_form.rb
@@ -31,8 +31,8 @@
module WorkPackages
module Types
class SettingsForm < ApplicationForm
- form do |subject_form|
- subject_form.text_field(
+ form do |settings_form|
+ settings_form.text_field(
name: :name,
label: label(:name),
placeholder: I18n.t(:label_name),
@@ -41,7 +41,7 @@ module WorkPackages
disabled: model.is_standard?
)
- subject_form.color_select_list(
+ settings_form.color_select_list(
name: :color_id,
label: Color.model_name.human,
caption: I18n.t("types.edit.settings.type_color_text"),
@@ -49,41 +49,45 @@ module WorkPackages
)
if show_work_flow_copy?
- subject_form.select_list(
+ settings_form.select_list(
name: :copy_workflow_from,
label: label(:copy_workflow_from),
include_blank: true,
input_width: :large
) do |other_types|
work_package_types.each do |type|
- other_types.option(value: type.id, label: type.name)
+ other_types.option(
+ value: type.id,
+ label: type.name,
+ selected: type.id == prefilled_copy_workflow_from
+ )
end
end
end
- subject_form.rich_text_area(
+ settings_form.rich_text_area(
name: :description,
label: label(:description),
input_width: :large,
rich_text_options: { showAttachments: false }
)
- subject_form.check_box(
+ settings_form.check_box(
name: :is_milestone,
label: label(:is_milestone)
)
- subject_form.check_box(
+ settings_form.check_box(
name: :is_in_roadmap,
label: label(:is_in_roadmap)
)
- subject_form.check_box(
+ settings_form.check_box(
name: :is_default,
label: label(:is_default)
)
- subject_form.submit(
+ settings_form.submit(
name: :submit,
label: I18n.t(:button_save),
scheme: :primary
@@ -103,6 +107,10 @@ module WorkPackages
def work_package_types
Type.all
end
+
+ def prefilled_copy_workflow_from
+ @builder.options[:copy_workflow_from]
+ end
end
end
end
diff --git a/app/views/types/new.html.erb b/app/views/types/new.html.erb
index 4b937fc9b35..b1094027dfc 100644
--- a/app/views/types/new.html.erb
+++ b/app/views/types/new.html.erb
@@ -39,4 +39,10 @@ See COPYRIGHT and LICENSE files for more details.
end
%>
-<%= render WorkPackages::Types::SettingsComponent.new(@type) %>
+<%=
+ render WorkPackages::Types::SettingsComponent.new(
+ @type,
+ copy_workflow_from: params.dig(:type, :copy_workflow_from),
+ params:
+ )
+%>
diff --git a/spec/controllers/types_controller_spec.rb b/spec/controllers/types_controller_spec.rb
index 1a01a7ef299..afc9d926514 100644
--- a/spec/controllers/types_controller_spec.rb
+++ b/spec/controllers/types_controller_spec.rb
@@ -180,10 +180,14 @@ RSpec.describe TypesController do
end
let(:params) do
- { "type" => { name: "New type",
- project_ids: { "1" => project.id },
- custom_field_ids: { "1" => custom_field_1.id, "2" => custom_field_2.id } },
- "copy_workflow_from" => existing_type.id }
+ {
+ "type" => {
+ name: "New type",
+ project_ids: { "1" => project.id },
+ custom_field_ids: { "1" => custom_field_1.id, "2" => custom_field_2.id },
+ copy_workflow_from: existing_type.id
+ }
+ }
end
before do
diff --git a/spec/features/types/crud_spec.rb b/spec/features/types/crud_spec.rb
index ede513857a8..a9ea8cf3014 100644
--- a/spec/features/types/crud_spec.rb
+++ b/spec/features/types/crud_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -50,21 +52,20 @@ RSpec.describe "Types", :js do
fill_in "Name", with: existing_type.name
select existing_type.name, from: "Copy workflow from"
- click_button "Create"
+ click_on "Save"
- expect_flash(type: :error, message: "Name has already been taken.")
+ expect(page).to have_css(".FormControl-inlineValidation", text: "Name has already been taken.", wait: 12)
# Values are retained
- expect(page)
- .to have_field("Name", with: existing_type.name)
+ expect(page).to have_field("Name", with: existing_type.name)
+ expect(page).to have_field("Copy workflow from", with: existing_type.id)
# Successful creation
fill_in "Name", with: "A new type"
- click_button "Create"
+ click_on "Save"
- expect(page)
- .to have_content I18n.t(:notice_successful_create)
+ expect(page).to have_content I18n.t(:notice_successful_create)
# Workflow should be copied over.
# Workflow routes are not resource-oriented.
@@ -72,15 +73,14 @@ RSpec.describe "Types", :js do
select existing_role.name, from: "Role"
select "A new type", from: "Type"
- click_button "Edit"
+ click_on "Edit"
from_id = existing_workflow.old_status_id
to_id = existing_workflow.new_status_id
checkbox = page.find("input.old-status-#{from_id}.new-status-#{to_id}[value=always]")
- expect(checkbox)
- .to be_checked
+ expect(checkbox).to be_checked
index_page.visit!
@@ -90,10 +90,9 @@ RSpec.describe "Types", :js do
fill_in "Name", with: "Renamed type"
- click_button "Save"
+ click_on "Save"
- expect(page)
- .to have_content I18n.t(:notice_successful_update)
+ expect_flash(type: :success, message: I18n.t(:notice_successful_update))
index_page.visit!