Class: ActiveAdmin::Views::Scopes

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

Overview

Renders a collection of ActiveAdmin::Scope objects as a simple list with a seperator

Instance Method Summary collapse

Methods included from Helpers::Collection

#collection_is_empty?, #collection_size

Methods included from ScopeChain

#scope_chain

Instance Method Details

#build(scopes, options = {}) ⇒ Object



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

def build(scopes, options = {})
  scopes.each do |scope|
    build_scope(scope, options) if call_method_or_proc_on(self, scope.display_if_block)
  end
end

#build_scope(scope, options) ⇒ Object (protected)



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/active_admin/views/components/scopes.rb', line 32

def build_scope(scope, options)
  li :class => classes_for_scope(scope) do
    scope_name = I18n.t("active_admin.scopes.#{scope.id}", :default => scope.name)

    a :href => url_for(params.merge(:scope => scope.id, :page => 1)), :class => "table_tools_button" do
      text_node scope_name
      span :class => 'count' do
        "(#{get_scope_count(scope)})"
      end if options[:scope_count] && scope.show_count
    end
  end
end

#classes_for_scope(scope) ⇒ Object (protected)



45
46
47
48
49
# File 'lib/active_admin/views/components/scopes.rb', line 45

def classes_for_scope(scope)
  classes = ["scope", scope.id]
  classes << "selected" if current_scope?(scope)
  classes.join(" ")
end

#current_scope?(scope) ⇒ Boolean (protected)

Returns:

  • (Boolean)


51
52
53
54
55
56
57
# File 'lib/active_admin/views/components/scopes.rb', line 51

def current_scope?(scope)
  if params[:scope]
    params[:scope] == scope.id
  else
    active_admin_config.default_scope(self) == scope
  end
end

#default_class_nameObject



16
17
18
# File 'lib/active_admin/views/components/scopes.rb', line 16

def default_class_name
  "scopes table_tools_segmented_control"
end

#get_scope_count(scope) ⇒ Object (protected)

Return the count for the scope passed in.



60
61
62
# File 'lib/active_admin/views/components/scopes.rb', line 60

def get_scope_count(scope)
  collection_size(scope_chain(scope, collection_before_scope))
end

#tag_nameObject



20
21
22
# File 'lib/active_admin/views/components/scopes.rb', line 20

def tag_name
  'ul'
end