Class: ActiveAdmin::Views::Scopes

Inherits:
Component
  • Object
show all
Includes:
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 ScopeChain

#scope_chain

Methods inherited from Component

#initialize

Constructor Details

This class inherits a constructor from ActiveAdmin::Component

Instance Method Details

#build(scopes) ⇒ Object



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

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

#build_scope(scope) ⇒ Object (protected)



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/active_admin/views/components/scopes.rb', line 25

def build_scope(scope)
  li :class => classes_for_scope(scope) do
    begin
      scope_name = I18n.t!("active_admin.scopes.#{scope.id}")
    rescue I18n::MissingTranslationData
      scope_name = scope.name
    end

    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).to_s + ")"
      end
    end
  end
end

#classes_for_scope(scope) ⇒ Object (protected)



42
43
44
45
46
# File 'lib/active_admin/views/components/scopes.rb', line 42

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)


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

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

#default_class_nameObject



9
10
11
# File 'lib/active_admin/views/components/scopes.rb', line 9

def default_class_name
  "scopes table_tools_segmented_control"
end

#get_scope_count(scope) ⇒ Object (protected)

Return the count for the scope passed in.



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

def get_scope_count(scope)
  scope_chain(scope, scoping_class).count
end

#scoping_classObject (protected)



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

def scoping_class
  assigns["before_scope_collection"] || active_admin_config.resource_class
end

#tag_nameObject



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

def tag_name
  'ul'
end