app/controllers/spina/admin/pages_controller.rb in spina-0.12.0 vs app/controllers/spina/admin/pages_controller.rb in spina-1.0.0
- old
+ new
@@ -1,19 +1,21 @@
module Spina
module Admin
class PagesController < AdminController
- before_action :set_breadcrumb
before_action :set_tabs, only: [:new, :create, :edit, :update]
before_action :set_locale
def index
+ add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
redirect_to admin_pages_path unless current_admin_path.starts_with?('/pages')
- @pages = Page.active.sorted.roots
+ @pages = Page.active.sorted.roots.regular_pages
end
def new
- @page = Page.new
+ @resource = Resource.find_by(id: params[:resource_id])
+ @page = Page.new(resource: @resource, parent: @resource&.parent_page)
+ add_index_breadcrumb
if current_theme.new_page_templates.any? { |template| template[0] == params[:view_template] }
@page.view_template = params[:view_template]
end
add_breadcrumb I18n.t('spina.pages.new')
@page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
@@ -32,10 +34,11 @@
end
end
def edit
@page = Page.find(params[:id])
+ add_index_breadcrumb
add_breadcrumb @page.title
@page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
render layout: 'spina/admin/admin'
end
@@ -48,10 +51,13 @@
@page.touch
I18n.locale = I18n.default_locale
format.html { redirect_to spina.edit_admin_page_url(@page, params: {locale: @locale}), flash: {success: t('spina.pages.saved')} }
format.js
else
+ 50.times do
+ Rails.logger.info @page.errors.inspect
+ end
format.html do
@page_parts = @page.view_template_page_parts(current_theme).map { |part| @page.part(part) }
render :edit, layout: 'spina/admin/admin'
end
end
@@ -76,12 +82,16 @@
def set_locale
@locale = params[:locale] || I18n.default_locale
end
- def set_breadcrumb
- add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
+ def add_index_breadcrumb
+ if @page.resource.present?
+ add_breadcrumb @page.resource.label, spina.admin_resource_path(@page.resource)
+ else
+ add_breadcrumb I18n.t('spina.website.pages'), spina.admin_pages_path
+ end
end
def set_tabs
@tabs = %w{page_content page_seo advanced}
end
@@ -98,10 +108,10 @@
end
end
end
def page_params
- params.require(:page).permit!.merge(locale: params[:locale] || I18n.default_locale)
+ params.require(:page).permit!
end
end
end
end