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 typeahead sort based on lft now
Oliver Günther82b8724bd913
diff --git a/app/models/queries/projects.rb b/app/models/queries/projects.rbindex 6e3bde4f5b4..cb61498d7d5 100644--- a/app/models/queries/projects.rb+++ b/app/models/queries/projects.rb@@ -56,5 +56,6 @@ module Queries::Projectsorder query, orders::CustomFieldOrderorder query, orders::ProjectStatusOrderorder query, orders::NameOrder+ order query, orders::TypeaheadOrderendenddiff --git a/app/models/queries/projects/orders/typeahead_order.rb b/app/models/queries/projects/orders/typeahead_order.rbnew file mode 100644index 00000000000..58551835d28--- /dev/null+++ b/app/models/queries/projects/orders/typeahead_order.rb@@ -0,0 +1,41 @@+#-- encoding: UTF-8++#-- copyright+# OpenProject is an open source project management software.+# Copyright (C) 2012-2021 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.+#++++class Queries::Projects::Orders::TypeaheadOrder < Queries::Projects::Orders::DefaultOrder+ self.model = Project++ def self.key+ :typeahead+ end++ def order+ model.order(lft: :asc, name: :asc)+ end+enddiff --git a/spec/models/queries/projects/project_query_spec.rb b/spec/models/queries/projects/project_query_spec.rbindex 4aa3f4f1b62..3d0f28117a9 100644--- a/spec/models/queries/projects/project_query_spec.rb+++ b/spec/models/queries/projects/project_query_spec.rb@@ -140,4 +140,17 @@ describe Queries::Projects::ProjectQuery, type: :model doendendend++ context 'with an order by typeahead asc' do+ before do+ instance.order(typeahead: :asc)+ end++ describe '#results' do+ it 'returns all visible projects ordered by lft asc' do+ expect(instance.results.to_sql)+ .to eql base_scope.except(:order).order(lft: :asc, name: :asc, id: :desc).to_sql+ end+ end+ endend