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

Make the typeahead project filter search for name only

Oliver Güntherd6737433c4d1
diff --git a/app/models/queries/projects.rb b/app/models/queries/projects.rb
index 93d7efd8a09..90e7b50748e 100644
--- a/app/models/queries/projects.rb
+++ b/app/models/queries/projects.rb
@@ -33,6 +33,7 @@ module Queries::Projects
filter Filters::ActiveFilter
filter Filters::TemplatedFilter
filter Filters::PublicFilter
+ filter Filters::NameFilter
filter Filters::NameAndIdentifierFilter
filter Filters::TypeaheadFilter
filter Filters::CustomFieldFilter
diff --git a/app/models/queries/projects/filters/name_filter.rb b/app/models/queries/projects/filters/name_filter.rb
new file mode 100644
index 00000000000..e3f4c750360
--- /dev/null
+++ b/app/models/queries/projects/filters/name_filter.rb
@@ -0,0 +1,65 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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::Filters::NameFilter < Queries::Projects::Filters::ProjectFilter
+ def type
+ :string
+ end
+
+ def where
+ case operator
+ when '='
+ ["LOWER(projects.name) IN (?)", sql_value]
+ when '!'
+ ["LOWER(projects.name) NOT IN (?)", sql_value]
+ when '~', '**'
+ ["LOWER(projects.name) LIKE ?", "%#{sql_value}%"]
+ when '!~'
+ ["LOWER(projects.name) NOT LIKE ?", "%#{sql_value}%"]
+ end
+ end
+
+ def human_name
+ I18n.t(:label_name)
+ end
+
+ def self.key
+ :name
+ end
+
+ private
+
+ def sql_value
+ case operator
+ when '=', '!'
+ values.map { |val| self.class.connection.quote_string(val.downcase) }.join(',')
+ when '**', '~', '!~'
+ values.first.downcase
+ end
+ end
+end
diff --git a/app/models/queries/projects/filters/typeahead_filter.rb b/app/models/queries/projects/filters/typeahead_filter.rb
index 9cdb42807f3..0d9eda9d75d 100644
--- a/app/models/queries/projects/filters/typeahead_filter.rb
+++ b/app/models/queries/projects/filters/typeahead_filter.rb
@@ -26,7 +26,7 @@
# See COPYRIGHT and LICENSE files for more details.
#++
-class Queries::Projects::Filters::TypeaheadFilter < Queries::Projects::Filters::NameAndIdentifierFilter
+class Queries::Projects::Filters::TypeaheadFilter < Queries::Projects::Filters::NameFilter
def self.key
:typeahead
end
diff --git a/spec/models/queries/projects/filters/name_filter_spec.rb b/spec/models/queries/projects/filters/name_filter_spec.rb
new file mode 100644
index 00000000000..8dd334b5e1d
--- /dev/null
+++ b/spec/models/queries/projects/filters/name_filter_spec.rb
@@ -0,0 +1,48 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2022 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'
+
+describe Queries::Projects::Filters::NameFilter, type: :model do
+ include_context 'filter tests'
+ let(:values) { ['A name'] }
+ let(:model) { Project }
+
+ it_behaves_like 'basic query filter' do
+ let(:class_key) { :name }
+ let(:human_name) { 'Name' }
+ let(:type) { :string }
+ let(:model) { Project }
+
+ describe '#allowed_values' do
+ it 'is nil' do
+ expect(instance.allowed_values).to be_nil
+ end
+ end
+ end
+end