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
fix ordering of multi value list custom fields
Ivan Kuchin749020dfa9e3
diff --git a/app/models/custom_field/order_statements.rb b/app/models/custom_field/order_statements.rbindex 0802bdccced..013e57d6701 100644--- a/app/models/custom_field/order_statements.rb+++ b/app/models/custom_field/order_statements.rb@@ -33,11 +33,7 @@ module CustomField::OrderStatementsdef order_statementscase field_formatwhen "list"- if multi_value?- [select_custom_values_joined_options_as_group]- else- [select_custom_option_position]- end+ [select_custom_option_position]when "string", "date", "bool", "link"[coalesce_select_custom_value_as_string]when "int", "float"@@ -93,14 +89,28 @@ module CustomField::OrderStatementsenddef select_custom_option_position- <<-SQL- (SELECT co_sort.position FROM #{CustomOption.quoted_table_name} co_sort- LEFT JOIN #{CustomValue.quoted_table_name} cv_sort- ON co_sort.id = CAST(cv_sort.value AS decimal(60,3))- WHERE #{cv_sort_only_custom_field_condition_sql}- LIMIT 1- )- SQL+ if multi_value?+ <<-SQL.squish+ (+ SELECT array_agg(co_sort.position ORDER BY co_sort.position)+ FROM #{CustomOption.quoted_table_name} co_sort+ LEFT JOIN #{CustomValue.quoted_table_name} cv_sort+ ON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::bigint+ WHERE #{cv_sort_only_custom_field_condition_sql}+ )+ SQL+ else+ <<-SQL.squish+ (+ SELECT co_sort.position+ FROM #{CustomOption.quoted_table_name} co_sort+ LEFT JOIN #{CustomValue.quoted_table_name} cv_sort+ ON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::bigint+ WHERE #{cv_sort_only_custom_field_condition_sql}+ LIMIT 1+ )+ SQL+ endenddef select_custom_values_as_group@@ -111,15 +121,6 @@ module CustomField::OrderStatementsSQLend- def select_custom_values_joined_options_as_group- <<-SQL- COALESCE((SELECT string_agg(co_sort.value, '.' ORDER BY co_sort.position ASC) FROM #{CustomOption.quoted_table_name} co_sort- LEFT JOIN #{CustomValue.quoted_table_name} cv_sort- ON cv_sort.value IS NOT NULL AND co_sort.id = cv_sort.value::numeric- WHERE #{cv_sort_only_custom_field_condition_sql}), '')- SQL- end-def select_custom_value_as_decimal<<-SQL(SELECT CAST(cv_sort.value AS decimal(60,3)) FROM #{CustomValue.quoted_table_name} cv_sortdiff --git a/spec/models/queries/projects/project_query_custom_field_order_spec.rb b/spec/models/queries/projects/project_query_custom_field_order_spec.rbindex ce7b5eba85d..5ac0873957c 100644--- a/spec/models/queries/projects/project_query_custom_field_order_spec.rb+++ b/spec/models/queries/projects/project_query_custom_field_order_spec.rb@@ -193,15 +193,14 @@ RSpec.describe ProjectQuery, "order using CustomFieldOrder" dolet(:projects) do[- project_without_cf_value,- # TODO: sorting is done by values sorted by position and joined by `.`, why?- project_with_cf_value(*id_by_value.fetch_values("100")), # => 100- project_with_cf_value(*id_by_value.fetch_values("20", "100")), # => 100.20- project_with_cf_value(*id_by_value.fetch_values("3", "100")), # => 100.3- project_with_cf_value(*id_by_value.fetch_values("100", "3", "20")), # => 100.3.20- project_with_cf_value(*id_by_value.fetch_values("20")), # => 20- project_with_cf_value(*id_by_value.fetch_values("3")), # => 3- project_with_cf_value(*id_by_value.fetch_values("3", "20")) # => 3.20+ project_with_cf_value(*id_by_value.fetch_values("100")),+ project_with_cf_value(*id_by_value.fetch_values("3", "100")),+ project_with_cf_value(*id_by_value.fetch_values("100", "3", "20")),+ project_with_cf_value(*id_by_value.fetch_values("20", "100")),+ project_with_cf_value(*id_by_value.fetch_values("3")),+ project_with_cf_value(*id_by_value.fetch_values("3", "20")),+ project_with_cf_value(*id_by_value.fetch_values("20")),+ project_without_cf_value # TODO: decide on order of absent values]endenddiff --git a/spec/models/query/results_cf_sorting_integration_spec.rb b/spec/models/query/results_cf_sorting_integration_spec.rbindex 668cebcdcb7..93bfb74f138 100644--- a/spec/models/query/results_cf_sorting_integration_spec.rb+++ b/spec/models/query/results_cf_sorting_integration_spec.rb@@ -204,15 +204,14 @@ RSpec.describe Query::Results, "Sorting by custom field" dolet(:work_packages) do[- wp_without_cf_value,- # TODO: sorting is done by values sorted by position and joined by `.`, why?- wp_with_cf_value(id_by_value.fetch_values("100")), # => 100- wp_with_cf_value(id_by_value.fetch_values("20", "100")), # => 100.20- wp_with_cf_value(id_by_value.fetch_values("3", "100")), # => 100.3- wp_with_cf_value(id_by_value.fetch_values("100", "3", "20")), # => 100.3.20- wp_with_cf_value(id_by_value.fetch_values("20")), # => 20- wp_with_cf_value(id_by_value.fetch_values("3")), # => 3- wp_with_cf_value(id_by_value.fetch_values("3", "20")) # => 3.20+ wp_with_cf_value(id_by_value.fetch_values("100")),+ wp_with_cf_value(id_by_value.fetch_values("3", "100")),+ wp_with_cf_value(id_by_value.fetch_values("100", "3", "20")),+ wp_with_cf_value(id_by_value.fetch_values("20", "100")),+ wp_with_cf_value(id_by_value.fetch_values("3")),+ wp_with_cf_value(id_by_value.fetch_values("3", "20")),+ wp_with_cf_value(id_by_value.fetch_values("20")),+ wp_without_cf_value # TODO: decide on order of absent values]endend