From e808c62253235f4635de314dd1f42231dc608e62 Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 14 Jan 2017 12:26:13 +0000 Subject: Filtering out specific subprojects (using 'is not' operator) (#15773). Patch by Marius BALTEANU. git-svn-id: http://svn.redmine.org/redmine/trunk@16196 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/models/query.rb | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'app') diff --git a/app/models/query.rb b/app/models/query.rb index 1fe405deb..640db190d 100644 --- a/app/models/query.rb +++ b/app/models/query.rb @@ -269,7 +269,7 @@ class Query < ActiveRecord::Base :list => [ "=", "!" ], :list_status => [ "o", "=", "!", "c", "*" ], :list_optional => [ "=", "!", "!*", "*" ], - :list_subprojects => [ "*", "!*", "=" ], + :list_subprojects => [ "*", "!*", "=", "!" ], :date => [ "=", ">=", "<=", "><", "t+", ">t-", " [ "=", ">=", "<=", "><", ">t-", " [ "=", "~", "!", "!~", "!*", "*" ], @@ -756,12 +756,19 @@ class Query < ActiveRecord::Base def project_statement project_clauses = [] - if project && !project.descendants.active.empty? + active_subprojects_ids = [] + + active_subprojects_ids = project.descendants.active.map(&:id) if project + if active_subprojects_ids.any? if has_filter?("subproject_id") case operator_for("subproject_id") when '=' # include the selected subprojects - ids = [project.id] + values_for("subproject_id").each(&:to_i) + ids = [project.id] + values_for("subproject_id").map(&:to_i) + project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') + when '!' + # exclude the selected subprojects + ids = [project.id] + active_subprojects_ids - values_for("subproject_id").map(&:to_i) project_clauses << "#{Project.table_name}.id IN (%s)" % ids.join(',') when '!*' # main project only -- cgit v1.2.3