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

Inherits:
Base show all
Defined in:
lib/active_admin/views/pages/index.rb

Instance Attribute Summary

Attributes inherited from Arbre::HTML::Tag

#attributes

Attributes inherited from Arbre::HTML::Element

#children, #parent

Instance Method Summary collapse

Methods inherited from Base

#build

Methods inherited from Arbre::HTML::Document

#build, #build_body, #build_head, #doctype, #document, #tag_name, #to_s

Methods inherited from Arbre::HTML::Tag

#add_class, #build, #class_list, #class_names, #get_attribute, #has_attribute?, #id, #id!, #id=, #initialize, #remove_attribute, #remove_class, #set_attribute, #to_s

Methods inherited from Arbre::HTML::Element

#+, #<<, #add_child, #assigns, #build, builder_method, #children?, #content, #content=, #document, #each, #get_elements_by_class_name, #get_elements_by_tag_name, #helpers, #html_safe, #indent_level, #initialize, #parent?, #remove_child, #tag_name, #to_ary, #to_s, #to_str

Methods included from Arbre::Builder::BuilderMethods

#append_return_block, #appendable_return_block?, #build_tag, #current_dom_context, #insert_tag, #with_current_dom_context

Methods included from Arbre::Builder

#current_dom_context, #helpers, #method_missing

Constructor Details

This class inherits a constructor from Arbre::HTML::Tag

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Arbre::Builder

Instance Method Details

TODO: Refactor to new HTML DSL



45
46
47
48
49
50
# File 'lib/active_admin/views/pages/index.rb', line 45

def build_download_format_links(formats = [:csv, :xml, :json])
  links = formats.collect do |format|
    link_to format.to_s.upcase, { :format => format}.merge(request.query_parameters.except(:commit, :format))
  end
  text_node [I18n.t('active_admin.download'), links].flatten.join("&nbsp;").html_safe
end

#build_scopesObject (protected)



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/active_admin/views/pages/index.rb', line 52

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

    div :class => "table_tools" do
      scopes_renderer active_admin_config.scopes, scope_options
    end
  end
end

#configObject



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

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



66
67
68
# File 'lib/active_admin/views/pages/index.rb', line 66

def default_index_config
  @default_index_config ||= ::ActiveAdmin::PagePresenter.new(:as => :table)
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.



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

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)



33
34
35
36
37
38
39
40
41
42
# File 'lib/active_admin/views/pages/index.rb', line 33

def items_in_collection?
  # Remove the order clause before limiting to 1. This ensures that
  # any referenced columns in the order will not try to be accessed.
  #
  # When we call #exists?, the query's select statement is changed to "1".
  #
  # If we don't reorder, there may be some columns referenced in the order
  # clause that requires the original select.
  collection.reorder("").limit(1).exists?
end

#main_contentObject

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



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/active_admin/views/pages/index.rb', line 17

def main_content
  build_scopes

  if items_in_collection?
    render_index
  else
    if params[:q]
      render_empty_results
    else
      render_blank_slate
    end
  end
end

#render_blank_slateObject (protected)



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

def render_blank_slate
  blank_slate_content = I18n.t("active_admin.blank_slate.content", :resource_name => active_admin_config.plural_resource_name)
  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)



91
92
93
94
# File 'lib/active_admin/views/pages/index.rb', line 91

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

#render_indexObject (protected)



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

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_name,
                                   :entries_name   => active_admin_config.plural_resource_name,
                                   :download_links => download_links,
                                   :paginator      => paginator) do
    div :class => 'index_content' do
      insert_tag(renderer_class, config, collection)
    end
  end
end

#titleObject



7
8
9
# File 'lib/active_admin/views/pages/index.rb', line 7

def title
  active_admin_config.plural_resource_name
end