diff --git a/Gemfile b/Gemfile
index ceb1ecf..5e84a09 100644
--- a/Gemfile
+++ b/Gemfile
@@ -31,6 +31,10 @@ gem 'jbuilder', '~> 2.5'
# A gem to automate using jQuery with Rails
gem 'jquery-rails', '~> 4.3.1'
+# Gem for pagination
+gem 'kaminari'
+gem 'bootstrap4-kaminari-views'
+
# required for Bootstrap tooltips
source 'https://rails-assets.org' do
gem 'rails-assets-tether', '>= 1.3.3'
diff --git a/Gemfile.lock b/Gemfile.lock
index 46bcd03..ac67bb9 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -51,6 +51,9 @@ GEM
bootstrap (4.0.0.alpha6)
autoprefixer-rails (>= 6.0.3)
sass (>= 3.4.19)
+ bootstrap4-kaminari-views (1.0.0)
+ kaminari (>= 0.13)
+ rails (>= 3.1)
builder (3.2.3)
bullet (5.6.1)
activesupport (>= 3.0.0)
@@ -109,6 +112,18 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jwt (1.5.6)
+ kaminari (1.1.1)
+ activesupport (>= 4.1.0)
+ kaminari-actionview (= 1.1.1)
+ kaminari-activerecord (= 1.1.1)
+ kaminari-core (= 1.1.1)
+ kaminari-actionview (1.1.1)
+ actionview
+ kaminari-core (= 1.1.1)
+ kaminari-activerecord (1.1.1)
+ activerecord
+ kaminari-core (= 1.1.1)
+ kaminari-core (1.1.1)
launchy (2.4.3)
addressable (~> 2.3)
listen (3.1.5)
@@ -272,6 +287,7 @@ PLATFORMS
DEPENDENCIES
annotate (~> 2.7)
bootstrap (~> 4.0.0.alpha6)
+ bootstrap4-kaminari-views
bullet
byebug
capybara (~> 2.13)
@@ -282,6 +298,7 @@ DEPENDENCIES
httparty
jbuilder (~> 2.5)
jquery-rails (~> 4.3.1)
+ kaminari
launchy (~> 2.4.3)
listen (>= 3.0.5, < 3.2)
newrelic_rpm
diff --git a/app/assets/stylesheets/playtime.scss b/app/assets/stylesheets/playtime.scss
index 2602f59..dd7a156 100644
--- a/app/assets/stylesheets/playtime.scss
+++ b/app/assets/stylesheets/playtime.scss
@@ -88,3 +88,6 @@ h3 {
border-color: $teal;
}
}
+.pagination {
+ margin-top: 16px;
+}
diff --git a/app/controllers/wishlist_items_controller.rb b/app/controllers/wishlist_items_controller.rb
index e88b1aa..757d713 100644
--- a/app/controllers/wishlist_items_controller.rb
+++ b/app/controllers/wishlist_items_controller.rb
@@ -3,7 +3,7 @@ class WishlistItemsController < ApplicationController
def index
skip_authorization
- @wishlist_items = WishlistItem.includes(:item, :wishlist).priority_order
+ @wishlist_items = WishlistItem.includes(:item, :wishlist).page(params[:page])
end
def create
diff --git a/app/controllers/wishlists_controller.rb b/app/controllers/wishlists_controller.rb
index 57b95a1..a854679 100644
--- a/app/controllers/wishlists_controller.rb
+++ b/app/controllers/wishlists_controller.rb
@@ -5,7 +5,7 @@ def show
skip_authorization
@wishlist = Wishlist.includes(wishlist_items: :item).find(params[:id])
@site_managers = @wishlist.users
- @wishlist_items = @wishlist.wishlist_items.priority_order
+ @wishlist_items = @wishlist.wishlist_items.page(params[:page]).per(10)
end
def new
diff --git a/app/models/wishlist_item.rb b/app/models/wishlist_item.rb
index 79ea440..ea05e13 100644
--- a/app/models/wishlist_item.rb
+++ b/app/models/wishlist_item.rb
@@ -27,5 +27,4 @@ class WishlistItem < ApplicationRecord
validates :quantity, presence: true,
numericality: { greater_than_or_equal_to: 0 }
- scope :priority_order, -> { order(priority: :desc) }
end
diff --git a/app/views/kaminari/_first_page.html.erb b/app/views/kaminari/_first_page.html.erb
new file mode 100644
index 0000000..cc107ec
--- /dev/null
+++ b/app/views/kaminari/_first_page.html.erb
@@ -0,0 +1,3 @@
+
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
+
diff --git a/app/views/kaminari/_gap.html.erb b/app/views/kaminari/_gap.html.erb
new file mode 100644
index 0000000..d241fc4
--- /dev/null
+++ b/app/views/kaminari/_gap.html.erb
@@ -0,0 +1,3 @@
+
+ <%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
+
diff --git a/app/views/kaminari/_last_page.html.erb b/app/views/kaminari/_last_page.html.erb
new file mode 100644
index 0000000..9a7584e
--- /dev/null
+++ b/app/views/kaminari/_last_page.html.erb
@@ -0,0 +1,3 @@
+
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
+
diff --git a/app/views/kaminari/_next_page.html.erb b/app/views/kaminari/_next_page.html.erb
new file mode 100644
index 0000000..7ca72a8
--- /dev/null
+++ b/app/views/kaminari/_next_page.html.erb
@@ -0,0 +1,3 @@
+
+ <%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
+
diff --git a/app/views/kaminari/_page.html.erb b/app/views/kaminari/_page.html.erb
new file mode 100644
index 0000000..57bc591
--- /dev/null
+++ b/app/views/kaminari/_page.html.erb
@@ -0,0 +1,9 @@
+<% if page.current? %>
+
+ <%= content_tag :a, page, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), class: 'page-link' %>
+
+<% else %>
+
+ <%= link_to page, url, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), class: 'page-link' %>
+
+<% end %>
diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb
new file mode 100644
index 0000000..17cf469
--- /dev/null
+++ b/app/views/kaminari/_paginator.html.erb
@@ -0,0 +1,17 @@
+ <%= paginator.render do %>
+
+ <% end %>
diff --git a/app/views/kaminari/_prev_page.html.erb b/app/views/kaminari/_prev_page.html.erb
new file mode 100644
index 0000000..c7803fa
--- /dev/null
+++ b/app/views/kaminari/_prev_page.html.erb
@@ -0,0 +1,3 @@
+
+ <%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %>
+
diff --git a/app/views/wishlist_items/index.html.erb b/app/views/wishlist_items/index.html.erb
index bedfd47..10758b7 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -9,4 +9,7 @@
<%= render @wishlist_items %>
+
+ <%= paginate @wishlist_items%>
+
diff --git a/app/views/wishlists/show.html.erb b/app/views/wishlists/show.html.erb
index 4e87999..9ef80f6 100644
--- a/app/views/wishlists/show.html.erb
+++ b/app/views/wishlists/show.html.erb
@@ -20,7 +20,9 @@
<%= @wishlist.users.map(&:display_name).join(", ") %>
- <%= render @wishlist_items %>
+
+ <%= render @wishlist.wishlist_items %>
+ <%= paginate @wishlist_items %>
<%= link_to 'Back', root_path %>
diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb
new file mode 100644
index 0000000..373150f
--- /dev/null
+++ b/config/initializers/kaminari_config.rb
@@ -0,0 +1,12 @@
+# frozen_string_literal: true
+Kaminari.configure do |config|
+ config.default_per_page = 10
+ # config.max_per_page = nil
+ # config.window = 4
+ # config.outer_window = 0
+ # config.left = 0
+ # config.right = 0
+ # config.page_method_name = :page
+ # config.param_name = :page
+ # config.params_on_first_page = false
+end
diff --git a/config/locales/en.yml b/config/locales/en.yml
index decc5a8..2986b62 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -30,4 +30,10 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
- hello: "Hello world"
+ views:
+ pagination:
+ first: "« First"
+ last: "Last »"
+ previous: "‹ Prev"
+ next: "Next ›"
+ truncate: "…"