Skip to content
Open
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 17 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -272,6 +287,7 @@ PLATFORMS
DEPENDENCIES
annotate (~> 2.7)
bootstrap (~> 4.0.0.alpha6)
bootstrap4-kaminari-views
bullet
byebug
capybara (~> 2.13)
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/wishlist_items_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]).per(10)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will this work if we specify default_per_page = 10 in the config file and remove .per(10)?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the .per(10) and using the config.yml instead for this

end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/wishlists_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/models/wishlist_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions app/views/kaminari/_first_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.first'), url, remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_gap.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class='page-item disabled'>
<%= link_to raw(t 'views.pagination.truncate'), '#', class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_last_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.last'), url, remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/kaminari/_next_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.last?, raw(t 'views.pagination.next'), url, rel: 'next', remote: remote, class: 'page-link' %>
</li>
9 changes: 9 additions & 0 deletions app/views/kaminari/_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% if page.current? %>
<li class="page-item active">
<%= content_tag :a, page, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), class: 'page-link' %>
</li>
<% else %>
<li class="page-item">
<%= link_to page, url, remote: remote, rel: (page.next? ? 'next' : (page.prev? ? 'prev' : nil)), class: 'page-link' %>
</li>
<% end %>
17 changes: 17 additions & 0 deletions app/views/kaminari/_paginator.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<%= paginator.render do %>
<nav>
<ul class="pagination justify-content-center">
<%= first_page_tag unless current_page.first? %>
<%= prev_page_tag unless current_page.first? %>
<% each_page do |page| %>
<% if page.left_outer? || page.right_outer? || page.inside_window? %>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is one of the auto generated files, right?

The indentation looks a little off. Is it possible to fix it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is. It looks to be centered to the content div, but let me check and play around with it.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

center

So, I'm pretty sure it is horizontally centered. I did add some top margins so it's uniform to the bottom and not hugging the line below the item

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was referring to code indentation not the alignment.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, my mistake. Fixed with latest push

<%= page_tag page %>
<% elsif !page.was_truncated? -%>
<%= gap_tag %>
<% end %>
<% end %>
<%= next_page_tag unless current_page.last? %>
<%= last_page_tag unless current_page.last? %>
</ul>
</nav>
<% end %>
3 changes: 3 additions & 0 deletions app/views/kaminari/_prev_page.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<li class="page-item">
<%= link_to_unless current_page.first?, raw(t 'views.pagination.previous'), url, rel: 'prev', remote: remote, class: 'page-link' %>
</li>
3 changes: 3 additions & 0 deletions app/views/wishlist_items/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@
</div>

<%= render @wishlist_items %>

<%= paginate @wishlist_items%>

</div>
4 changes: 3 additions & 1 deletion app/views/wishlists/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
<%= @wishlist.users.map(&:display_name).join(", ") %>
</p>

<%= render @wishlist_items %>

<%= render @wishlist.wishlist_items %>
<%= paginate @wishlist_items %>

<%= link_to 'Back', root_path %>
</div>
12 changes: 12 additions & 0 deletions config/initializers/kaminari_config.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true
Kaminari.configure do |config|
# config.default_per_page = 5
# 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
8 changes: 7 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@
# available at http://guides.rubyonrails.org/i18n.html.

en:
hello: "Hello world"
views:
pagination:
first: "&laquo; First"
last: "Last &raquo;"
previous: "&lsaquo; Prev"
next: "Next &rsaquo;"
truncate: "&hellip;"