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
enable SortCriteria to handle sort bys Procs
ulferts125d51c2b8b9
diff --git a/app/models/queries/work_packages/columns/property_column.rb b/app/models/queries/work_packages/columns/property_column.rbindex 59087ba0994..f2ef20935df 100644--- a/app/models/queries/work_packages/columns/property_column.rb+++ b/app/models/queries/work_packages/columns/property_column.rb@@ -97,7 +97,7 @@ class Queries::WorkPackages::Columns::PropertyColumn < Queries::WorkPackages::Co},fixed_version: {association: 'fixed_version',- sortable: [->(table_name) { Versions::Scopes::OrderBySemverName.semver_sql(table_name) }, 'name'],+ sortable: [->(table_name = Version.table_name) { Versions::Scopes::OrderBySemverName.semver_sql(table_name) }, 'name'],default_order: 'ASC',null_handling: 'NULLS LAST',groupable: "#{WorkPackage.table_name}.fixed_version_id"diff --git a/app/models/query/sort_criteria.rb b/app/models/query/sort_criteria.rbindex 9f956fd87e0..f511527fe9b 100644--- a/app/models/query/sort_criteria.rb+++ b/app/models/query/sort_criteria.rb@@ -45,6 +45,7 @@ class ::Query::SortCriteria < ::SortHelper::SortCriteria@criteria.map { |attribute, order| [find_column(attribute), @available_criteria[attribute], order] }.reject { |column, criterion, _| column.nil? || criterion.nil? }+ .map { |column, criterion, order| [column, execute_criterion(criterion), order] }.map { |column, criterion, order| append_order(column, Array(criterion), order) }.compactend@@ -69,4 +70,14 @@ class ::Query::SortCriteria < ::SortHelper::SortCriteriaordered_criterionendend++ def execute_criterion(criteria)+ Array(criteria).map do |criterion|+ if criterion.respond_to?(:call)+ criterion.call+ else+ criterion+ end+ end+ endenddiff --git a/spec/models/query/sort_criteria_spec.rb b/spec/models/query/sort_criteria_spec.rbindex 594c8486b01..829211636ad 100644--- a/spec/models/query/sort_criteria_spec.rb+++ b/spec/models/query/sort_criteria_spec.rb@@ -28,10 +28,10 @@require 'spec_helper'-describe ::Query::SortCriteria, type: :model, with_mail: false do+describe ::Query::SortCriteria, type: :model dolet(:query) do- FactoryBot.build :query,- show_hierarchies: false+ FactoryBot.build_stubbed :query,+ show_hierarchies: falseendlet(:available_criteria) { query.sortable_key_by_column_name }@@ -76,9 +76,15 @@ describe ::Query::SortCriteria, type: :model, with_mail: false dolet(:sort_criteria) { [['fixed_version', 'desc'], ['start_date', 'asc']] }it 'adds the order handling' do- expect(subject.length).to eq 2+ expect(subject.length)+ .to eq 2++ sort_sql = <<~SQL+ array_remove(regexp_split_to_array(regexp_replace(substring(versions.name from '^[^a-zA-Z]+'), '\\D+', ' ', 'g'), ' '), '')::int[]+ SQL+expect(subject.first)- .to eq ['start_date DESC NULLS LAST', 'effective_date DESC NULLS LAST', 'name DESC NULLS LAST']+ .to eq ["#{sort_sql} DESC NULLS LAST", 'name DESC NULLS LAST']expect(subject.last).to eq ['work_packages.start_date NULLS LAST']endend