Module: Faalis::Dashboard::Sections::ResourcesIndex

Extended by:
ActiveSupport::Concern
Included in:
DSL
Defined in:
lib/faalis/dashboard/sections/resources_index.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary (collapse)

Instance Method Details

- (Object) fetch_and_set_all (private)



59
60
61
62
63
64
65
# File 'lib/faalis/dashboard/sections/resources_index.rb', line 59

def fetch_and_set_all
  result = fetch_index_objects
  instance_variable_set("@#{plural_name}", result)

  @index_fields = index_properties.fields
  @resources    = result
end

- (Object) fetch_index_objects (protected)

Fetch all or part of the corresponding resource from data base with respect to scope DSL.

The important thing here is that by using scope DSL this method will chain the resulted scope with other scopes like page and policy_scope



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/faalis/dashboard/sections/resources_index.rb', line 30

def fetch_index_objects
  scope = index_properties.default_scope

  if !scope.nil?
    # If user provided an scope for `index` section.

    if scope.respond_to? :call
      # If scope provided by a block
      scope = scope.call
    else
      # If scope provided by a symbol
      # which should be a method name
      scope = self.send(scope)
    end

  else
    scope = model.all
  end

  scope = scope.order('created_at DESC').page(params[:page])
  policy_scope(scope)
end

- (Object) index

The actual action method of a dashboard controller



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/faalis/dashboard/sections/resources_index.rb', line 9

def index
  authorize model

  fetch_and_set_all
  action_buttons(index_properties)
  @_tools_buttons = index_properties.tool_buttons || {}

  index_hook(@resources)

  return if _override_views.include? :index
  render 'faalis/dashboard/resource/index'
end

- (Object) index_hook(resources) (private)

You can override this method to change the behaviour of index action



69
70
71
# File 'lib/faalis/dashboard/sections/resources_index.rb', line 69

def index_hook(resources)

end

- (Object) index_properties (protected)



53
54
55
# File 'lib/faalis/dashboard/sections/resources_index.rb', line 53

def index_properties
  Faalis::Dashboard::DSL::Index.new(model)
end