Set order of page context to match the order of structure
Add some params to keep the sorting
This commit is contained in:
parent
127ab3845c
commit
c2331695cd
|
@ -64,6 +64,10 @@ class Item
|
|||
true
|
||||
end
|
||||
end
|
||||
|
||||
def self.structure_ordered_items
|
||||
self.get_children(Item.root, [])
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
|
@ -87,5 +91,13 @@ class Item
|
|||
def validates_presence_of_parent_id?
|
||||
true
|
||||
end
|
||||
|
||||
def self.get_children(item, tree)
|
||||
tree << item
|
||||
item.children.each do |child|
|
||||
self.get_children(child, tree)
|
||||
end
|
||||
tree
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -8,7 +8,7 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
|
|||
#before_filter :is_admin?
|
||||
|
||||
def index
|
||||
@page_contexts = (params.has_key?:sort)? get_sorted_and_filtered("page_contexts", {:archived => false}) : PageContext.where(:archived => false).page(params[:page]).per(10)
|
||||
@page_contexts = (params.has_key?:sort)? get_sorted_and_filtered("page_contexts", {:archived => false}) : get_sorted_page_from_structure
|
||||
|
||||
respond_to do |format|
|
||||
format.html # index.html.erb
|
||||
|
@ -65,7 +65,8 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
|
|||
|
||||
respond_to do |format|
|
||||
if @page_context.save
|
||||
format.html { redirect_to(panel_page_content_back_end_page_contexts_url, :notice => t('page_content.create_page_content_success')) }
|
||||
# format.html { redirect_to(panel_page_content_back_end_page_contexts_url, :notice => t('page_content.create_page_content_success')) }
|
||||
format.html { redirect_to(panel_page_content_back_end_page_contexts_url) }
|
||||
format.xml { render :xml => @page_context, :status => :created, :location => @page_context }
|
||||
else
|
||||
format.html { render :action => "new" }
|
||||
|
@ -79,29 +80,24 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
|
|||
def update
|
||||
@page_context = PageContext.find(params[:id])
|
||||
|
||||
if ( @page_context.version > 0 )
|
||||
@create_page_context = PageContext.new(:version => @page_context.version)
|
||||
@create_page_context = @page_context.clone
|
||||
@create_page_context.context = @page_context.context.clone
|
||||
@create_page_context.archived = true
|
||||
end
|
||||
if ( @page_context.version > 0 )
|
||||
@create_page_context = PageContext.new(:version => @page_context.version)
|
||||
@create_page_context = @page_context.clone
|
||||
@create_page_context.context = @page_context.context.clone
|
||||
@create_page_context.archived = true
|
||||
end
|
||||
|
||||
@page_context.update_user_id = current_user.id
|
||||
@page_context.version = @page_context.version + 1
|
||||
|
||||
respond_to do |format|
|
||||
if @page_context.update_attributes(params[:page_context])
|
||||
|
||||
if ( @page_context.version > 1 )
|
||||
@create_page_context.save
|
||||
end
|
||||
|
||||
if !params[:page].blank?
|
||||
format.html { redirect_to(panel_page_content_back_end_page_contexts_url(:page =>params[:page]), :notice => t('page_content.update_page_content_success')) }
|
||||
else
|
||||
format.html { redirect_to(panel_page_content_back_end_page_contexts_url, :notice => t('page_content.update_page_content_success')) }
|
||||
end
|
||||
format.js { render 'toggle_enable' }
|
||||
if ( @page_context.version > 1 )
|
||||
@create_page_context.save
|
||||
end
|
||||
# format.html { redirect_to(panel_page_content_back_end_page_contexts_url(:page =>params[:page]), :notice => t('page_content.update_page_content_success')) }
|
||||
format.html { redirect_to(panel_page_content_back_end_page_contexts_url(page: params[:page], sort: params[:sort], direction: params[:direction], sort_options: params[:sort_options])) }
|
||||
format.js { render 'toggle_enable' }
|
||||
format.xml { head :ok }
|
||||
else
|
||||
format.html { render :action => "edit" }
|
||||
|
@ -122,5 +118,13 @@ class Panel::PageContent::BackEnd::PageContextsController < OrbitBackendControll
|
|||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def get_sorted_page_from_structure
|
||||
page_contexts = Item.structure_ordered_items.inject([]){ |pages, page|
|
||||
pages << page.page_contexts.where(archived: false).limit(1)[0] if page.is_a?(Page) && !page.page_contexts.blank?
|
||||
pages
|
||||
}
|
||||
Kaminari.paginate_array(page_contexts).page(params[:page]).per(10)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -38,6 +38,9 @@
|
|||
|
||||
<div class="form-actions">
|
||||
<%= hidden_field_tag 'page', params[:page] if !params[:page].blank? %>
|
||||
<%= hidden_field_tag 'sort', params[:sort] if !params[:sort].blank? %>
|
||||
<%= hidden_field_tag 'direction', params[:direction] if !params[:direction].blank? %>
|
||||
<%= hidden_field_tag 'sort_options', params[:sort_options] if !params[:sort_options].blank? %>
|
||||
<%= f.submit t('submit'), :class=>'btn btn-primary' %>
|
||||
<%= link_to t('cancel'), get_go_back, :class=>"btn" %>
|
||||
</div>
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
<div class="quick-edit">
|
||||
<ul class="nav nav-pills hide">
|
||||
<%if is_manager? || is_admin? || page_context.authed_users(:edit).include?(current_user)%>
|
||||
<li><%= link_to t(:edit), edit_panel_page_content_back_end_page_context_path(page_context, :page => params[:page]) %></li>
|
||||
<li><%= link_to t(:edit), edit_panel_page_content_back_end_page_context_path(page_context, page: params[:page], sort: params[:sort], direction: params[:direction], sort_options: params[:sort_options]) %></li>
|
||||
<%if (is_manager? || is_admin?) %>
|
||||
<li><%=show_page_context_edit_auth_link page_context%></li>
|
||||
<% end%>
|
||||
|
|
Loading…
Reference in New Issue