Class: Kadmin::Finder::Presenter
- Defined in:
- app/components/kadmin/finder/presenter.rb
Pager properties collapse
-
#displayed_items ⇒ Integer
The current number of items displayed for this page.
-
#offset_end ⇒ Integer
The index number of the last item for this page.
-
#offset_start ⇒ Integer
The index number of the start item for this page.
- #pager ⇒ Object
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.
-
#resource_name ⇒ String
Human readable, singular/plural form of the finder’s model.
-
#results ⇒ Array
An array of optionally presented models.
Methods inherited from Presenter
#initialize, #present, #render
Constructor Details
This class inherits a constructor from Kadmin::Presenter
Instance Method Details
#applied_filters ⇒ String
Returns a description of the current applied filters.
28 29 30 31 32 33 34 35 36 37 |
# File 'app/components/kadmin/finder/presenter.rb', line 28 def applied_filters applied_filters = '' filters = self.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).
12 13 14 15 16 17 18 19 20 |
# File 'app/components/kadmin/finder/presenter.rb', line 12 def currently_showing resource = resource_name.downcase displayed = empty? ? 0 : displayed_items currently_showing_phrase = "#{displayed} #{resource}" currently_showing_phrase = "#{currently_showing_phrase} (#{offset_start} - #{offset_end})" if self.results.size > 1 return currently_showing_phrase end |
#displayed_items ⇒ Integer
Returns the current number of items displayed for this page.
57 58 59 |
# File 'app/components/kadmin/finder/presenter.rb', line 57 def displayed_items return offset_end - self.pager.offset end |
#empty? ⇒ Boolean
Returns true if no results, false otherwise.
7 8 9 |
# File 'app/components/kadmin/finder/presenter.rb', line 7 def empty? return self.results.empty? end |
#offset_end ⇒ Integer
Returns the index number of the last item for this page.
62 63 64 65 |
# File 'app/components/kadmin/finder/presenter.rb', line 62 def offset_end next_page_offset = self.pager.offset_at(self.pager.current_page + 1) return [next_page_offset, self.pager.total].min end |
#offset_start ⇒ Integer
Returns the index number of the start item for this page.
68 69 70 |
# File 'app/components/kadmin/finder/presenter.rb', line 68 def offset_start return self.pager.offset + 1 end |
#pager ⇒ Object
52 53 54 |
# File 'app/components/kadmin/finder/presenter.rb', line 52 def pager return @pager ||= __getobj__.pager.present(@view) end |
#resource_name ⇒ String
Returns human readable, singular/plural form of the finder’s model.
23 24 25 |
# File 'app/components/kadmin/finder/presenter.rb', line 23 def resource_name return self.scope.model_name.human(count: displayed_items) end |
#results ⇒ Array
Returns an array of optionally presented models.
40 41 42 43 44 45 46 47 48 |
# File 'app/components/kadmin/finder/presenter.rb', line 40 def results return @results ||= __getobj__.results.map do |object| if object.class < Kadmin::Presentable object.present(@view) else object end end end |