Skip to content

Commit

Permalink
criteria editor can display simple existing expression trees
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Koch committed May 22, 2017
1 parent 2716594 commit cd72339
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 12 deletions.
@@ -1,6 +1,6 @@
<div class="criteria_group_row" data-locator="<%= @locator %>" data-childcount="0">
<div class="criteria_group_row" data-locator="<%= @locator %>" data-childcount="<%= @group.operand_collection.count %>">
<button class="criteria_expression_options_button">...</button>
<span class="criteria_group_row_header"><%= test %></span>
<span class="criteria_group_row_header"><%= caption %></span>
<% if @allow_delete %>
<a href="#" class="criteria_group_delete">Delete</a>
<% end %>
Expand Down
35 changes: 33 additions & 2 deletions app/cells/criteria_operator/ui_component/criteria_editor_cell.rb
Expand Up @@ -11,22 +11,53 @@ def show
def group_row(options = {})
@allow_delete = options.has_key?(:allow_delete) ? options[:allow_delete] : true
@locator = options.has_key?(:locator) ? options[:locator] : ''
@group = 42
if model.kind_of? GroupOperator
@group = model
elsif model.kind_of?(UnaryOperator) && (model.operator_type == UnaryOperatorType::NOT) && model.operand.kind_of?(GroupOperator)
@group = model.operand
else
@group = nil
end
render
end

def expression_row(options = {})
@locator = options.has_key?(:locator) ? options[:locator] : ''
@expression = 42
if model.kind_of? BinaryOperator
@expression = model
else
@expression = nil
end
render
end

def choose_template(options = {})
if model.kind_of? BinaryOperator
expression_row options
else
group_row options
end
end

private

def test
"abcdefg " + model.inspect
end

def caption
if model.kind_of? GroupOperator
case model.operator_type
when GroupOperatorType::AND
'AND'
when GroupOperatorType::OR
'OR'
else
'Invalid Group Operator!'
end
end
end

def serialized_operator
YAML.dump(model) if model.is_a? BaseOperator
end
Expand Down
29 changes: 26 additions & 3 deletions app/cells/criteria_operator/ui_component/expression_cell.rb
Expand Up @@ -9,15 +9,38 @@ def show
private

def property_name
''
if model.kind_of?(BinaryOperator) && model.left_operand.kind_of?(OperandProperty)
model.left_operand.property_name
else
''
end
end

def value
''
if model.kind_of?(BinaryOperator) && model.right_operand.kind_of?(OperandValue)
model.right_operand.value
else
''
end
end

def operator
'equals'
if model.kind_of?(BinaryOperator)
case model.operator_type
when BinaryOperatorType::EQUAL
'equal to'
when BinaryOperatorType::NOT_EQUAL
'not equal to'
when BinaryOperatorType::GREATER
'greater than'
when BinaryOperatorType::GREATER_OR_EQUAL
'greater than or equal to'
when BinaryOperatorType::LESS
'less than'
when BinaryOperatorType::LESS_OR_EQUAL
'less than or equal to'
end
end
end
end
end
Expand Down
10 changes: 9 additions & 1 deletion app/cells/criteria_operator/ui_component/group/show.erb
@@ -1,3 +1,11 @@
<div class="criteria_editor_row_wrapper">
<div class="criteria_editor_empty_placeholder">It's lonely inside here...</div>
<% if empty? %>
<div class="criteria_editor_empty_placeholder">It's lonely inside here...</div>
<% else %>
<% c = 0 %>
<% model.operand_collection.each do |operand| %>
<%= cell('criteria_operator/ui_component/criteria_editor', operand).(:choose_template, locator: c) %>
<% c += 1 %>
<% end %>
<% end %>
</div>
6 changes: 6 additions & 0 deletions app/cells/criteria_operator/ui_component/group_cell.rb
Expand Up @@ -6,6 +6,12 @@ def show
render
end

private

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

end
end
end
9 changes: 5 additions & 4 deletions test/dummy/app/controllers/dummy_controller.rb
@@ -1,9 +1,10 @@
class DummyController < ApplicationController
def show
# first_op = CriteriaOperator::UnaryOperator.new(CriteriaOperator::OperandValue.new(true), 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::GroupOperator.new [], CriteriaOperator::GroupOperatorType::OR
#first_op = CriteriaOperator::UnaryOperator.new(CriteriaOperator::OperandValue.new(true), CriteriaOperator::UnaryOperatorType::NOT)
first_op = CriteriaOperator::GroupOperator.new [], CriteriaOperator::GroupOperatorType::AND
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::GroupOperator.new [], CriteriaOperator::GroupOperatorType::OR
render
end
end

0 comments on commit cd72339

Please sign in to comment.