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, #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, #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



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

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)



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

def build_scopes
  if active_admin_config.scopes.any?
    div :class => "table_tools" do
      scopes_renderer active_admin_config.scopes
    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



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

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



64
65
66
67
68
69
70
71
72
73
# File 'lib/active_admin/views/pages/index.rb', line 64

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

#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 collection.any?
    render_index
  else
    if params[:q]
      render_empty_results
    else
      render_blank_slate
    end
  end
end

#render_blank_slateObject (protected)



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

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)



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

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)



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

def render_index
  renderer_class = find_index_renderer_class(config[:as])
  
  paginated_collection(collection, :entry_name   => active_admin_config.resource_name,
                                   :entries_name => active_admin_config.plural_resource_name) 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