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, #present, #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



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_showingString

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

Returns:

  • (String)

    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_itemsInteger

Returns the current number of items displayed for this page.

Returns:

  • (Integer)

    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.

Returns:

  • (Boolean)

    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_endInteger

Returns the index number of the last item for this page.

Returns:

  • (Integer)

    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_startInteger

Returns the index number of the start item for this page.

Returns:

  • (Integer)

    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

#pagerObject



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

def pager
  return @pager ||= __getobj__.pager.present(@view)
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



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

#resultsArray

Returns an array of optionally presented models.

Returns:

  • (Array)

    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