now pages are sorted according to the page number in structure

This commit is contained in:
Harry Bomrah 2016-06-07 16:46:58 +08:00
parent 8be1843081
commit 4f53f41cc9
1 changed files with 22 additions and 3 deletions

View File

@ -3,10 +3,15 @@ class Admin::PageContentsController < OrbitAdminController
def index
@table_fields = [:page_id, :name,:version,:update_at,:last_modified, :category]
@filter_fields = {}
@pages = Page.where(:module=>"page_content").order_by(sort)
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
@categories = @module_app.categories.enabled.authorized(current_user).collect{|c| [c.title, c.id]}
@pages = search_data(@pages,[:name, :page_id]).page(params[:page]).per(10)
render :partial => "index" if request.xhr?
end
@ -52,4 +57,18 @@ class Admin::PageContentsController < OrbitAdminController
def update_params
params.require(:page_context).permit!
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
end