Sha256: 84c11a7bf40d97d7cd91a9d25c996e0262497a14d872aed307ba242be3848d8b

Contents?: true

Size: 1.33 KB

Versions: 5

Compression:

Stored size: 1.33 KB

Contents

module CriteriaOperator
  module UiComponent
    class GroupCell < BaseCell

      def show(options = {})
        @allow_delete = options.has_key?(:allow_delete) ? options[:allow_delete] : true
        @locator = options.has_key?(:locator) ? options[:locator] : ''
        if model.kind_of? GroupOperator
          @group = model
        elsif model_negated_group?
          @group = model.operand
        else
          @group = nil
        end
        render
      end

    private

      def operator_type
        if model.kind_of? GroupOperator
          model.operator_type
        elsif model_negated_group?
          model.operand.operator_type * -1
        else
          0
        end
      end

      def operators
        ops = []
        ops << { value: GroupOperatorType::AND, text: 'AND' }
        ops << { value: GroupOperatorType::OR, text: 'OR' }
        ops << { value: -1 * GroupOperatorType::AND, text: 'NAND' }
        ops << { value: -1 * GroupOperatorType::OR, text: 'NOR' }
        ops
      end

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

      def model_negated_group?
        model.kind_of?(UnaryOperator) && (model.operator_type == UnaryOperatorType::NOT) && model.operand.kind_of?(GroupOperator)
      end

    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
criteria_operator-ui_component-0.3.1 app/cells/criteria_operator/ui_component/group_cell.rb
criteria_operator-ui_component-0.3.0 app/cells/criteria_operator/ui_component/group_cell.rb
criteria_operator-ui_component-0.2.2 app/cells/criteria_operator/ui_component/group_cell.rb
criteria_operator-ui_component-0.2.1 app/cells/criteria_operator/ui_component/group_cell.rb
criteria_operator-ui_component-0.2.0 app/cells/criteria_operator/ui_component/group_cell.rb