From 7ad09beeb64e393be69f1f794ae267e6d1d55165 Mon Sep 17 00:00:00 2001
From: nenadmil
Date: Sat, 21 Oct 2017 20:01:27 +0200
Subject: [PATCH 1/2] Add pagination for wishlist_items. #141
---
Gemfile | 3 +++
Gemfile.lock | 13 +++++++++++++
app/controllers/wishlist_items_controller.rb | 2 +-
app/controllers/wishlists_controller.rb | 2 +-
app/views/wishlist_items/index.html.erb | 1 +
app/views/wishlists/show.html.erb | 1 +
config/initializers/kaminari_config.rb | 12 ++++++++++++
7 files changed, 32 insertions(+), 2 deletions(-)
create mode 100644 config/initializers/kaminari_config.rb
diff --git a/Gemfile b/Gemfile
index 8356444..990a335 100644
--- a/Gemfile
+++ b/Gemfile
@@ -29,6 +29,9 @@ gem 'jbuilder', '~> 2.5'
# A gem to automate using jQuery with Rails
gem 'jquery-rails', '~> 4.3.1'
+# A gem for pagination
+gem 'kaminari'
+
# 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 e13a405..ddafd54 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -109,6 +109,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)
@@ -281,6 +293,7 @@ DEPENDENCIES
httparty
jbuilder (~> 2.5)
jquery-rails (~> 4.3.1)
+ kaminari
launchy (~> 2.4.3)
listen (>= 3.0.5, < 3.2)
omniauth-amazon
diff --git a/app/controllers/wishlist_items_controller.rb b/app/controllers/wishlist_items_controller.rb
index 5cd4cf1..9e4e16e 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)
+ @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 d3fcbab..d624342 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
+ @wishlist_items = @wishlist.wishlist_items.page params[:page]
end
def new
diff --git a/app/views/wishlist_items/index.html.erb b/app/views/wishlist_items/index.html.erb
index bedfd47..512e973 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -9,4 +9,5 @@
<%= render @wishlist_items %>
+ <%= paginate @wishlist_items %>
diff --git a/app/views/wishlists/show.html.erb b/app/views/wishlists/show.html.erb
index f9dc7fc..3a6af13 100644
--- a/app/views/wishlists/show.html.erb
+++ b/app/views/wishlists/show.html.erb
@@ -21,6 +21,7 @@
<%= 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
From 7044529f64f968842663678b43da94806fda409a Mon Sep 17 00:00:00 2001
From: nenadmil
Date: Mon, 23 Oct 2017 21:25:20 +0200
Subject: [PATCH 2/2] Fix wishlist items pagination, pagination per page to 5.
---
app/assets/stylesheets/playtime.scss | 6 ++++++
app/views/wishlists/show.html.erb | 2 +-
config/initializers/kaminari_config.rb | 2 +-
3 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/app/assets/stylesheets/playtime.scss b/app/assets/stylesheets/playtime.scss
index 86d6da1..0576f6b 100644
--- a/app/assets/stylesheets/playtime.scss
+++ b/app/assets/stylesheets/playtime.scss
@@ -88,3 +88,9 @@ h3 {
border-color: $teal;
}
}
+
+.pagination a {
+ color: $teal;
+ padding: 4px 8px;
+ text-decoration: underline;
+}
diff --git a/app/views/wishlists/show.html.erb b/app/views/wishlists/show.html.erb
index 3a6af13..8049d9d 100644
--- a/app/views/wishlists/show.html.erb
+++ b/app/views/wishlists/show.html.erb
@@ -20,7 +20,7 @@
<%= @wishlist.users.map(&:display_name).join(", ") %>
- <%= render @wishlist.wishlist_items %>
+ <%= render @wishlist_items %>
<%= paginate @wishlist_items %>
<%= link_to 'Back', root_path %>
diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb
index 373150f..b02c76f 100644
--- a/config/initializers/kaminari_config.rb
+++ b/config/initializers/kaminari_config.rb
@@ -1,6 +1,6 @@
# frozen_string_literal: true
Kaminari.configure do |config|
- config.default_per_page = 10
+ config.default_per_page = 5
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0