Class: Kadmin::Finder::Presenter

Inherits:
Presenter
  • Object
show all
Defined in:
app/components/kadmin/finder/presenter.rb

Pager properties collapse

Instance Method Summary collapse

Methods inherited from Presenter

#initialize, #render

Constructor Details

This class inherits a constructor from Kadmin::Presenter

Instance Method Details

#applied_filtersString

Returns a description of the current applied filters

Returns:

  • (String)

    a description of the current applied filters



27
28
29
30
31
32
33
34
35
36
# File 'app/components/kadmin/finder/presenter.rb', line 27

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_showingString

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

Returns:

  • (String)

    how many resources are being displayed (along with indices)



11
12
13
14
15
16
17
18
19
# File 'app/components/kadmin/finder/presenter.rb', line 11

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_itemsInteger

Returns the current number of items displayed for this page

Returns:

  • (Integer)

    the current number of items displayed for this page



41
42
43
# File 'app/components/kadmin/finder/presenter.rb', line 41

def displayed_items
  return offset_end - self.pager.offset
end

#empty?Boolean

Returns true if no results, false otherwise

Returns:

  • (Boolean)

    true if no results, false otherwise



6
7
8
# File 'app/components/kadmin/finder/presenter.rb', line 6

def empty?
  return self.results.empty?
end

#offset_endInteger

Returns the index number of the last item for this page

Returns:

  • (Integer)

    the index number of the last item for this page



46
47
48
49
# File 'app/components/kadmin/finder/presenter.rb', line 46

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_startInteger

Returns the index number of the start item for this page

Returns:

  • (Integer)

    the index number of the start item for this page



52
53
54
# File 'app/components/kadmin/finder/presenter.rb', line 52

def offset_start
  return self.pager.offset + 1
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



22
23
24
# File 'app/components/kadmin/finder/presenter.rb', line 22

def resource_name
  return self.scope.model_name.human(count: displayed_items)
end