Class: EasyAdmin::Versions::PaginationComponent

Inherits:
BaseComponent
  • Object
show all
Defined in:
app/components/easy_admin/versions/pagination_component.rb

Instance Method Summary collapse

Methods inherited from BaseComponent

#easy_admin_url_helpers, #helpers, #rails_url_helpers

Methods included from Permissions::Component

#current_user_can?, #current_user_has_role?, #if_can, #if_has_role, #permission_attrs, #permission_button, #permission_case, #permission_classes, #permission_field, #permission_link, #unless_can, #unless_has_role

Methods included from FieldsHelper

#field_component, #render_field

Methods included from DashboardsHelper

#delta_badge_classes, #metric_value_classes, #render_card, #sparkline_color, #sparkline_points, #trend_direction, #trend_icon, #trend_indicator_classes

Constructor Details

#initialize(pagy:, resource_class:, record:) ⇒ PaginationComponent

Returns a new instance of PaginationComponent.



4
5
6
7
8
# File 'app/components/easy_admin/versions/pagination_component.rb', line 4

def initialize(pagy:, resource_class:, record:)
  @pagy = pagy
  @resource_class = resource_class
  @record = record
end

Instance Method Details

#view_templateObject



10
11
12
13
14
15
16
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'app/components/easy_admin/versions/pagination_component.rb', line 10

def view_template
  return unless @pagy.pages > 1

  div(id: "versions-pagination", class: "mt-6 flex items-center justify-between border-t border-gray-200 bg-white px-4 py-3 sm:px-6") do
    # Mobile pagination info
    div(class: "flex flex-1 justify-between sm:hidden") do
      if @pagy.prev
        link_to_previous_page
      else
        span(class: "relative inline-flex items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-500") do
          "Previous"
        end
      end

      if @pagy.next
        link_to_next_page
      else
        span(class: "relative ml-3 inline-flex items-center rounded-md border border-gray-300 bg-white px-4 py-2 text-sm font-medium text-gray-500") do
          "Next"
        end
      end
    end

    # Desktop pagination
    div(class: "hidden sm:flex sm:flex-1 sm:items-center sm:justify-between") do
      # Results info
      div do
        p(class: "text-sm text-gray-700") do
          plain "Showing "
          span(class: "font-medium") { @pagy.from }
          plain " to "
          span(class: "font-medium") { @pagy.to }
          plain " of "
          span(class: "font-medium") { @pagy.count }
          plain " versions"
        end
      end

      # Page navigation
      div do
        nav(class: "isolate inline-flex -space-x-px rounded-md shadow-sm", "aria-label": "Pagination") do
          # Previous page
          if @pagy.prev
            link_to_previous_page_desktop
          else
            span(class: "relative inline-flex items-center rounded-l-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0") do
              span(class: "sr-only") { "Previous" }
              unsafe_raw <<~SVG
                <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                  <path fill-rule="evenodd" d="M12.79 5.23a.75.75 0 01-.02 1.06L8.832 10l3.938 3.71a.75.75 0 11-1.04 1.08l-4.5-4.25a.75.75 0 010-1.08l4.5-4.25a.75.75 0 011.06.02z" clip-rule="evenodd"/>
                </svg>
              SVG
            end
          end

          # Page numbers (show first, current range, and last)
          render_page_numbers

          # Next page
          if @pagy.next
            link_to_next_page_desktop
          else
            span(class: "relative inline-flex items-center rounded-r-md px-2 py-2 text-gray-400 ring-1 ring-inset ring-gray-300 hover:bg-gray-50 focus:z-20 focus:outline-offset-0") do
              span(class: "sr-only") { "Next" }
              unsafe_raw <<~SVG
                <svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true">
                  <path fill-rule="evenodd" d="M7.21 14.77a.75.75 0 01.02-1.06L11.168 10 7.23 6.29a.75.75 0 111.04-1.08l4.5 4.25a.75.75 0 010 1.08l-4.5 4.25a.75.75 0 01-1.06-.02z" clip-rule="evenodd"/>
                </svg>
              SVG
            end
          end
        end
      end
    end
  end
end