diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index 1c0ec9f..dd919ce 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -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 diff --git a/app/controllers/books_controller.rb b/app/controllers/books_controller.rb index 5081477..6a4cb72 100644 --- a/app/controllers/books_controller.rb +++ b/app/controllers/books_controller.rb @@ -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 diff --git a/app/controllers/series_controller.rb b/app/controllers/series_controller.rb index a8bdbf7..7dd91ee 100644 --- a/app/controllers/series_controller.rb +++ b/app/controllers/series_controller.rb @@ -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 diff --git a/app/helpers/preferences_helper.rb b/app/helpers/preferences_helper.rb new file mode 100644 index 0000000..fc7863e --- /dev/null +++ b/app/helpers/preferences_helper.rb @@ -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 diff --git a/app/views/authors/_index.html.erb b/app/views/authors/_index.html.erb index e1da93b..2033cd3 100644 --- a/app/views/authors/_index.html.erb +++ b/app/views/authors/_index.html.erb @@ -1,3 +1,4 @@ +<%= render 'layouts/initials' %> <%= will_paginate class: "center" %> @@ -14,3 +15,4 @@
<%= will_paginate class: "center" %> +<%= render 'layouts/perpage' %> diff --git a/app/views/books/_index.html.erb b/app/views/books/_index.html.erb index e1ce4f2..7f3a25b 100644 --- a/app/views/books/_index.html.erb +++ b/app/views/books/_index.html.erb @@ -1,3 +1,4 @@ +<%= render'layouts/initials' %> <%= will_paginate class: "center" %> @@ -25,3 +26,4 @@
<%= will_paginate class: "center" %> +<%= render'layouts/perpage' %> diff --git a/app/views/layouts/_initials.html.erb b/app/views/layouts/_initials.html.erb new file mode 100644 index 0000000..0c8a176 --- /dev/null +++ b/app/views/layouts/_initials.html.erb @@ -0,0 +1,10 @@ +<% initials = ['0'] + ('A'..'Z').to_a %> +
+ +
diff --git a/app/views/layouts/_perpage.html.erb b/app/views/layouts/_perpage.html.erb new file mode 100644 index 0000000..833d166 --- /dev/null +++ b/app/views/layouts/_perpage.html.erb @@ -0,0 +1,9 @@ +
+ +
diff --git a/app/views/series/_index.html.erb b/app/views/series/_index.html.erb index f5d8e5d..2da12c4 100644 --- a/app/views/series/_index.html.erb +++ b/app/views/series/_index.html.erb @@ -1,3 +1,4 @@ +<%= render'layouts/initials' %> <%= will_paginate class: "center" %> @@ -31,3 +32,4 @@
<%= will_paginate class: "center" %> +<%= render'layouts/perpage' %> diff --git a/config/application.rb b/config/application.rb index 2e5e95c..ec9cbb5 100644 --- a/config/application.rb +++ b/config/application.rb @@ -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