Class: ActiveAdmin::Views::Pages::Index

Inherits:
Base
  • Object
show all
Includes:
Helpers::Collection, ActiveAdmin::ViewHelpers::DownloadFormatLinksHelper
Defined in:
lib/active_admin/views/pages/index.rb

Instance Method Summary collapse

Methods included from Helpers::Collection

#collection_is_empty?, #collection_size

Methods inherited from Base

#build, #html_title

Instance Method Details

#any_table_tools?Boolean (protected)

Returns:

  • (Boolean)


78
79
80
81
82
# File 'lib/active_admin/views/pages/index.rb', line 78

def any_table_tools?
  active_admin_config.batch_actions.any? ||
  active_admin_config.scopes.any? ||
  active_admin_config.page_presenters[:index].try(:size).try(:>, 1)
end

#build_batch_actions_selectorObject (protected)



84
85
86
87
88
# File 'lib/active_admin/views/pages/index.rb', line 84

def build_batch_actions_selector
  if active_admin_config.batch_actions.any?
    insert_tag view_factory.batch_action_selector, active_admin_config.batch_actions
  end
end

#build_collectionObject (protected)



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/active_admin/views/pages/index.rb', line 56

def build_collection
  if items_in_collection?
    render_index
  else
    if params[:q] || params[:scope]
      render_empty_results
    else
      render_blank_slate
    end
  end
end

#build_index_listObject (protected)



100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/active_admin/views/pages/index.rb', line 100

def build_index_list
  indexes = active_admin_config.page_presenters[:index]

  if indexes.kind_of?(Hash) && indexes.length > 1
    index_classes = []
    active_admin_config.page_presenters[:index].each do |type, page_presenter|
      index_classes << find_index_renderer_class(page_presenter[:as])
    end

    index_list_renderer index_classes
  end
end

#build_scopesObject (protected)



90
91
92
93
94
95
96
97
98
# File 'lib/active_admin/views/pages/index.rb', line 90

def build_scopes
  if active_admin_config.scopes.any?
    scope_options = {
      scope_count: config.fetch(:scope_count, true)
    }

    scopes_renderer active_admin_config.scopes, scope_options
  end
end

#build_table_toolsObject (protected)



70
71
72
73
74
75
76
# File 'lib/active_admin/views/pages/index.rb', line 70

def build_table_tools
  div class: "table_tools" do
    build_batch_actions_selector
    build_scopes
    build_index_list
  end if any_table_tools?
end

#configObject

Retrieves the given page presenter, or uses the default.



19
20
21
22
# File 'lib/active_admin/views/pages/index.rb', line 19

def config
  active_admin_config.get_page_presenter(:index, params[:as]) ||
  ActiveAdmin::PagePresenter.new(as: :table)
end

#find_index_renderer_class(klass) ⇒ Object (protected)

Returns the actual class for renderering the main content on the index page. To set this, use the :as option in the page_presenter block.



115
116
117
118
119
120
121
# File 'lib/active_admin/views/pages/index.rb', line 115

def find_index_renderer_class(klass)
  if klass.is_a?(Class)
    klass
  else
    ::ActiveAdmin::Views.const_get("IndexAs" + klass.to_s.camelcase)
  end
end

#items_in_collection?Boolean (protected)

Returns:

  • (Boolean)


52
53
54
# File 'lib/active_admin/views/pages/index.rb', line 52

def items_in_collection?
  !collection_is_empty?
end

#main_contentObject

Renders the index configuration that was set in the controller. Defaults to rendering the ActiveAdmin::Pages::Index::Table



26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/active_admin/views/pages/index.rb', line 26

def main_content
  wrap_with_batch_action_form do
    build_table_tools
    build_collection
  end
  if active_admin_config.batch_actions.any?
    active_admin_config.batch_actions.each do |batch_action|
      if batch_action.partial.present?
        render(batch_action.partial)
      end
    end
  end
end

#render_blank_slateObject (protected)



123
124
125
126
127
128
129
# File 'lib/active_admin/views/pages/index.rb', line 123

def render_blank_slate
  blank_slate_content = I18n.t("active_admin.blank_slate.content", resource_name: active_admin_config.plural_resource_label)
  if controller.action_methods.include?("new") && authorized?(ActiveAdmin::Auth::NEW, active_admin_config.resource_class)
    blank_slate_content = [blank_slate_content, blank_slate_link].compact.join(" ")
  end
  insert_tag(view_factory.blank_slate, blank_slate_content)
end

#render_empty_resultsObject (protected)



131
132
133
134
# File 'lib/active_admin/views/pages/index.rb', line 131

def render_empty_results
  empty_results_content = I18n.t("active_admin.pagination.empty", model: active_admin_config.plural_resource_label)
  insert_tag(view_factory.blank_slate, empty_results_content)
end

#render_indexObject (protected)



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/active_admin/views/pages/index.rb', line 136

def render_index
  renderer_class = find_index_renderer_class(config[:as])

  paginator = config.fetch(:paginator, true)
  download_links = config.fetch(:download_links, active_admin_config.namespace.download_links)
  pagination_total = config.fetch(:pagination_total, true)
  per_page = config.fetch(:per_page, active_admin_config.per_page)

  paginated_collection(
    collection, entry_name: active_admin_config.resource_label,
                entries_name: active_admin_config.plural_resource_label(count: collection_size),
                download_links: download_links,
                paginator: paginator,
                per_page: per_page,
                pagination_total: pagination_total) do
    div class: "index_content" do
      insert_tag(renderer_class, config, collection)
    end
  end
end

#titleObject



10
11
12
13
14
15
16
# File 'lib/active_admin/views/pages/index.rb', line 10

def title
  if Proc === config[:title]
    controller.instance_exec &config[:title]
  else
    config[:title] || assigns[:page_title] || active_admin_config.plural_resource_label
  end
end

#wrap_with_batch_action_form(&block) ⇒ Object (protected)



42
43
44
45
46
47
48
# File 'lib/active_admin/views/pages/index.rb', line 42

def wrap_with_batch_action_form(&block)
  if active_admin_config.batch_actions.any?
    batch_action_form(&block)
  else
    block.call
  end
end