From 4f53f41cc96c8c60ffbe02314effe16713c4b4e7 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 7 Jun 2016 16:46:58 +0800 Subject: [PATCH] now pages are sorted according to the page number in structure --- .../admin/page_contents_controller.rb | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/app/controllers/admin/page_contents_controller.rb b/app/controllers/admin/page_contents_controller.rb index 5b427c2..ea2fde2 100644 --- a/app/controllers/admin/page_contents_controller.rb +++ b/app/controllers/admin/page_contents_controller.rb @@ -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