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
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.rbindex 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 Boardsenddef 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 Boardsraise '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.rbindex 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 Boardsenddef create_query_params(params, version)- {- project: params[:project],+ default_create_query_params(params).merge(name: query_name(version),- public: true,filters: query_filters(version)- }+ )enddef 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.rbnew file mode 100644index 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+enddiff --git a/modules/boards/spec/services/basic_board_create_service_spec.rb b/modules/boards/spec/services/basic_board_create_service_spec.rbindex 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 doshared_let(:project) { create(:project) }@@ -79,6 +80,8 @@ RSpec.describe Boards::BasicBoardCreateService doexpect(query_filter).to have_key :manual_sortexpect(query_filter).to eq widget_filterend++ it_behaves_like 'sets the appropriate sort_criteria on each query'endendenddiff --git a/modules/boards/spec/services/status_board_create_service_spec.rb b/modules/boards/spec/services/status_board_create_service_spec.rbindex 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 doshared_let(:project) { create(:project) }@@ -79,6 +80,8 @@ RSpec.describe Boards::StatusBoardCreateService doexpect(query_filter).to match_array(widget_filter)end++ it_behaves_like 'sets the appropriate sort_criteria on each query'endendenddiff --git a/modules/boards/spec/services/version_board_create_service_spec.rb b/modules/boards/spec/services/version_board_create_service_spec.rbindex 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 doshared_let(:project) { create(:project) }@@ -79,6 +80,8 @@ RSpec.describe Boards::VersionBoardCreateService doexpect(queries_filters).to match_array(widgets_filters)end++ it_behaves_like 'sets the appropriate sort_criteria on each query'endendend