Class: ActiveAdmin::Views::Pages::Index
- Inherits:
-
Base
- Object
- Arbre::HTML::Element
- Arbre::HTML::Tag
- Arbre::HTML::Document
- Base
- ActiveAdmin::Views::Pages::Index
- Defined in:
- lib/active_admin/views/pages/index.rb
Instance Attribute Summary
Attributes inherited from Arbre::HTML::Tag
Attributes inherited from Arbre::HTML::Element
Instance Method Summary collapse
-
#build_download_format_links(formats = [:csv, :xml, :json]) ⇒ Object
protected
TODO: Refactor to new HTML DSL.
- #build_scopes ⇒ Object protected
- #config ⇒ Object
-
#default_index_config ⇒ Object
protected
Creates a default configuration for the resource class.
-
#find_index_renderer_class(symbol_or_class) ⇒ Object
protected
Returns the actual class for renderering the main content on the index page.
- #items_in_collection? ⇒ Boolean protected
-
#main_content ⇒ Object
Render’s the index configuration that was set in the controller.
- #render_blank_slate ⇒ Object protected
- #render_empty_results ⇒ Object protected
- #render_index ⇒ Object protected
- #title ⇒ Object
Methods inherited from Base
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
#build_download_format_links(formats = [:csv, :xml, :json]) ⇒ Object (protected)
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(" ").html_safe end |
#build_scopes ⇒ Object (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_count => config[:scope_count].nil? ? true : config[:scope_count] } div :class => "table_tools" do scopes_renderer active_admin_config.scopes, end end end |
#config ⇒ Object
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_config ⇒ Object (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_content ⇒ Object
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_slate ⇒ Object (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_results ⇒ Object (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_index ⇒ Object (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 |
#title ⇒ Object
7 8 9 |
# File 'lib/active_admin/views/pages/index.rb', line 7 def title active_admin_config.plural_resource_name end |