Class: Avo::Index::ResourceTableComponent

Inherits:
BaseComponent
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/components/avo/index/resource_table_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApplicationHelper

#a_button, #a_link, #button_classes, #chart_color, #decode_filter_params, #empty_state, #encode_filter_params, #frame_id, #get_model_class, #input_classes, #mount_path, #number_to_social, #render_license_warning, #root_path_without_url, #svg, #white_panel_classes

Methods included from ResourcesHelper

#field_wrapper, #filter_wrapper, #index_field_wrapper, #item_select_all_input, #item_selector_init, #item_selector_input, #resource_grid, #resource_table

Methods inherited from BaseComponent

#has_with_trial

Constructor Details

#initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil, actions: nil) ⇒ ResourceTableComponent

Returns a new instance of ResourceTableComponent.



7
8
9
10
11
12
13
14
15
16
# File 'app/components/avo/index/resource_table_component.rb', line 7

def initialize(resources: nil, resource: nil, reflection: nil, parent_record: nil, parent_resource: nil, pagy: nil, query: nil, actions: nil)
  @resources = resources
  @resource = resource
  @reflection = reflection
  @parent_record = parent_record
  @parent_resource = parent_resource
  @pagy = pagy
  @query = query
  @actions = actions
end

Instance Attribute Details

#pagyObject (readonly)

Returns the value of attribute pagy.



5
6
7
# File 'app/components/avo/index/resource_table_component.rb', line 5

def pagy
  @pagy
end

#queryObject (readonly)

Returns the value of attribute query.



5
6
7
# File 'app/components/avo/index/resource_table_component.rb', line 5

def query
  @query
end

Instance Method Details

#encrypted_queryObject



18
19
20
21
22
23
24
25
# File 'app/components/avo/index/resource_table_component.rb', line 18

def encrypted_query
  # TODO: move this to the resource where we can apply the adapter pattern
  if Module.const_defined?("Ransack::Search") && query.instance_of?(Ransack::Search)
    @query = @query.result
  end

  Avo::Services::EncryptionService.encrypt(message: @query, purpose: :select_all, serializer: Marshal)
end

#selected_all_labelObject



35
36
37
38
39
40
41
# File 'app/components/avo/index/resource_table_component.rb', line 35

def selected_all_label
  if @resource.pagination_type.countless?
    t "avo.records_selected_from_all_pages_html"
  else
    t "avo.x_records_selected_from_all_pages_html", count: pagy.count
  end
end

#selected_page_labelObject



27
28
29
30
31
32
33
# File 'app/components/avo/index/resource_table_component.rb', line 27

def selected_page_label
  if @resource.pagination_type.countless?
    t "avo.x_records_selected_from_page_html", selected: pagy.in
  else
    t "avo.x_records_selected_from_a_total_of_x_html", selected: pagy.in, count: pagy.count
  end
end