Class: Pageflow::Admin::EmbeddedIndexTable

Inherits:
ViewComponent
  • Object
show all
Defined in:
app/views/components/pageflow/admin/embedded_index_table.rb

Overview

Since:

  • 12.2

Defined Under Namespace

Classes: SortColumnRecorder

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#base_collectionObject (readonly)

Since:

  • 12.2



6
7
8
# File 'app/views/components/pageflow/admin/embedded_index_table.rb', line 6

def base_collection
  @base_collection
end

#scopesObject (readonly)

Since:

  • 12.2



6
7
8
# File 'app/views/components/pageflow/admin/embedded_index_table.rb', line 6

def scopes
  @scopes
end

Instance Method Details

#build(base_collection, options = {}) ⇒ Object

Since:

  • 12.2



8
9
10
11
12
13
14
15
# File 'app/views/components/pageflow/admin/embedded_index_table.rb', line 8

def build(base_collection, options = {})
  @base_collection = base_collection
  @scopes = []
  @sort_columns = []
  @blank_slate_text = options[:blank_slate_text]
  @model = options[:model]
  super()
end

#scope(*args) ⇒ Object

Since:

  • 12.2



17
18
19
20
21
22
23
# File 'app/views/components/pageflow/admin/embedded_index_table.rb', line 17

def scope(*args)
  options = args.extract_options!
  title = args[0]
  method = args[1]
  options[:localizer] ||= ActiveAdmin::Localizers::ResourceLocalizer.new(@model&.model_name)
  scopes << ActiveAdmin::Scope.new(title, method, options)
end

#table_for_collection(options = {}, &block) ⇒ Object

Since:

  • 12.2



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/views/components/pageflow/admin/embedded_index_table.rb', line 25

def table_for_collection(options = {}, &block)
  if scopes.any?
    custom_scopes_renderer(scopes, default_scope: scopes.first.id)
  end

  record_sort_columns(&block) if options[:sortable]

  if scoped_collection.any?
    build_table(options, &block)
  else
    build_blank_slate
  end
end