app/controllers/spotlight/pages_controller.rb in blacklight-spotlight-0.1.0 vs app/controllers/spotlight/pages_controller.rb in blacklight-spotlight-0.2.0

- old
+ new

@@ -1,33 +1,42 @@ module Spotlight class PagesController < Spotlight::ApplicationController before_filter :authenticate_user!, except: [:show] - load_resource :exhibit, class: Spotlight::Exhibit + load_and_authorize_resource :exhibit, class: Spotlight::Exhibit include Spotlight::Base include Blacklight::Catalog::SearchContext include Spotlight::Catalog::AccessControlsEnforcement - helper_method :get_search_results, :get_solr_response_for_doc_id, :get_solr_response_for_field_values, :page_collection_name + helper_method :get_search_results, :get_solr_response_for_doc_id, :get_solr_response_for_document_ids, :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) + fresh_when([@page.exhibit, @page]) end + def preview + @block = SirTrevorRails::Block.from_hash(JSON.parse(params[:block], symbolize_names: true), "block") + + respond_to do |format| + format.html { render 'preview', layout: false } + end + end + # GET /exhibits/1/pages/new def new end # GET /pages/1/edit def edit + @page.lock! current_user end # POST /exhibits/1/pages def create @page.attributes = page_params @@ -40,19 +49,22 @@ end end # PATCH/PUT /pages/1 def update + @page.lock.delete if @page.lock + if @page.update(page_params.merge(last_edited_by: current_user)) 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_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