Skip to content

Commit

Permalink
WIP proposal on operator for any with descendants
Browse files Browse the repository at this point in the history
  • Loading branch information
brunopagno committed Nov 25, 2024
1 parent 00cb106 commit c45ea51
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/models/queries/filters/strategies/hierarchy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@ module Queries
module Filters
module Strategies
class Hierarchy < BaseStrategy
self.supported_operators = %w[= !]
self.supported_operators = %w[= ! eq_with_descendants]
self.default_operator = "="

def operator_map
super.dup.tap do |super_value|
super_value["eq_with_descendants"] = ::Queries::Operators::CustomFields::Hierarchies::EqualsWithDescendants
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) 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 Operators
module CustomFields
module Hierarchies
class EqualsWithDescendants < Base
label "equals_with_descendants"
set_symbol "eq_with_descendants"

def self.sql_for_field(values, db_table, db_field)
items = CustomField::Hierarchy::Item.find(values)

actual_values = items.map do |item|
item.self_and_descendants.collect(&:id)
end.flatten.uniq

Equals.sql_for_field(actual_values, db_table, db_field)
end
end
end
end
end
end
1 change: 1 addition & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,7 @@ en:
label_environment: "Environment"
label_estimates_and_progress: "Estimates and progress"
label_equals: "is"
label_equals_with_descendants: "is any with descendants"
label_everywhere: "everywhere"
label_example: "Example"
label_experimental: "Experimental"
Expand Down

0 comments on commit c45ea51

Please sign in to comment.