Class: Kadmin::FinderDecorator

Inherits:
Object
  • Object
show all
Defined in:
app/decorators/kadmin/finder_decorator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(finder) ⇒ FinderDecorator

Returns a new instance of FinderDecorator.



8
9
10
# File 'app/decorators/kadmin/finder_decorator.rb', line 8

def initialize(finder)
  @finder = finder
end

Instance Attribute Details

#finderKadmin::Finder (readonly)

Returns underlying finder model.

Returns:



4
5
6
# File 'app/decorators/kadmin/finder_decorator.rb', line 4

def finder
  @finder
end

Instance Method Details

#applied_filtersString

Returns a description of the current applied filters.

Returns:

  • (String)

    a description of the current applied filters



34
35
36
37
38
39
40
41
42
43
# File 'app/decorators/kadmin/finder_decorator.rb', line 34

def applied_filters
  applied_filters = ''
  filters = @finder.filters.reduce([]) do |acc, (name, filter)|
    next(acc) if filter.value.blank?
    acc << %(<strong>#{filter.value}</strong> on <em>#{name}</em>)
  end
  applied_filters = "(filtering: #{filters.join('; ')})" unless filters.empty?

  return applied_filters.html_safe
end

#currently_showingString

Returns how many resources are being displayed (along with indices).

Returns:

  • (String)

    how many resources are being displayed (along with indices)



18
19
20
21
22
23
24
25
26
# File 'app/decorators/kadmin/finder_decorator.rb', line 18

def currently_showing
  resource = resource_name.downcase
  displayed = empty? ? 0 : pager.displayed_items

  currently_showing_phrase = "#{displayed} #{resource}"
  currently_showing_phrase = "#{currently_showing_phrase} (#{pager.page_start} - #{pager.page_end})" if finder.results.count > 1

  return currently_showing_phrase
end

#empty?Boolean

Returns true if no results, false otherwise.

Returns:

  • (Boolean)

    true if no results, false otherwise



13
14
15
# File 'app/decorators/kadmin/finder_decorator.rb', line 13

def empty?
  return finder.results.count.zero?
end

#pagerKadmin::PagerDecorator

Returns decorated pager of the underlying finder.

Returns:



46
47
48
# File 'app/decorators/kadmin/finder_decorator.rb', line 46

def pager
  return @pager ||= Kadmin::PagerDecorator.new(@finder.pager)
end

#resource_nameString

Returns human readable, singular/plural form of the finder's model.

Returns:

  • (String)

    human readable, singular/plural form of the finder's model



29
30
31
# File 'app/decorators/kadmin/finder_decorator.rb', line 29

def resource_name
  return @finder.scope.model_name.human(count: pager.displayed_items)
end