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

Add default `sort_criteria` to queries created for Boards

Aaron Contreras3d41e525f6d9
diff --git a/modules/boards/app/services/boards/base_create_service.rb b/modules/boards/app/services/boards/base_create_service.rb
index b45da131e9f..d3538f94906 100644
--- a/modules/boards/app/services/boards/base_create_service.rb
+++ b/modules/boards/app/services/boards/base_create_service.rb
@@ -46,11 +46,17 @@ module Boards
end
def create_query_params(params)
+ default_create_query_params(params).merge(
+ name: query_name,
+ filters: query_filters
+ )
+ end
+
+ def default_create_query_params(params)
{
project: params[:project],
- name: query_name,
public: true,
- filters: query_filters
+ sort_criteria: query_sort_criteria
}
end
@@ -62,6 +68,10 @@ module Boards
raise 'Define the query filters'
end
+ def query_sort_criteria
+ [[:manual_sorting, 'asc'], [:id, 'asc']]
+ end
+
def options_for_grid(params)
{}.tap do |options|
if params[:attribute] == 'basic'
diff --git a/modules/boards/app/services/boards/version_board_create_service.rb b/modules/boards/app/services/boards/version_board_create_service.rb
index 9a43bb32170..bbbafc4b758 100644
--- a/modules/boards/app/services/boards/version_board_create_service.rb
+++ b/modules/boards/app/services/boards/version_board_create_service.rb
@@ -26,12 +26,10 @@ module Boards
end
def create_query_params(params, version)
- {
- project: params[:project],
+ default_create_query_params(params).merge(
name: query_name(version),
- public: true,
filters: query_filters(version)
- }
+ )
end
def query_name(version)
diff --git a/modules/boards/spec/services/base_create_service_shared_examples.rb b/modules/boards/spec/services/base_create_service_shared_examples.rb
new file mode 100644
index 00000000000..6e9b91e57af
--- /dev/null
+++ b/modules/boards/spec/services/base_create_service_shared_examples.rb
@@ -0,0 +1,41 @@
+# frozen_string_literal: true
+
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2023 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.
+#++
+
+require 'spec_helper'
+
+RSpec.shared_examples 'sets the appropriate sort_criteria on each query' do
+ it '', :aggregate_failures do
+ subject
+
+ queries_sort_criteria = queries.map(&:sort_criteria)
+
+ expect(queries_sort_criteria).to all eq([%w[manual_sorting asc], %w[id asc]])
+ end
+end
diff --git a/modules/boards/spec/services/basic_board_create_service_spec.rb b/modules/boards/spec/services/basic_board_create_service_spec.rb
index 087ae119b52..5666e0a6f45 100644
--- a/modules/boards/spec/services/basic_board_create_service_spec.rb
+++ b/modules/boards/spec/services/basic_board_create_service_spec.rb
@@ -29,6 +29,7 @@
#++
require 'spec_helper'
+require_relative 'base_create_service_shared_examples'
RSpec.describe Boards::BasicBoardCreateService do
shared_let(:project) { create(:project) }
@@ -79,6 +80,8 @@ RSpec.describe Boards::BasicBoardCreateService do
expect(query_filter).to have_key :manual_sort
expect(query_filter).to eq widget_filter
end
+
+ it_behaves_like 'sets the appropriate sort_criteria on each query'
end
end
end
diff --git a/modules/boards/spec/services/status_board_create_service_spec.rb b/modules/boards/spec/services/status_board_create_service_spec.rb
index b478a864456..b585eb6dca9 100644
--- a/modules/boards/spec/services/status_board_create_service_spec.rb
+++ b/modules/boards/spec/services/status_board_create_service_spec.rb
@@ -29,6 +29,7 @@
#++
require 'spec_helper'
+require_relative 'base_create_service_shared_examples'
RSpec.describe Boards::StatusBoardCreateService do
shared_let(:project) { create(:project) }
@@ -79,6 +80,8 @@ RSpec.describe Boards::StatusBoardCreateService do
expect(query_filter).to match_array(widget_filter)
end
+
+ it_behaves_like 'sets the appropriate sort_criteria on each query'
end
end
end
diff --git a/modules/boards/spec/services/version_board_create_service_spec.rb b/modules/boards/spec/services/version_board_create_service_spec.rb
index 402a4ac4ede..16aeb767dc3 100644
--- a/modules/boards/spec/services/version_board_create_service_spec.rb
+++ b/modules/boards/spec/services/version_board_create_service_spec.rb
@@ -29,6 +29,7 @@
#++
require 'spec_helper'
+require_relative 'base_create_service_shared_examples'
RSpec.describe Boards::VersionBoardCreateService do
shared_let(:project) { create(:project) }
@@ -79,6 +80,8 @@ RSpec.describe Boards::VersionBoardCreateService do
expect(queries_filters).to match_array(widgets_filters)
end
+
+ it_behaves_like 'sets the appropriate sort_criteria on each query'
end
end
end