app/controllers/spina/admin/pages_controller.rb in spina-0.6.29 vs app/controllers/spina/admin/pages_controller.rb in spina-0.7.0
- old
+ new
@@ -1,10 +1,11 @@
module Spina
module Admin
class PagesController < AdminController
before_filter :set_breadcrumb
+ before_filter :set_tabs, only: [:new, :create, :edit, :update]
authorize_resource class: Page
layout "spina/admin/website"
@@ -13,19 +14,20 @@
end
def new
@page = Page.new
if current_theme.new_page_templates.any? { |template| template[0] == params[:view_template] }
- @page.view_template = params[:view_template]
+ @page.view_template = params[:view_template]
end
add_breadcrumb I18n.t('spina.pages.new')
@page_parts = current_theme.config.page_parts.map { |page_part| @page.page_part(page_part) }
end
def create
@page = Page.new(page_params)
add_breadcrumb I18n.t('spina.pages.new')
+ # @page.set_materialized_path
if @page.save
redirect_to spina.edit_admin_page_url(@page)
else
@page_parts = @page.page_parts
render :new
@@ -53,18 +55,18 @@
end
end
end
def sort
- params[:list].each do |id|
- if id[1][:children].present?
- id[1][:children].each do |child|
- child[1][:children].each { |child_child| update_page_position(child_child, child[1][:id]) } if child[1][:children].present?
- update_page_position(child, id[1][:id])
+ params[:list].each_pair do |parent_pos, parent_node|
+ if parent_node[:children].present?
+ parent_node[:children].each_pair do |child_pos, child_node|
+ child_node[:children].each_pair { |grand_child_pos, grand_child| update_page_position(grand_child, grand_child_pos, child_node[:id]) } if child_node[:children].present?
+ update_page_position(child_node, child_pos, parent_node[:id])
end
end
- update_page_position(id, nil)
+ update_page_position(parent_node, parent_pos, nil)
end
render nothing: true
end
def destroy
@@ -77,11 +79,15 @@
def set_breadcrumb
add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
end
- def update_page_position(page, parent_id = nil)
- Page.update(page[1][:id], position: page[0].to_i + 1, parent_id: parent_id )
+ def set_tabs
+ @tabs = %w{page_content page_seo advanced}
+ end
+
+ def update_page_position(page, position, parent_id = nil)
+ Page.update(page[:id], position: position.to_i + 1, parent_id: parent_id )
end
def page_params
params.require(:page).permit!
end