Class: TinyAdmin::Actions::Index

Inherits:
BasicAction show all
Defined in:
lib/tiny_admin/actions/index.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from BasicAction

#attribute_options

Methods included from Utils

#humanize, #params_to_s, #prepare_page, #to_class

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def context
  @context
end

#current_pageObject (readonly)

Returns the value of attribute current_page.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def current_page
  @current_page
end

#fields_optionsObject (readonly)

Returns the value of attribute fields_options.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def fields_options
  @fields_options
end

Returns the value of attribute links.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def links
  @links
end

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def options
  @options
end

#pagesObject (readonly)

Returns the value of attribute pages.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def pages
  @pages
end

#paginationObject (readonly)

Returns the value of attribute pagination.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def pagination
  @pagination
end

#paramsObject (readonly)

Returns the value of attribute params.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def params
  @params
end

#query_stringObject (readonly)

Returns the value of attribute query_string.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def query_string
  @query_string
end

#repositoryObject (readonly)

Returns the value of attribute repository.



6
7
8
# File 'lib/tiny_admin/actions/index.rb', line 6

def repository
  @repository
end

Instance Method Details

#call(app:, context:, options:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/tiny_admin/actions/index.rb', line 17

def call(app:, context:, options:)
  @context = context
  @options = options || {}
  evaluate_options(options)
  fields = repository.fields(options: fields_options)
  filters = prepare_filters(fields)
  records, count = repository.list(page: current_page, limit: pagination, filters: filters, sort: options[:sort])
  attributes = {
    actions: context.actions,
    fields: fields,
    filters: filters,
    links: options[:links],
    prepare_record: ->(record) { repository.index_record_attrs(record, fields: fields_options) },
    records: records,
    slug: context.slug,
    title: repository.index_title,
    widgets: options[:widgets]
  }

  prepare_page(Views::Actions::Index, slug: context.slug, attributes: attributes) do |page|
    setup_pagination(page, TinyAdmin.settings.components[:pagination], total_count: count)
  end
end