pagecontent/app/controllers/admin/page_contents_controller.rb

87 lines
2.5 KiB
Ruby
Raw Normal View History

2014-05-06 09:20:15 +00:00
class Admin::PageContentsController < OrbitAdminController
2014-12-01 10:06:31 +00:00
before_action ->(module_app = @app_title) { set_variables module_app }
2014-05-05 07:05:59 +00:00
def index
2018-01-19 09:07:00 +00:00
@table_fields = ["page_content.id", :name,:version,:update_at,:last_modified, :category]
2014-08-07 10:48:51 +00:00
@filter_fields = {}
if params[:sort].blank? && params[:keywords].blank?
@pages = get_pages_sorted(Page.root)
@pages = Kaminari.paginate_array(@pages).page(params[:page]).per(10)
else
@pages = Page.where(:module=>"page_content").order_by(sort)
@pages = search_data(@pages,[:name, :page_id]).page(params[:page]).per(10)
end
2014-12-01 13:20:08 +00:00
@categories = @module_app.categories.enabled.authorized(current_user).collect{|c| [c.title, c.id]}
2014-08-07 10:48:51 +00:00
render :partial => "index" if request.xhr?
2014-05-06 09:20:15 +00:00
end
def show
@page_context = PageContext.find(params[:id])
end
def new
2014-12-01 13:07:00 +00:00
@page = Page.find(params[:page_id])
if can_edit_or_delete?(@page)
2014-07-31 12:42:42 +00:00
@page_content = PageContext.new
2016-08-24 13:28:22 +00:00
@options = {}
@site_in_use_locales.each do |l|
@options[l.to_s] = @page.wiki_pages.collect{|wp|[wp.title_translations[l], wp.uid]}
end
2014-07-31 12:42:42 +00:00
else
render_401
end
2014-05-06 09:20:15 +00:00
end
def create
PageContext.where("page_id" => params["page_context"]["page_id"]).destroy_all
2014-08-05 06:45:30 +00:00
@page_content = PageContext.new(update_params)
2014-05-06 09:20:15 +00:00
@page_content.update_user_id = current_user.id
2014-08-05 06:45:30 +00:00
@page_content.save
redirect_to params['referer_url']
2014-05-06 09:20:15 +00:00
end
def view
@table_fields = ["Name","Version","Updated At","Last Modified By"]
@page = Page.find(params[:id])
@page_contexts = @page.page_contexts.desc(:version)
end
2014-12-01 10:06:31 +00:00
def save_category
page_id = params[:page_id]
category_id = params[:category_id]
page = Page.find(page_id) rescue nil
if !page.nil?
page.category_id = category_id
page.save
end
render :json => {"success" => true}.to_json
end
2019-11-28 08:43:43 +00:00
def wiki_parent
parent_page_id = params[:id]
@wiki_parent_page = Page.where(:id => parent_page_id).first
@table_fields = ["page_content.id", :name,:version,:update_at,:last_modified, :category]
@categories = @module_app.categories.enabled.authorized(current_user).collect{|c| [c.title, c.id]}
end
2014-05-06 09:20:15 +00:00
private
def update_params
2014-08-07 10:48:51 +00:00
params.require(:page_context).permit!
2014-05-05 07:05:59 +00:00
end
def get_pages_sorted(page)
pages = []
page.child_page.asc(:number).each do |cp|
if cp.child_page.blank? || cp.child_page.nil?
pages << cp if cp.module == "page_content"
else
pages << cp if cp.module == "page_content"
pages.concat(get_pages_sorted(cp))
end
end
pages
end
2014-05-05 07:05:59 +00:00
end