sort latest books
This commit is contained in:
parent
7da655e0b2
commit
21a6fb98dc
@ -10,7 +10,7 @@ class BooksController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@books = Book.where(initial_filter).order(:sort)
|
@books = Book.where(initial_filter).order(sort_col)
|
||||||
.paginate(page: params[:page], per_page: session[:current_per_page])
|
.paginate(page: params[:page], per_page: session[:current_per_page])
|
||||||
@title = "Books"
|
@title = "Books"
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
@ -24,4 +24,12 @@ class BooksController < ApplicationController
|
|||||||
redirect_to "/calibre/#{url_encode(@book.path)}/cover.jpg"
|
redirect_to "/calibre/#{url_encode(@book.path)}/cover.jpg"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def sort_col
|
||||||
|
if session[:sort] == "latest"
|
||||||
|
return { last_modified: :desc }
|
||||||
|
end
|
||||||
|
:sort
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -5,12 +5,13 @@ module PreferencesHelper
|
|||||||
["UPPER(sort) LIKE ?", session[:initial] + "%"] if session[:initial]
|
["UPPER(sort) LIKE ?", session[:initial] + "%"] if session[:initial]
|
||||||
end
|
end
|
||||||
|
|
||||||
# update preferences (per_page, initial)
|
# update preferences (per_page, initial, sort)
|
||||||
def preferences
|
def preferences
|
||||||
session[:current_per_page] = params[:per_page] ? params[:per_page].to_i : (session[:current_per_page] || WillPaginate.per_page)
|
session[:current_per_page] = params[:per_page] ? params[:per_page].to_i : (session[:current_per_page] || WillPaginate.per_page)
|
||||||
if params[:initial]
|
if params[:initial]
|
||||||
session[:initial] = (params[:initial] == "reset" ? nil : params[:initial])
|
session[:initial] = (params[:initial] == "reset" ? nil : params[:initial])
|
||||||
end
|
end
|
||||||
|
session[:sort] = params[:sort]
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,4 +1,13 @@
|
|||||||
|
<div class="panel panel-default">
|
||||||
|
<div class="panel-heading">
|
||||||
|
<h3 class="panel-title">Filter</h3>
|
||||||
|
</div>
|
||||||
|
<div class="panel-body">
|
||||||
|
<% isLatest = session[:sort] == "latest" %>
|
||||||
|
<%= link_to "Latest", url_for(sort: (isLatest ? "alpha" : "latest")), class: "btn btn-default btn-sm " + (isLatest ? " active" : ""), remote: true %>
|
||||||
<%= render'layouts/initials' %>
|
<%= render'layouts/initials' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<%= will_paginate class: "center" %>
|
<%= will_paginate class: "center" %>
|
||||||
|
|
||||||
<table class="table table-striped authors">
|
<table class="table table-striped authors">
|
||||||
|
Loading…
Reference in New Issue
Block a user