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 ActiveAdmin::ViewHelpers::DownloadFormatLinksHelper

#build_download_format_links

Methods included from Helpers::Collection

#collection_is_empty?, #collection_size

Methods inherited from Base

#build

Instance Method Details

#build_batch_actions_selectorObject (protected)



67
68
69
70
71
# File 'lib/active_admin/views/pages/index.rb', line 67

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)



46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_admin/views/pages/index.rb', line 46

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_scopesObject (protected)



73
74
75
76
77
78
79
80
81
# File 'lib/active_admin/views/pages/index.rb', line 73

def build_scopes
  if active_admin_config.scopes.any?
    scope_options = {
      :scope_count => config[:scope_count].nil? ? true : config[:scope_count]
    }

    scopes_renderer active_admin_config.scopes, scope_options
  end
end

#build_table_toolsObject (protected)



60
61
62
63
64
65
# File 'lib/active_admin/views/pages/index.rb', line 60

def build_table_tools
  div :class => "table_tools" do
    build_batch_actions_selector
    build_scopes
  end
end

#configObject



17
18
19
# File 'lib/active_admin/views/pages/index.rb', line 17

def config
  active_admin_config.get_page_presenter(:index) || default_index_config
end

#default_index_configObject (protected)

Creates a default configuration for the resource class. This is a table with each column displayed as well as all the default actions



85
86
87
88
89
90
91
92
93
94
# File 'lib/active_admin/views/pages/index.rb', line 85

def default_index_config
  @default_index_config ||= ::ActiveAdmin::PagePresenter.new(:as => :table) do |display|
    selectable_column
    id_column
    resource_class.content_columns.each do |col|
      column col.name.to_sym
    end
    default_actions
  end
end

#find_index_renderer_class(symbol_or_class) ⇒ 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.



98
99
100
101
102
103
104
105
106
107
# File 'lib/active_admin/views/pages/index.rb', line 98

def find_index_renderer_class(symbol_or_class)
  case symbol_or_class
  when Symbol
    ::ActiveAdmin::Views.const_get("IndexAs" + symbol_or_class.to_s.camelcase)
  when Class
    symbol_or_class
  else
    raise ArgumentError, "'as' requires a class or a symbol"
  end
end

#items_in_collection?Boolean (protected)

Returns:

  • (Boolean)


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

def items_in_collection?
  !collection_is_empty?
end

#main_contentObject

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



23
24
25
26
27
28
# File 'lib/active_admin/views/pages/index.rb', line 23

def main_content
  wrap_with_batch_action_form do
    build_table_tools
    build_collection
  end
end

#render_blank_slateObject (protected)



109
110
111
112
113
114
115
# File 'lib/active_admin/views/pages/index.rb', line 109

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')
    blank_slate_content += " " + link_to(I18n.t("active_admin.blank_slate.link"), new_resource_path)
  end
  insert_tag(view_factory.blank_slate, blank_slate_content)
end

#render_empty_resultsObject (protected)



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

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)



122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/active_admin/views/pages/index.rb', line 122

def render_index
  renderer_class = find_index_renderer_class(config[:as])
  paginator      = config[:paginator].nil?      ? true : config[:paginator]
  download_links = config[:download_links].nil? ? true : config[:download_links]
  
  paginated_collection(collection, :entry_name     => active_admin_config.resource_label,
                                   :entries_name   => active_admin_config.plural_resource_label,
                                   :download_links => download_links,
                                   :paginator      => paginator) do
    div :class => 'index_content' do
      insert_tag(renderer_class, config, collection)
    end
  end
end

#titleObject



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

def title
  if config[:title].is_a? String
    config[:title]
  else
    active_admin_config.plural_resource_label
  end
end

#wrap_with_batch_action_form(&block) ⇒ Object (protected)



32
33
34
35
36
37
38
# File 'lib/active_admin/views/pages/index.rb', line 32

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