Class: ActiveAdmin::Views::IndexList

Inherits:
Component
  • Object
show all
Includes:
Helpers::Collection
Defined in:
lib/active_admin/views/components/index_list.rb

Overview

Renders a collection of index views available to the resource as a list with a separator

Instance Method Summary collapse

Methods included from Helpers::Collection

#collection_is_empty?, #collection_size

Instance Method Details

#build(index_classes) ⇒ Object

Builds the links for presenting different index views to the user

Parameters:

  • index_classes (Array)

    The class constants that represent index page presenters



24
25
26
27
28
29
30
# File 'lib/active_admin/views/components/index_list.rb', line 24

def build(index_classes)
  unless current_filter_search_empty?
    index_classes.each do |index_class|
      build_index_list(index_class)
    end
  end
end

#build_index_list(index_class) ⇒ Object (protected)

Builds the individual link and HTML classes for each index page presenter

Parameters:

  • index_class (Class)

    The class on which to build the link and html classes



37
38
39
40
41
42
43
44
45
46
47
# File 'lib/active_admin/views/components/index_list.rb', line 37

def build_index_list(index_class)
  li class: classes_for_index(index_class) do
    params = request.query_parameters.except :page, :commit, :format
    url_with_params = url_for(**params.merge(as: index_class.index_name.to_sym).symbolize_keys)

    a href: url_with_params, class: "table_tools_button" do
      name = index_class.index_name
      I18n.t("active_admin.index_list.#{name}", default: name.to_s.titleize)
    end
  end
end

#classes_for_index(index_class) ⇒ Object (protected)



49
50
51
52
53
# File 'lib/active_admin/views/components/index_list.rb', line 49

def classes_for_index(index_class)
  classes = ["index"]
  classes << "selected" if current_index?(index_class)
  classes.join(" ")
end

#current_filter_search_empty?Boolean (protected)

Returns:

  • (Boolean)


63
64
65
# File 'lib/active_admin/views/components/index_list.rb', line 63

def current_filter_search_empty?
  params.include?(:q) && collection_is_empty?
end

#current_index?(index_class) ⇒ Boolean (protected)

Returns:

  • (Boolean)


55
56
57
58
59
60
61
# File 'lib/active_admin/views/components/index_list.rb', line 55

def current_index?(index_class)
  if params[:as]
    params[:as] == index_class.index_name
  else
    active_admin_config.default_index_class == index_class
  end
end

#default_class_nameObject



13
14
15
# File 'lib/active_admin/views/components/index_list.rb', line 13

def default_class_name
  "indexes table_tools_segmented_control"
end

#tag_nameObject



17
18
19
# File 'lib/active_admin/views/components/index_list.rb', line 17

def tag_name
  'ul'
end