Class: Spotlight::PagesController
- Inherits:
-
ApplicationController
- Object
- ApplicationController
- ApplicationController
- Spotlight::PagesController
- Includes:
- Blacklight::SearchContext, Base
- Defined in:
- app/controllers/spotlight/pages_controller.rb
Overview
Base CRUD controller for pages rubocop:disable Metrics/ClassLength Disableing class length because this is a base controller that gives other controllers their behavior
Direct Known Subclasses
AboutPagesController, FeaturePagesController, HomePagesController
Instance Method Summary collapse
- #clone ⇒ Object
-
#create ⇒ Object
POST /exhibits/1/pages.
-
#destroy ⇒ Object
DELETE /pages/1.
-
#edit ⇒ Object
GET /pages/1/edit.
-
#index ⇒ Object
GET /exhibits/1/pages.
-
#new ⇒ Object
GET /exhibits/1/pages/new.
- #preview ⇒ Object
-
#show ⇒ Object
GET /pages/1.
-
#update ⇒ Object
PATCH/PUT /pages/1.
- #update_all ⇒ Object
Methods included from Base
#autocomplete_json_response, #autocomplete_json_response_for_document, #blacklight_config
Methods included from Config
#exhibit_specific_blacklight_config
Methods included from Concerns::ApplicationController
#enabled_in_spotlight_view_type_configuration?, #field_enabled?
Methods included from Controller
#blacklight_config, #current_exhibit, #current_masthead, #current_masthead=, #current_site, #default_url_options, #exhibit_masthead?, #exhibit_search_action_url, #exhibit_search_facet_url, #resource_masthead?, #search_action_url, #search_facet_url, #set_exhibit_locale_scope, #set_locale
Instance Method Details
#clone ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'app/controllers/spotlight/pages_controller.rb', line 92 def clone new_page = CloneTranslatedPageFromLocale.call(locale: clone_params, page: @page) model_name = @page.class.model_name.human.downcase if new_page.save redirect_to( edit_exhibit_translations_path(current_exhibit, language: clone_params, tab: 'pages'), notice: t(:'helpers.submit.page.created', model: model_name) ) else redirect_to :back, error: t(:'helpers.submit.page.clone_error', model: model_name) end end |
#create ⇒ Object
POST /exhibits/1/pages
54 55 56 57 58 59 60 61 62 63 |
# File 'app/controllers/spotlight/pages_controller.rb', line 54 def create @page.attributes = page_params @page.last_edited_by = @page.created_by = current_user if @page.save redirect_to [spotlight, @page.exhibit, page_collection_name], notice: t(:'helpers.submit.page.created', model: @page.class.model_name.human.downcase) else render action: 'new' end end |
#destroy ⇒ Object
DELETE /pages/1
77 78 79 80 81 |
# File 'app/controllers/spotlight/pages_controller.rb', line 77 def destroy @page.destroy redirect_to [spotlight, @page.exhibit, page_collection_name], flash: { html_safe: true }, notice: undo_notice(:destroyed) end |
#edit ⇒ Object
GET /pages/1/edit
49 50 51 |
# File 'app/controllers/spotlight/pages_controller.rb', line 49 def edit @page.lock! current_user end |
#index ⇒ Object
GET /exhibits/1/pages
20 21 22 23 24 25 26 27 28 |
# File 'app/controllers/spotlight/pages_controller.rb', line 20 def index # set up a model the inline "add a new page" form @page = CanCan::ControllerResource.new(self).send(:build_resource) respond_to do |format| format.html format.json { render json: @pages.for_locale.published.to_json(methods: [:thumbnail_image_url]) } end end |
#new ⇒ Object
GET /exhibits/1/pages/new
46 |
# File 'app/controllers/spotlight/pages_controller.rb', line 46 def new; end |
#preview ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'app/controllers/spotlight/pages_controller.rb', line 35 def preview @page = current_exhibit.pages.find(params['id']) :read, @page @block = SirTrevorRails::Block.from_hash(JSON.parse(params[:block], symbolize_names: true), @page) respond_to do |format| format.html { render 'preview', layout: false } end end |
#show ⇒ Object
GET /pages/1
31 32 33 |
# File 'app/controllers/spotlight/pages_controller.rb', line 31 def show fresh_when([@page.exhibit, @page]) end |
#update ⇒ Object
PATCH/PUT /pages/1
66 67 68 69 70 71 72 73 74 |
# File 'app/controllers/spotlight/pages_controller.rb', line 66 def update @page.lock.delete if @page.lock if @page.update(page_params.merge(last_edited_by: current_user)) redirect_to [spotlight, @page.exhibit, @page], flash: { html_safe: true }, notice: undo_notice(:updated) else render action: 'edit' end end |
#update_all ⇒ Object
83 84 85 86 87 88 89 90 |
# File 'app/controllers/spotlight/pages_controller.rb', line 83 def update_all notice = if @exhibit.update update_all_page_params t(:'helpers.submit.page.batch_updated', model: human_name) else t(:'helpers.submit.page.batch_error', model: human_name) end redirect_back fallback_location: spotlight.exhibit_dashboard_path(@exhibit), notice: notice end |