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

[#65242] moved most of the wp types related files to new namespace

Eric Schuberte36d115295e2
diff --git a/app/components/_index.sass b/app/components/_index.sass
index c8a5624de14..51b5beecb6d 100644
--- a/app/components/_index.sass
+++ b/app/components/_index.sass
@@ -13,6 +13,7 @@
@import "users/hover_card_component"
@import "work_package_relations_tab/index_component"
@import "work_package_relations_tab/relation_component"
+@import "work_package_types/pattern_input"
@import "work_packages/activities_tab/index_component"
@import "work_packages/activities_tab/journals/new_component"
@import "work_packages/activities_tab/journals/index_component"
@@ -29,5 +30,4 @@
@import "work_packages/hover_card_component"
@import "work_packages/progress/modal_body_component"
@import "work_packages/reminder/modal_body_component"
-@import "work_packages/types/pattern_input"
@import "work_packages/split_view_component"
diff --git a/app/components/work_packages/types/export_configuration_component.html.erb b/app/components/work_package_types/export_configuration_component.html.erb
similarity index 93%
rename from app/components/work_packages/types/export_configuration_component.html.erb
rename to app/components/work_package_types/export_configuration_component.html.erb
index 657a294e510..36a18817b90 100644
--- a/app/components/work_packages/types/export_configuration_component.html.erb
+++ b/app/components/work_package_types/export_configuration_component.html.erb
@@ -28,4 +28,4 @@ See COPYRIGHT and LICENSE files for more details.
++#%>
<p><%= I18n.t("types.edit.export_configuration.intro") %></p>
-<%= render(WorkPackages::Types::ExportTemplateListComponent.new(type: model)) %>
+<%= render(WorkPackageTypes::ExportTemplateListComponent.new(type: model)) %>
diff --git a/app/components/work_packages/types/export_configuration_component.rb b/app/components/work_package_types/export_configuration_component.rb
similarity index 92%
rename from app/components/work_packages/types/export_configuration_component.rb
rename to app/components/work_package_types/export_configuration_component.rb
index 17f5ff5c67a..da4839c1178 100644
--- a/app/components/work_packages/types/export_configuration_component.rb
+++ b/app/components/work_package_types/export_configuration_component.rb
@@ -28,9 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module WorkPackages
- module Types
- class ExportConfigurationComponent < ApplicationComponent
- end
+module WorkPackageTypes
+ class ExportConfigurationComponent < ApplicationComponent
end
end
diff --git a/app/components/work_packages/types/export_template_list_component.html.erb b/app/components/work_package_types/export_template_list_component.html.erb
similarity index 98%
rename from app/components/work_packages/types/export_template_list_component.html.erb
rename to app/components/work_package_types/export_template_list_component.html.erb
index 75c03fd5e32..fb4af1456a5 100644
--- a/app/components/work_packages/types/export_template_list_component.html.erb
+++ b/app/components/work_package_types/export_template_list_component.html.erb
@@ -76,7 +76,7 @@ See COPYRIGHT and LICENSE files for more details.
@type.pdf_export_templates.list.each do |template|
component.with_row(data: draggable_item_config(template)) do
render(
- WorkPackages::Types::ExportTemplateRowComponent.new(
+ WorkPackageTypes::ExportTemplateRowComponent.new(
type: @type,
template:
)
diff --git a/app/components/work_packages/types/export_template_list_component.rb b/app/components/work_package_types/export_template_list_component.rb
similarity index 56%
rename from app/components/work_packages/types/export_template_list_component.rb
rename to app/components/work_package_types/export_template_list_component.rb
index e8ed1fe3eba..ace1a352c41 100644
--- a/app/components/work_packages/types/export_template_list_component.rb
+++ b/app/components/work_package_types/export_template_list_component.rb
@@ -28,42 +28,40 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module WorkPackages
- module Types
- class ExportTemplateListComponent < ApplicationComponent
- include ApplicationHelper
- include OpPrimer::ComponentHelpers
- include OpTurbo::Streamable
+module WorkPackageTypes
+ class ExportTemplateListComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
- def initialize(type:)
- super
+ def initialize(type:)
+ super
- @type = type
- end
+ @type = type
+ end
- def wrapper_data_attributes
- {
- controller: "generic-drag-and-drop"
- }
- end
+ def wrapper_data_attributes
+ {
+ controller: "generic-drag-and-drop"
+ }
+ end
- def drag_and_drop_target_config
- {
- "is-drag-and-drop-target": true,
- "target-container-accessor": "& > ul",
- "target-allowed-drag-type": "template",
- test_selector: "pdf-export-template-rows"
- }
- end
+ def drag_and_drop_target_config
+ {
+ "is-drag-and-drop-target": true,
+ "target-container-accessor": "& > ul",
+ "target-allowed-drag-type": "template",
+ test_selector: "pdf-export-template-rows"
+ }
+ end
- def draggable_item_config(template)
- {
- "draggable-id": template.id,
- "draggable-type": "template",
- "drop-url": drop_type_pdf_export_template_path(type_id: @type.id, id: template.id),
- test_selector: "pdf-export-template-row-#{template.id}"
- }
- end
+ def draggable_item_config(template)
+ {
+ "draggable-id": template.id,
+ "draggable-type": "template",
+ "drop-url": drop_type_pdf_export_template_path(type_id: @type.id, id: template.id),
+ test_selector: "pdf-export-template-row-#{template.id}"
+ }
end
end
end
diff --git a/app/components/work_packages/types/export_template_row_component.html.erb b/app/components/work_package_types/export_template_row_component.html.erb
similarity index 76%
rename from app/components/work_packages/types/export_template_row_component.html.erb
rename to app/components/work_package_types/export_template_row_component.html.erb
index 89278f32145..de7dac1c92f 100644
--- a/app/components/work_packages/types/export_template_row_component.html.erb
+++ b/app/components/work_package_types/export_template_row_component.html.erb
@@ -45,16 +45,18 @@ See COPYRIGHT and LICENSE files for more details.
end
end
item_information.with_column(py: 1, mr: 2) do
- render(Primer::Alpha::ToggleSwitch.new(
- src: toggle_type_pdf_export_template_path(type_id: @type.id, id: @template.id),
- csrf_token: form_authenticity_token,
- data: { "turbo-method": :post, "turbo-stream": true },
- checked: @template.enabled,
- size: :small,
- status_label_position: :start,
- test_selector: "toggle-pdf-export-template-row-#{@template.id}",
- classes: "op-primer-adjustments__toggle-switch--hidden-loading-indicator"
- ))
+ render(
+ Primer::Alpha::ToggleSwitch.new(
+ src: toggle_type_pdf_export_template_path(type_id: @type.id, id: @template.id),
+ csrf_token: form_authenticity_token,
+ data: { "turbo-method": :post, "turbo-stream": true },
+ checked: @template.enabled,
+ size: :small,
+ status_label_position: :start,
+ test_selector: "toggle-pdf-export-template-row-#{@template.id}",
+ classes: "op-primer-adjustments__toggle-switch--hidden-loading-indicator"
+ )
+ )
end
end
end
diff --git a/app/components/work_packages/types/export_template_row_component.rb b/app/components/work_package_types/export_template_row_component.rb
similarity index 79%
rename from app/components/work_packages/types/export_template_row_component.rb
rename to app/components/work_package_types/export_template_row_component.rb
index 07d9a9aaff2..dd2796f2eef 100644
--- a/app/components/work_packages/types/export_template_row_component.rb
+++ b/app/components/work_package_types/export_template_row_component.rb
@@ -28,18 +28,17 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module WorkPackages
- module Types
- class ExportTemplateRowComponent < ApplicationComponent
- include ApplicationHelper
- include OpPrimer::ComponentHelpers
- include OpTurbo::Streamable
- def initialize(type:, template:)
- super
+module WorkPackageTypes
+ class ExportTemplateRowComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
- @template = template
- @type = type
- end
+ def initialize(type:, template:)
+ super
+
+ @template = template
+ @type = type
end
end
end
diff --git a/app/components/work_packages/types/pattern_input.html.erb b/app/components/work_package_types/pattern_input.html.erb
similarity index 100%
rename from app/components/work_packages/types/pattern_input.html.erb
rename to app/components/work_package_types/pattern_input.html.erb
diff --git a/app/components/work_packages/types/pattern_input.rb b/app/components/work_package_types/pattern_input.rb
similarity index 64%
rename from app/components/work_packages/types/pattern_input.rb
rename to app/components/work_package_types/pattern_input.rb
index aec45fc3e06..8915573a26d 100644
--- a/app/components/work_packages/types/pattern_input.rb
+++ b/app/components/work_package_types/pattern_input.rb
@@ -28,32 +28,30 @@
# See COPYRIGHT and LICENSE files for more details.
# ++
-module WorkPackages
- module Types
- class PatternInput < Primer::Forms::BaseComponent
- prepend Primer::OpenProject::Forms::WrappedInput
+module WorkPackageTypes
+ class PatternInput < Primer::Forms::BaseComponent
+ prepend Primer::OpenProject::Forms::WrappedInput
- delegate :name, to: :@input
+ delegate :name, to: :@input
- def initialize(input:, value:, suggestions:)
- super()
- @input = input
- @value = value
- @suggestions = suggestions
- end
+ def initialize(input:, value:, suggestions:)
+ super()
+ @input = input
+ @value = value
+ @suggestions = suggestions
+ end
- def suggestions_for_stimulus
- @suggestions_for_stimulus ||= @suggestions.to_json
- end
+ def suggestions_for_stimulus
+ @suggestions_for_stimulus ||= @suggestions.to_json
+ end
- def suggestions_list_component
- @suggestions_list_component ||= Primer::Alpha::ActionList.new(
- role: :list,
- scheme: :inset,
- ml: 0,
- "data-pattern-input-target": "suggestions"
- )
- end
+ def suggestions_list_component
+ @suggestions_list_component ||= Primer::Alpha::ActionList.new(
+ role: :list,
+ scheme: :inset,
+ ml: 0,
+ "data-pattern-input-target": "suggestions"
+ )
end
end
end
diff --git a/app/components/work_packages/types/pattern_input.sass b/app/components/work_package_types/pattern_input.sass
similarity index 100%
rename from app/components/work_packages/types/pattern_input.sass
rename to app/components/work_package_types/pattern_input.sass
diff --git a/app/components/work_packages/types/settings_component.html.erb b/app/components/work_package_types/settings_component.html.erb
similarity index 95%
rename from app/components/work_packages/types/settings_component.html.erb
rename to app/components/work_package_types/settings_component.html.erb
index bae0a30f35e..f8a398fc0b9 100644
--- a/app/components/work_packages/types/settings_component.html.erb
+++ b/app/components/work_package_types/settings_component.html.erb
@@ -29,6 +29,6 @@ See COPYRIGHT and LICENSE files for more details.
<%=
settings_primer_form_with(**form_options) do |f|
- render(WorkPackages::Types::SettingsForm.new(f))
+ render(WorkPackageTypes::SettingsForm.new(f))
end
%>
diff --git a/app/components/work_packages/types/settings_component.rb b/app/components/work_package_types/settings_component.rb
similarity index 62%
rename from app/components/work_packages/types/settings_component.rb
rename to app/components/work_package_types/settings_component.rb
index 926039e5bc8..a92c9fc00f8 100644
--- a/app/components/work_packages/types/settings_component.rb
+++ b/app/components/work_package_types/settings_component.rb
@@ -28,37 +28,35 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module WorkPackages
- module Types
- class SettingsComponent < ApplicationComponent
- include ApplicationHelper
- include OpPrimer::ComponentHelpers
- include OpTurbo::Streamable
-
- def initialize(model, copy_workflow_from: nil, **)
- @copy_workflow_from = copy_workflow_from
- super(model, **)
- end
+module WorkPackageTypes
+ class SettingsComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(model, copy_workflow_from: nil, **)
+ @copy_workflow_from = copy_workflow_from
+ super(model, **)
+ end
- def form_options
- if model.new_record?
- create_form_options
- else
- update_form_options
- end
+ def form_options
+ if model.new_record?
+ create_form_options
+ else
+ update_form_options
end
+ end
- private
+ private
- attr_reader :copy_workflow_from
+ attr_reader :copy_workflow_from
- def create_form_options
- { url: types_path, method: :post, model:, copy_workflow_from: }
- end
+ def create_form_options
+ { url: types_path, method: :post, model:, copy_workflow_from: }
+ end
- def update_form_options
- { url: update_tab_type_path(id: model.id, tab: :settings), method: :patch, model: }
- end
+ def update_form_options
+ { url: update_tab_type_path(id: model.id, tab: :settings), method: :patch, model: }
end
end
end
diff --git a/app/components/work_packages/types/subject_configuration_component.html.erb b/app/components/work_package_types/subject_configuration_component.html.erb
similarity index 95%
rename from app/components/work_packages/types/subject_configuration_component.html.erb
rename to app/components/work_package_types/subject_configuration_component.html.erb
index 4c1550b80f4..6fff3153b36 100644
--- a/app/components/work_packages/types/subject_configuration_component.html.erb
+++ b/app/components/work_package_types/subject_configuration_component.html.erb
@@ -33,6 +33,6 @@ See COPYRIGHT and LICENSE files for more details.
<%=
settings_primer_form_with(**form_options) do |f|
- render(WorkPackages::Types::SubjectConfigurationForm.new(f))
+ render(WorkPackageTypes::SubjectConfigurationForm.new(f))
end
%>
diff --git a/app/components/work_package_types/subject_configuration_component.rb b/app/components/work_package_types/subject_configuration_component.rb
new file mode 100644
index 00000000000..a407c2b5b94
--- /dev/null
+++ b/app/components/work_package_types/subject_configuration_component.rb
@@ -0,0 +1,110 @@
+# 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 WorkPackageTypes
+ class SubjectConfigurationComponent < ApplicationComponent
+ include ApplicationHelper
+ include OpPrimer::ComponentHelpers
+ include OpTurbo::Streamable
+
+ def initialize(model, subject_configuration_form_data: nil, **)
+ @subject_configuration_form_data = subject_configuration_form_data
+ super(model, **)
+ end
+
+ def form_options
+ form_model = subject_form_object
+
+ {
+ url: subject_configuration_type_path(id: model.id),
+ method: :put,
+ model: form_model,
+ data: {
+ controller: "admin--subject-configuration",
+ admin__subject_configuration_hide_pattern_input_value: form_model.subject_configuration == :manual
+ }
+ }
+ end
+
+ private
+
+ def subject_form_object
+ values = subject_configuration_form_values
+
+ Forms::SubjectConfigurationFormModel.new(
+ subject_configuration: values[:subject_configuration],
+ pattern: values[:pattern],
+ suggestions: sort_attributes(supported_attributes),
+ validation_errors: model.errors
+ )
+ end
+
+ def supported_attributes
+ attribute_tokens = Patterns::TokenPropertyMapper.new.tokens_for_type(model)
+
+ result = {
+ work_package: {
+ title: I18n.t("types.edit.subject_configuration.token.context.work_package"),
+ tokens: []
+ },
+ parent: {
+ title: I18n.t("types.edit.subject_configuration.token.context.parent"),
+ tokens: []
+ },
+ project: {
+ title: I18n.t("types.edit.subject_configuration.token.context.project"),
+ tokens: []
+ }
+ }
+
+ attribute_tokens.each_with_object(result) do |token, obj|
+ token_hash = { key: token.key, label: token.label, label_with_context: token.label_with_context }
+ obj[token.context][:tokens] << token_hash
+ end
+ end
+
+ def sort_attributes(attributes)
+ attributes.each_value { |group| group[:tokens] = group[:tokens].sort_by { |a| a[:label] } }
+ attributes
+ end
+
+ def subject_configuration_form_values
+ if @subject_configuration_form_data.present?
+ @subject_configuration_form_data
+ else
+ persisted_subject_pattern = model.patterns.subject || Pattern.new(blueprint: "", enabled: false)
+ subject_configuration = persisted_subject_pattern.enabled ? :generated : :manual
+ pattern = persisted_subject_pattern.blueprint
+
+ { subject_configuration:, pattern: }
+ end
+ end
+ end
+end
diff --git a/app/components/work_packages/types/subject_configuration_component.rb b/app/components/work_packages/types/subject_configuration_component.rb
deleted file mode 100644
index 7d2ecbb53fe..00000000000
--- a/app/components/work_packages/types/subject_configuration_component.rb
+++ /dev/null
@@ -1,112 +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 WorkPackages
- module Types
- class SubjectConfigurationComponent < ApplicationComponent
- include ApplicationHelper
- include OpPrimer::ComponentHelpers
- include OpTurbo::Streamable
-
- def initialize(model, subject_configuration_form_data: nil, **)
- @subject_configuration_form_data = subject_configuration_form_data
- super(model, **)
- end
-
- def form_options
- form_model = subject_form_object
-
- {
- url: subject_configuration_type_path(id: model.id),
- method: :put,
- model: form_model,
- data: {
- controller: "admin--subject-configuration",
- admin__subject_configuration_hide_pattern_input_value: form_model.subject_configuration == :manual
- }
- }
- end
-
- private
-
- def subject_form_object
- values = subject_configuration_form_values
-
- ::Types::Forms::SubjectConfigurationFormModel.new(
- subject_configuration: values[:subject_configuration],
- pattern: values[:pattern],
- suggestions: sort_attributes(supported_attributes),
- validation_errors: model.errors
- )
- end
-
- def supported_attributes
- attribute_tokens = ::Types::Patterns::TokenPropertyMapper.new.tokens_for_type(model)
-
- result = {
- work_package: {
- title: I18n.t("types.edit.subject_configuration.token.context.work_package"),
- tokens: []
- },
- parent: {
- title: I18n.t("types.edit.subject_configuration.token.context.parent"),
- tokens: []
- },
- project: {
- title: I18n.t("types.edit.subject_configuration.token.context.project"),
- tokens: []
- }
- }
-
- attribute_tokens.each_with_object(result) do |token, obj|
- token_hash = { key: token.key, label: token.label, label_with_context: token.label_with_context }
- obj[token.context][:tokens] << token_hash
- end
- end
-
- def sort_attributes(attributes)
- attributes.each_value { |group| group[:tokens] = group[:tokens].sort_by { |a| a[:label] } }
- attributes
- end
-
- def subject_configuration_form_values
- if @subject_configuration_form_data.present?
- @subject_configuration_form_data
- else
- persisted_subject_pattern = model.patterns.subject || ::Types::Pattern.new(blueprint: "", enabled: false)
- subject_configuration = persisted_subject_pattern.enabled ? :generated : :manual
- pattern = persisted_subject_pattern.blueprint
-
- { subject_configuration:, pattern: }
- end
- end
- end
- end
-end
diff --git a/app/contracts/types/base_contract.rb b/app/contracts/types/base_contract.rb
index 8a1920e93e0..af2fbd1b02e 100644
--- a/app/contracts/types/base_contract.rb
+++ b/app/contracts/types/base_contract.rb
@@ -112,9 +112,9 @@ module Types
return if blueprint.nil?
valid_tokens = flat_valid_token_list
- invalid_tokens = blueprint.scan(PatternResolver::TOKEN_REGEX)
+ invalid_tokens = blueprint.scan(::WorkPackageTypes::PatternResolver::TOKEN_REGEX)
.reduce([]) do |acc, match|
- token = Patterns::PatternToken.build(match).key
+ token = ::WorkPackageTypes::Patterns::PatternToken.build(match).key
valid_tokens.include?(token) ? acc : acc << token
end
@@ -123,6 +123,6 @@ module Types
end
end
- def flat_valid_token_list = Patterns::TokenPropertyMapper.new.tokens_for_type(model).map(&:key)
+ def flat_valid_token_list = ::WorkPackageTypes::Patterns::TokenPropertyMapper.new.tokens_for_type(model).map(&:key)
end
end
diff --git a/app/contracts/work_package_types/update_subject_pattern_contract.rb b/app/contracts/work_package_types/update_subject_pattern_contract.rb
index 521fc240957..00d7a6a6fb5 100644
--- a/app/contracts/work_package_types/update_subject_pattern_contract.rb
+++ b/app/contracts/work_package_types/update_subject_pattern_contract.rb
@@ -41,9 +41,9 @@ module WorkPackageTypes
return if blueprint.nil?
valid_tokens = flat_valid_token_list
- invalid_tokens = blueprint.scan(Types::PatternResolver::TOKEN_REGEX)
+ invalid_tokens = blueprint.scan(WorkPackageTypes::PatternResolver::TOKEN_REGEX)
.reduce([]) do |acc, match|
- token = Types::Patterns::PatternToken.build(match).key
+ token = WorkPackageTypes::Patterns::PatternToken.build(match).key
valid_tokens.include?(token) ? acc : acc << token
end
@@ -52,6 +52,6 @@ module WorkPackageTypes
end
end
- def flat_valid_token_list = Types::Patterns::TokenPropertyMapper.new.tokens_for_type(model).map(&:key)
+ def flat_valid_token_list = WorkPackageTypes::Patterns::TokenPropertyMapper.new.tokens_for_type(model).map(&:key)
end
end
diff --git a/app/controllers/work_package_types/pdf_export_template_controller.rb b/app/controllers/work_package_types/pdf_export_template_controller.rb
new file mode 100644
index 00000000000..f4870cff90f
--- /dev/null
+++ b/app/controllers/work_package_types/pdf_export_template_controller.rb
@@ -0,0 +1,91 @@
+# 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 WorkPackageTypes
+ class PdfExportTemplateController < ApplicationController
+ include OpTurbo::ComponentStream
+ before_action :require_admin
+ before_action :find_type, only: %i[toggle drop enable_all disable_all]
+ before_action :find_template, only: %i[toggle drop]
+
+ def enable_all
+ return render_404_turbo_stream if @type.nil?
+
+ @type.pdf_export_templates.enable_all
+ @type.save!
+ respond_section_with_turbo_streams
+ end
+
+ def disable_all
+ return render_404_turbo_stream if @type.nil?
+
+ @type.pdf_export_templates.disable_all
+ @type.save!
+ respond_section_with_turbo_streams
+ end
+
+ def toggle
+ return render_404_turbo_stream if @template.nil?
+
+ @type.pdf_export_templates.toggle(@template.id)
+ @type.save!
+ respond_with_turbo_streams
+ end
+
+ def drop
+ return render_404_turbo_stream if @template.nil?
+
+ @type.pdf_export_templates.move(@template.id, params[:position].to_i - 1) # drop index starts at 1
+ @type.save!
+ respond_to_with_turbo_streams
+ end
+
+ protected
+
+ def respond_section_with_turbo_streams
+ replace_via_turbo_stream(
+ component: ::WorkPackageTypes::ExportTemplateListComponent.new(type: @type)
+ )
+ respond_to_with_turbo_streams
+ end
+
+ def render_404_turbo_stream
+ render_error_flash_message_via_turbo_stream(message: t(:notice_file_not_found))
+ end
+
+ def find_type
+ @type = ::Type.find(params[:type_id])
+ end
+
+ def find_template
+ @template = @type.pdf_export_templates.find(params[:id])
+ end
+ end
+end
diff --git a/app/controllers/work_package_types/subject_configuration_tab_controller.rb b/app/controllers/work_package_types/subject_configuration_tab_controller.rb
new file mode 100644
index 00000000000..c2c269f82e4
--- /dev/null
+++ b/app/controllers/work_package_types/subject_configuration_tab_controller.rb
@@ -0,0 +1,91 @@
+# 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 WorkPackageTypes
+ class SubjectConfigurationTabController < ApplicationController
+ layout "admin"
+
+ before_action :require_admin
+ before_action :find_type, only: %i[update_subject_configuration]
+
+ def update_subject_configuration
+ form_params = params.expect(
+ work_package_types_forms_subject_configuration_form_model: %i[subject_configuration pattern]
+ ).to_h
+
+ UpdateTypeService.new(@type, current_user)
+ .call({ patterns: pattern_collection_update(form_params) }) do |call|
+ call.on_success do
+ redirect_to tab_path, notice: I18n.t(:notice_successful_update)
+ end
+
+ call.on_failure do
+ params[:tab] = "subject_configuration"
+ render template: "types/edit", status: :unprocessable_entity
+ end
+ end
+ end
+
+ private
+
+ def find_type
+ @type = ::Type.find(params[:id])
+ end
+
+ def tab_path = edit_tab_type_path(id: @type.id, tab: :subject_configuration)
+
+ def pattern_collection_update(form_params)
+ patterns = @type.patterns.to_h.symbolize_keys
+
+ subject_pattern =
+ case form_params
+ in { subject_configuration: "generated", pattern: String => blueprint }
+ { subject: { blueprint:, enabled: true } }
+ in { subject_configuration: "manual", pattern: String => blueprint }
+ if blueprint.empty?
+ # Submitting the form with an empty blueprint and manual subject configuration will
+ # remove the subject pattern from the collection
+ nil
+ else
+ { subject: { blueprint:, enabled: false } }
+ end
+ else
+ nil
+ end
+
+ if subject_pattern.nil?
+ patterns.delete(:subject)
+ patterns
+ else
+ patterns.merge(subject_pattern)
+ end
+ end
+ end
+end
diff --git a/app/controllers/work_packages/types/pdf_export_template_controller.rb b/app/controllers/work_packages/types/pdf_export_template_controller.rb
deleted file mode 100644
index f39133f8456..00000000000
--- a/app/controllers/work_packages/types/pdf_export_template_controller.rb
+++ /dev/null
@@ -1,93 +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 WorkPackages
- module Types
- class PdfExportTemplateController < ApplicationController
- include OpTurbo::ComponentStream
- before_action :require_admin
- before_action :find_type, only: %i[toggle drop enable_all disable_all]
- before_action :find_template, only: %i[toggle drop]
-
- def enable_all
- return render_404_turbo_stream if @type.nil?
-
- @type.pdf_export_templates.enable_all
- @type.save!
- respond_section_with_turbo_streams
- end
-
- def disable_all
- return render_404_turbo_stream if @type.nil?
-
- @type.pdf_export_templates.disable_all
- @type.save!
- respond_section_with_turbo_streams
- end
-
- def toggle
- return render_404_turbo_stream if @template.nil?
-
- @type.pdf_export_templates.toggle(@template.id)
- @type.save!
- respond_with_turbo_streams
- end
-
- def drop
- return render_404_turbo_stream if @template.nil?
-
- @type.pdf_export_templates.move(@template.id, params[:position].to_i - 1) # drop index starts at 1
- @type.save!
- respond_to_with_turbo_streams
- end
-
- protected
-
- def respond_section_with_turbo_streams
- replace_via_turbo_stream(
- component: ::WorkPackages::Types::ExportTemplateListComponent.new(type: @type)
- )
- respond_to_with_turbo_streams
- end
-
- def render_404_turbo_stream
- render_error_flash_message_via_turbo_stream(message: t(:notice_file_not_found))
- end
-
- def find_type
- @type = ::Type.find(params[:type_id])
- end
-
- def find_template
- @template = @type.pdf_export_templates.find(params[:id])
- end
- end
- end
-end
diff --git a/app/controllers/work_packages/types/subject_configuration_tab_controller.rb b/app/controllers/work_packages/types/subject_configuration_tab_controller.rb
deleted file mode 100644
index f39837b1c27..00000000000
--- a/app/controllers/work_packages/types/subject_configuration_tab_controller.rb
+++ /dev/null
@@ -1,93 +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 WorkPackages
- module Types
- class SubjectConfigurationTabController < ApplicationController
- layout "admin"
-
- before_action :require_admin
- before_action :find_type, only: %i[update_subject_configuration]
-
- def update_subject_configuration
- form_params = params.require(:types_forms_subject_configuration_form_model)
- .permit(:subject_configuration, :pattern)
- .to_h
-
- UpdateTypeService.new(@type, current_user)
- .call({ patterns: pattern_collection_update(form_params) }) do |call|
- call.on_success do
- redirect_to tab_path, notice: I18n.t(:notice_successful_update)
- end
-
- call.on_failure do
- params[:tab] = "subject_configuration"
- render template: "types/edit", status: :unprocessable_entity
- end
- end
- end
-
- private
-
- def find_type
- @type = ::Type.find(params[:id])
- end
-
- def tab_path = edit_tab_type_path(id: @type.id, tab: :subject_configuration)
-
- def pattern_collection_update(form_params)
- patterns = @type.patterns.to_h.symbolize_keys
-
- subject_pattern =
- case form_params
- in { subject_configuration: "generated", pattern: String => blueprint }
- { subject: { blueprint:, enabled: true } }
- in { subject_configuration: "manual", pattern: String => blueprint }
- if blueprint.empty?
- # Submitting the form with an empty blueprint and manual subject configuration will
- # remove the subject pattern from the collection
- nil
- else
- { subject: { blueprint:, enabled: false } }
- end
- else
- nil
- end
-
- if subject_pattern.nil?
- patterns.delete(:subject)
- patterns
- else
- patterns.merge(subject_pattern)
- end
- end
- end
- end
-end
diff --git a/app/forms/work_package_types/settings_form.rb b/app/forms/work_package_types/settings_form.rb
new file mode 100644
index 00000000000..7ae69313334
--- /dev/null
+++ b/app/forms/work_package_types/settings_form.rb
@@ -0,0 +1,117 @@
+# 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 WorkPackageTypes
+ class SettingsForm < ApplicationForm
+ form do |settings_form|
+ settings_form.text_field(
+ name: :name,
+ label: label(:name),
+ placeholder: I18n.t(:label_name),
+ required: true,
+ disabled: model.is_standard?
+ )
+
+ settings_form.color_select_list(
+ name: :color_id,
+ label: Color.model_name.human,
+ input_width: :medium,
+ caption: I18n.t("types.edit.settings.type_color_text")
+ )
+
+ if show_work_flow_copy?
+ settings_form.select_list(
+ name: :copy_workflow_from,
+ input_width: :medium,
+ label: I18n.t(:label_copy_workflow_from),
+ include_blank: true,
+ validation_message: validation_message_for(:copy_workflow_from)
+ ) do |other_types|
+ work_package_types.each do |type|
+ other_types.option(
+ value: type.id,
+ label: type.name,
+ selected: type.id == prefilled_copy_workflow_from
+ )
+ end
+ end
+ end
+
+ settings_form.rich_text_area(
+ name: :description,
+ label: label(:description),
+ rich_text_options: { showAttachments: false }
+ )
+
+ settings_form.check_box(
+ name: :is_milestone,
+ label: label(:is_milestone)
+ )
+
+ settings_form.check_box(
+ name: :is_in_roadmap,
+ label: label(:is_in_roadmap)
+ )
+
+ settings_form.check_box(
+ name: :is_default,
+ label: label(:is_default)
+ )
+
+ settings_form.submit(
+ name: :submit,
+ label: I18n.t(:button_save),
+ scheme: :primary
+ )
+ end
+
+ private
+
+ def label(attribute)
+ model.class.human_attribute_name(attribute)
+ end
+
+ def show_work_flow_copy?
+ model.new_record?
+ end
+
+ def work_package_types
+ Type.all
+ end
+
+ def validation_message_for(attribute)
+ model.errors.messages_for(attribute).to_sentence.presence
+ end
+
+ def prefilled_copy_workflow_from
+ @builder.options[:copy_workflow_from]
+ end
+ end
+end
diff --git a/app/forms/work_package_types/subject_configuration_form.rb b/app/forms/work_package_types/subject_configuration_form.rb
new file mode 100644
index 00000000000..046c0d39524
--- /dev/null
+++ b/app/forms/work_package_types/subject_configuration_form.rb
@@ -0,0 +1,99 @@
+# 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 WorkPackageTypes
+ class SubjectConfigurationForm < ApplicationForm
+ form do |subject_form|
+ subject_form.radio_button_group(name: :subject_configuration) do |group|
+ group.radio_button(
+ value: :manual,
+ checked: subject_configuration_manual?,
+ 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: :generated,
+ checked: !subject_configuration_manual?,
+ label: I18n.t("types.edit.subject_configuration.automatically_generated_subjects.label"),
+ caption: I18n.t("types.edit.subject_configuration.automatically_generated_subjects.caption"),
+ disabled: !enterprise? && subject_configuration_manual?,
+ data: { action: "admin--subject-configuration#showPatternInput" }
+ )
+ end
+
+ subject_form.group(data: { "admin--subject-configuration-target": "patternInput" }) do |toggleable_group|
+ toggleable_group.pattern_input(
+ name: :pattern,
+ value: model.pattern,
+ suggestions: model.suggestions,
+ label: I18n.t("types.edit.subject_configuration.pattern.label"),
+ caption: pattern_input_caption,
+ required: true,
+ validation_message: validation_message_for(:patterns)
+ )
+ end
+
+ subject_form.submit(
+ name: :submit,
+ label: I18n.t(:button_save),
+ scheme: :primary
+ )
+ end
+
+ private
+
+ def subject_configuration_manual?
+ model.subject_configuration == :manual
+ end
+
+ def enterprise?
+ EnterpriseToken.allows_to?(:work_package_subject_generation)
+ end
+
+ def validation_message_for(attribute)
+ model.validation_errors.messages_for(attribute).to_sentence.presence
+ end
+
+ def pattern_input_caption
+ I18n.t(
+ "types.edit.subject_configuration.pattern.caption_with_supported_attributes_link",
+ link: make_link(
+ ::OpenProject::Static::Links.url_for(:enterprise_features, :work_package_subject_generation),
+ I18n.t("types.edit.subject_configuration.pattern.supported_attributes_link")
+ )
+ ).html_safe
+ end
+
+ def make_link(href, link_text)
+ render(Primer::Beta::Link.new(href:, target: "_blank")) { link_text }
+ end
+ end
+end
diff --git a/app/forms/work_packages/types/settings_form.rb b/app/forms/work_packages/types/settings_form.rb
deleted file mode 100644
index a6ab9bba160..00000000000
--- a/app/forms/work_packages/types/settings_form.rb
+++ /dev/null
@@ -1,119 +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 WorkPackages
- module Types
- class SettingsForm < ApplicationForm
- form do |settings_form|
- settings_form.text_field(
- name: :name,
- label: label(:name),
- placeholder: I18n.t(:label_name),
- required: true,
- disabled: model.is_standard?
- )
-
- settings_form.color_select_list(
- name: :color_id,
- label: Color.model_name.human,
- input_width: :medium,
- caption: I18n.t("types.edit.settings.type_color_text")
- )
-
- if show_work_flow_copy?
- settings_form.select_list(
- name: :copy_workflow_from,
- input_width: :medium,
- label: I18n.t(:label_copy_workflow_from),
- include_blank: true,
- validation_message: validation_message_for(:copy_workflow_from)
- ) do |other_types|
- work_package_types.each do |type|
- other_types.option(
- value: type.id,
- label: type.name,
- selected: type.id == prefilled_copy_workflow_from
- )
- end
- end
- end
-
- settings_form.rich_text_area(
- name: :description,
- label: label(:description),
- rich_text_options: { showAttachments: false }
- )
-
- settings_form.check_box(
- name: :is_milestone,
- label: label(:is_milestone)
- )
-
- settings_form.check_box(
- name: :is_in_roadmap,
- label: label(:is_in_roadmap)
- )
-
- settings_form.check_box(
- name: :is_default,
- label: label(:is_default)
- )
-
- settings_form.submit(
- name: :submit,
- label: I18n.t(:button_save),
- scheme: :primary
- )
- end
-
- private
-
- def label(attribute)
- model.class.human_attribute_name(attribute)
- end
-
- def show_work_flow_copy?
- model.new_record?
- end
-
- def work_package_types
- Type.all
- end
-
- def validation_message_for(attribute)
- model.errors.messages_for(attribute).to_sentence.presence
- end
-
- def prefilled_copy_workflow_from
- @builder.options[:copy_workflow_from]
- 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
deleted file mode 100644
index 9a6897c98e6..00000000000
--- a/app/forms/work_packages/types/subject_configuration_form.rb
+++ /dev/null
@@ -1,101 +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 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: subject_configuration_manual?,
- 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: :generated,
- checked: !subject_configuration_manual?,
- label: I18n.t("types.edit.subject_configuration.automatically_generated_subjects.label"),
- caption: I18n.t("types.edit.subject_configuration.automatically_generated_subjects.caption"),
- disabled: !enterprise? && subject_configuration_manual?,
- data: { action: "admin--subject-configuration#showPatternInput" }
- )
- end
-
- subject_form.group(data: { "admin--subject-configuration-target": "patternInput" }) do |toggleable_group|
- toggleable_group.pattern_input(
- name: :pattern,
- value: model.pattern,
- suggestions: model.suggestions,
- label: I18n.t("types.edit.subject_configuration.pattern.label"),
- caption: pattern_input_caption,
- required: true,
- validation_message: validation_message_for(:patterns)
- )
- end
-
- subject_form.submit(
- name: :submit,
- label: I18n.t(:button_save),
- scheme: :primary
- )
- end
-
- private
-
- def subject_configuration_manual?
- model.subject_configuration == :manual
- end
-
- def enterprise?
- EnterpriseToken.allows_to?(:work_package_subject_generation)
- end
-
- def validation_message_for(attribute)
- model.validation_errors.messages_for(attribute).to_sentence.presence
- end
-
- def pattern_input_caption
- I18n.t(
- "types.edit.subject_configuration.pattern.caption_with_supported_attributes_link",
- link: make_link(
- ::OpenProject::Static::Links.url_for(:enterprise_features, :work_package_subject_generation),
- I18n.t("types.edit.subject_configuration.pattern.supported_attributes_link")
- )
- ).html_safe
- end
-
- def make_link(href, link_text)
- render(Primer::Beta::Link.new(href:, target: "_blank")) { link_text }
- end
- end
- end
-end
diff --git a/app/helpers/types_helper.rb b/app/helpers/types_helper.rb
index 84855815ddc..5ab45d2d8ee 100644
--- a/app/helpers/types_helper.rb
+++ b/app/helpers/types_helper.rb
@@ -36,7 +36,7 @@ module ::TypesHelper
name: "settings",
path: edit_tab_type_path(id: @type.id, tab: :settings),
label: I18n.t("types.edit.settings.tab"),
- view_component: WorkPackages::Types::SettingsComponent
+ view_component: WorkPackageTypes::SettingsComponent
},
{
name: "form_configuration",
@@ -48,7 +48,7 @@ module ::TypesHelper
name: "subject_configuration",
path: edit_tab_type_path(id: @type.id, tab: :subject_configuration),
label: I18n.t("types.edit.subject_configuration.tab"),
- view_component: WorkPackages::Types::SubjectConfigurationComponent,
+ view_component: WorkPackageTypes::SubjectConfigurationComponent,
enterprise_feature: :work_package_subject_generation
},
{
@@ -61,7 +61,7 @@ module ::TypesHelper
name: "export_configuration",
path: edit_tab_type_path(id: @type.id, tab: :export_configuration),
label: I18n.t("types.edit.export_configuration.tab"),
- view_component: WorkPackages::Types::ExportConfigurationComponent
+ view_component: WorkPackageTypes::ExportConfigurationComponent
}
]
end
diff --git a/app/models/type.rb b/app/models/type.rb
index 2bbd17aefda..a3b26c86b54 100644
--- a/app/models/type.rb
+++ b/app/models/type.rb
@@ -36,7 +36,7 @@ class Type < ApplicationRecord
include ::Scopes::Scoped
- attribute :patterns, Types::Patterns::CollectionType.new
+ attribute :patterns, WorkPackageTypes::Patterns::CollectionType.new
store_attribute :pdf_export_templates_config, :export_templates_disabled, :json
store_attribute :pdf_export_templates_config, :export_templates_order, :json
diff --git a/app/models/types/forms/subject_configuration_form_model.rb b/app/models/work_package_types/forms/subject_configuration_form_model.rb
similarity index 98%
rename from app/models/types/forms/subject_configuration_form_model.rb
rename to app/models/work_package_types/forms/subject_configuration_form_model.rb
index 3a8a53cff94..878d78962dd 100644
--- a/app/models/types/forms/subject_configuration_form_model.rb
+++ b/app/models/work_package_types/forms/subject_configuration_form_model.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Forms
class SubjectConfigurationFormModel
extend ActiveModel::Naming
diff --git a/app/models/types/pattern.rb b/app/models/work_package_types/pattern.rb
similarity index 98%
rename from app/models/types/pattern.rb
rename to app/models/work_package_types/pattern.rb
index 8efe8eac5c4..3e10276075b 100644
--- a/app/models/types/pattern.rb
+++ b/app/models/work_package_types/pattern.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
Pattern = Data.define(:blueprint, :enabled) do
def enabled? = !!enabled
diff --git a/app/models/types/pattern_resolver.rb b/app/models/work_package_types/pattern_resolver.rb
similarity index 99%
rename from app/models/types/pattern_resolver.rb
rename to app/models/work_package_types/pattern_resolver.rb
index 084a42ecbbb..1fb0dcde3bb 100644
--- a/app/models/types/pattern_resolver.rb
+++ b/app/models/work_package_types/pattern_resolver.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
class PatternResolver
TOKEN_REGEX = /{{[0-9A-Za-z_]+}}/
ATTRIBUTE_PLACEHOLDER = "N/A"
diff --git a/app/models/types/patterns/attribute_token.rb b/app/models/work_package_types/patterns/attribute_token.rb
similarity index 97%
rename from app/models/types/patterns/attribute_token.rb
rename to app/models/work_package_types/patterns/attribute_token.rb
index 2b5f5859c5e..27a8125adb9 100644
--- a/app/models/types/patterns/attribute_token.rb
+++ b/app/models/work_package_types/patterns/attribute_token.rb
@@ -23,12 +23,12 @@
#
# 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.
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Patterns
AttributeToken = Data.define(:key, :label_fn, :resolve_fn) do
def label_with_context
diff --git a/app/models/types/patterns/collection.rb b/app/models/work_package_types/patterns/collection.rb
similarity index 98%
rename from app/models/types/patterns/collection.rb
rename to app/models/work_package_types/patterns/collection.rb
index c779f1278fa..54951129ae1 100644
--- a/app/models/types/patterns/collection.rb
+++ b/app/models/work_package_types/patterns/collection.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Patterns
Collection = Data.define(:patterns) do
extend Dry::Monads[:result]
diff --git a/app/models/types/patterns/collection_contract.rb b/app/models/work_package_types/patterns/collection_contract.rb
similarity index 98%
rename from app/models/types/patterns/collection_contract.rb
rename to app/models/work_package_types/patterns/collection_contract.rb
index 74f06b8a2da..c518694360b 100644
--- a/app/models/types/patterns/collection_contract.rb
+++ b/app/models/work_package_types/patterns/collection_contract.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Patterns
class CollectionContract < Dry::Validation::Contract
config.messages.backend = :i18n
diff --git a/app/models/types/patterns/collection_type.rb b/app/models/work_package_types/patterns/collection_type.rb
similarity index 98%
rename from app/models/types/patterns/collection_type.rb
rename to app/models/work_package_types/patterns/collection_type.rb
index f7c84b23416..c7a4b2f4250 100644
--- a/app/models/types/patterns/collection_type.rb
+++ b/app/models/work_package_types/patterns/collection_type.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Patterns
class CollectionType < ActiveModel::Type::Value
def assert_valid_value(value)
diff --git a/app/models/types/patterns/pattern_token.rb b/app/models/work_package_types/patterns/pattern_token.rb
similarity index 98%
rename from app/models/types/patterns/pattern_token.rb
rename to app/models/work_package_types/patterns/pattern_token.rb
index 04abe5016e4..ad2b449f791 100644
--- a/app/models/types/patterns/pattern_token.rb
+++ b/app/models/work_package_types/patterns/pattern_token.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Patterns
PatternToken = Data.define(:pattern, :key) do
private_class_method :new
diff --git a/app/models/types/patterns/token_property_mapper.rb b/app/models/work_package_types/patterns/token_property_mapper.rb
similarity index 99%
rename from app/models/types/patterns/token_property_mapper.rb
rename to app/models/work_package_types/patterns/token_property_mapper.rb
index 780c7c29b98..c9391be3ad9 100644
--- a/app/models/types/patterns/token_property_mapper.rb
+++ b/app/models/work_package_types/patterns/token_property_mapper.rb
@@ -28,7 +28,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-module Types
+module WorkPackageTypes
module Patterns
class TokenPropertyMapper
# rubocop:disable Layout/LineLength
diff --git a/app/services/update_type_service.rb b/app/services/update_type_service.rb
index d41b417f9ac..3d3ca1aa14a 100644
--- a/app/services/update_type_service.rb
+++ b/app/services/update_type_service.rb
@@ -63,7 +63,7 @@ class UpdateTypeService < BaseTypeService
end
def set_patterns(patterns)
- Types::Patterns::Collection
+ WorkPackageTypes::Patterns::Collection
.build(patterns:)
.either(
->(collection) { type.patterns = collection },
diff --git a/app/services/work_package_types/set_attributes_service.rb b/app/services/work_package_types/set_attributes_service.rb
index 2b658ffb80c..f9b7abed268 100644
--- a/app/services/work_package_types/set_attributes_service.rb
+++ b/app/services/work_package_types/set_attributes_service.rb
@@ -65,7 +65,7 @@ module WorkPackageTypes
return unless params.key?(:patterns)
return if params.key?(:patterns) && params[:patterns].blank?
- result = Types::Patterns::CollectionContract.new.call(params[:patterns])
+ result = WorkPackageTypes::Patterns::CollectionContract.new.call(params[:patterns])
if result.failure?
@param_validations.update({ patterns: validation_failure_to_message(result).join(", ") })
end
diff --git a/app/views/types/new.html.erb b/app/views/types/new.html.erb
index 899c3b45861..23af62c8b5a 100644
--- a/app/views/types/new.html.erb
+++ b/app/views/types/new.html.erb
@@ -43,5 +43,5 @@ See COPYRIGHT and LICENSE files for more details.
<%=
copy_workflow_from = maybe_integer(params.dig(:type, :copy_workflow_from)).value_or(nil)
- render WorkPackages::Types::SettingsComponent.new(@type, copy_workflow_from:)
+ render WorkPackageTypes::SettingsComponent.new(@type, copy_workflow_from:)
%>
diff --git a/config/routes.rb b/config/routes.rb
index edf55acfa57..41a3cbaabe2 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -144,12 +144,12 @@ Rails.application.routes.draw do
get "edit/:tab" => "types#edit", as: "edit_tab"
match "update/:tab" => "types#update", as: "update_tab", via: %i[post patch]
put :subject_configuration,
- controller: "work_packages/types/subject_configuration_tab",
+ controller: "work_package_types/subject_configuration_tab",
action: "update_subject_configuration"
end
resources :pdf_export_template, only: %i[],
- controller: "work_packages/types/pdf_export_template",
+ controller: "work_package_types/pdf_export_template",
path: "pdf_export_template" do
member do
post :toggle
diff --git a/lib/primer/open_project/forms/dsl/pattern_input.rb b/lib/primer/open_project/forms/dsl/pattern_input.rb
index 31388419be1..62037b627b5 100644
--- a/lib/primer/open_project/forms/dsl/pattern_input.rb
+++ b/lib/primer/open_project/forms/dsl/pattern_input.rb
@@ -45,7 +45,7 @@ module Primer
end
def to_component
- WorkPackages::Types::PatternInput.new(input: self, value:, suggestions:)
+ WorkPackageTypes::PatternInput.new(input: self, value:, suggestions:)
end
def type
diff --git a/lookbook/docs/patterns/17-settings-pages.md.erb b/lookbook/docs/patterns/17-settings-pages.md.erb
index 47c8c12dd62..b08286a198d 100644
--- a/lookbook/docs/patterns/17-settings-pages.md.erb
+++ b/lookbook/docs/patterns/17-settings-pages.md.erb
@@ -10,7 +10,7 @@ way, the rendered form is wrapped into a container with `680px` max-width.
```erb
<%%=
settings_primer_form_with(**form_options) do |f|
- render(WorkPackages::Types::SettingsForm.new(f))
+ render(WorkPackageTypes::SettingsForm.new(f))
end %>
```
diff --git a/spec/components/work_packages/types/subject_configuration_component_spec.rb b/spec/components/work_package_types/subject_configuration_component_spec.rb
similarity index 91%
rename from spec/components/work_packages/types/subject_configuration_component_spec.rb
rename to spec/components/work_package_types/subject_configuration_component_spec.rb
index 532bd803d3a..56578de9c21 100644
--- a/spec/components/work_packages/types/subject_configuration_component_spec.rb
+++ b/spec/components/work_package_types/subject_configuration_component_spec.rb
@@ -30,7 +30,7 @@
require "rails_helper"
-RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :component do
+RSpec.describe WorkPackageTypes::SubjectConfigurationComponent, type: :component do
let(:type) { create(:type) }
let(:subject_configuration_form_data) { nil }
@@ -68,8 +68,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
it "must have generated option checked and pattern input filled" do
expect(page.find("input[type=radio][value=generated]")).to be_checked
- expect(page.find("input[type=hidden][id=types_forms_subject_configuration_form_model_pattern]", visible: false).value)
- .to eq("Created by {{assignee}}")
+ expect(page.find(hidden_input_field_selector, visible: false).value).to eq("Created by {{assignee}}")
end
end
end
@@ -98,8 +97,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
it "must have generated option checked and pattern input filled" do
expect(page.find("input[type=radio][value=generated]")).to be_checked
- expect(page.find("input[type=hidden][id=types_forms_subject_configuration_form_model_pattern]", visible: false).value)
- .to eq("Created by {{assignee}}")
+ expect(page.find(hidden_input_field_selector, visible: false).value).to eq("Created by {{assignee}}")
end
end
end
@@ -136,4 +134,10 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationComponent, type: :compon
end
end
end
+
+ private
+
+ def hidden_input_field_selector
+ "input[type=hidden][id=work_package_types_forms_subject_configuration_form_model_pattern]"
+ end
end
diff --git a/spec/contracts/types/base_contract_spec.rb b/spec/contracts/types/base_contract_spec.rb
index ec76e81524b..7c40efc395f 100644
--- a/spec/contracts/types/base_contract_spec.rb
+++ b/spec/contracts/types/base_contract_spec.rb
@@ -38,15 +38,15 @@ RSpec.describe Types::BaseContract do
describe "#validation" do
context "if subject generation patterns contains invalid tokens" do
- let(:valid_tokens) { [Types::Patterns::AttributeToken.new(:assignee, nil, nil)] }
+ let(:valid_tokens) { [WorkPackageTypes::Patterns::AttributeToken.new(:assignee, nil, nil)] }
let(:work_package_type) do
Type.new(patterns: { subject: { blueprint: "Vacation {{vaders_toy}}", enabled: true } })
end
before do
- token_mapper_double = instance_double(Types::Patterns::TokenPropertyMapper)
+ token_mapper_double = instance_double(WorkPackageTypes::Patterns::TokenPropertyMapper)
allow(token_mapper_double).to receive(:tokens_for_type).and_return(valid_tokens)
- allow(Types::Patterns::TokenPropertyMapper).to receive(:new).and_return(token_mapper_double)
+ allow(WorkPackageTypes::Patterns::TokenPropertyMapper).to receive(:new).and_return(token_mapper_double)
end
it "is invalid" do
diff --git a/spec/controllers/work_packages/types/pdf_export_template_controller_spec.rb b/spec/controllers/work_package_types/pdf_export_template_controller_spec.rb
similarity index 98%
rename from spec/controllers/work_packages/types/pdf_export_template_controller_spec.rb
rename to spec/controllers/work_package_types/pdf_export_template_controller_spec.rb
index 900079822ca..b3c846a33e8 100644
--- a/spec/controllers/work_packages/types/pdf_export_template_controller_spec.rb
+++ b/spec/controllers/work_package_types/pdf_export_template_controller_spec.rb
@@ -31,7 +31,7 @@
require "spec_helper"
-RSpec.describe WorkPackages::Types::PdfExportTemplateController do
+RSpec.describe WorkPackageTypes::PdfExportTemplateController do
let(:user) { create(:admin) }
let(:wp_type) { create(:type) }
diff --git a/spec/controllers/work_packages/types/subject_configuration_tab_controller_spec.rb b/spec/controllers/work_package_types/subject_configuration_tab_controller_spec.rb
similarity index 96%
rename from spec/controllers/work_packages/types/subject_configuration_tab_controller_spec.rb
rename to spec/controllers/work_package_types/subject_configuration_tab_controller_spec.rb
index 76c6aeb92b4..8cade82168b 100644
--- a/spec/controllers/work_packages/types/subject_configuration_tab_controller_spec.rb
+++ b/spec/controllers/work_package_types/subject_configuration_tab_controller_spec.rb
@@ -31,7 +31,7 @@
require "spec_helper"
-RSpec.describe WorkPackages::Types::SubjectConfigurationTabController do
+RSpec.describe WorkPackageTypes::SubjectConfigurationTabController do
let(:user) { create(:admin) }
let(:wp_type) { create(:type) }
@@ -67,7 +67,7 @@ RSpec.describe WorkPackages::Types::SubjectConfigurationTabController do
put :update_subject_configuration,
params: {
id: wp_type.id,
- types_forms_subject_configuration_form_model: form_data
+ work_package_types_forms_subject_configuration_form_model: form_data
}
end
diff --git a/spec/models/type_spec.rb b/spec/models/type_spec.rb
index dc010a922ac..14e464cc7fc 100644
--- a/spec/models/type_spec.rb
+++ b/spec/models/type_spec.rb
@@ -132,7 +132,7 @@ RSpec.describe Type do
it "returns an empty collection when no patterns are defined" do
type = create(:type)
- expect(type.patterns).to eq(Types::Patterns::Collection.empty)
+ expect(type.patterns).to eq(WorkPackageTypes::Patterns::Collection.empty)
end
it "returns a PatternCollection" do
@@ -140,9 +140,9 @@ RSpec.describe Type do
subject: { blueprint: "{{work_package:custom_field_123}} - {{project:custom_field_321}}", enabled: true }
})
- expect(type.patterns).to be_a(Types::Patterns::Collection)
+ expect(type.patterns).to be_a(WorkPackageTypes::Patterns::Collection)
expect(type.patterns.subject)
- .to eq(Types::Pattern.new("{{work_package:custom_field_123}} - {{project:custom_field_321}}", true))
+ .to eq(WorkPackageTypes::Pattern.new("{{work_package:custom_field_123}} - {{project:custom_field_321}}", true))
end
end
@@ -150,7 +150,7 @@ RSpec.describe Type do
subject(:type) { build(:type) }
it "assigns a patterns collection as-is" do
- collection = Types::Patterns::Collection.build(patterns: {
+ collection = WorkPackageTypes::Patterns::Collection.build(patterns: {
subject: { blueprint: "some_string", enabled: false }
}).value!
@@ -164,7 +164,7 @@ RSpec.describe Type do
it "defaults to an empty collection" do
type.patterns = 4
- expect(type.patterns).to eq(Types::Patterns::Collection.empty)
+ expect(type.patterns).to eq(WorkPackageTypes::Patterns::Collection.empty)
expect { type.save! }.not_to raise_error
end
end
@@ -173,8 +173,8 @@ RSpec.describe Type do
it "converts the incoming hash into a PatternCollection" do
type.patterns = { subject: { blueprint: "some_string", enabled: false } }
- expect(type.patterns).to be_a(Types::Patterns::Collection)
- expect(type.patterns.subject).to be_a(Types::Pattern)
+ expect(type.patterns).to be_a(WorkPackageTypes::Patterns::Collection)
+ expect(type.patterns.subject).to be_a(WorkPackageTypes::Pattern)
expect { type.save! }.not_to raise_error
end
diff --git a/spec/models/types/pattern_resolver_spec.rb b/spec/models/work_package_types/pattern_resolver_spec.rb
similarity index 98%
rename from spec/models/types/pattern_resolver_spec.rb
rename to spec/models/work_package_types/pattern_resolver_spec.rb
index bcd550a7034..9c94b737a26 100644
--- a/spec/models/types/pattern_resolver_spec.rb
+++ b/spec/models/work_package_types/pattern_resolver_spec.rb
@@ -30,7 +30,7 @@
require "spec_helper"
-RSpec.describe Types::PatternResolver do
+RSpec.describe WorkPackageTypes::PatternResolver do
let(:subject_pattern) { "ID Please: {{id}}" }
shared_let(:work_package) { create(:work_package) }
diff --git a/spec/models/types/patterns/token_property_mapper_spec.rb b/spec/models/work_package_types/patterns/token_property_mapper_spec.rb
similarity index 97%
rename from spec/models/types/patterns/token_property_mapper_spec.rb
rename to spec/models/work_package_types/patterns/token_property_mapper_spec.rb
index 200df7572b2..995fa744e49 100644
--- a/spec/models/types/patterns/token_property_mapper_spec.rb
+++ b/spec/models/work_package_types/patterns/token_property_mapper_spec.rb
@@ -30,7 +30,7 @@
require "spec_helper"
-RSpec.describe Types::Patterns::TokenPropertyMapper do
+RSpec.describe WorkPackageTypes::Patterns::TokenPropertyMapper do
shared_let(:responsible) { create(:user, firstname: "Responsible") }
shared_let(:assignee) { create(:user, firstname: "Assignee") }
shared_let(:version) { create(:version) }
@@ -128,7 +128,7 @@ RSpec.describe Types::Patterns::TokenPropertyMapper do
cf = string_custom_field
tokens = described_class.new.tokens_for_type(work_package.type)
- expect(tokens.first).to be_a(Types::Patterns::AttributeToken)
+ expect(tokens.first).to be_a(WorkPackageTypes::Patterns::AttributeToken)
expect(detect(tokens, :project_status).label).to eq(Project.human_attribute_name(:status_code))
expect(detect(tokens, :"custom_field_#{cf.id}").label).to eq(cf.name)
end
diff --git a/spec/services/work_package_types/set_attributes_service_spec.rb b/spec/services/work_package_types/set_attributes_service_spec.rb
index 68537c94f98..e30e15fe45d 100644
--- a/spec/services/work_package_types/set_attributes_service_spec.rb
+++ b/spec/services/work_package_types/set_attributes_service_spec.rb
@@ -86,7 +86,7 @@ module WorkPackageTypes
it "sets the patterns to an empty collection" do
service.call(params)
- expect(model.patterns).to eq(Types::Patterns::Collection.empty)
+ expect(model.patterns).to eq(WorkPackageTypes::Patterns::Collection.empty)
end
end