publication/app/controllers/admin/publications_controller.rb

69 lines
1.7 KiB
Ruby
Raw Normal View History

2023-06-04 14:41:53 +00:00
class Admin::PublicationsController < OrbitAdminController
2018-10-04 02:47:23 +00:00
before_action :categories, only: [:index, :new, :edit]
def index
@table_fields = [:title, :status, :author, :pub_date, :category]
@filter_fields = filter_fields(@categories, @tags)
2023-06-04 14:41:53 +00:00
@publications = Publication.order_by(sort)
2018-10-04 02:47:23 +00:00
.with_categories(filters("category"))
.with_status(filters("status"))
2023-06-04 14:41:53 +00:00
@publications = search_data(@publications, [:title]).page(params[:page]).per(10)
2018-10-04 02:47:23 +00:00
render partial: "index" if request.xhr?
end
def new
2023-06-04 14:41:53 +00:00
@publication = Publication.new
2018-10-04 02:47:23 +00:00
end
def create
2023-06-04 14:41:53 +00:00
publication = Publication.create(publication_params)
redirect_to admin_publications_path
2018-10-04 02:47:23 +00:00
end
def edit
2023-06-04 14:41:53 +00:00
@publication = Publication.find(params[:id])
2018-10-04 02:47:23 +00:00
end
def update
2023-06-04 14:41:53 +00:00
publication = Publication.find(params[:id])
publication.update_attributes(publication_params)
redirect_to admin_publications_path
2018-10-04 02:47:23 +00:00
end
def show
2023-06-04 14:41:53 +00:00
@publication = Publication.find(params[:id])
@chapters = @publication.chapters.order_by(sort).page(params[:page]).per(10)
2018-10-04 09:44:54 +00:00
@table_fields = [:title, :author, :page, :sort_number]
2018-10-04 02:47:23 +00:00
end
def destroy
2023-06-04 14:41:53 +00:00
publication = Publication.find(params[:id])
publication.destroy
redirect_to admin_publications_path
2018-10-04 02:47:23 +00:00
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
2023-06-04 14:41:53 +00:00
def publication_params
params.require(:publication).permit!
2018-10-04 02:47:23 +00:00
end
def categories
@categories = @module_app.categories
@tags = @module_app.tags
end
end