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

Instance Method Details

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


23
24
25
26
27
28
29
30
31
32
33
# File 'lib/active_admin/views/components/scopes.rb', line 23

def build(scopes, options = {})
  scopes.group_by(&:group).each do |group, group_scopes|
    ul class: "table_tools_segmented_control #{group_class(group)}" do
      group_scopes.each do |scope|
        build_scope(scope, options) if call_method_or_exec_proc(scope.display_if_block)
      end

      nil
    end
  end
end

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


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

def build_scope(scope, options)
  li class: classes_for_scope(scope) do
    params = request.query_parameters.except :page, :scope, :commit, :format

    a href: url_for(scope: scope.id, params: params), class: 'table_tools_button' do
      text_node scope_name(scope)
      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)


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

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)

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

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

#default_class_nameObject


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

def default_class_name
  "scopes"
end

#get_scope_count(scope) ⇒ Object (protected)

Return the count for the scope passed in.


65
66
67
# File 'lib/active_admin/views/components/scopes.rb', line 65

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

#group_class(group) ⇒ Object (protected)


69
70
71
# File 'lib/active_admin/views/components/scopes.rb', line 69

def group_class(group)
  group.present? ? "scope-group-#{group}" : "scope-default-group"
end

#tag_nameObject


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

def tag_name
  'div'
end