2018-10-04 02:47:23 +00:00
|
|
|
class Admin::JournalsController < OrbitAdminController
|
|
|
|
before_action :categories, only: [:index, :new, :edit]
|
|
|
|
|
|
|
|
def index
|
|
|
|
@table_fields = [:title, :status, :author, :pub_date, :category]
|
|
|
|
@filter_fields = filter_fields(@categories, @tags)
|
|
|
|
@journals = Journal.order_by(sort)
|
|
|
|
.with_categories(filters("category"))
|
|
|
|
.with_status(filters("status"))
|
|
|
|
@journals = search_data(@journals, [:title]).page(params[:page]).per(10)
|
|
|
|
|
|
|
|
render partial: "index" if request.xhr?
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
|
|
|
@journal = Journal.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
|
|
|
journal = Journal.create(journal_params)
|
|
|
|
redirect_to admin_journals_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
@journal = Journal.find(params[:id])
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
journal = Journal.find(params[:id])
|
|
|
|
journal.update_attributes(journal_params)
|
|
|
|
redirect_to admin_journals_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def show
|
|
|
|
@journal = Journal.find(params[:id])
|
2018-10-04 09:44:54 +00:00
|
|
|
@chapters = @journal.chapters.order_by(sort).page(params[:page]).per(10)
|
|
|
|
@table_fields = [:title, :author, :page, :sort_number]
|
2018-10-04 02:47:23 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
journal = Journal.find(params[:id])
|
|
|
|
journal.destroy
|
|
|
|
redirect_to admin_journals_path
|
|
|
|
end
|
|
|
|
|
|
|
|
def save_chapter_order
|
|
|
|
ids = params[:ids]
|
|
|
|
ids.each_with_index do |id,index|
|
|
|
|
chapter = Chapter.find(id) rescue nil
|
|
|
|
if !chapter.nil?
|
|
|
|
chapter.sort_number = index
|
|
|
|
chapter.save
|
|
|
|
end
|
|
|
|
end
|
|
|
|
render json: {success: true}.to_json
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def journal_params
|
|
|
|
params.require(:journal).permit!
|
|
|
|
end
|
|
|
|
|
|
|
|
def categories
|
|
|
|
@categories = @module_app.categories
|
|
|
|
@tags = @module_app.tags
|
|
|
|
end
|
|
|
|
end
|