Module: Matestack::Ui::Bootstrap::Content::SmartCollection::Paginate

Included in:
Collection
Defined in:
lib/matestack/ui/bootstrap/content/smart_collection/paginate.rb

Instance Method Summary collapse

Instance Method Details

#current_pageObject



79
80
81
82
83
84
85
86
# File 'lib/matestack/ui/bootstrap/content/smart_collection/paginate.rb', line 79

def current_page
  current_offset = params["#{context.id}-offset"].try(:to_i)
  if current_offset && context.paginate.present?
    (current_offset/context.paginate)+1 
  elsif context.paginate.present?
    1
  end
end

#last_pageObject



89
90
91
92
93
94
95
# File 'lib/matestack/ui/bootstrap/content/smart_collection/paginate.rb', line 89

def last_page
  if @collection.filtered_count%context.paginate == 0
    (@collection.filtered_count/context.paginate)
  else
    (@collection.filtered_count/context.paginate)+1
  end
end

#paginate_partialObject



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/matestack/ui/bootstrap/content/smart_collection/paginate.rb', line 3

def paginate_partial
  div class: "current-pagination-state ps-2" do
    small do
      plain "showing #{@collection.from} "
      plain "to #{@collection.to} "
      plain "of #{@collection.filtered_count} "
      if (@collection.base_count - @collection.filtered_count) > 0
        plain "(#{@collection.base_count - @collection.filtered_count} hidden by filter)"
      end
    end
  end
  pagination_nav_partial
end

#pagination_nav_partialObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/matestack/ui/bootstrap/content/smart_collection/paginate.rb', line 17

def pagination_nav_partial
  nav class: "table-responsive", style: "display: -webkit-box;" do
    ul class: ul_classes do
      li class: "page-item previous #{ 'disabled' if current_page == 1 }" do
        collection_content_previous class: 'page-link' do
          bs_icon name: "chevron-left", size: 10
        end
      end
      if @collection.pages.count >= 9 && current_page > 5
        li class: "page-item" do
          collection_content_page_link class: 'page-link', page: 1 do
            plain 1
          end
        end
        unless current_page == 6
          li class: "page-item disabled" do
            a class: 'page-link', path: "#" do
              plain "..."
            end
          end
        end
      end
      @collection.pages.each do |page|
        if (current_page-page).abs < 5
          li class: "page-item #{ 'active' if current_page == page }" do
            collection_content_page_link class: 'page-link', page: page do
              plain page
            end
          end
        end
      end
      if @collection.pages.count >= 9 && last_page-current_page > 4
        unless current_page == last_page-5
          li class: "page-item disabled" do
            a class: 'page-link', path: "#" do
              plain "..."
            end
          end
        end
        li class: "page-item" do
          collection_content_page_link class: 'page-link', page: last_page do
            plain last_page
          end
        end
      end
      li class: "page-item next #{ 'disabled' if current_page == last_page }" do
        collection_content_next class: 'page-link' do
          bs_icon name: "chevron-right", size: 10
        end
      end
    end
  end
end

#ul_classesObject



71
72
73
74
75
76
77
# File 'lib/matestack/ui/bootstrap/content/smart_collection/paginate.rb', line 71

def ul_classes
  [].tap do |classes|
    classes << "pagination"
    classes << "justify-content-end"
    classes << "mt-3"
  end.join(' ').strip
end