From e9b66fa748e88fa851b169d6b989a8a56df2bd8d Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Sat, 21 Oct 2017 13:26:14 -0600
Subject: [PATCH 01/13] Added gem, paginating according to defaults for page
---
Gemfile | 3 +++
Gemfile.lock | 13 +++++++++++++
app/controllers/wishlist_items_controller.rb | 2 +-
app/controllers/wishlists_controller.rb | 2 +-
4 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/Gemfile b/Gemfile
index 8356444..260da9b 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'
+# 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..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)
+ @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..7f32a07 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
From c9aa3c201a972b5b8a0ae267bbf07c169666cc2a Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Sat, 21 Oct 2017 13:31:42 -0600
Subject: [PATCH 02/13] Paginated,following the railscast, seems to simple. I
expect the Bootstrap to give problems
---
app/views/wishlist_items/index.html.erb | 1 +
app/views/wishlists/show.html.erb | 1 +
2 files changed, 2 insertions(+)
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 %>
From 557969716b333cbe30a9dc2ebcf16b8e1f2e6ab3 Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Sat, 21 Oct 2017 14:10:02 -0600
Subject: [PATCH 03/13] customizations of the Prev and Next
---
config/locales/en.yml | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/config/locales/en.yml b/config/locales/en.yml
index decc5a8..a664552 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -31,3 +31,7 @@
en:
hello: "Hello world"
+ views:
+ pagination:
+ previous: "< Previous"
+ next: "Next >"
From b0fc2dba97c4cafafaa8e04aee5251f40235507c Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Sat, 21 Oct 2017 14:26:21 -0600
Subject: [PATCH 04/13] default pages loaded
---
app/views/wishlist_items/index.html.erb | 5 ++++-
config/initializers/kaminari_config.rb | 12 ++++++++++++
2 files changed, 16 insertions(+), 1 deletion(-)
create mode 100644 config/initializers/kaminari_config.rb
diff --git a/app/views/wishlist_items/index.html.erb b/app/views/wishlist_items/index.html.erb
index 512e973..5bffd61 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -9,5 +9,8 @@
<%= render @wishlist_items %>
- <%= paginate @wishlist_items %>
+
+
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 cf5e5a662e6780bd44c6379b45c89a0c547a3ce8 Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Sat, 21 Oct 2017 14:34:06 -0600
Subject: [PATCH 05/13] removed the UI component since there's only one
wishlist item etc
---
app/views/wishlist_items/index.html.erb | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/app/views/wishlist_items/index.html.erb b/app/views/wishlist_items/index.html.erb
index 5bffd61..8cf2f2d 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -9,8 +9,6 @@
<%= render @wishlist_items %>
+ <%= paginate @wishlist_items %>
-
From b6c68dc9f8cb87090680274e8116af0434ed94f8 Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Wed, 25 Oct 2017 16:29:38 -0600
Subject: [PATCH 06/13] Forcing truncation of items to 10 per page, and cutting
down 'Previous' to 'Prev'. I may even get rid of that if need be. Looks busy
---
app/controllers/wishlist_items_controller.rb | 2 +-
app/controllers/wishlists_controller.rb | 2 +-
app/models/wishlist_item.rb | 1 +
app/views/wishlist_items/index.html.erb | 2 +-
config/initializers/kaminari_config.rb | 2 +-
config/locales/en.yml | 7 +++++--
6 files changed, 10 insertions(+), 6 deletions(-)
diff --git a/app/controllers/wishlist_items_controller.rb b/app/controllers/wishlist_items_controller.rb
index 757d713..d1e899b 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).page(params[:page])
+ @wishlist_items = WishlistItem.includes(:item, :wishlist).page(params[:page]).per(10)
end
def create
diff --git a/app/controllers/wishlists_controller.rb b/app/controllers/wishlists_controller.rb
index 7f32a07..9af7dab 100644
--- a/app/controllers/wishlists_controller.rb
+++ b/app/controllers/wishlists_controller.rb
@@ -3,7 +3,7 @@ class WishlistsController < ApplicationController
def show
skip_authorization
- @wishlist = Wishlist.includes(wishlist_items: :item).find(params[:id])
+ @wishlist = Wishlist.includes(wishlist_items: :item).find(params[:id]).per(10)
@site_managers = @wishlist.users
@wishlist_items = @wishlist.wishlist_items.page(params[:page])
end
diff --git a/app/models/wishlist_item.rb b/app/models/wishlist_item.rb
index 0bfed29..d3fbee5 100644
--- a/app/models/wishlist_item.rb
+++ b/app/models/wishlist_item.rb
@@ -26,4 +26,5 @@ class WishlistItem < ApplicationRecord
validates :priority, presence: true
validates :quantity, presence: true,
numericality: { greater_than_or_equal_to: 0 }
+
end
diff --git a/app/views/wishlist_items/index.html.erb b/app/views/wishlist_items/index.html.erb
index 8cf2f2d..c07fc96 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -9,6 +9,6 @@
<%= render @wishlist_items %>
- <%= paginate @wishlist_items %>
+ <%= paginate @wishlist_items%>
diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb
index 373150f..4482548 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 = 10
# config.max_per_page = nil
# config.window = 4
# config.outer_window = 0
diff --git a/config/locales/en.yml b/config/locales/en.yml
index a664552..2ee38cf 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -33,5 +33,8 @@ en:
hello: "Hello world"
views:
pagination:
- previous: "< Previous"
- next: "Next >"
+ first: "« First"
+ last: "Last »"
+ previous: "‹ Prev"
+ next: "Next ›"
+ truncate: "…"
From 575f189eb692aeb387186b60e03846d298037250 Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Wed, 25 Oct 2017 16:44:26 -0600
Subject: [PATCH 07/13] removed global variable config, and enforcing at the
controller level.
---
app/controllers/wishlists_controller.rb | 4 ++--
config/initializers/kaminari_config.rb | 2 +-
config/locales/en.yml | 1 -
3 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/app/controllers/wishlists_controller.rb b/app/controllers/wishlists_controller.rb
index 9af7dab..a854679 100644
--- a/app/controllers/wishlists_controller.rb
+++ b/app/controllers/wishlists_controller.rb
@@ -3,9 +3,9 @@ class WishlistsController < ApplicationController
def show
skip_authorization
- @wishlist = Wishlist.includes(wishlist_items: :item).find(params[:id]).per(10)
+ @wishlist = Wishlist.includes(wishlist_items: :item).find(params[:id])
@site_managers = @wishlist.users
- @wishlist_items = @wishlist.wishlist_items.page(params[:page])
+ @wishlist_items = @wishlist.wishlist_items.page(params[:page]).per(10)
end
def new
diff --git a/config/initializers/kaminari_config.rb b/config/initializers/kaminari_config.rb
index 4482548..fad507f 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
diff --git a/config/locales/en.yml b/config/locales/en.yml
index 2ee38cf..2986b62 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -30,7 +30,6 @@
# available at http://guides.rubyonrails.org/i18n.html.
en:
- hello: "Hello world"
views:
pagination:
first: "« First"
From e8416c8755b2cfa4e0941eb5cabbbaecfc4f18b4 Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Thu, 26 Oct 2017 16:32:20 -0600
Subject: [PATCH 08/13] ran the generator for kaminari bootstrap themes, didn't
even know about it
---
app/views/kaminari/_first_page.html.erb | 3 +++
app/views/kaminari/_gap.html.erb | 3 +++
app/views/kaminari/_last_page.html.erb | 3 +++
app/views/kaminari/_next_page.html.erb | 3 +++
app/views/kaminari/_page.html.erb | 9 +++++++++
app/views/kaminari/_paginator.html.erb | 17 +++++++++++++++++
app/views/kaminari/_prev_page.html.erb | 3 +++
app/views/wishlist_items/index.html.erb | 5 ++++-
8 files changed, 45 insertions(+), 1 deletion(-)
create mode 100644 app/views/kaminari/_first_page.html.erb
create mode 100644 app/views/kaminari/_gap.html.erb
create mode 100644 app/views/kaminari/_last_page.html.erb
create mode 100644 app/views/kaminari/_next_page.html.erb
create mode 100644 app/views/kaminari/_page.html.erb
create mode 100644 app/views/kaminari/_paginator.html.erb
create mode 100644 app/views/kaminari/_prev_page.html.erb
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..bb5ed0f
--- /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 c07fc96..c74bd4e 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -9,6 +9,9 @@
<%= render @wishlist_items %>
- <%= paginate @wishlist_items%>
+
+
From 03beb55e01106a12b82fcf0e68584b678edcd5ec Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Thu, 26 Oct 2017 16:50:30 -0600
Subject: [PATCH 09/13] just won't center
---
app/views/kaminari/_paginator.html.erb | 24 ++++++++++++------------
app/views/wishlist_items/index.html.erb | 4 +---
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb
index bb5ed0f..1e56cc2 100644
--- a/app/views/kaminari/_paginator.html.erb
+++ b/app/views/kaminari/_paginator.html.erb
@@ -1,17 +1,17 @@
-<%= paginator.render do %>
+ <%= paginator.render do %>
-<% end %>
+ <% end %>
diff --git a/app/views/wishlist_items/index.html.erb b/app/views/wishlist_items/index.html.erb
index c74bd4e..10758b7 100644
--- a/app/views/wishlist_items/index.html.erb
+++ b/app/views/wishlist_items/index.html.erb
@@ -10,8 +10,6 @@
<%= render @wishlist_items %>
-
+ <%= paginate @wishlist_items%>
From 23429986bfa65772112417849cfdb01d7057ec2b Mon Sep 17 00:00:00 2001
From: Edward McCarthy
Date: Thu, 26 Oct 2017 16:54:00 -0600
Subject: [PATCH 10/13] Now the paginate is centered
---
Gemfile | 1 +
Gemfile.lock | 4 ++++
app/views/kaminari/_paginator.html.erb | 2 +-
3 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/Gemfile b/Gemfile
index 260da9b..b0aab53 100644
--- a/Gemfile
+++ b/Gemfile
@@ -31,6 +31,7 @@ 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
diff --git a/Gemfile.lock b/Gemfile.lock
index ddafd54..6575e1a 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)
@@ -283,6 +286,7 @@ PLATFORMS
DEPENDENCIES
annotate (~> 2.7)
bootstrap (~> 4.0.0.alpha6)
+ bootstrap4-kaminari-views
bullet
byebug
capybara (~> 2.13)
diff --git a/app/views/kaminari/_paginator.html.erb b/app/views/kaminari/_paginator.html.erb
index 1e56cc2..df70617 100644
--- a/app/views/kaminari/_paginator.html.erb
+++ b/app/views/kaminari/_paginator.html.erb
@@ -1,6 +1,6 @@
<%= paginator.render do %>