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 an empty filter to fallback for typeahead

Oliver Günther1eaf8ed0fb31
diff --git a/app/models/queries/base_query.rb b/app/models/queries/base_query.rb
index 7e1401ca824..c0356cac90b 100644
--- a/app/models/queries/base_query.rb
+++ b/app/models/queries/base_query.rb
@@ -163,7 +163,7 @@ class Queries::BaseQuery
end
def context
- nil
+ self
end
def apply_filters(scope)
diff --git a/app/models/queries/filters/available_filters.rb b/app/models/queries/filters/available_filters.rb
index 68c17db1cc6..b4bc663efba 100644
--- a/app/models/queries/filters/available_filters.rb
+++ b/app/models/queries/filters/available_filters.rb
@@ -76,7 +76,12 @@ module Queries
private
def non_existing_filter(key)
- ::Queries::Filters::NotExistingFilter.create!(name: key)
+ case key.to_sym
+ when :typeahead
+ ::Queries::Filters::EmptyFilter.create!(name: key)
+ else
+ ::Queries::Filters::NotExistingFilter.create!(name: key)
+ end
end
def get_initialized_filter(key, no_memoization)
diff --git a/app/models/queries/filters/empty_filter.rb b/app/models/queries/filters/empty_filter.rb
new file mode 100644
index 00000000000..38877883592
--- /dev/null
+++ b/app/models/queries/filters/empty_filter.rb
@@ -0,0 +1,62 @@
+#-- 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.
+#++
+
+module Queries
+ module Filters
+ class EmptyFilter < Base
+ def available?
+ true
+ end
+
+ def type
+ :inexistent
+ end
+
+ def self.key
+ :empty
+ end
+
+ def human_name
+ name.to_s.presence || type
+ end
+
+ # deactivating superclass validation
+ def validate_inclusion_of_operator; end
+
+ def scope
+ context.default_scope
+ end
+
+ def attributes_hash
+ nil
+ end
+ end
+ end
+end