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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Simplify the project acts as customizable patch, load all the field data in one query and sort it via sql instead of ruby.
Dombi Attilab5866a620af0
diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb b/app/components/projects/settings/project_custom_field_sections/show_component.html.erbindex 78f28405247..3571e88b9e7 100644--- a/app/components/projects/settings/project_custom_field_sections/show_component.html.erb+++ b/app/components/projects/settings/project_custom_field_sections/show_component.html.erb@@ -59,7 +59,7 @@render(Primer::Beta::Text.new(color: :subtle)) { t("settings.project_attributes.label_no_project_custom_fields") }endelse- sorted_project_custom_fields.each do |project_custom_field|+ @project_custom_fields.each do |project_custom_field|component.with_row(data: { 'projects--settings--project-custom-fields-mapping-filter-target': 'searchItem' }) dorender(Projects::Settings::ProjectCustomFieldSections::CustomFieldRowComponent.new(project: @project,diff --git a/app/components/projects/settings/project_custom_field_sections/show_component.rb b/app/components/projects/settings/project_custom_field_sections/show_component.rbindex beb8c9dee73..a1ef3289deb 100644--- a/app/components/projects/settings/project_custom_field_sections/show_component.rb+++ b/app/components/projects/settings/project_custom_field_sections/show_component.rb@@ -53,10 +53,6 @@ module Projectsdef wrapper_uniq_by@project_custom_field_section.idend-- def sorted_project_custom_fields- @project_custom_fields.sort_by { |pcf| pcf.position_in_custom_field_section }- endendendenddiff --git a/app/controllers/projects/settings/project_custom_fields_controller.rb b/app/controllers/projects/settings/project_custom_fields_controller.rbindex caec7e41d2b..b4c3e7527a0 100644--- a/app/controllers/projects/settings/project_custom_fields_controller.rb+++ b/app/controllers/projects/settings/project_custom_fields_controller.rb@@ -89,7 +89,7 @@ class Projects::Settings::ProjectCustomFieldsController < Projects::SettingsCont.includes(:custom_fields).merge(ProjectCustomField.visible).group(:id, "custom_fields.id")- .order(:position)+ .order(:position, :position_in_custom_field_section)@project_custom_field_project_mappings = ProjectCustomFieldProjectMapping.where(project_id: @project.id)diff --git a/app/forms/projects/custom_fields/form.rb b/app/forms/projects/custom_fields/form.rbindex 5d4c00542f7..3a7ba99892b 100644--- a/app/forms/projects/custom_fields/form.rb+++ b/app/forms/projects/custom_fields/form.rb@@ -28,7 +28,7 @@module Projects::CustomFieldsclass Form < ApplicationFormform do |custom_fields_form|- sorted_custom_fields.each do |custom_field|+ custom_fields.each do |custom_field|custom_fields_form.fields_for(:custom_field_values) do |builder|custom_field_input(builder, custom_field)end@@ -50,16 +50,17 @@ module Projects::CustomFieldsprivate- def sorted_custom_fields- return @custom_fields if @custom_fields.present?-- @custom_fields = if @custom_field.present?- [@custom_field]- elsif @custom_field_section.present?- @project.sorted_available_custom_fields_by_section(@custom_field_section)- else- @project.sorted_available_custom_fields- end+ def custom_fields+ @custom_fields ||=+ if @custom_field.present?+ [@custom_field]+ elsif @custom_field_section.present?+ @project+ .available_custom_fields+ .where(custom_field_section: @custom_field_section)+ else+ @project.available_custom_fields+ endenddef custom_field_input(builder, custom_field)diff --git a/app/models/projects/acts_as_customizable_patches.rb b/app/models/projects/acts_as_customizable_patches.rbindex cde7c21725f..41441fe6cc7 100644--- a/app/models/projects/acts_as_customizable_patches.rb+++ b/app/models/projects/acts_as_customizable_patches.rb@@ -120,6 +120,7 @@ module Projects::ActsAsCustomizablePatchescustom_fields = ProjectCustomField.visible.includes(:project_custom_field_section)+ .order("custom_field_sections.position", :position_in_custom_field_section)# available_custom_fields is called from within the acts_as_customizable module# we don't want to adjust these calls, but need a way to query the available custom fields on a global level in some cases@@ -137,22 +138,6 @@ module Projects::ActsAsCustomizablePatchescustom_fieldsend- def available_project_custom_fields_grouped_by_section- sorted_available_custom_fields- .group_by(&:custom_field_section_id)- end-- def sorted_available_custom_fields- available_custom_fields- .sort_by { |pcf| [pcf.project_custom_field_section&.position, pcf.position_in_custom_field_section] }- end-- def sorted_available_custom_fields_by_section(section)- available_custom_fields- .where(custom_field_section_id: section.id)- .sort_by(&:position_in_custom_field_section)- end-def validate_custom_values# validate custom values only of a specified section# instead of validating ALL custom values like done in acts_as_customizablediff --git a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erbindex 57be4beb911..b42340b6e21 100644--- a/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sections/show_component.html.erb@@ -25,7 +25,7 @@endend- sorted_project_custom_fields.each do |project_custom_field|+ @project_custom_fields.each do |project_custom_field|details_container.with_row(mb: 3) dorender(ProjectCustomFields::Sections::ProjectCustomFields::ShowComponent.new(project_custom_field: project_custom_field,diff --git a/modules/overviews/app/components/project_custom_fields/sections/show_component.rb b/modules/overviews/app/components/project_custom_fields/sections/show_component.rbindex e3352cad3e9..bce4f3bf995 100644--- a/modules/overviews/app/components/project_custom_fields/sections/show_component.rb+++ b/modules/overviews/app/components/project_custom_fields/sections/show_component.rb@@ -60,10 +60,6 @@ module ProjectCustomFields.to_aend- def sorted_project_custom_fields- @project_custom_fields.sort_by { |pcf| pcf.position_in_custom_field_section }- end-def get_eager_loaded_project_custom_field_values_for(custom_field_id)@eager_loaded_project_custom_field_values.select { |pcfv| pcfv.custom_field_id == custom_field_id }enddiff --git a/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erb b/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erbindex de5672b3b16..6f8f746c66e 100644--- a/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erb+++ b/modules/overviews/app/components/project_custom_fields/sidebar_component.html.erb@@ -2,11 +2,11 @@component_wrapper doif available_project_custom_fields_grouped_by_section.any?flex_layout(data: { qa_selector: "project-custom-fields-sidebar-async-content" }) do |sections_container|- available_project_custom_fields_grouped_by_section.each do |project_custom_field_section_id, project_custom_fields|+ available_project_custom_fields_grouped_by_section.each do |project_custom_field_section, project_custom_fields|sections_container.with_row(mb: 3) dorender(ProjectCustomFields::Sections::ShowComponent.new(project: @project,- project_custom_field_section: get_eager_loaded_project_custom_field_section(project_custom_field_section_id),+ project_custom_field_section: ,project_custom_fields: project_custom_fields))enddiff --git a/modules/overviews/app/components/project_custom_fields/sidebar_component.rb b/modules/overviews/app/components/project_custom_fields/sidebar_component.rbindex 2b6731ca762..73350be6ecd 100644--- a/modules/overviews/app/components/project_custom_fields/sidebar_component.rb+++ b/modules/overviews/app/components/project_custom_fields/sidebar_component.rb@@ -32,21 +32,16 @@ module ProjectCustomFieldsinclude OpPrimer::ComponentHelpersinclude OpTurbo::Streamable- def initialize(project:, eager_loaded_project_custom_field_sections:)+ def initialize(project:)super@project = project- @eager_loaded_project_custom_field_sections = eager_loaded_project_custom_field_sectionsendprivate-- def get_eager_loaded_project_custom_field_section(project_custom_field_section_id)- @eager_loaded_project_custom_field_sections.find { |pcfs| pcfs.id == project_custom_field_section_id }- end-def available_project_custom_fields_grouped_by_section- @available_project_custom_fields_grouped_by_section ||= @project.available_project_custom_fields_grouped_by_section+ @available_project_custom_fields_grouped_by_section ||=+ @project.available_custom_fields.group_by(&:project_custom_field_section)endendenddiff --git a/modules/overviews/app/controllers/overviews/overviews_controller.rb b/modules/overviews/app/controllers/overviews/overviews_controller.rbindex 9bd492f62c7..386b86988a5 100644--- a/modules/overviews/app/controllers/overviews/overviews_controller.rb+++ b/modules/overviews/app/controllers/overviews/overviews_controller.rb@@ -8,8 +8,6 @@ module ::Overviewsmenu_item :overviewdef project_custom_fields_sidebar- @eager_loaded_project_custom_field_sections = eager_loaded_project_custom_field_sections-render :project_custom_fields_sidebar, layout: falseend@@ -70,15 +68,8 @@ module ::Overviewsdef update_sidebar_componentupdate_via_turbo_stream(- component: ProjectCustomFields::SidebarComponent.new(- project: @project,- eager_loaded_project_custom_field_sections:- )+ component: ProjectCustomFields::SidebarComponent.new(project: @project))end-- def eager_loaded_project_custom_field_sections- ProjectCustomFieldSection.all.to_a- endendenddiff --git a/modules/overviews/app/views/overviews/overviews/project_custom_fields_sidebar.html.erb b/modules/overviews/app/views/overviews/overviews/project_custom_fields_sidebar.html.erbindex f156037180d..33deb6558c3 100644--- a/modules/overviews/app/views/overviews/overviews/project_custom_fields_sidebar.html.erb+++ b/modules/overviews/app/views/overviews/overviews/project_custom_fields_sidebar.html.erb@@ -27,8 +27,5 @@ See COPYRIGHT and LICENSE files for more details.++#%><%= content_tag("turbo-frame", id: "project-custom-fields-sidebar") do %>- <%= render(ProjectCustomFields::SidebarComponent.new(- project: @project,- eager_loaded_project_custom_field_sections: @eager_loaded_project_custom_field_sections- )) %>+ <%= render(ProjectCustomFields::SidebarComponent.new(project: @project)) %><% end %>\ No newline at end of file