add basic pagination on wow_mounts page
This commit is contained in:
3
Gemfile
3
Gemfile
@@ -42,7 +42,8 @@ gem 'sentry-rails', '~> 4.3.4'
|
|||||||
gem 'sentry-ruby', '~> 4.3.2'
|
gem 'sentry-ruby', '~> 4.3.2'
|
||||||
# Simple, efficient background processing for Ruby
|
# Simple, efficient background processing for Ruby
|
||||||
gem 'sidekiq', '~> 6.2.1'
|
gem 'sidekiq', '~> 6.2.1'
|
||||||
|
# Agnostic pagination in plain ruby
|
||||||
|
gem 'pagy', '~> 4.3.0'
|
||||||
# Reduces boot times through caching; required in config/boot.rb
|
# Reduces boot times through caching; required in config/boot.rb
|
||||||
gem 'bootsnap', '>= 1.4.4', require: false
|
gem 'bootsnap', '>= 1.4.4', require: false
|
||||||
|
|
||||||
|
|||||||
@@ -184,6 +184,7 @@ GEM
|
|||||||
actionpack (>= 4.2)
|
actionpack (>= 4.2)
|
||||||
omniauth (>= 1.3.1)
|
omniauth (>= 1.3.1)
|
||||||
orm_adapter (0.5.0)
|
orm_adapter (0.5.0)
|
||||||
|
pagy (4.3.0)
|
||||||
parallel (1.20.1)
|
parallel (1.20.1)
|
||||||
parser (3.0.1.0)
|
parser (3.0.1.0)
|
||||||
ast (~> 2.4.1)
|
ast (~> 2.4.1)
|
||||||
@@ -396,6 +397,7 @@ DEPENDENCIES
|
|||||||
mobility (~> 1.1.1)
|
mobility (~> 1.1.1)
|
||||||
omniauth-bnet (~> 2.0.0)
|
omniauth-bnet (~> 2.0.0)
|
||||||
omniauth-rails_csrf_protection (~> 0.1.2)
|
omniauth-rails_csrf_protection (~> 0.1.2)
|
||||||
|
pagy (~> 4.3.0)
|
||||||
pg (~> 1.1)
|
pg (~> 1.1)
|
||||||
pry-rails (~> 0.3.9)
|
pry-rails (~> 0.3.9)
|
||||||
puma (~> 5.0)
|
puma (~> 5.0)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
class ProtectedController < ApplicationController
|
class ProtectedController < ApplicationController
|
||||||
before_action :authenticate_user!
|
before_action :authenticate_user!
|
||||||
|
include Pagy::Backend
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class WowMountsController < ProtectedController
|
class WowMountsController < ProtectedController
|
||||||
def index
|
def index
|
||||||
@wow_mounts = WowMount.all
|
@pagy, @wow_mounts = pagy(WowMount.all, items: 12)
|
||||||
end
|
end
|
||||||
|
|
||||||
def show
|
def show
|
||||||
|
|||||||
@@ -1,2 +1,3 @@
|
|||||||
module ApplicationHelper
|
module ApplicationHelper
|
||||||
|
include Pagy::Frontend
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,20 +1,17 @@
|
|||||||
<h2>Mount list</h2>
|
<h2>Mount list</h2>
|
||||||
|
|
||||||
<table class="table table-hover table-dark table-image">
|
<div class="row">
|
||||||
<thead>
|
|
||||||
<tr>
|
|
||||||
<th scope="col"><%= t('wow_mounts.mount_list.name') %></th>
|
|
||||||
<th scope="col"><%= t('wow_mounts.mount_list.description') %></th>
|
|
||||||
<th scope="col"><%= t('wow_mounts.mount_list.owned') %></th>
|
|
||||||
</tr>
|
|
||||||
</thead>
|
|
||||||
<tbody>
|
|
||||||
<% @wow_mounts.each do |mount| %>
|
<% @wow_mounts.each do |mount| %>
|
||||||
<tr>
|
<div class="col-2 d-flex justify-content-center">
|
||||||
<td><%= link_to mount.name, mount %></td>
|
<div class="card" style="width: 18rem;">
|
||||||
<td><%= mount.description %></td>
|
<img src=<%= mount.asset_zoom %> class="card-img-top" alt="<%= mount.name %>-zoom-image">
|
||||||
<td></td>
|
<div class="card-body">
|
||||||
</tr>
|
<h5 class="card-title"><%= mount.name %></h5>
|
||||||
|
<p class="card-text"><%= mount.description %></p>
|
||||||
|
<%= link_to 'Detail', mount, class: "btn btn-primary" %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
<%== pagy_bootstrap_nav(@pagy) %>
|
||||||
</table>
|
</div>
|
||||||
|
|||||||
176
config/initializers/pagy.rb
Normal file
176
config/initializers/pagy.rb
Normal file
@@ -0,0 +1,176 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
# Pagy initializer file (4.3.0)
|
||||||
|
# Customize only what you really need and notice that Pagy works also without any of the following lines.
|
||||||
|
# Should you just cherry pick part of this file, please maintain the require-order of the extras
|
||||||
|
|
||||||
|
|
||||||
|
# Extras
|
||||||
|
# See https://ddnexus.github.io/pagy/extras
|
||||||
|
|
||||||
|
|
||||||
|
# Backend Extras
|
||||||
|
|
||||||
|
# Array extra: Paginate arrays efficiently, avoiding expensive array-wrapping and without overriding
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/array
|
||||||
|
# require 'pagy/extras/array'
|
||||||
|
|
||||||
|
# Countless extra: Paginate without any count, saving one query per rendering
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/countless
|
||||||
|
# require 'pagy/extras/countless'
|
||||||
|
# Pagy::VARS[:cycle] = false # default
|
||||||
|
|
||||||
|
# Elasticsearch Rails extra: Paginate `ElasticsearchRails::Results` objects
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/elasticsearch_rails
|
||||||
|
# default :pagy_search method: change only if you use
|
||||||
|
# also the searchkick extra that defines the same
|
||||||
|
# VARS[:elasticsearch_rails_search_method] = :pagy_search
|
||||||
|
# require 'pagy/extras/elasticsearch_rails'
|
||||||
|
|
||||||
|
# Searchkick extra: Paginate `Searchkick::Results` objects
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/searchkick
|
||||||
|
# default :pagy_search method: change only if you use
|
||||||
|
# also the elasticsearch_rails extra that defines the same
|
||||||
|
# VARS[:searchkick_search_method] = :pagy_search
|
||||||
|
# require 'pagy/extras/searchkick'
|
||||||
|
|
||||||
|
# Frontend Extras
|
||||||
|
|
||||||
|
# Bootstrap extra: Add nav, nav_js and combo_nav_js helpers and templates for Bootstrap pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/bootstrap
|
||||||
|
require 'pagy/extras/bootstrap'
|
||||||
|
|
||||||
|
# Bulma extra: Add nav, nav_js and combo_nav_js helpers and templates for Bulma pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/bulma
|
||||||
|
# require 'pagy/extras/bulma'
|
||||||
|
|
||||||
|
# Foundation extra: Add nav, nav_js and combo_nav_js helpers and templates for Foundation pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/foundation
|
||||||
|
# require 'pagy/extras/foundation'
|
||||||
|
|
||||||
|
# Materialize extra: Add nav, nav_js and combo_nav_js helpers for Materialize pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/materialize
|
||||||
|
# require 'pagy/extras/materialize'
|
||||||
|
|
||||||
|
# Navs extra: Add nav_js and combo_nav_js javascript helpers
|
||||||
|
# Notice: the other frontend extras add their own framework-styled versions,
|
||||||
|
# so require this extra only if you need the unstyled version
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/navs
|
||||||
|
# require 'pagy/extras/navs'
|
||||||
|
|
||||||
|
# Semantic extra: Add nav, nav_js and combo_nav_js helpers for Semantic UI pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/semantic
|
||||||
|
# require 'pagy/extras/semantic'
|
||||||
|
|
||||||
|
# UIkit extra: Add nav helper and templates for UIkit pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/uikit
|
||||||
|
# require 'pagy/extras/uikit'
|
||||||
|
|
||||||
|
# Multi size var used by the *_nav_js helpers
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/navs#steps
|
||||||
|
# Pagy::VARS[:steps] = { 0 => [2,3,3,2], 540 => [3,5,5,3], 720 => [5,7,7,5] } # example
|
||||||
|
|
||||||
|
|
||||||
|
# Feature Extras
|
||||||
|
|
||||||
|
# Headers extra: http response headers (and other helpers) useful for API pagination
|
||||||
|
# See http://ddnexus.github.io/pagy/extras/headers
|
||||||
|
# require 'pagy/extras/headers'
|
||||||
|
# Pagy::VARS[:headers] = { page: 'Current-Page', items: 'Page-Items', count: 'Total-Count', pages: 'Total-Pages' } # default
|
||||||
|
|
||||||
|
# Support extra: Extra support for features like: incremental, infinite, auto-scroll pagination
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/support
|
||||||
|
# require 'pagy/extras/support'
|
||||||
|
|
||||||
|
# Items extra: Allow the client to request a custom number of items per page with an optional selector UI
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/items
|
||||||
|
# require 'pagy/extras/items'
|
||||||
|
# Pagy::VARS[:items_param] = :items # default
|
||||||
|
# Pagy::VARS[:max_items] = 100 # default
|
||||||
|
|
||||||
|
# Overflow extra: Allow for easy handling of overflowing pages
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/overflow
|
||||||
|
# require 'pagy/extras/overflow'
|
||||||
|
# Pagy::VARS[:overflow] = :empty_page # default (other options: :last_page and :exception)
|
||||||
|
|
||||||
|
# Metadata extra: Provides the pagination metadata to Javascript frameworks like Vue.js, react.js, etc.
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/metadata
|
||||||
|
# you must require the shared internal extra (BEFORE the metadata extra) ONLY if you need also the :sequels
|
||||||
|
# require 'pagy/extras/shared'
|
||||||
|
# require 'pagy/extras/metadata'
|
||||||
|
# For performance reason, you should explicitly set ONLY the metadata you use in the frontend
|
||||||
|
# Pagy::VARS[:metadata] = [:scaffold_url, :count, :page, :prev, :next, :last] # example
|
||||||
|
|
||||||
|
# Trim extra: Remove the page=1 param from links
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/trim
|
||||||
|
# require 'pagy/extras/trim'
|
||||||
|
# after requiring it will trim by default
|
||||||
|
# set to false if you want to make :trim an opt-in variable
|
||||||
|
# Pagy::VARS[:trim] = true # default
|
||||||
|
|
||||||
|
|
||||||
|
# Pagy Variables
|
||||||
|
# See https://ddnexus.github.io/pagy/api/pagy#variables
|
||||||
|
# All the Pagy::VARS are set for all the Pagy instances but can be overridden
|
||||||
|
# per instance by just passing them to Pagy.new or the #pagy controller method
|
||||||
|
|
||||||
|
|
||||||
|
# Instance variables
|
||||||
|
# See https://ddnexus.github.io/pagy/api/pagy#instance-variables
|
||||||
|
# Pagy::VARS[:items] = 20 # default
|
||||||
|
|
||||||
|
|
||||||
|
# Other Variables
|
||||||
|
# See https://ddnexus.github.io/pagy/api/pagy#other-variables
|
||||||
|
# Pagy::VARS[:size] = [1,4,4,1] # default
|
||||||
|
# Pagy::VARS[:page_param] = :page # default
|
||||||
|
# Pagy::VARS[:params] = {} # default
|
||||||
|
# Pagy::VARS[:anchor] = '#anchor' # example
|
||||||
|
# Pagy::VARS[:link_extra] = 'data-remote="true"' # example
|
||||||
|
|
||||||
|
|
||||||
|
# Rails
|
||||||
|
|
||||||
|
# Rails: extras assets path required by the helpers that use javascript
|
||||||
|
# (pagy*_nav_js, pagy*_combo_nav_js, and pagy_items_selector_js)
|
||||||
|
# See https://ddnexus.github.io/pagy/extras#javascript
|
||||||
|
# Rails.application.config.assets.paths << Pagy.root.join('javascripts')
|
||||||
|
|
||||||
|
|
||||||
|
# I18n
|
||||||
|
|
||||||
|
# Pagy internal I18n: ~18x faster using ~10x less memory than the i18n gem
|
||||||
|
# See https://ddnexus.github.io/pagy/api/frontend#i18n
|
||||||
|
# Notice: No need to configure anything in this section if your app uses only "en"
|
||||||
|
# or if you use the i18n extra below
|
||||||
|
#
|
||||||
|
# Examples:
|
||||||
|
# load the "de" built-in locale:
|
||||||
|
# Pagy::I18n.load(locale: 'de')
|
||||||
|
#
|
||||||
|
# load the "de" locale defined in the custom file at :filepath:
|
||||||
|
# Pagy::I18n.load(locale: 'de', filepath: 'path/to/pagy-de.yml')
|
||||||
|
#
|
||||||
|
# load the "de", "en" and "es" built-in locales:
|
||||||
|
# (the first passed :locale will be used also as the default_locale)
|
||||||
|
# Pagy::I18n.load({locale: 'de'},
|
||||||
|
# {locale: 'en'},
|
||||||
|
# {locale: 'es'})
|
||||||
|
#
|
||||||
|
# load the "en" built-in locale, a custom "es" locale,
|
||||||
|
# and a totally custom locale complete with a custom :pluralize proc:
|
||||||
|
# (the first passed :locale will be used also as the default_locale)
|
||||||
|
# Pagy::I18n.load({locale: 'en'},
|
||||||
|
# {locale: 'es', filepath: 'path/to/pagy-es.yml'},
|
||||||
|
# {locale: 'xyz', # not built-in
|
||||||
|
# filepath: 'path/to/pagy-xyz.yml',
|
||||||
|
# pluralize: lambda{|count| ... } )
|
||||||
|
|
||||||
|
|
||||||
|
# I18n extra: uses the standard i18n gem which is ~18x slower using ~10x more memory
|
||||||
|
# than the default pagy internal i18n (see above)
|
||||||
|
# See https://ddnexus.github.io/pagy/extras/i18n
|
||||||
|
# require 'pagy/extras/i18n'
|
||||||
|
|
||||||
|
# Default i18n key
|
||||||
|
# Pagy::VARS[:i18n_key] = 'pagy.item_name' # default
|
||||||
Reference in New Issue
Block a user