app/controllers/spotlight/pages_controller.rb in blacklight-spotlight-0.0.3 vs app/controllers/spotlight/pages_controller.rb in blacklight-spotlight-0.1.0
- old
+ new
@@ -1,29 +1,25 @@
module Spotlight
class PagesController < Spotlight::ApplicationController
before_filter :authenticate_user!, except: [:show]
+ load_resource :exhibit, class: Spotlight::Exhibit
- load_resource :exhibit, class: Spotlight::Exhibit, only: [:index, :new, :create, :update_all]
- load_and_authorize_resource through: :exhibit, shallow: true, instance_name: 'page'
-
- before_filter :attach_breadcrumbs
-
- include Blacklight::Base
+ include Spotlight::Base
include Blacklight::Catalog::SearchContext
+ include Spotlight::Catalog::AccessControlsEnforcement
- copy_blacklight_config_from(CatalogController)
-
helper_method :get_search_results, :get_solr_response_for_doc_id, :get_solr_response_for_field_values, :page_collection_name
# GET /exhibits/1/pages
def index
# set up a model the inline "add a new page" form
@page = CanCan::ControllerResource.new(self).send(:build_resource)
end
# GET /pages/1
def show
+ fresh_when(@page)
end
# GET /exhibits/1/pages/new
def new
end
@@ -36,64 +32,76 @@
def create
@page.attributes = page_params
@page.last_edited_by = @page.created_by = current_user
if @page.save
- redirect_to [@page.exhibit, page_collection_name], notice: 'Page was successfully created.'
+ redirect_to [@page.exhibit, page_collection_name], notice: t(:'helpers.submit.page.created', model: @page.class.model_name.human.downcase)
else
render action: 'new'
end
end
# PATCH/PUT /pages/1
def update
if @page.update(page_params.merge(last_edited_by: current_user))
- redirect_to [@page.exhibit, page_collection_name], notice: 'Page was successfully updated.'
+ redirect_to [@page.exhibit, @page], notice: t(:'helpers.submit.page.updated', model: @page.class.model_name.human.downcase)
else
render action: 'edit'
end
end
# DELETE /pages/1
def destroy
@page.destroy
- redirect_to [@page.exhibit, @page], notice: 'Page was successfully destroyed.'
+ redirect_to [@page.exhibit, page_collection_name], notice: t(:'helpers.submit.page.destroyed', model: @page.class.model_name.human.downcase)
end
def update_all
notice = if @exhibit.update update_all_page_params
- "#{human_name} were successfully updated."
+ t(:'helpers.submit.page.batch_updated', model: human_name)
else
- "There was an error updating the requested pages."
+ t(:'helpers.submit.page.batch_error', model: human_name)
end
redirect_to :back, notice: notice
end
+ def _prefixes
+ @_prefixes ||= super + ['catalog']
+ end
+
protected
- def update_all_page_params
- params.require(:exhibit).permit("#{page_collection_name}_attributes" => [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ])
+ ##
+ # Browsing an exhibit should start a new search session
+ def start_new_search_session?
+ params[:action] == 'show'
end
+ def page_attributes
+ [:id, :published, :title, :weight, :display_sidebar, :parent_page_id ]
+ end
+
+ def allowed_page_params
+ [:title, :content]
+ end
+
def human_name
@human_name ||= page_collection_name.humanize
end
alias page_collection_name controller_name
def attach_breadcrumbs
- load_exhibit
- add_breadcrumb @exhibit.title, @exhibit
+ if view_context.current_page? "/"
+ add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: current_exhibit.title), main_app.root_path
+ else
+ add_breadcrumb t(:'spotlight.exhibits.breadcrumb', title: current_exhibit.title), spotlight.exhibit_root_path(current_exhibit)
+ end
end
- def load_exhibit
- @exhibit ||= @page.exhibit
- end
-
private
-
# Only allow a trusted parameter "white list" through.
def page_params
- params.require(controller_name.singularize).permit(:title, :content)
+ params.require(controller_name.singularize).permit(allowed_page_params)
end
end
end