Extended pagination (select page size, per initial, remember selection)
This commit is contained in:
parent
3d4d97f66c
commit
e5263033dd
@ -1,4 +1,7 @@
|
||||
class AuthorsController < ApplicationController
|
||||
include PreferencesHelper
|
||||
|
||||
before_action :preferences, only: :index
|
||||
|
||||
def show
|
||||
@author = Author.find(params[:id])
|
||||
@ -6,7 +9,8 @@ class AuthorsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@authors = Author.paginate(page: params[:page])
|
||||
@authors = Author.where(initial_filter).order(:sort)
|
||||
.paginate(page: params[:page], per_page: session[:current_per_page])
|
||||
@title = "Authors"
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
@ -1,4 +1,7 @@
|
||||
class BooksController < ApplicationController
|
||||
include PreferencesHelper
|
||||
|
||||
before_action :preferences, only: :index
|
||||
|
||||
def show
|
||||
@book = Book.find(params[:id])
|
||||
@ -6,7 +9,8 @@ class BooksController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@books = Book.paginate(page: params[:page])
|
||||
@books = Book.where(initial_filter).order(:sort)
|
||||
.paginate(page: params[:page], per_page: session[:current_per_page])
|
||||
@title = "Books"
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
@ -1,4 +1,7 @@
|
||||
class SeriesController < ApplicationController
|
||||
include PreferencesHelper
|
||||
|
||||
before_action :preferences, only: :index
|
||||
|
||||
def show
|
||||
@serie = Serie.find(params[:id])
|
||||
@ -6,7 +9,8 @@ class SeriesController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@series = Serie.paginate(page: params[:page])
|
||||
@series = Serie.where(initial_filter).order(:sort)
|
||||
.paginate(page: params[:page], per_page: session[:current_per_page])
|
||||
@title = "Series"
|
||||
respond_to do |format|
|
||||
format.html
|
||||
|
16
app/helpers/preferences_helper.rb
Normal file
16
app/helpers/preferences_helper.rb
Normal file
@ -0,0 +1,16 @@
|
||||
module PreferencesHelper
|
||||
|
||||
# filter data on first letter
|
||||
def initial_filter
|
||||
["UPPER(sort) LIKE ?", session[:initial] + "%"] if session[:initial]
|
||||
end
|
||||
|
||||
# update preferences (per_page, initial)
|
||||
def preferences
|
||||
session[:current_per_page] = params[:per_page] ? params[:per_page].to_i : (session[:current_per_page] || WillPaginate.per_page)
|
||||
if params[:initial]
|
||||
session[:initial] = (session[:initial] == params[:initial] ? nil : params[:initial])
|
||||
end
|
||||
end
|
||||
|
||||
end
|
@ -1,3 +1,4 @@
|
||||
<%= render 'layouts/initials' %>
|
||||
<%= will_paginate class: "center" %>
|
||||
|
||||
<table class="table table-striped authors">
|
||||
@ -14,3 +15,4 @@
|
||||
</table>
|
||||
|
||||
<%= will_paginate class: "center" %>
|
||||
<%= render 'layouts/perpage' %>
|
||||
|
@ -1,3 +1,4 @@
|
||||
<%= render'layouts/initials' %>
|
||||
<%= will_paginate class: "center" %>
|
||||
|
||||
<table class="table table-striped authors">
|
||||
@ -25,3 +26,4 @@
|
||||
</table>
|
||||
|
||||
<%= will_paginate class: "center" %>
|
||||
<%= render'layouts/perpage' %>
|
||||
|
10
app/views/layouts/_initials.html.erb
Normal file
10
app/views/layouts/_initials.html.erb
Normal file
@ -0,0 +1,10 @@
|
||||
<% initials = ['0'] + ('A'..'Z').to_a %>
|
||||
<div class="center">
|
||||
<ul class="pagination">
|
||||
<% initials.each do |i| %>
|
||||
<%= content_tag :li, class: (i == session[:initial] ? "active": nil) do %>
|
||||
<%= link_to i, url_for(initial: i), remote: true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
9
app/views/layouts/_perpage.html.erb
Normal file
9
app/views/layouts/_perpage.html.erb
Normal file
@ -0,0 +1,9 @@
|
||||
<div class="center">
|
||||
<ul class="pagination">
|
||||
<% [10,20,50,100].each do |p| %>
|
||||
<%= content_tag :li, class: (p == session[:current_per_page] ? "active": nil) do %>
|
||||
<%= link_to p, url_for(per_page: p), remote: true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
@ -1,3 +1,4 @@
|
||||
<%= render'layouts/initials' %>
|
||||
<%= will_paginate class: "center" %>
|
||||
|
||||
<table class="table table-striped series">
|
||||
@ -31,3 +32,4 @@
|
||||
</table>
|
||||
|
||||
<%= will_paginate class: "center" %>
|
||||
<%= render'layouts/perpage' %>
|
||||
|
@ -22,5 +22,7 @@ module BouquinsRor
|
||||
|
||||
# Do not swallow errors in after_commit/after_rollback callbacks.
|
||||
config.active_record.raise_in_transactional_callbacks = true
|
||||
|
||||
config.web_console.whitelisted_ips = '10.8.0.0/24'
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user