Class: Kadmin::FinderDecorator
- Inherits:
-
Object
- Object
- Kadmin::FinderDecorator
- Defined in:
- app/decorators/kadmin/finder_decorator.rb
Instance Attribute Summary collapse
-
#finder ⇒ Kadmin::Finder
readonly
Underlying finder model.
Instance Method Summary collapse
-
#applied_filters ⇒ String
A description of the current applied filters.
-
#currently_showing ⇒ String
How many resources are being displayed (along with indices).
-
#empty? ⇒ Boolean
True if no results, false otherwise.
-
#initialize(finder) ⇒ FinderDecorator
constructor
A new instance of FinderDecorator.
-
#pager ⇒ Kadmin::PagerDecorator
Decorated pager of the underlying finder.
-
#resource_name ⇒ String
Human readable, singular/plural form of the finder's model.
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
#finder ⇒ Kadmin::Finder (readonly)
Returns underlying finder model.
4 5 6 |
# File 'app/decorators/kadmin/finder_decorator.rb', line 4 def finder @finder end |
Instance Method Details
#applied_filters ⇒ String
Returns 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_showing ⇒ String
Returns 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.
13 14 15 |
# File 'app/decorators/kadmin/finder_decorator.rb', line 13 def empty? return finder.results.count.zero? end |
#pager ⇒ Kadmin::PagerDecorator
Returns decorated pager of the underlying finder.
46 47 48 |
# File 'app/decorators/kadmin/finder_decorator.rb', line 46 def pager return @pager ||= Kadmin::PagerDecorator.new(@finder.pager) end |
#resource_name ⇒ String
Returns 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 |