Skip to content

Commit

Permalink
implemented support for negated group operators
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Koch committed May 22, 2017
1 parent a33f118 commit 0e6fa1a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/cells/criteria_operator/ui_component/group_cell.rb
Expand Up @@ -40,7 +40,7 @@ def caption
end

def empty?
!model.kind_of?(GroupOperator) || model.operand_collection.empty?
!@group.kind_of?(GroupOperator) || @group.operand_collection.empty?
end

def model_negated_group?
Expand Down
Expand Up @@ -59,11 +59,12 @@ def new_locator
end

def locate_sub_operator(operator, locator)
op = operator
op = get_negated_group_if_exist operator
locator.split(',').map(&:to_i).each do |pos|
# TODO: some kind of error handling beside cancelling?
return nil unless op.is_a? GroupOperator
op = op.operand_collection[pos]
op = get_negated_group_if_exist op
end
op
end
Expand All @@ -82,6 +83,14 @@ def remove_sub_operator(root_op, locator)
end
op.operand_collection.delete_at pos.to_i
end

def get_negated_group_if_exist(op)
if op.is_a?(UnaryOperator) && (op.operator_type == UnaryOperatorType::NOT)
op.operand
else
op
end
end
end
end
end
5 changes: 2 additions & 3 deletions test/dummy/app/controllers/dummy_controller.rb
@@ -1,9 +1,8 @@
class DummyController < ApplicationController
def show
#first_op = CriteriaOperator::UnaryOperator.new(CriteriaOperator::OperandValue.new(true), CriteriaOperator::UnaryOperatorType::NOT)
first_op = CriteriaOperator::GroupOperator.new [], CriteriaOperator::GroupOperatorType::AND
first_op = CriteriaOperator::UnaryOperator.new(CriteriaOperator::GroupOperator.new([], CriteriaOperator::GroupOperatorType::AND), CriteriaOperator::UnaryOperatorType::NOT)
second_op = CriteriaOperator::BinaryOperator.new(CriteriaOperator::OperandProperty.new("column xyz"), CriteriaOperator::OperandValue.new(42), CriteriaOperator::BinaryOperatorType::GREATER_OR_EQUAL)
@example_op = CriteriaOperator::GroupOperator.new [first_op, second_op], CriteriaOperator::GroupOperatorType::OR
@example_op = CriteriaOperator::UnaryOperator.new(CriteriaOperator::GroupOperator.new([first_op, second_op], CriteriaOperator::GroupOperatorType::OR), CriteriaOperator::UnaryOperatorType::NOT)
# @example_op = CriteriaOperator::GroupOperator.new [], CriteriaOperator::GroupOperatorType::OR
render
end
Expand Down

0 comments on commit 0e6fa1a

Please sign in to comment.