Sha256: 11bc3623004b56ed849c25a7def63eb5a67e5ff90a20156f1f51b8b820abf522

Contents?: true

Size: 897 Bytes

Versions: 4

Compression:

Stored size: 897 Bytes

Contents

# frozen_string_literal: true

class Avo::Index::Ordering::ButtonsComponent < Avo::Index::Ordering::BaseComponent
  def initialize(resource: nil, reflection: nil, view_type: nil)
    @resource = resource
    @reflection = reflection
    @view_type = view_type
  end

  def render?
    has_with_trial(:resource_ordering) && can_order_any? && view_type_is_table? && enabled_in_view?
  end

  private

  def can_order_any?
    order_actions.present?
  end

  def view_type_is_table?
    @view_type.to_sym == :table
  end

  def display_inline?
    ordering[:display_inline]
  end

  def enabled_in_view?
    in_association = @reflection.present?

    if in_association
      visible_on_option.include? :association
    else
      visible_on_option.include? :index
    end
  end

  def visible_on_option
    [ordering[:visible_on]].flatten
  end

  def ordering
    @resource.class.ordering
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
avo-1.25.2 app/components/avo/index/ordering/buttons_component.rb
avo-1.25.1 app/components/avo/index/ordering/buttons_component.rb
avo-1.25.0 app/components/avo/index/ordering/buttons_component.rb
avo-1.24.2 app/components/avo/index/ordering/buttons_component.rb