2015-06-28 12:29:09 +00:00
|
|
|
class BooksController < ApplicationController
|
2015-07-04 18:10:58 +00:00
|
|
|
include PreferencesHelper
|
2015-07-05 11:01:47 +00:00
|
|
|
include ERB::Util
|
2015-07-04 18:10:58 +00:00
|
|
|
|
|
|
|
before_action :preferences, only: :index
|
2015-06-28 12:29:09 +00:00
|
|
|
|
|
|
|
def show
|
2015-06-28 12:59:37 +00:00
|
|
|
@book = Book.find(params[:id])
|
2015-06-28 13:03:30 +00:00
|
|
|
@title = @book.title
|
2015-06-28 12:59:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def index
|
2015-08-04 11:47:26 +00:00
|
|
|
@books = Book.where(query_filter).order(sort_col)
|
|
|
|
.paginate(page: params[:page], per_page: @preference.per_page)
|
2015-06-28 13:03:30 +00:00
|
|
|
@title = "Books"
|
2015-06-29 16:58:02 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
format.js
|
|
|
|
end
|
2015-06-28 12:29:09 +00:00
|
|
|
end
|
|
|
|
|
2015-07-05 11:01:47 +00:00
|
|
|
def cover
|
|
|
|
@book = Book.find(params[:id])
|
|
|
|
redirect_to "/calibre/#{url_encode(@book.path)}/cover.jpg"
|
|
|
|
end
|
|
|
|
|
2015-08-02 09:12:04 +00:00
|
|
|
private
|
|
|
|
def sort_col
|
2015-08-04 11:47:26 +00:00
|
|
|
if @preference.sort == "latest"
|
2015-08-02 09:12:04 +00:00
|
|
|
return { last_modified: :desc }
|
|
|
|
end
|
|
|
|
:sort
|
|
|
|
end
|
|
|
|
|
2015-06-28 12:29:09 +00:00
|
|
|
end
|