-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kaminari pagination default view (#42)
* Use values in forms * Use form builder methods * Some refactoring * Add anyway-config * Add Tailwind-styled pagination * Add tailwind-styled pagination * Make default pagination by configuration * Add pagination config tests * Add pagination tests * Remove unused test * Update README.md * Minor updates * Remove fixing on anyway_config version * Remove empty lines in Gemfile * Ordered gems * Little fix
- Loading branch information
1 parent
66f77e6
commit a9e5536
Showing
22 changed files
with
242 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-# Link to the "First" page | ||
-# available local variables | ||
-# url: url to the first page | ||
-# current_page: a page object for the currently displayed page | ||
-# total_pages: total number of pages | ||
-# per_page: number of items to fetch per page | ||
-# remote: data-remote | ||
%span.first{ class: 'px-3 py-2 text-sm font-medium text-purple-700 bg-white rounded-md hover:bg-purple-100' } | ||
= link_to_unless current_page.first?, t('views.pagination.first').html_safe, url, remote: remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-# Non-link tag that stands for skipped pages... | ||
-# available local variables | ||
-# current_page: a page object for the currently displayed page | ||
-# total_pages: total number of pages | ||
-# per_page: number of items to fetch per page | ||
-# remote: data-remote | ||
%span.page.gap{ class: 'px-3 py-2 text-sm font-medium text-purple-700' } | ||
= t('views.pagination.truncate').html_safe |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-# Link to the "Last" page | ||
-# available local variables | ||
-# url: url to the last page | ||
-# current_page: a page object for the currently displayed page | ||
-# total_pages: total number of pages | ||
-# per_page: number of items to fetch per page | ||
-# remote: data-remote | ||
%span.last{ class: 'px-3 py-2 text-sm font-medium text-purple-700 bg-white rounded-md hover:bg-purple-100' } | ||
= link_to_unless current_page.last?, t('views.pagination.last').html_safe, url, remote: remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-# Link to the "Next" page | ||
-# available local variables | ||
-# url: url to the next page | ||
-# current_page: a page object for the currently displayed page | ||
-# total_pages: total number of pages | ||
-# per_page: number of items to fetch per page | ||
-# remote: data-remote | ||
%span.next{ class: 'px-3 py-2 text-sm font-medium text-purple-700 bg-white rounded-md hover:bg-purple-100' } | ||
= link_to_unless current_page.last?, t('views.pagination.next').html_safe, url, rel: 'next', remote: remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
-# Link showing page number | ||
-# available local variables | ||
-# page: a page object for "this" page | ||
-# url: url to this page | ||
-# current_page: a page object for the currently displayed page | ||
-# total_pages: total number of pages | ||
-# per_page: number of items to fetch per page | ||
-# remote: data-remote | ||
- if page.current? | ||
%span{class: "px-3 py-2 font-medium rounded-md bg-purple-500 text-white" } | ||
= page | ||
- else | ||
%span{class: "cursor px-3 py-2 font-medium text-purple-700 bg-white rounded-md hover:bg-purple-100"} | ||
= link_to_unless page.current?, page, url, {remote: remote, rel: page.rel} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
= paginator.render do | ||
%nav.pagination.flex.items-center.justify-center.space-x-1 | ||
= first_page_tag unless current_page.first? | ||
= prev_page_tag unless current_page.first? | ||
- each_page do |page| | ||
- if page.display_tag? | ||
= page_tag page | ||
- elsif !page.was_truncated? | ||
= gap_tag | ||
= next_page_tag unless current_page.last? | ||
= last_page_tag unless current_page.last? | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
-# Link to the "Previous" page | ||
-# available local variables | ||
-# url: url to the previous page | ||
-# current_page: a page object for the currently displayed page | ||
-# total_pages: total number of pages | ||
-# per_page: number of items to fetch per page | ||
-# remote: data-remote | ||
%span.prev{ class: 'px-3 py-2 text-sm font-medium text-purple-700 bg-white rounded-md hover:bg-purple-100' } | ||
= link_to_unless current_page.first?, t('views.pagination.previous').html_safe, url, rel: 'prev', remote: remote |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'anyway' | ||
require 'singleton' | ||
require 'tramway/configs/entity' | ||
|
||
module Tramway | ||
# Basic configuration of Tramway | ||
# | ||
class Config | ||
class Config < Anyway::Config | ||
include Singleton | ||
|
||
def initialize | ||
@entities = [] | ||
end | ||
attr_config( | ||
pagination: { enabled: false }, | ||
entities: [] | ||
) | ||
|
||
def entities=(collection) | ||
@entities = collection.map do |entity| | ||
super(collection.map do |entity| | ||
entity_options = entity.is_a?(Hash) ? entity : { name: entity } | ||
|
||
Tramway::Configs::Entity.new(**entity_options) | ||
end | ||
end) | ||
end | ||
|
||
attr_reader :entities | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# frozen_string_literal: true | ||
|
||
class UsersController < ApplicationController | ||
def index | ||
@users = User.all.page(params[:page]) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
%tr | ||
- [:email].each do |attribute| | ||
%td.py-2.px-4.border-b.border-r | ||
= user.public_send(attribute) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
.flex.justify-between.mb-4.mt-4 | ||
%h1{ class: "text-4xl font-bold text-left text-black-700 mb-8 mt-4" } | ||
= t('activerecord.plural.models.user.many') | ||
%table.w-full.bg-white.border.border-gray-200 | ||
%thead | ||
%tr | ||
- [:email].each do |attribute| | ||
%th.py-2.px-4.border-b.border-r | ||
= User.human_attribute_name attribute | ||
%tbody#users | ||
= render @users | ||
.flex.flex-end.border-t.border-gray-200.px-4.pt-4.w-full | ||
= paginate @users |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# frozen_string_literal: true | ||
|
||
Tramway.configure do |config| | ||
config.pagination = { enabled: true } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,7 @@ | ||
# Files in the config/locales directory are used for internationalization | ||
# and are automatically loaded by Rails. If you want to use locales other | ||
# than English, add the necessary files in this directory. | ||
# | ||
# To use the locales, use `I18n.t`: | ||
# | ||
# I18n.t "hello" | ||
# | ||
# In views, this is aliased to just `t`: | ||
# | ||
# <%= t("hello") %> | ||
# | ||
# To use a different locale, set it with `I18n.locale`: | ||
# | ||
# I18n.locale = :es | ||
# | ||
# This would use the information in config/locales/es.yml. | ||
# | ||
# The following keys must be escaped otherwise they will not be retrieved by | ||
# the default I18n backend: | ||
# | ||
# true, false, on, off, yes, no | ||
# | ||
# Instead, surround them with single quotes. | ||
# | ||
# en: | ||
# "true": "foo" | ||
# | ||
# To learn more, please read the Rails Internationalization guide | ||
# available at https://guides.rubyonrails.org/i18n.html. | ||
|
||
en: | ||
hello: "Hello world" | ||
views: | ||
pagination: | ||
first: First | ||
last: Last | ||
next: Next | ||
previous: Previous |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
shared_examples 'Click on Page' do |page_number, text = nil| | ||
it "navigates to the correct #{text || page_number} page link is clicked" do | ||
visit users_path | ||
|
||
within 'nav.pagination', match: :first do | ||
click_link text || page_number | ||
end | ||
|
||
expect(page).to have_current_path(users_path(page: page_number)) | ||
end | ||
end | ||
|
||
feature 'Order Index Page', type: %i[feature admin] do | ||
context 'check pagination' do | ||
before do | ||
User.destroy_all | ||
create_list :user, 125 | ||
end | ||
|
||
it 'displays 1..5 pages links and next/last buttons' do | ||
visit users_path | ||
|
||
expect(page).to have_css('span', text: '1', class: 'bg-purple-500') | ||
|
||
(2..5).each do |i| | ||
expect(page).to have_link(i.to_s, href: users_path(page: i)) | ||
end | ||
|
||
expect(page).to have_link('Next', href: users_path(page: 2)) | ||
|
||
expect(page).to have_link('Last', href: users_path(page: 5)) | ||
end | ||
|
||
include_examples 'Click on Page', '2' | ||
include_examples 'Click on Page', '3' | ||
include_examples 'Click on Page', '4' | ||
include_examples 'Click on Page', '5' | ||
include_examples 'Click on Page', '2', 'Next' | ||
include_examples 'Click on Page', '5', 'Last' | ||
end | ||
end |
Oops, something went wrong.